return True
def __le__(self, other):
- if not isinstance(other, set_types + (IdentitySet,)):
+ if not isinstance(other, IdentitySet):
return NotImplemented
return self.issubset(other)
def __lt__(self, other):
- if not isinstance(other, set_types + (IdentitySet,)):
+ if not isinstance(other, IdentitySet):
return NotImplemented
return len(self) < len(other) and self.issubset(other)
return True
def __ge__(self, other):
- if not isinstance(other, set_types + (IdentitySet,)):
+ if not isinstance(other, IdentitySet):
return NotImplemented
return self.issuperset(other)
def __gt__(self, other):
- if not isinstance(other, set_types + (IdentitySet,)):
+ if not isinstance(other, IdentitySet):
return NotImplemented
return len(self) > len(other) and self.issuperset(other)
return result
def __or__(self, other):
- if not isinstance(other, set_types + (IdentitySet,)):
+ if not isinstance(other, IdentitySet):
return NotImplemented
return self.union(other)
- __ror__ = __or__
def update(self, iterable):
self._members = self.union(iterable)._members
def __ior__(self, other):
- if not isinstance(other, set_types + (IdentitySet,)):
+ if not isinstance(other, IdentitySet):
return NotImplemented
self.update(other)
return self
return result
def __sub__(self, other):
- if not isinstance(other, set_types + (IdentitySet,)):
+ if not isinstance(other, IdentitySet):
return NotImplemented
return self.difference(other)
- __rsub__ = __sub__
def difference_update(self, iterable):
self._members = self.difference(iterable)._members
def __isub__(self, other):
- if not isinstance(other, set_types + (IdentitySet,)):
+ if not isinstance(other, IdentitySet):
return NotImplemented
self.difference_update(other)
return self
return result
def __and__(self, other):
- if not isinstance(other, set_types + (IdentitySet,)):
+ if not isinstance(other, IdentitySet):
return NotImplemented
return self.intersection(other)
- __rand__ = __and__
def intersection_update(self, iterable):
self._members = self.intersection(iterable)._members
def __iand__(self, other):
- if not isinstance(other, set_types + (IdentitySet,)):
+ if not isinstance(other, IdentitySet):
return NotImplemented
self.intersection_update(other)
return self
return result
def __xor__(self, other):
- if not isinstance(other, set_types + (IdentitySet,)):
+ if not isinstance(other, IdentitySet):
return NotImplemented
return self.symmetric_difference(other)
- __rxor__ = __xor__
def symmetric_difference_update(self, iterable):
self._members = self.symmetric_difference(iterable)._members
def __ixor__(self, other):
- if not isinstance(other, set_types + (IdentitySet,)):
+ if not isinstance(other, IdentitySet):
return NotImplemented
self.symmetric_difference(other)
return self
self.assert_(False)
except TypeError:
self.assert_(True)
- s = set([o1,o2])
- s |= ids
- self.assert_(isinstance(s, IdentitySet))
+
+ try:
+ s = set([o1,o2])
+ s |= ids
+ self.assert_(False)
+ except TypeError:
+ self.assert_(True)
self.assertRaises(TypeError, cmp, ids)
self.assertRaises(TypeError, hash, ids)
+ def test_difference(self):
+ os1 = util.IdentitySet([1,2,3])
+ os2 = util.IdentitySet([3,4,5])
+ s1 = set([1,2,3])
+ s2 = set([3,4,5])
+
+ self.assertEquals(os1 - os2, util.IdentitySet([1, 2]))
+ self.assertEquals(os2 - os1, util.IdentitySet([4, 5]))
+ self.assertRaises(TypeError, lambda: os1 - s2)
+ self.assertRaises(TypeError, lambda: os1 - [3, 4, 5])
+ self.assertRaises(TypeError, lambda: s1 - os2)
+ self.assertRaises(TypeError, lambda: s1 - [3, 4, 5])
+
class DictlikeIteritemsTest(unittest.TestCase):
baseline = set([('a', 1), ('b', 2), ('c', 3)])