Issue #16373: Prevent infinite recursion for ABC Set class comparisons.
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py
index 3aaecb2..784a318 100644
--- a/Lib/test/test_collections.py
+++ b/Lib/test/test_collections.py
@@ -594,6 +594,35 @@
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()
+ self.assertFalse(ncs < cs)
+ self.assertFalse(ncs <= cs)
+ self.assertFalse(cs > ncs)
+ self.assertFalse(cs >= ncs)
+
def test_Mapping(self):
for sample in [dict]:
self.assertIsInstance(sample(), Mapping)