summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorAndrew Svetlov <andrew.svetlov@gmail.com>2012-11-01 11:31:12 (GMT)
committerAndrew Svetlov <andrew.svetlov@gmail.com>2012-11-01 11:31:12 (GMT)
commitb904e4256e739ccd40b634842a248fe6a9971ad9 (patch)
tree22c87700b83ab3c4617f06ffd625d8711835af2c /Lib
parent5e5bbfb69b5c0eb2f72c3e1ec702f9363defe05f (diff)
parentbcac6ad1f3776fed63ce5de57b6182352efcb2ca (diff)
downloadcpython-b904e4256e739ccd40b634842a248fe6a9971ad9.zip
cpython-b904e4256e739ccd40b634842a248fe6a9971ad9.tar.gz
cpython-b904e4256e739ccd40b634842a248fe6a9971ad9.tar.bz2
Merge issue #16373: Prevent infinite recursion for ABC Set class operations.
Patch by Serhiy Storchaka.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/collections/abc.py4
-rw-r--r--Lib/test/test_collections.py33
2 files changed, 35 insertions, 2 deletions
diff --git a/Lib/collections/abc.py b/Lib/collections/abc.py
index d17cfdc..c23b7dd 100644
--- a/Lib/collections/abc.py
+++ b/Lib/collections/abc.py
@@ -200,12 +200,12 @@ class Set(Sized, Iterable, Container):
def __gt__(self, other):
if not isinstance(other, Set):
return NotImplemented
- return other < self
+ return other.__lt__(self)
def __ge__(self, other):
if not isinstance(other, Set):
return NotImplemented
- return other <= self
+ return other.__le__(self)
def __eq__(self, other):
if not isinstance(other, Set):
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py
index 88c3129..8850e8b 100644
--- a/Lib/test/test_collections.py
+++ b/Lib/test/test_collections.py
@@ -663,6 +663,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)