This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Danny Yoo
Recipients Danny Yoo
Date 2016-12-08.17:32:51
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1481218371.67.0.185317403078.issue28905@psf.upfronthosting.co.za>
In-reply-to
Content
Alternatively, change the representation of flag values from integers to some class extension that supports the common bitwise operators.

As a very rough sketch:

>>> class FlagInt(int):
...     def __or__(self, other):
...         return FlagInt(int(self) | int(other))
... 
>>> f1 = FlagInt(1)
>>> f2 = FlagInt(2)
>>> f1 | f2
3
>>> isinstance(3, FlagInt)
False
>>> isinstance(f1 | f2, FlagInt)
True


That way, flag arguments can be determined at runtime to have derived from the proper flag values.

This kind of approach may have some backwards-incompatibility, unfortunately, since other folks have been hardcoding integers rather than use the flag constants.  Other concerns might include serialization, in case someone tries to save a FlagInt somewhere and pull it out at some other time.
History
Date User Action Args
2016-12-08 17:32:51Danny Yoosetrecipients: + Danny Yoo
2016-12-08 17:32:51Danny Yoosetmessageid: <1481218371.67.0.185317403078.issue28905@psf.upfronthosting.co.za>
2016-12-08 17:32:51Danny Yoolinkissue28905 messages
2016-12-08 17:32:51Danny Yoocreate