[Python-checkins] asyncio: Remove asyncio/compat.py (#4606)

Victor Stinner webhook-mailer at python.org
Tue Nov 28 08:43:56 EST 2017


https://github.com/python/cpython/commit/3f438a9fa0aab5a598b4c94bbc24f9d0a23d012e
commit: 3f438a9fa0aab5a598b4c94bbc24f9d0a23d012e
branch: master
author: Victor Stinner <victor.stinner at gmail.com>
committer: GitHub <noreply at github.com>
date: 2017年11月28日T14:43:52+01:00
summary:
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 ;-)
files:
D Lib/asyncio/compat.py
M Lib/asyncio/coroutines.py
M Lib/asyncio/futures.py
M Lib/asyncio/locks.py
M Lib/asyncio/queues.py
M Lib/asyncio/streams.py
M Lib/asyncio/tasks.py
diff --git a/Lib/asyncio/compat.py b/Lib/asyncio/compat.py
deleted file mode 100644
index 520ec6870c8..00000000000
--- a/Lib/asyncio/compat.py
+++ /dev/null
@@ -1,6 +0,0 @@
-"""Compatibility helpers for the different Python versions."""
-
-import sys
-
-PY35 = sys.version_info >= (3, 5)
-PY352 = sys.version_info >= (3, 5, 2)
diff --git a/Lib/asyncio/coroutines.py b/Lib/asyncio/coroutines.py
index a87c9f9b0b6..3e305f90abb 100644
--- a/Lib/asyncio/coroutines.py
+++ b/Lib/asyncio/coroutines.py
@@ -9,7 +9,6 @@
 import traceback
 import types
 
-from . import compat
 from . import constants
 from . import events
 from . import base_futures
@@ -151,35 +150,33 @@ def gi_running(self):
 def gi_code(self):
 return self.gen.gi_code
 
- if compat.PY35:
-
- def __await__(self):
- cr_await = getattr(self.gen, 'cr_await', None)
- if cr_await is not None:
- raise RuntimeError(
- "Cannot await on coroutine {!r} while it's "
- "awaiting for {!r}".format(self.gen, cr_await))
- return self
+ def __await__(self):
+ cr_await = getattr(self.gen, 'cr_await', None)
+ if cr_await is not None:
+ raise RuntimeError(
+ "Cannot await on coroutine {!r} while it's "
+ "awaiting for {!r}".format(self.gen, cr_await))
+ return self
 
- @property
- def gi_yieldfrom(self):
- return self.gen.gi_yieldfrom
+ @property
+ def gi_yieldfrom(self):
+ return self.gen.gi_yieldfrom
 
- @property
- def cr_await(self):
- return self.gen.cr_await
+ @property
+ def cr_await(self):
+ return self.gen.cr_await
 
- @property
- def cr_running(self):
- return self.gen.cr_running
+ @property
+ def cr_running(self):
+ return self.gen.cr_running
 
- @property
- def cr_code(self):
- return self.gen.cr_code
+ @property
+ def cr_code(self):
+ return self.gen.cr_code
 
- @property
- def cr_frame(self):
- return self.gen.cr_frame
+ @property
+ def cr_frame(self):
+ return self.gen.cr_frame
 
 def __del__(self):
 # Be careful accessing self.gen.frame -- self.gen might not exist.
diff --git a/Lib/asyncio/futures.py b/Lib/asyncio/futures.py
index b2e57efdb66..7b6204a626f 100644
--- a/Lib/asyncio/futures.py
+++ b/Lib/asyncio/futures.py
@@ -9,7 +9,6 @@
 import traceback
 
 from . import base_futures
-from . import compat
 from . import events
 
 
@@ -238,8 +237,7 @@ def __iter__(self):
 assert self.done(), "yield from wasn't used with future"
 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.
diff --git a/Lib/asyncio/locks.py b/Lib/asyncio/locks.py
index 92661830a06..750c4359179 100644
--- a/Lib/asyncio/locks.py
+++ b/Lib/asyncio/locks.py
@@ -4,7 +4,6 @@
 
 import collections
 
-from . import compat
 from . import events
 from . import futures
 from .coroutines import coroutine
@@ -67,23 +66,21 @@ def __iter__(self):
 yield from self.acquire()
 return _ContextManager(self)
 
- if compat.PY35:
-
- def __await__(self):
- # To make "with await lock" work.
- yield from self.acquire()
- return _ContextManager(self)
+ def __await__(self):
+ # To make "with await lock" work.
+ yield from self.acquire()
+ return _ContextManager(self)
 
- @coroutine
- def __aenter__(self):
- yield from self.acquire()
- # We have no use for the "as ..." clause in the with
- # statement for locks.
- return None
+ @coroutine
+ def __aenter__(self):
+ yield from self.acquire()
+ # We have no use for the "as ..." clause in the with
+ # statement for locks.
+ return None
 
- @coroutine
- def __aexit__(self, exc_type, exc, tb):
- self.release()
+ @coroutine
+ def __aexit__(self, exc_type, exc, tb):
+ self.release()
 
 
 class Lock(_ContextManagerMixin):
diff --git a/Lib/asyncio/queues.py b/Lib/asyncio/queues.py
index 1c66d67b041..4fc681dde97 100644
--- a/Lib/asyncio/queues.py
+++ b/Lib/asyncio/queues.py
@@ -5,7 +5,6 @@
 import collections
 import heapq
 
-from . import compat
 from . import events
 from . import locks
 from .coroutines import coroutine
@@ -251,9 +250,3 @@ def _put(self, item):
 
 def _get(self):
 return self._queue.pop()
-
-
-if not compat.PY35:
- JoinableQueue = Queue
- """Deprecated alias for Queue."""
- __all__.append('JoinableQueue')
diff --git a/Lib/asyncio/streams.py b/Lib/asyncio/streams.py
index 30b751e9891..05774e95300 100644
--- a/Lib/asyncio/streams.py
+++ b/Lib/asyncio/streams.py
@@ -12,7 +12,6 @@
 __all__.extend(['open_unix_connection', 'start_unix_server'])
 
 from . import coroutines
-from . import compat
 from . import events
 from . import protocols
 from .coroutines import coroutine
diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py
index 52fef181cec..5d744c3d30e 100644
--- a/Lib/asyncio/tasks.py
+++ b/Lib/asyncio/tasks.py
@@ -13,7 +13,6 @@
 import weakref
 
 from . import base_tasks
-from . import compat
 from . import coroutines
 from . import events
 from . import futures
@@ -525,7 +524,7 @@ def ensure_future(coro_or_future, *, loop=None):
 if task._source_traceback:
 del task._source_traceback[-1]
 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)
 else:
 raise TypeError('An asyncio.Future, a coroutine or an awaitable is '


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /