summaryrefslogtreecommitdiffstats
path: root/Lib/_collections_abc.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@dropbox.com>2016-04-04 17:59:29 (GMT)
committerGuido van Rossum <guido@dropbox.com>2016-04-04 17:59:29 (GMT)
commit16ca06b8cb2426b540fdab75914d7cd0f715b7f0 (patch)
tree1579954986fe3c8637f41d08702b3f8f58b6a60b /Lib/_collections_abc.py
parent9ad764601bb94f48e3048635f47a8e61f2a587b0 (diff)
downloadcpython-16ca06b8cb2426b540fdab75914d7cd0f715b7f0.zip
cpython-16ca06b8cb2426b540fdab75914d7cd0f715b7f0.tar.gz
cpython-16ca06b8cb2426b540fdab75914d7cd0f715b7f0.tar.bz2
Add collections.Reversible. Patch by Ivan Levkivskyi. Fixes issue #25987.
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 f89bb6f..d337584 100644
--- a/Lib/_collections_abc.py
+++ b/Lib/_collections_abc.py
@@ -10,7 +10,7 @@ from abc import ABCMeta, abstractmethod
import sys
__all__ = ["Awaitable", "Coroutine", "AsyncIterable", "AsyncIterator",
- "Hashable", "Iterable", "Iterator", "Generator",
+ "Hashable", "Iterable", "Iterator", "Generator", "Reversible",
"Sized", "Container", "Callable",
"Set", "MutableSet",
"Mapping", "MutableMapping",
@@ -240,6 +240,25 @@ Iterator.register(tuple_iterator)
Iterator.register(zip_iterator)
+class Reversible(Iterable):
+
+ __slots__ = ()
+
+ @abstractmethod
+ def __reversed__(self):
+ return NotImplemented
+
+ @classmethod
+ def __subclasshook__(cls, C):
+ if cls is Reversible:
+ for B in C.__mro__:
+ if "__reversed__" in B.__dict__:
+ if B.__dict__["__reversed__"] is not None:
+ return True
+ break
+ return NotImplemented
+
+
class Generator(Iterator):
__slots__ = ()
@@ -794,7 +813,7 @@ MutableMapping.register(dict)
### SEQUENCES ###
-class Sequence(Sized, Iterable, Container):
+class Sequence(Sized, Reversible, Container):
"""All the operations on a read-only sequence.