summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/enum.py5
-rw-r--r--Lib/test/test_enum.py13
2 files changed, 17 insertions, 1 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
diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py
index cf3e042..27f8bba 100644
--- a/Lib/test/test_enum.py
+++ b/Lib/test/test_enum.py
@@ -447,7 +447,7 @@ class _EnumTests:
def test_bad_new_super(self):
with self.assertRaisesRegex(
TypeError,
- 'has no members defined',
+ 'do not use .super...__new__;',
):
class BadSuper(self.enum_type):
def __new__(cls, value):
@@ -3409,6 +3409,17 @@ class TestSpecial(unittest.TestCase):
self.assertIs(Types(2), Types.NetList)
self.assertIs(Types('nl'), Types.NetList)
+ def test_no_members(self):
+ with self.assertRaisesRegex(
+ TypeError,
+ 'has no members',
+ ):
+ Enum(7)
+ with self.assertRaisesRegex(
+ TypeError,
+ 'has no members',
+ ):
+ Flag(7)
class TestOrder(unittest.TestCase):
"test usage of the `_order_` attribute"