-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
The iteration behavior of IntFlag has changed backwards-incompatibly in python 3.11 and the published documentation is now incorrect #99304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The change is to So in the example above, |
Is |
if it's not a member, then why is it in |
it's also not in class MyIntFlag(IntFlag):
VAL1 = 1
VAL2 = 2
VAL3 = 3
VAL4 = 4
print(dir(MyIntFlag)) for python 3.10:
python 3.11:
This is quite a signifcant change, AFAIK there was no deprecation warning, I'm not sure where this is documented either |
Compared to an enum, 3.11 now matches 3.10 and earlier: class Kind(IntEnum):
A = 1
B = 2
C = 3
D = 1
dir(Kind)
# ['A', 'B', 'C', ...] There is no Kind.__members__
# mappingproxy({'A': <Kind.A: 1>, 'B': <Kind.B: 2>, 'C': <Kind.C: 3>, 'D': <Kind.A: 1>})
The docs should be corrected, possibly by inserting 'canonical' into 'iterated over to return its members'. Flags did not have aliasing properly defined and implemented until 3.11, although enums did since they appeared in 3.4. |
OK so aliases are returned in |
Also this is definitely a behavioral change either way and should be noted. from my end it of course doesn't matter, I have to change my code regardless since we support all Python versions since 3.7. |
in [1], Python 3.11 seems to have changed the behavior of IntEnum. We didn't notice this because we have our own workaround class already, but typing did. Ensure we remain compatible with IntFlag. This change also modifies FastIntFlag to no longer use global symbols; this is unnecessary as we assign FastIntFlag members explicitly. Use of ``symbol()`` should probably be phased out. [1] python/cpython#99304 Fixes: #8783 Change-Id: I8ae2e871ff1467ae5ca1f63e66b5dae45d4a6c93
Co-authored-by: C.A.M. Gerlach <[email protected]>
…H-99395) (cherry picked from commit 73a921b) Co-authored-by: Ethan Furman <[email protected]> Co-authored-by: C.A.M. Gerlach <[email protected]>
…) (GH-99415) gh-99304: [Enum] clarify what constitutes a flag alias (GH-99395) (cherry picked from commit 73a921b) Co-authored-by: Ethan Furman <[email protected]> Co-authored-by: C.A.M. Gerlach <[email protected]>
great changes, thanks for clarifying |
Uh oh!
There was an error while loading. Please reload this page.
At the Python documentation for Enum at https://docs.python.org/3/library/enum.html, the first paragraph contains the definition of an enum:
The second bullet is no longer the case in Python 3.11. The demonstration below passes on Python 3.10 and earlier, fails on Python 3.11:
on Python 3.10, the script succeeds without output.
output on Python 3.11:
I would think this might be a regression in Python 3.11, but seeing as there are lots of changes in
IntEnum
overall, maybe this was intended. It does seem to be counter to the usual spirit of the standard library to change an explicitly documented behavior like this.The text was updated successfully, but these errors were encountered: