summaryrefslogtreecommitdiffstats
path: root/Lib/_collections_abc.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2014-05-26 07:14:14 (GMT)
committerRaymond Hettinger <python@rcn.com>2014-05-26 07:14:14 (GMT)
commitaa92d342f1249d3f8b5b7ca28a6efe43dd7e1eb5 (patch)
treeec984605d8b11d15899415fbff67389a26be1409 /Lib/_collections_abc.py
parentdfe098d2150b4dc2842a15c6c30438effb40c0b7 (diff)
parentdd5e53a086fcabc84ee1ac96b98057437863973a (diff)
downloadcpython-aa92d342f1249d3f8b5b7ca28a6efe43dd7e1eb5.zip
cpython-aa92d342f1249d3f8b5b7ca28a6efe43dd7e1eb5.tar.gz
cpython-aa92d342f1249d3f8b5b7ca28a6efe43dd7e1eb5.tar.bz2
merge
Diffstat (limited to 'Lib/_collections_abc.py')
-rw-r--r--Lib/_collections_abc.py23
1 files changed, 21 insertions, 2 deletions
diff --git a/Lib/_collections_abc.py b/Lib/_collections_abc.py
index 62817236..d9cb93a 100644
--- a/Lib/_collections_abc.py
+++ b/Lib/_collections_abc.py
@@ -207,12 +207,17 @@ class Set(Sized, Iterable, Container):
def __gt__(self, other):
if not isinstance(other, Set):
return NotImplemented
- return other.__lt__(self)
+ return len(self) > len(other) and self.__ge__(other)
def __ge__(self, other):
if not isinstance(other, Set):
return NotImplemented
- return other.__le__(self)
+ if len(self) < len(other):
+ return False
+ for elem in other:
+ if elem not in self:
+ return False
+ return True
def __eq__(self, other):
if not isinstance(other, Set):
@@ -236,6 +241,8 @@ class Set(Sized, Iterable, Container):
return NotImplemented
return self._from_iterable(value for value in other if value in self)
+ __rand__ = __and__
+
def isdisjoint(self, other):
'Return True if two sets have a null intersection.'
for value in other:
@@ -249,6 +256,8 @@ class Set(Sized, Iterable, Container):
chain = (e for s in (self, other) for e in s)
return self._from_iterable(chain)
+ __ror__ = __or__
+
def __sub__(self, other):
if not isinstance(other, Set):
if not isinstance(other, Iterable):
@@ -257,6 +266,14 @@ class Set(Sized, Iterable, Container):
return self._from_iterable(value for value in self
if value not in other)
+ def __rsub__(self, other):
+ if not isinstance(other, Set):
+ if not isinstance(other, Iterable):
+ return NotImplemented
+ other = self._from_iterable(other)
+ return self._from_iterable(value for value in other
+ if value not in self)
+
def __xor__(self, other):
if not isinstance(other, Set):
if not isinstance(other, Iterable):
@@ -264,6 +281,8 @@ class Set(Sized, Iterable, Container):
other = self._from_iterable(other)
return (self - other) | (other - self)
+ __rxor__ = __xor__
+
def _hash(self):
"""Compute the hash value of a set.