-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
Change in Flag enum behaviour in v3.11rc2 #96865
Comments
There were some significant changes to Enum. They were originally planned for 3.10, but then pushed back to 3.11. There are a few ways to adjust the above code:
The result of (1) would be The result of (2) would be (3) would be:
|
On 16/09/2022 16:14, Ethan Furman wrote:
There were some significant changes to Enum. They were originally
planned for 3.10, but then pushed back to 3.11.
There are a few ways to adjust the above code:
1. use an `IntEnum` instead (it seems the actual values are important)
2. specify the `boundary`; i.e. `class MethodHint(Enum,
boundary=KEEP):`
3. use `auto()` for the values and reorder the members
The result of (1) would be `31`.
The result of (2) would be
`MethodHint.HiddenText|DigitsOnly|LettersOnly|12`.
(3) would be:
>>> from enum import Flag, auto
>>> class MethodHint(Flag):
... DigitsOnly = auto()
... LettersOnly = auto()
... OnlyMask = DigitsOnly|LettersOnly
... HiddenText = auto()
...
>>> print(MethodHint.HiddenText|MethodHint.OnlyMask)
MethodHint.DigitsOnly|LettersOnly|HiddenText
My point is that it’s an incompatible change without a deprecation
period. Should the default boundary be KEEP for the next version?
Phil
|
@pablogsal -- Thoughts? |
The 3.10 docs: https://docs.python.org/3.10/library/enum.html#flag Neither of them proscribe specifics about what the Flag values must be, it just says that operations like |
Agreed on restoring the behavior and having the deprecation period, I was unsure if it should go into 3.11.0. I'll get a patch created for 3.11.1. |
Actually, won't need a deprecation period, since the proper default for Thank you, everyone. |
Phil wrote:
I edited my post: |
(cherry picked from commit b44372e) Co-authored-by: Ethan Furman <[email protected]>
(cherry picked from commit b44372e) Co-authored-by: Ethan Furman <[email protected]>
* main: pythonGH-88050: fix race in closing subprocess pipe in asyncio (python#97951) pythongh-93738: Disallow pre-v3 syntax in the C domain (python#97962) pythongh-95986: Fix the example using match keyword (python#95989) pythongh-97897: Prevent os.mkfifo and os.mknod segfaults with macOS 13 SDK (pythonGH-97944) pythongh-94808: Cover `PyUnicode_Count` in CAPI (python#96929) pythongh-94808: Cover `PyObject_PyBytes` case with custom `__bytes__` method (python#96610) pythongh-95691: Doc BufferedWriter and BufferedReader (python#95703) pythonGH-88968: Add notes about socket ownership transfers (python#97936) pythongh-96865: [Enum] fix Flag to use CONFORM boundary (pythonGH-97528)
* main: (53 commits) pythongh-94808: Coverage: Test that maximum indentation level is handled (python#95926) pythonGH-88050: fix race in closing subprocess pipe in asyncio (python#97951) pythongh-93738: Disallow pre-v3 syntax in the C domain (python#97962) pythongh-95986: Fix the example using match keyword (python#95989) pythongh-97897: Prevent os.mkfifo and os.mknod segfaults with macOS 13 SDK (pythonGH-97944) pythongh-94808: Cover `PyUnicode_Count` in CAPI (python#96929) pythongh-94808: Cover `PyObject_PyBytes` case with custom `__bytes__` method (python#96610) pythongh-95691: Doc BufferedWriter and BufferedReader (python#95703) pythonGH-88968: Add notes about socket ownership transfers (python#97936) pythongh-96865: [Enum] fix Flag to use CONFORM boundary (pythonGH-97528) pythongh-65961: Raise `DeprecationWarning` when `__package__` differs from `__spec__.parent` (python#97879) docs(typing): add "see PEP 675" to LiteralString (python#97926) pythongh-97850: Remove all known instances of module_repr() (python#97876) I changed my surname early this year (python#96671) pythongh-93738: Documentation C syntax (:c:type:<C type> -> :c:expr:<C type>) (python#97768) pythongh-91539: improve performance of get_proxies_environment (python#91566) build(deps): bump actions/stale from 5 to 6 (python#97701) pythonGH-95172 Make the same version `versionadded` oneline (python#95172) pythongh-88050: Fix asyncio subprocess to kill process cleanly when process is blocked (python#32073) pythongh-93738: Documentation C syntax (Function glob patterns -> literal markup) (python#97774) ...
(cherry picked from commit b44372e) Co-authored-by: Ethan Furman <[email protected]>
|
Bug report
The default behaviour of Flag enums has chenged between Python v3.10 and v3.11
Your environment
Python v3.11rc2 on macOS
The following script...
...raises a ValueError in v3.11 and prints...
MethodHint.HiddenText|OnlyMask|LettersOnly|DigitsOnly
in v3.10.
While it's not particularly sensible to bitwise-or a mask it is a significant change of behaviour without a deprecation period.
It will be common to have a mask value that covers more bits than currently defined when allowing for future expansion of the flags.
The text was updated successfully, but these errors were encountered: