mirror of
https://github.com/python/cpython.git
synced 2025-08-10 03:49:18 +00:00
bpo-41889: [Enum] fix multiple-inheritance regression (GH-22487) (GH-23673)
(cherry picked from commit c266736ec1
)
This commit is contained in:
parent
60463e8e4f
commit
be52ca45d9
3 changed files with 35 additions and 3 deletions
|
@ -1998,6 +1998,32 @@ class TestEnum(unittest.TestCase):
|
|||
REVERT_ALL = "REVERT_ALL"
|
||||
RETRY = "RETRY"
|
||||
|
||||
def test_multiple_mixin_inherited(self):
|
||||
class MyInt(int):
|
||||
def __new__(cls, value):
|
||||
return super().__new__(cls, value)
|
||||
|
||||
class HexMixin:
|
||||
def __repr__(self):
|
||||
return hex(self)
|
||||
|
||||
class MyIntEnum(HexMixin, MyInt, enum.Enum):
|
||||
pass
|
||||
|
||||
class Foo(MyIntEnum):
|
||||
TEST = 1
|
||||
self.assertTrue(isinstance(Foo.TEST, MyInt))
|
||||
self.assertEqual(repr(Foo.TEST), "0x1")
|
||||
|
||||
class Fee(MyIntEnum):
|
||||
TEST = 1
|
||||
def __new__(cls, value):
|
||||
value += 1
|
||||
member = int.__new__(cls, value)
|
||||
member._value_ = value
|
||||
return member
|
||||
self.assertEqual(Fee.TEST, 2)
|
||||
|
||||
def test_empty_globals(self):
|
||||
# bpo-35717: sys._getframe(2).f_globals['__name__'] fails with KeyError
|
||||
# when using compile and exec because f_globals is empty
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue