diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2023-11-29 21:49:52 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-29 21:49:52 (GMT) |
commit | 749c8fdafbc924a2b37637d9a28b8c4accfdd1ae (patch) | |
tree | eb402221854490042850b9b6725522caa7b1feb8 | |
parent | 8f43250c9167a191799e4c570cb3474f9b4c5a5b (diff) | |
download | cpython-749c8fdafbc924a2b37637d9a28b8c4accfdd1ae.zip cpython-749c8fdafbc924a2b37637d9a28b8c4accfdd1ae.tar.gz cpython-749c8fdafbc924a2b37637d9a28b8c4accfdd1ae.tar.bz2 |
[3.12] [Enum] update class creation for RuntimeError changes (GH-111815) (GH-112526)
(cherry picked from commit f9e6ce03953e9ee988d55324dc715b0ef2303cfb)
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
-rw-r--r-- | Doc/howto/enum.rst | 1 | ||||
-rw-r--r-- | Lib/enum.py | 14 |
2 files changed, 9 insertions, 6 deletions
diff --git a/Doc/howto/enum.rst b/Doc/howto/enum.rst index a136c76..ffdafb7 100644 --- a/Doc/howto/enum.rst +++ b/Doc/howto/enum.rst @@ -1439,7 +1439,6 @@ alias:: Traceback (most recent call last): ... ValueError: aliases not allowed in DuplicateFreeEnum: 'GRENE' --> 'GREEN' - Error calling __set_name__ on '_proto_member' instance 'GRENE' in 'Color' .. note:: diff --git a/Lib/enum.py b/Lib/enum.py index 4bd3756..1502bfe 100644 --- a/Lib/enum.py +++ b/Lib/enum.py @@ -581,12 +581,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__) |