cpython: a7a9c8631d0e (original) (raw)

Mercurial > cpython

changeset 96349:a7a9c8631d0e

Issue 24315: Make collections.abc.Coroutine derived from Awaitable (Merge 3.5)

Yury Selivanov yselivanov@sprymix.com
date Fri, 29 May 2015 09:01:47 -0400
parents c9d89d3f3ff1(current diff)968af3838553(diff)
children 748c55375225
files Lib/test/test_collections.py
diffstat 4 files changed, 67 insertions(+), 40 deletions(-)[+] [-] Doc/library/collections.abc.rst 10 Lib/_collections_abc.py 49 Lib/test/test_asyncio/test_pep492.py 14 Lib/test/test_collections.py 34

line wrap: on

line diff

--- a/Doc/library/collections.abc.rst +++ b/Doc/library/collections.abc.rst @@ -82,7 +82,7 @@ ABC Inherits from :class:Set __iter__ :class:ValuesView :class:MappingView __contains__, __iter__ :class:Awaitable __await__ -:class:Coroutine send, throw close +:class:Coroutine :class:Awaitable send, throw close :class:AsyncIterable __aiter__ :class:AsyncIterator :class:AsyncIterable __anext__ __aiter__ ========================== ====================== ======================= ==================================================== @@ -166,10 +166,10 @@ ABC Inherits from ABC for coroutine compatible classes that implement a subset of generator methods defined in :pep:342, namely:

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

+

+

+ + +class Coroutine(Awaitable): slots = () @@ -126,27 +145,19 @@ class Coroutine(metaclass=_CoroutineMeta else: raise RuntimeError("coroutine ignored GeneratorExit") - -class Awaitable(metaclass=_CoroutineMeta): -

-

- @classmethod def subclasshook(cls, C):

-Awaitable.register(Coroutine) - class AsyncIterable(metaclass=ABCMeta):

--- a/Lib/test/test_asyncio/test_pep492.py +++ b/Lib/test/test_asyncio/test_pep492.py @@ -97,18 +97,14 @@ class CoroutineTests(BaseTest): finally: f.close() # silence warning

if name == 'main':

--- a/Lib/test/test_collections.py +++ b/Lib/test/test_collections.py @@ -496,6 +496,8 @@ class TestOneTrickPonyABCs(ABCTestCase): return value def throw(self, typ, val=None, tb=None): super().throw(typ, val, tb)

non_samples = [None, int(), gen(), object()] for x in non_samples: @@ -515,13 +517,7 @@ class TestOneTrickPonyABCs(ABCTestCase): self.assertIsInstance(c, Awaitable) c.close() # awoid RuntimeWarning that coro() was not awaited

@@ -548,6 +544,8 @@ class TestOneTrickPonyABCs(ABCTestCase): return value def throw(self, typ, val=None, tb=None): super().throw(typ, val, tb)

non_samples = [None, int(), gen(), object(), Bar()] for x in non_samples: @@ -567,6 +565,28 @@ class TestOneTrickPonyABCs(ABCTestCase): self.assertIsInstance(c, Coroutine) c.close() # awoid RuntimeWarning that coro() was not awaited

+

+ def test_Hashable(self): # Check some non-hashables non_samples = [bytearray(), list(), set(), dict()]