Danny Yoo added the comment:

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.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue28905>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to