mirror of
https://github.com/python/cpython.git
synced 2025-12-23 09:19:18 +00:00
[3.12] gh-125259: Fix error notes removal in enum initialization (GH-125647) (GH-125953)
(cherry picked from commit 34653bba64)
Co-authored-by: Mario Šaško <mariosasko777@gmail.com>
This commit is contained in:
parent
f6682fbe49
commit
d0b2fa4804
3 changed files with 25 additions and 11 deletions
16
Lib/enum.py
16
Lib/enum.py
|
|
@ -592,19 +592,13 @@ class EnumType(type):
|
|||
classdict['_all_bits_'] = 0
|
||||
classdict['_inverted_'] = None
|
||||
try:
|
||||
exc = None
|
||||
enum_class = super().__new__(metacls, cls, bases, classdict, **kwds)
|
||||
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.with_traceback(tb)
|
||||
#
|
||||
# since 3.12 the note "Error calling __set_name__ on '_proto_member' instance ..."
|
||||
# is tacked on to the error instead of raising a RuntimeError, so discard it
|
||||
if hasattr(e, '__notes__'):
|
||||
del e.__notes__
|
||||
raise
|
||||
# update classdict with any changes made by __init_subclass__
|
||||
classdict.update(enum_class.__dict__)
|
||||
#
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue