summaryrefslogtreecommitdiffstats
path: root/Lib/_collections_abc.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@dropbox.com>2016-08-23 17:47:07 (GMT)
committerGuido van Rossum <guido@dropbox.com>2016-08-23 17:47:07 (GMT)
commitf0666949fda1f418eb656b7503b4609e6bd58163 (patch)
treea9c1f0e0b7ec9c16f7f30a54a9b1dc90b79f85fb /Lib/_collections_abc.py
parent9ff4fb36199f94818d97be56d0b3ab1c9e989209 (diff)
downloadcpython-f0666949fda1f418eb656b7503b4609e6bd58163.zip
cpython-f0666949fda1f418eb656b7503b4609e6bd58163.tar.gz
cpython-f0666949fda1f418eb656b7503b4609e6bd58163.tar.bz2
Issue 27598: Add Collections to collections.abc.
Patch by Ivan Levkivskyi, docs by Neil Girdhar.
Diffstat (limited to 'Lib/_collections_abc.py')
-rw-r--r--Lib/_collections_abc.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/Lib/_collections_abc.py b/Lib/_collections_abc.py
index 077bde4..f035970 100644
--- a/Lib/_collections_abc.py
+++ b/Lib/_collections_abc.py
@@ -11,7 +11,7 @@ import sys
__all__ = ["Awaitable", "Coroutine", "AsyncIterable", "AsyncIterator",
"Hashable", "Iterable", "Iterator", "Generator", "Reversible",
- "Sized", "Container", "Callable",
+ "Sized", "Container", "Callable", "Collection",
"Set", "MutableSet",
"Mapping", "MutableMapping",
"MappingView", "KeysView", "ItemsView", "ValuesView",
@@ -326,6 +326,15 @@ class Container(metaclass=ABCMeta):
return _check_methods(C, "__contains__")
return NotImplemented
+class Collection(Sized, Iterable, Container):
+
+ __slots__ = ()
+
+ @classmethod
+ def __subclasshook__(cls, C):
+ if cls is Collection:
+ return _check_methods(C, "__len__", "__iter__", "__contains__")
+ return NotImplemented
class Callable(metaclass=ABCMeta):
@@ -345,7 +354,7 @@ class Callable(metaclass=ABCMeta):
### SETS ###
-class Set(Sized, Iterable, Container):
+class Set(Collection):
"""A set is a finite, iterable container.
@@ -570,7 +579,7 @@ MutableSet.register(set)
### MAPPINGS ###
-class Mapping(Sized, Iterable, Container):
+class Mapping(Collection):
__slots__ = ()
@@ -794,7 +803,7 @@ MutableMapping.register(dict)
### SEQUENCES ###
-class Sequence(Sized, Reversible, Container):
+class Sequence(Reversible, Collection):
"""All the operations on a read-only sequence.