Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
Closed
Labels
3.11only security fixesonly security fixes3.12only security fixesonly security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
In acf7403 (#30582), @ethanfurman implemented a global_enum decorator, replacing the __str__ of an enum with enum.global_str:
Lines 1638 to 1645 in 760ec89
| defglobal_str(self): | |
| """ | |
| use enum_name instead of class.enum_name | |
| """ | |
| ifself._name_isNone: | |
| return"%s(%r)"% (cls_name, self._value_) | |
| else: | |
| returnself._name_ |
(This was later reverted in 42a64c0 and reintroduced in 83d544b, but I believe the code to be the same).
If the ._name_ attribute is None, this uses cls_name, but that's not defined anywhere in that function!
Here is a (somewhat contrived) example:
importenum@enum.global_enumclassEnumTest(enum.Enum): VAL=1EnumTest.VAL._name_=Noneprint(str(VAL))this fails with:
Traceback (most recent call last): File "/home/florian/tmp/x.py", line 9, in <module>print(str(VAL)) ^^^^^^^^ File "/usr/lib/python3.11/enum.py", line 1646, in global_strreturn"%s(%r)"% (cls_name, self._value_) ^^^^^^^^NameError: name 'cls_name' is not defined(Found by running flake8 over Lib/ out of curiosity, see #93010 (comment))
Your environment
- CPython versions tested on: Python 3.11.0b1
- Operating system and architecture: Archlinux x86_64
mguinhos
Metadata
Metadata
Assignees
Labels
3.11only security fixesonly security fixes3.12only security fixesonly security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error