summaryrefslogtreecommitdiffstats
path: root/Lib/_collections_abc.py
diff options
context:
space:
mode:
authorYury Selivanov <yselivanov@sprymix.com>2015-05-29 13:01:29 (GMT)
committerYury Selivanov <yselivanov@sprymix.com>2015-05-29 13:01:29 (GMT)
commit56fc61402533dc550244efe3e860242872f35bad (patch)
tree859b4c58dac06f2760d97814f36f8664a50af121 /Lib/_collections_abc.py
parent8fa6d4f75311bb459da50226c726d1ab7ccf115b (diff)
downloadcpython-56fc61402533dc550244efe3e860242872f35bad.zip
cpython-56fc61402533dc550244efe3e860242872f35bad.tar.gz
cpython-56fc61402533dc550244efe3e860242872f35bad.tar.bz2
Issue 24315: Make collections.abc.Coroutine derived from Awaitable
Diffstat (limited to 'Lib/_collections_abc.py')
-rw-r--r--Lib/_collections_abc.py49
1 files changed, 30 insertions, 19 deletions
diff --git a/Lib/_collections_abc.py b/Lib/_collections_abc.py
index 0ca7deb..a02b219 100644
--- a/Lib/_collections_abc.py
+++ b/Lib/_collections_abc.py
@@ -75,7 +75,7 @@ class Hashable(metaclass=ABCMeta):
return NotImplemented
-class _CoroutineMeta(ABCMeta):
+class _AwaitableMeta(ABCMeta):
def __instancecheck__(cls, instance):
# 0x80 = CO_COROUTINE
@@ -92,7 +92,26 @@ class _CoroutineMeta(ABCMeta):
return super().__instancecheck__(instance)
-class Coroutine(metaclass=_CoroutineMeta):
+class Awaitable(metaclass=_AwaitableMeta):
+
+ __slots__ = ()
+
+ @abstractmethod
+ def __await__(self):
+ yield
+
+ @classmethod
+ def __subclasshook__(cls, C):
+ if cls is Awaitable:
+ for B in C.__mro__:
+ if "__await__" in B.__dict__:
+ if B.__dict__["__await__"]:
+ return True
+ break
+ return NotImplemented
+
+
+class Coroutine(Awaitable):
__slots__ = ()
@@ -126,27 +145,19 @@ class Coroutine(metaclass=_CoroutineMeta):
else:
raise RuntimeError("coroutine ignored GeneratorExit")
-
-class Awaitable(metaclass=_CoroutineMeta):
-
- __slots__ = ()
-
- @abstractmethod
- def __await__(self):
- yield
-
@classmethod
def __subclasshook__(cls, C):
- if cls is Awaitable:
- for B in C.__mro__:
- if "__await__" in B.__dict__:
- if B.__dict__["__await__"]:
- return True
- break
+ if cls is Coroutine:
+ mro = C.__mro__
+ for method in ('__await__', 'send', 'throw', 'close'):
+ for base in mro:
+ if method in base.__dict__:
+ break
+ else:
+ return NotImplemented
+ return True
return NotImplemented
-Awaitable.register(Coroutine)
-
class AsyncIterable(metaclass=ABCMeta):