[issue28905] re.sub appears not to check count optional argument for integerness

Danny Yoo report at bugs.python.org
Thu Dec 8 12:32:51 EST 2016


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 <report at bugs.python.org>
<http://bugs.python.org/issue28905>
_______________________________________


More information about the Python-bugs-list mailing list