[issue33219] x in IntFlag() should test int x's inclusion in IntFlag

Dutcho report at bugs.python.org
Wed Apr 4 17:03:56 EDT 2018


Dutcho <dutcho at ziggo.nl> added the comment:

@Nitish
The easiest way would probably be to change __contains__ in Flag to:

    def __contains__(self, other):
        try:
            return other & self == other # leave selection of _value_ attribute (if other is Flag) or conversion (if other is int mixin of IntFlag) to __and__
        except TypeError:
            return False

Although this would be somewhat convoluted (the generic delegation to __and__ isn't clear at first sight and therefore less maintainable) and may lead to confusing error messages

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33219>
_______________________________________


More information about the Python-bugs-list mailing list