summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-01-17 21:34:48 (GMT)
committerGitHub <noreply@github.com>2024-01-17 21:34:48 (GMT)
commitc1890e666eaaa819a318b4a6b4f2c8c33a8c679e (patch)
tree66c5f0bcfa02462b12895ec03f2a719fe0038634 /Lib/test
parent24d23929d6b77d644fc6ffec5d565deba2231504 (diff)
downloadcpython-c1890e666eaaa819a318b4a6b4f2c8c33a8c679e.zip
cpython-c1890e666eaaa819a318b4a6b4f2c8c33a8c679e.tar.gz
cpython-c1890e666eaaa819a318b4a6b4f2c8c33a8c679e.tar.bz2
[3.12] gh-114149: [Enum] fix tuple subclass handling when using custom __new__ (GH-114160) (GH-114196)
(cherry picked from commit 33b47a2c2853066b549f242065f6c2e12e18b33b) Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_enum.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py
index 3bd918f..2db3b2f 100644
--- a/Lib/test/test_enum.py
+++ b/Lib/test/test_enum.py
@@ -3163,6 +3163,22 @@ class TestSpecial(unittest.TestCase):
[x.value for x in NTEnum],
[TTuple(id=0, a=0, blist=[]), TTuple(id=1, a=2, blist=[4]), TTuple(id=2, a=4, blist=[0, 1, 2])],
)
+ #
+ class NTDEnum(Enum):
+ def __new__(cls, t_value):
+ member = object.__new__(cls)
+ member._value_ = t_value[0]
+ member.id = t_value[0]
+ member.a = t_value[1]
+ member.blist = t_value[2]
+ return member
+ NONE = TTuple(0, 0, [])
+ A = TTuple(1, 2, [4])
+ B = TTuple(2, 4, [0, 1, 2])
+ self.assertEqual(repr(NTDEnum.NONE), "<NTDEnum.NONE: 0>")
+ self.assertEqual(NTDEnum.NONE.id, 0)
+ self.assertEqual(NTDEnum.A.a, 2)
+ self.assertEqual(NTDEnum.B.blist, [0, 1 ,2])
def test_flag_with_custom_new(self):
class FlagFromChar(IntFlag):