Skip to content

Commit f9e6ce0

Browse files
authored
[Enum] update class creation for RuntimeError changes (GH-111815)
1 parent e723700 commit f9e6ce0

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
@@ -568,12 +568,16 @@ def __new__(metacls, cls, bases, classdict, *, boundary=None, _simple=False, **k
568568
try:
569569
exc = None
570570
enum_class = super().__new__(metacls, cls, bases, classdict, **kwds)
571-
except RuntimeError as e:
572-
# any exceptions raised by member.__new__ will get converted to a
573-
# RuntimeError, so get that original exception back and raise it instead
574-
exc = e.__cause__ or e
571+
except Exception as e:
572+
# since 3.12 the line "Error calling __set_name__ on '_proto_member' instance ..."
573+
# is tacked on to the error instead of raising a RuntimeError
574+
# recreate the exception to discard
575+
exc = type(e)(str(e))
576+
exc.__cause__ = e.__cause__
577+
exc.__context__ = e.__context__
578+
tb = e.__traceback__
575579
if exc is not None:
576-
raise exc
580+
raise exc.with_traceback(tb)
577581
#
578582
# update classdict with any changes made by __init_subclass__
579583
classdict.update(enum_class.__dict__)

0 commit comments

Comments
 (0)