summaryrefslogtreecommitdiffstats
path: root/Lib/enum.py
diff options
context:
space:
mode:
authorEthan Furman <ethan@stoneleaf.us>2024-02-28 23:17:49 (GMT)
committerGitHub <noreply@github.com>2024-02-28 23:17:49 (GMT)
commit3ea78fd5bc93fc339ef743e6a5dfde35f04d972e (patch)
treed2721c6a87742242d2f4310fa584e16980d191fe /Lib/enum.py
parent4d1d35b906010c6db15f54443a9701c20af1db2d (diff)
downloadcpython-3ea78fd5bc93fc339ef743e6a5dfde35f04d972e.zip
cpython-3ea78fd5bc93fc339ef743e6a5dfde35f04d972e.tar.gz
cpython-3ea78fd5bc93fc339ef743e6a5dfde35f04d972e.tar.bz2
gh-115821: [Enum] better error message for calling super().__new__() (GH-116063)
docs now state to not call super().__new__ if super().__new__ is called, a better error message is now used
Diffstat (limited to 'Lib/enum.py')
-rw-r--r--Lib/enum.py5
1 files changed, 5 insertions, 0 deletions
diff --git a/Lib/enum.py b/Lib/enum.py
index d10b996..22963cc 100644
--- a/Lib/enum.py
+++ b/Lib/enum.py
@@ -547,7 +547,10 @@ class EnumType(type):
classdict['_inverted_'] = None
try:
exc = None
+ classdict['_%s__in_progress' % cls] = True
enum_class = super().__new__(metacls, cls, bases, classdict, **kwds)
+ classdict['_%s__in_progress' % cls] = False
+ delattr(enum_class, '_%s__in_progress' % cls)
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
@@ -1155,6 +1158,8 @@ class Enum(metaclass=EnumType):
# still not found -- verify that members exist, in-case somebody got here mistakenly
# (such as via super when trying to override __new__)
if not cls._member_map_:
+ if getattr(cls, '_%s__in_progress' % cls.__name__, False):
+ raise TypeError('do not use `super().__new__; call the appropriate __new__ directly') from None
raise TypeError("%r has no members defined" % cls)
#
# still not found -- try _missing_ hook