Skip to content

Commit 28df8f0

Browse files
ethanfurmanmiss-islington
authored andcommitted
[Enum] update class creation for RuntimeError changes (GH-111815)
(cherry picked from commit f9e6ce0) Co-authored-by: Ethan Furman <[email protected]>
1 parent 3e6b328 commit 28df8f0

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

Doc/howto/enum.rst

-1
Original file line numberDiff line numberDiff line change
@@ -1439,7 +1439,6 @@ alias::
14391439
Traceback (most recent call last):
14401440
...
14411441
ValueError: aliases not allowed in DuplicateFreeEnum: 'GRENE' --> 'GREEN'
1442-
Error calling __set_name__ on '_proto_member' instance 'GRENE' in 'Color'
14431442

14441443
.. note::
14451444

Lib/enum.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -581,12 +581,16 @@ def __new__(metacls, cls, bases, classdict, *, boundary=None, _simple=False, **k
581581
try:
582582
exc = None
583583
enum_class = super().__new__(metacls, cls, bases, classdict, **kwds)
584-
except RuntimeError as e:
585-
# any exceptions raised by member.__new__ will get converted to a
586-
# RuntimeError, so get that original exception back and raise it instead
587-
exc = e.__cause__ or e
584+
except Exception as e:
585+
# since 3.12 the line "Error calling __set_name__ on '_proto_member' instance ..."
586+
# is tacked on to the error instead of raising a RuntimeError
587+
# recreate the exception to discard
588+
exc = type(e)(str(e))
589+
exc.__cause__ = e.__cause__
590+
exc.__context__ = e.__context__
591+
tb = e.__traceback__
588592
if exc is not None:
589-
raise exc
593+
raise exc.with_traceback(tb)
590594
#
591595
# update classdict with any changes made by __init_subclass__
592596
classdict.update(enum_class.__dict__)

0 commit comments

Comments
 (0)