summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorAndrew Svetlov <andrew.svetlov@gmail.com>2012-11-01 11:28:54 (GMT)
committerAndrew Svetlov <andrew.svetlov@gmail.com>2012-11-01 11:28:54 (GMT)
commitbcac6ad1f3776fed63ce5de57b6182352efcb2ca (patch)
treed9fe5972998c97d51b7eabfd645c9ac37c84474a /Lib/test
parenteda1f4cf07557f030a33130c5845f3cdca8e2fba (diff)
downloadcpython-bcac6ad1f3776fed63ce5de57b6182352efcb2ca.zip
cpython-bcac6ad1f3776fed63ce5de57b6182352efcb2ca.tar.gz
cpython-bcac6ad1f3776fed63ce5de57b6182352efcb2ca.tar.bz2
Issue #16373: Prevent infinite recursion for ABC Set class operations.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_collections.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py
index 8dc5559..b2a5f05 100644
--- a/Lib/test/test_collections.py
+++ b/Lib/test/test_collections.py
@@ -651,6 +651,39 @@ class TestCollectionABCs(ABCTestCase):
s |= s
self.assertEqual(s, full)
+ def test_issue16373(self):
+ # Recursion error comparing comparable and noncomparable
+ # Set instances
+ class MyComparableSet(Set):
+ def __contains__(self, x):
+ return False
+ def __len__(self):
+ return 0
+ def __iter__(self):
+ return iter([])
+ class MyNonComparableSet(Set):
+ def __contains__(self, x):
+ return False
+ def __len__(self):
+ return 0
+ def __iter__(self):
+ return iter([])
+ def __le__(self, x):
+ return NotImplemented
+ def __lt__(self, x):
+ return NotImplemented
+
+ cs = MyComparableSet()
+ ncs = MyNonComparableSet()
+ with self.assertRaises(TypeError):
+ ncs < cs
+ with self.assertRaises(TypeError):
+ ncs <= cs
+ with self.assertRaises(TypeError):
+ cs > ncs
+ with self.assertRaises(TypeError):
+ cs >= ncs
+
def test_Mapping(self):
for sample in [dict]:
self.assertIsInstance(sample(), Mapping)