diff options
author | Yury Selivanov <yselivanov@sprymix.com> | 2015-05-29 09:01:47 -0400 |
---|---|---|
committer | Yury Selivanov <yselivanov@sprymix.com> | 2015-05-29 09:01:47 -0400 |
commit | a24fcfdf23f6b1c1757e04bbc743039d55aceca3 (patch) | |
tree | 24d04cefe93ecb919c126f347d36056ffe95f3ef /Lib/_collections_abc.py | |
parent | 41a6a625d488fee413427f9bf682c199dce97be7 (diff) | |
parent | 56fc61402533dc550244efe3e860242872f35bad (diff) | |
download | cpython-git-a24fcfdf23f6b1c1757e04bbc743039d55aceca3.tar.gz |
Issue 24315: Make collections.abc.Coroutine derived from Awaitable
(Merge 3.5)
Diffstat (limited to 'Lib/_collections_abc.py')
-rw-r--r-- | Lib/_collections_abc.py | 49 |
1 files changed, 30 insertions, 19 deletions
diff --git a/Lib/_collections_abc.py b/Lib/_collections_abc.py index 0ca7debddb..a02b219861 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): |