bpo-36921: Deprecate @coroutine for sake of async def (GH-13346)

The second attempt. Now deprecate `@coroutine` only, keep `yield from fut` as is.


https://bugs.python.org/issue36921
This commit is contained in:
Andrew Svetlov 2019-05-16 17:52:10 +03:00 committed by Miss Islington (bot)
parent dbacfc2273
commit 68b34a7204
12 changed files with 311 additions and 320 deletions

View file

@ -3,12 +3,13 @@
__all__ = ('Lock', 'Event', 'Condition', 'Semaphore', 'BoundedSemaphore')
import collections
import types
import warnings
from . import events
from . import futures
from . import exceptions
from .coroutines import coroutine
from .import coroutines
class _ContextManager:
@ -55,7 +56,7 @@ class _ContextManagerMixin:
# always raises; that's how the with-statement works.
pass
@coroutine
@types.coroutine
def __iter__(self):
# This is not a coroutine. It is meant to enable the idiom:
#
@ -78,6 +79,9 @@ class _ContextManagerMixin:
yield from self.acquire()
return _ContextManager(self)
# The flag is needed for legacy asyncio.iscoroutine()
__iter__._is_coroutine = coroutines._is_coroutine
async def __acquire_ctx(self):
await self.acquire()
return _ContextManager(self)