[issue23591] Add Flags and IntFlags

Vedran Čačić report at bugs.python.org
Mon Aug 15 17:06:24 EDT 2016


Vedran Čačić added the comment:

I suppose you'll also forbid adding new members to Flags, just like Enum does, right? (https://docs.python.org/3/library/enum.html#restricted-subclassing-of-enumerations) Otherwise cropping -1 at a fixed number of bits might be very counterintuitive.

But still, your "simple algorithm" seems too simple. You might easily produce values you won't be able to interpret.

    class ThirdBitMustBeSet(Flags):
        FIRST = 5
        SECOND = 6

    >>> ThirdBitMustBeSet.FIRST | ThirdBitMustBeSet.SECOND

produces error when printing, but otherwise works completely fine. A debugging nightmare. :-/ I'd at least ensure each bit has a separate name if you're going to use that scheme.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue23591>
_______________________________________


More information about the Python-bugs-list mailing list