summaryrefslogtreecommitdiff
path: root/Lib/test
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2021-05-03 00:38:22 +0100
committerGitHub <noreply@github.com>2021-05-03 00:38:22 +0100
commit33ec88ac81f23668293d101b83367b086c795e5e (patch)
treeba5203f9375440ef1f63ceffe55f423d3b28195b /Lib/test
parent9387fac100db359cbb6ec2a76f8a5eba8f9d7b65 (diff)
downloadcpython-git-33ec88ac81f23668293d101b83367b086c795e5e.tar.gz
bpo-43977: Make sure that tp_flags for pattern matching are inherited correctly. (GH-25813)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_collections.py6
-rw-r--r--Lib/test/test_patma.py41
2 files changed, 47 insertions, 0 deletions
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py
index 98690d231e..2ba1a19ead 100644
--- a/Lib/test/test_collections.py
+++ b/Lib/test/test_collections.py
@@ -1967,6 +1967,12 @@ class TestCollectionABCs(ABCTestCase):
self.assertEqual(len(mss), len(mss2))
self.assertEqual(list(mss), list(mss2))
+ def test_illegal_patma_flags(self):
+ with self.assertRaises(TypeError):
+ class Both(Collection):
+ __abc_tpflags__ = (Sequence.__flags__ | Mapping.__flags__)
+
+
################################################################################
### Counter
diff --git a/Lib/test/test_patma.py b/Lib/test/test_patma.py
index 8a273be725..084d0879f1 100644
--- a/Lib/test/test_patma.py
+++ b/Lib/test/test_patma.py
@@ -2979,6 +2979,47 @@ class TestPatma(unittest.TestCase):
self.assertEqual(f((False, range(10, 20), True)), alts[4])
+class TestInheritance(unittest.TestCase):
+
+ def test_multiple_inheritance(self):
+ class C:
+ pass
+ class S1(collections.UserList, collections.abc.Mapping):
+ pass
+ class S2(C, collections.UserList, collections.abc.Mapping):
+ pass
+ class S3(list, C, collections.abc.Mapping):
+ pass
+ class S4(collections.UserList, dict, C):
+ pass
+ class M1(collections.UserDict, collections.abc.Sequence):
+ pass
+ class M2(C, collections.UserDict, collections.abc.Sequence):
+ pass
+ class M3(collections.UserDict, C, list):
+ pass
+ class M4(dict, collections.abc.Sequence, C):
+ pass
+ def f(x):
+ match x:
+ case []:
+ return "seq"
+ case {}:
+ return "map"
+ def g(x):
+ match x:
+ case {}:
+ return "map"
+ case []:
+ return "seq"
+ for Seq in (S1, S2, S3, S4):
+ self.assertEqual(f(Seq()), "seq")
+ self.assertEqual(g(Seq()), "seq")
+ for Map in (M1, M2, M3, M4):
+ self.assertEqual(f(Map()), "map")
+ self.assertEqual(g(Map()), "map")
+
+
class PerfPatma(TestPatma):
def assertEqual(*_, **__):