Repository navigation
enum.CONFORM behavior breaks backwards compatibility #103365
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Apr 8, 2023 - addedstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
on 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
Only single-bit values will be considered in Flag
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-minutiaI think this should be added to the API reference here:
https://docs.python.org/3/library/enum.html#enum.Flaghttps://docs.python.org/3.11/howto/enum.html#flag-and-intflag-minutia
It's also documented there that the default for Flag in Python 3.11 is STRICT, but it's really CONFORM
- added a commit that references this issue
on Apr 13, 2023 @benburrill Thank you for the bug report.
STRICThas been restored as the default forFlag, and the underlying issues fixed.Reacted by sunmy2019
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsDone
Encountered yet another breaking change for enums. There are two problems here:
Example to reproduce:
In Python 3.10.6, this code outputs:
In Python 3.11.2:
Having such members as C is useful to create a flags that are distinct from B but always implies B.
In a previous comment bug report it was stated that the previous behavior of Flag was CONFORM:
Originally posted by @ethanfurman in #96865 (comment)
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.Cwould fail to be created completely.Linked PRs