diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2022-07-18 02:18:41 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-18 02:18:41 (GMT) |
commit | e747562345238cefd68ef6581feb17707a3a06ff (patch) | |
tree | ef44c9989736928ad2f1c2a577b309b09b8a82e1 /Lib/test | |
parent | 8d0249e3458109f3d3b5d0e2b87cbf9d58dce072 (diff) | |
download | cpython-e747562345238cefd68ef6581feb17707a3a06ff.zip cpython-e747562345238cefd68ef6581feb17707a3a06ff.tar.gz cpython-e747562345238cefd68ef6581feb17707a3a06ff.tar.bz2 |
gh-94601: [Enum] fix inheritance for __str__ and friends (GH-94942)
(cherry picked from commit c961d14f85a0e3e53d5ad1182206ef34030f10b8)
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_enum.py | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py index 74f31be..80834f2 100644 --- a/Lib/test/test_enum.py +++ b/Lib/test/test_enum.py @@ -2658,12 +2658,15 @@ class TestSpecial(unittest.TestCase): @dataclass class Foo: __qualname__ = 'Foo' - a: int = 0 + a: int class Entries(Foo, Enum): - ENTRY1 = Foo(1) + ENTRY1 = 1 + self.assertTrue(isinstance(Entries.ENTRY1, Foo)) + self.assertTrue(Entries._member_type_ is Foo, Entries._member_type_) + self.assertTrue(Entries.ENTRY1.value == Foo(1), Entries.ENTRY1.value) self.assertEqual(repr(Entries.ENTRY1), '<Entries.ENTRY1: Foo(a=1)>') - def test_repr_with_non_data_type_mixin(self): + def test_repr_with_init_data_type_mixin(self): # non-data_type is a mixin that doesn't define __new__ class Foo: def __init__(self, a): @@ -2671,10 +2674,23 @@ class TestSpecial(unittest.TestCase): def __repr__(self): return f'Foo(a={self.a!r})' class Entries(Foo, Enum): - ENTRY1 = Foo(1) - + ENTRY1 = 1 + # self.assertEqual(repr(Entries.ENTRY1), '<Entries.ENTRY1: Foo(a=1)>') + def test_repr_and_str_with_non_data_type_mixin(self): + # non-data_type is a mixin that doesn't define __new__ + class Foo: + def __repr__(self): + return 'Foo' + def __str__(self): + return 'ooF' + class Entries(Foo, Enum): + ENTRY1 = 1 + # + self.assertEqual(repr(Entries.ENTRY1), 'Foo') + self.assertEqual(str(Entries.ENTRY1), 'ooF') + def test_value_backup_assign(self): # check that enum will add missing values when custom __new__ does not class Some(Enum): |