Commit 3f438a9f authored by Victor Stinner's avatar Victor Stinner Committed by GitHub

asyncio: Remove asyncio/compat.py (#4606)

The asyncio/compat.py file was written to support Python < 3.5 and
Python < 3.5.2. But Python 3.5 doesn't accept bugfixes anymore, only
security fixes. There is no more need to backport bugfixes to Python
3.5, and so no need to have a single code base for Python 3.5, 3.6
and 3.7.

Say hello (again) to "async" and "await", who became real keywords in
Python 3.7 ;-)
parent a10dc3ef
"""Compatibility helpers for the different Python versions."""
import sys
PY35 = sys.version_info >= (3, 5)
PY352 = sys.version_info >= (3, 5, 2)
...@@ -9,7 +9,6 @@ import sys ...@@ -9,7 +9,6 @@ import sys
import traceback import traceback
import types import types
from . import compat
from . import constants from . import constants
from . import events from . import events
from . import base_futures from . import base_futures
...@@ -151,35 +150,33 @@ class CoroWrapper: ...@@ -151,35 +150,33 @@ class CoroWrapper:
def gi_code(self): def gi_code(self):
return self.gen.gi_code return self.gen.gi_code
if compat.PY35: def __await__(self):
cr_await = getattr(self.gen, 'cr_await', None)
def __await__(self): if cr_await is not None:
cr_await = getattr(self.gen, 'cr_await', None) raise RuntimeError(
if cr_await is not None: "Cannot await on coroutine {!r} while it's "
raise RuntimeError( "awaiting for {!r}".format(self.gen, cr_await))
"Cannot await on coroutine {!r} while it's " return self
"awaiting for {!r}".format(self.gen, cr_await))
return self
@property @property
def gi_yieldfrom(self): def gi_yieldfrom(self):
return self.gen.gi_yieldfrom return self.gen.gi_yieldfrom
@property @property
def cr_await(self): def cr_await(self):
return self.gen.cr_await return self.gen.cr_await
@property @property
def cr_running(self): def cr_running(self):
return self.gen.cr_running return self.gen.cr_running
@property @property
def cr_code(self): def cr_code(self):
return self.gen.cr_code return self.gen.cr_code
@property @property
def cr_frame(self): def cr_frame(self):
return self.gen.cr_frame return self.gen.cr_frame
def __del__(self): def __del__(self):
# Be careful accessing self.gen.frame -- self.gen might not exist. # Be careful accessing self.gen.frame -- self.gen might not exist.
......
...@@ -9,7 +9,6 @@ import sys ...@@ -9,7 +9,6 @@ import sys
import traceback import traceback
from . import base_futures from . import base_futures
from . import compat
from . import events from . import events
...@@ -238,8 +237,7 @@ class Future: ...@@ -238,8 +237,7 @@ class Future:
assert self.done(), "yield from wasn't used with future" assert self.done(), "yield from wasn't used with future"
return self.result() # May raise too. return self.result() # May raise too.
if compat.PY35: __await__ = __iter__ # make compatible with 'await' expression
__await__ = __iter__ # make compatible with 'await' expression
# Needed for testing purposes. # Needed for testing purposes.
......
...@@ -4,7 +4,6 @@ __all__ = ['Lock', 'Event', 'Condition', 'Semaphore', 'BoundedSemaphore'] ...@@ -4,7 +4,6 @@ __all__ = ['Lock', 'Event', 'Condition', 'Semaphore', 'BoundedSemaphore']
import collections import collections
from . import compat
from . import events from . import events
from . import futures from . import futures
from .coroutines import coroutine from .coroutines import coroutine
...@@ -67,23 +66,21 @@ class _ContextManagerMixin: ...@@ -67,23 +66,21 @@ class _ContextManagerMixin:
yield from self.acquire() yield from self.acquire()
return _ContextManager(self) return _ContextManager(self)
if compat.PY35: def __await__(self):
# To make "with await lock" work.
def __await__(self): yield from self.acquire()
# To make "with await lock" work. return _ContextManager(self)
yield from self.acquire()
return _ContextManager(self)
@coroutine @coroutine
def __aenter__(self): def __aenter__(self):
yield from self.acquire() yield from self.acquire()
# We have no use for the "as ..." clause in the with # We have no use for the "as ..." clause in the with
# statement for locks. # statement for locks.
return None return None
@coroutine @coroutine
def __aexit__(self, exc_type, exc, tb): def __aexit__(self, exc_type, exc, tb):
self.release() self.release()
class Lock(_ContextManagerMixin): class Lock(_ContextManagerMixin):
......
...@@ -5,7 +5,6 @@ __all__ = ['Queue', 'PriorityQueue', 'LifoQueue', 'QueueFull', 'QueueEmpty'] ...@@ -5,7 +5,6 @@ __all__ = ['Queue', 'PriorityQueue', 'LifoQueue', 'QueueFull', 'QueueEmpty']
import collections import collections
import heapq import heapq
from . import compat
from . import events from . import events
from . import locks from . import locks
from .coroutines import coroutine from .coroutines import coroutine
...@@ -251,9 +250,3 @@ class LifoQueue(Queue): ...@@ -251,9 +250,3 @@ class LifoQueue(Queue):
def _get(self): def _get(self):
return self._queue.pop() return self._queue.pop()
if not compat.PY35:
JoinableQueue = Queue
"""Deprecated alias for Queue."""
__all__.append('JoinableQueue')
...@@ -12,7 +12,6 @@ if hasattr(socket, 'AF_UNIX'): ...@@ -12,7 +12,6 @@ if hasattr(socket, 'AF_UNIX'):
__all__.extend(['open_unix_connection', 'start_unix_server']) __all__.extend(['open_unix_connection', 'start_unix_server'])
from . import coroutines from . import coroutines
from . import compat
from . import events from . import events
from . import protocols from . import protocols
from .coroutines import coroutine from .coroutines import coroutine
......
...@@ -13,7 +13,6 @@ import warnings ...@@ -13,7 +13,6 @@ import warnings
import weakref import weakref
from . import base_tasks from . import base_tasks
from . import compat
from . import coroutines from . import coroutines
from . import events from . import events
from . import futures from . import futures
...@@ -525,7 +524,7 @@ def ensure_future(coro_or_future, *, loop=None): ...@@ -525,7 +524,7 @@ def ensure_future(coro_or_future, *, loop=None):
if task._source_traceback: if task._source_traceback:
del task._source_traceback[-1] del task._source_traceback[-1]
return task return task
elif compat.PY35 and inspect.isawaitable(coro_or_future): elif inspect.isawaitable(coro_or_future):
return ensure_future(_wrap_awaitable(coro_or_future), loop=loop) return ensure_future(_wrap_awaitable(coro_or_future), loop=loop)
else: else:
raise TypeError('An asyncio.Future, a coroutine or an awaitable is ' raise TypeError('An asyncio.Future, a coroutine or an awaitable is '
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment