summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_enum.py
diff options
context:
space:
mode:
authorEthan Furman <ethan@stoneleaf.us>2023-04-13 19:04:06 (GMT)
committerGitHub <noreply@github.com>2023-04-13 19:04:06 (GMT)
commit3b929a7b321dae113593d81caf47c4f08890c615 (patch)
treea63bc071059b47d988a0b97224631de283392211 /Lib/test/test_enum.py
parent804a973d8e5fd2728aeef268f3e577d2c0b05baa (diff)
downloadcpython-3b929a7b321dae113593d81caf47c4f08890c615.zip
cpython-3b929a7b321dae113593d81caf47c4f08890c615.tar.gz
cpython-3b929a7b321dae113593d81caf47c4f08890c615.tar.bz2
[3.11] gh-103479: [Enum] require __new__ to be considered a data type (GH-103495) (GH-103514)
a mixin must either have a __new__ method, or be a dataclass, to be interpreted as a data-type; an __init__ method is not enough (restores pre-3.11 behavior for non-dataclasses). (cherry picked from commit a6f95941a3d686707fb38e0f37758e666f25e180) Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
Diffstat (limited to 'Lib/test/test_enum.py')
-rw-r--r--Lib/test/test_enum.py11
1 files changed, 6 insertions, 5 deletions
diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py
index d3b4832..188e1a1 100644
--- a/Lib/test/test_enum.py
+++ b/Lib/test/test_enum.py
@@ -2672,19 +2672,18 @@ class TestSpecial(unittest.TestCase):
self.assertTrue(Entries.ENTRY1.value == Foo(1), Entries.ENTRY1.value)
self.assertEqual(repr(Entries.ENTRY1), '<Entries.ENTRY1: Foo(a=1)>')
- def test_repr_with_init_data_type_mixin(self):
- # non-data_type is a mixin that doesn't define __new__
+ def test_repr_with_init_mixin(self):
class Foo:
def __init__(self, a):
self.a = a
def __repr__(self):
- return f'Foo(a={self.a!r})'
+ return 'Foo(a=%r)' % self._value_
class Entries(Foo, Enum):
ENTRY1 = 1
#
- self.assertEqual(repr(Entries.ENTRY1), '<Entries.ENTRY1: Foo(a=1)>')
+ self.assertEqual(repr(Entries.ENTRY1), 'Foo(a=1)')
- def test_repr_and_str_with_non_data_type_mixin(self):
+ def test_repr_and_str_with_no_init_mixin(self):
# non-data_type is a mixin that doesn't define __new__
class Foo:
def __repr__(self):
@@ -2796,6 +2795,8 @@ class TestSpecial(unittest.TestCase):
def test_init_exception(self):
class Base:
+ def __new__(cls, *args):
+ return object.__new__(cls)
def __init__(self, x):
raise ValueError("I don't like", x)
with self.assertRaises(TypeError):