[3.9] bpo-42727: [Enum] EnumMeta.__prepare__ now accepts **kwds (GH-23917). (GH-23926)
* [3.9] [Enum] EnumMeta.__prepare__ now accepts **kwds (GH-23917).
(cherry picked from commit 6ec0adefad
)
This commit is contained in:
parent
3bb85672bb
commit
f7dca9b9c8
|
@ -170,7 +170,7 @@ class EnumMeta(type):
|
||||||
Metaclass for Enum
|
Metaclass for Enum
|
||||||
"""
|
"""
|
||||||
@classmethod
|
@classmethod
|
||||||
def __prepare__(metacls, cls, bases):
|
def __prepare__(metacls, cls, bases, **kwds):
|
||||||
# check that previous enum members do not exist
|
# check that previous enum members do not exist
|
||||||
metacls._check_for_existing_members(cls, bases)
|
metacls._check_for_existing_members(cls, bases)
|
||||||
# create the namespace dict
|
# create the namespace dict
|
||||||
|
|
|
@ -2065,7 +2065,7 @@ class TestEnum(unittest.TestCase):
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def test_init_subclass(self):
|
def test_init_subclass_calling(self):
|
||||||
class MyEnum(Enum):
|
class MyEnum(Enum):
|
||||||
def __init_subclass__(cls, **kwds):
|
def __init_subclass__(cls, **kwds):
|
||||||
super(MyEnum, cls).__init_subclass__(**kwds)
|
super(MyEnum, cls).__init_subclass__(**kwds)
|
||||||
|
@ -2101,6 +2101,16 @@ class TestEnum(unittest.TestCase):
|
||||||
self.assertFalse(NeverEnum.__dict__.get('_test1', False))
|
self.assertFalse(NeverEnum.__dict__.get('_test1', False))
|
||||||
self.assertFalse(NeverEnum.__dict__.get('_test2', False))
|
self.assertFalse(NeverEnum.__dict__.get('_test2', False))
|
||||||
|
|
||||||
|
def test_init_subclass_parameter(self):
|
||||||
|
class multiEnum(Enum):
|
||||||
|
def __init_subclass__(cls, multi):
|
||||||
|
for member in cls:
|
||||||
|
member._as_parameter_ = multi * member.value
|
||||||
|
class E(multiEnum, multi=3):
|
||||||
|
A = 1
|
||||||
|
B = 2
|
||||||
|
self.assertEqual(E.A._as_parameter_, 3)
|
||||||
|
self.assertEqual(E.B._as_parameter_, 6)
|
||||||
|
|
||||||
class TestOrder(unittest.TestCase):
|
class TestOrder(unittest.TestCase):
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
`EnumMeta.__prepare__` now accepts `**kwds` to properly support
|
||||||
|
`__init_subclass__`
|
Loading…
Reference in New Issue