cpython: cd8b5b5b6356 (original) (raw)

Mercurial > cpython

changeset 90840:cd8b5b5b6356 3.4

Issue 8743: Improve interoperability between sets and the collections.Set abstract base class.

Raymond Hettinger python@rcn.com
date Mon, 26 May 2014 00:09:04 -0700
parents ebeade01bd8e
children 754fcc099834 510c8dc38749
files Lib/_collections_abc.py Lib/test/test_collections.py Misc/NEWS
diffstat 3 files changed, 181 insertions(+), 7 deletions(-)[+] [-] Lib/_collections_abc.py 23 Lib/test/test_collections.py 162 Misc/NEWS 3

line wrap: on

line diff

--- 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

def ge(self, other): if not isinstance(other, Set): return NotImplemented

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)

+ 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)

+ 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 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)

+ def _hash(self): """Compute the hash value of a set.

--- a/Lib/test/test_collections.py +++ b/Lib/test/test_collections.py @@ -720,14 +720,166 @@ class TestCollectionABCs(ABCTestCase): cs = MyComparableSet() ncs = MyNonComparableSet()

+

+

+

+

+

+

+

+

+

+

+

+

+

+

def test_Mapping(self): for sample in [dict]:

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -24,6 +24,9 @@ Library