You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Encountered yet another breaking change for enums. There are two problems here:
CONFORM doesn't "conform" to members that are partially unsupported
CONFORM does not match the previous behavior for Flag. It used to be more similar to STRICT, but STRICT also doesn't allow partially unsupported members, while Flag in 3.10 did.
Clearly this is incorrect. The previous behavior was more similar to STRICT, but there appears to be no precise equivalent in Python 3.11 to the old behavior. Using STRICT in Python 3.11, SkipFlag.A | SkipFlag.C would fail to be created completely.
With #24215, only single-bit values will be considered in Flag when using bitwise ops like &, |, ^, ~. Multi-bit values are only considered an alias.
Thus SkipIntFlag.A | SkipIntFlag.C is actually SkipIntFlag.A | SkipIntFlag.B, since the 0b100 bit is discarded. But __contains__ will only consider its underlying values.
You will need an element with value 4 inside of SkipFlag.
This answers "why it behaves like this". Related Issues: #82431
Activity
sunmy2019 commentedon Apr 8, 2023
With #24215, only single-bit values will be considered in
Flagwhen using bitwise ops like&, |, ^, ~. Multi-bit values are only considered an alias.Thus
SkipIntFlag.A | SkipIntFlag.Cis actuallySkipIntFlag.A | SkipIntFlag.B, since the0b100bit is discarded. But__contains__will only consider its underlying values.You will need an element with value 4 inside of
SkipFlag.This answers "why it behaves like this". Related Issues: #82431
sunmy2019 commentedon Apr 8, 2023
This is documented with an inconspicuous line.
https://docs.python.org/3.10/library/enum.html#combining-members-of-flag
https://docs.python.org/3.11/howto/enum.html#flag-and-intflag-minutia
I think this should be added to the API reference here:
https://docs.python.org/3/library/enum.html#enum.Flag
benburrill commentedon Apr 8, 2023
It's also documented there that the default for Flag in Python 3.11 is STRICT, but it's really CONFORM
gh-103365: [Enum] STRICT boundary corrections (GH-103494)
pythongh-103365: [Enum] STRICT boundary corrections (pythonGH-103494)
gh-103365: [Enum] STRICT boundary corrections (GH-103494)
Merge branch 'main' into superopt
ethanfurman commentedon Apr 13, 2023
@benburrill Thank you for the bug report.
STRICThas been restored as the default forFlag, and the underlying issues fixed.