Repository navigation
[Enum] Exception being ignored in custom datatypes #102549
Copy link
Copy link
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
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or errorstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory3.11only security fixesonly security fixes3.12only security fixesonly security fixesneeds backport to 3.11only security fixesonly security fixes
on Mar 9, 2023 Just tested this -
MyEnumis indeed not created and theValueErroris raised.import enum class Base: def __init__(self, x): print('In Base init') raise ValueError("I don't like", x) class MyEnum(Base, enum.Enum): A = 'a' def __init__(self, y): print('In MyEnum init') self.y = y MyEnum(1)
Output
In Base init In MyEnum init Traceback (most recent call last): File "/Users/tnie/code/cpython/tmp.py", line 14, in <module> MyEnum(1) File "/Users/tnie/code/cpython/Lib/enum.py", line 728, in __call__ return cls.__new__(cls, value) ^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/tnie/code/cpython/Lib/enum.py", line 1132, in __new__ raise ve_exc ValueError: 1 is not a valid MyEnumWhat behaviour are you describing that's a bug?
MyEnumshould not have been created in the first place. The behavior in the patch I'm working on:import enum class Base: def __init__(self, x): print('In Base init') raise ValueError("I don't like", x) class MyEnum(Base, enum.Enum): A = 'a' def __init__(self, y): print('In MyEnum init') self.y = y
and
In Base init Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/source/python/cpython/Lib/enum.py", line 561, in __new__ raise exc File "/source/python/cpython/Lib/enum.py", line 278, in __set_name__ raise TypeError( TypeError: _value_ not set in __new__, unable to create it >>> MyEnum Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'MyEnum' is not definedReacted by Taylor- added a commit that references this issue
on Mar 31, 2023 - added a commit that references this issue
on Apr 3, 2023
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
Projects
- StatusShow more project fieldsDone
MyEnumshould not be created because of the exception inBase.__init__.Linked PRs