Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enum] update class creation for RuntimeError changes #111815

Merged
merged 2 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Doc/howto/enum.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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::

Expand Down
9 changes: 5 additions & 4 deletions Lib/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,10 +568,11 @@ def __new__(metacls, cls, bases, classdict, *, boundary=None, _simple=False, **k
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:
ethanfurman marked this conversation as resolved.
Show resolved Hide resolved
# 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))
ethanfurman marked this conversation as resolved.
Show resolved Hide resolved
if exc is not None:
raise exc
#
Expand Down