diff options
author | Ethan Furman <ethan@stoneleaf.us> | 2023-11-29 04:40:12 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-29 04:40:12 (GMT) |
commit | f9e6ce03953e9ee988d55324dc715b0ef2303cfb (patch) | |
tree | a84721b38edf83de28281b96cde15e1e99087dee /Lib/enum.py | |
parent | e723700190ba497d1601cb423ee48d5d222a9d26 (diff) | |
download | cpython-f9e6ce03953e9ee988d55324dc715b0ef2303cfb.zip cpython-f9e6ce03953e9ee988d55324dc715b0ef2303cfb.tar.gz cpython-f9e6ce03953e9ee988d55324dc715b0ef2303cfb.tar.bz2 |
[Enum] update class creation for RuntimeError changes (GH-111815)
Diffstat (limited to 'Lib/enum.py')
-rw-r--r-- | Lib/enum.py | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/Lib/enum.py b/Lib/enum.py index 4e76e96..648401e 100644 --- a/Lib/enum.py +++ b/Lib/enum.py @@ -568,12 +568,16 @@ class EnumType(type): try: exc = None enum_class = super().__new__(metacls, cls, bases, classdict, **kwds) - except RuntimeError as e: - # any exceptions raised by member.__new__ will get converted to a - # RuntimeError, so get that original exception back and raise it instead - exc = e.__cause__ or e + except Exception as e: + # since 3.12 the line "Error calling __set_name__ on '_proto_member' instance ..." + # is tacked on to the error instead of raising a RuntimeError + # recreate the exception to discard + exc = type(e)(str(e)) + exc.__cause__ = e.__cause__ + exc.__context__ = e.__context__ + tb = e.__traceback__ if exc is not None: - raise exc + raise exc.with_traceback(tb) # # update classdict with any changes made by __init_subclass__ classdict.update(enum_class.__dict__) |