-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bpo-32166: Drop Python 3.4 code from asyncio #4612
bpo-32166: Drop Python 3.4 code from asyncio #4612
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is also a code related to Python < 3.5.
Lib/asyncio/coroutines.py
Outdated
return gen.send_args != (value,) | ||
_YIELD_FROM_BUG = has_yield_from_bug() | ||
del has_yield_from_bug | ||
_types_coroutine = types.coroutine |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't the code look clearer if inline these definitions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
if _CoroutineABC is not None: | ||
_COROUTINE_TYPES += (_CoroutineABC,) | ||
if _types_CoroutineType is not None: | ||
# Prioritize native coroutine check to speed-up |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep this comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sense
If you are talking about |
Aren't these changes break backward compatibility with Python < 3.5? I think it is worth to open an issue on the tracker for discussion. |
Lib/asyncio/coroutines.py
Outdated
# Prioritize native coroutine check to speed-up | ||
# asyncio.iscoroutine. | ||
_COROUTINE_TYPES = (_types_CoroutineType,) + _COROUTINE_TYPES | ||
# Prioritize native coroutine check to speed-up |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The second line of the comment has been lost.
Lib/asyncio/coroutines.py
Outdated
@@ -218,23 +156,20 @@ def coro(*args, **kw): | |||
if (base_futures.isfuture(res) or inspect.isgenerator(res) or | |||
isinstance(res, CoroWrapper)): | |||
res = yield from res | |||
elif _AwaitableABC is not None: | |||
elif Awaitable is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is Awaitable
imported?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't Awaitable is not None
always true?
After PR merging asyncio code cannot be executed on Python 3.4, sure.
and
is still supported. |
@serhiy-storchaka I created https://bugs.python.org/issue32166 as you suggested. |
@1st1 should the PR be backported to 3.6? |
No. 3.6 is freezed for any refactorings—this policy ensures we dont break something accidentally. Let's treat 3.6 as a legacy code :) |
from . import constants | ||
from . import events | ||
from . import base_futures | ||
from .log import logger | ||
|
||
|
||
# Opcode of "yield from" instruction | ||
_YIELD_FROM = opcode.opmap['YIELD_FROM'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is opcode still used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. It was used for making a workaround for bug already fixed in Python 3.4
Lib/asyncio/coroutines.py
Outdated
@@ -218,23 +156,20 @@ def coro(*args, **kw): | |||
if (base_futures.isfuture(res) or inspect.isgenerator(res) or | |||
isinstance(res, CoroWrapper)): | |||
res = yield from res | |||
elif _AwaitableABC is not None: | |||
elif Awaitable is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't Awaitable is not None
always true?
Lib/asyncio/coroutines.py
Outdated
_COROUTINE_TYPES = (_types_CoroutineType,) + _COROUTINE_TYPES | ||
# Prioritize native coroutine check to speed-up | ||
# asyncio.iscoroutine. | ||
_COROUTINE_TYPES = (types.CoroutineType, Coroutine, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the current code the natural type types.GeneratorType
is tested before the abstract type Coroutine
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When async/await is used types.CoroutineType
and collections.abc.Coroutine
are more frequent than old styled generators.
That's why I've changed the order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But checking an instance of types.GeneratorType
is much faster than running the Python code in collections.abc.Coroutine.__subclasshook__
.
Redundant check for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM except that I'm not sure about the order in _COROUTINE_TYPES
.
Well, if check for generator is much faster than ABC -- let's put it first. |
Lib/asyncio/unix_events.py
Outdated
@@ -680,7 +646,7 @@ def _start(self, args, shell, stdin, stdout, stderr, bufsize, **kwargs): | |||
# needed by close_fds=False on Python 3.3 and older | |||
# (Python 3.4 implements the PEP 446, socketpair returns | |||
# non-inheritable sockets) | |||
_set_inheritable(stdin_w.fileno(), False) | |||
os.set_inheritable(stdin_w.fileno(), False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
os.set_inheritable(stdin_w.fileno(), False) is useless on Python 3.4 and newer. Remove the call with its comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you don't trust me, please trust the tests ;-)
cpython/Lib/test/test_socket.py
Lines 5145 to 5146 in ef83806
self.assertEqual(s1.get_inheritable(), False) | |
self.assertEqual(s2.get_inheritable(), False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
The call is removed.
NO! Such refactoring change must not be backport to prevent any risk of regression. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. It's nice to see such large cleanup changes, to simplify asyncio code base! It seems like Python core became better ;-)
Thanks everybody for review! |
types.coroutine
,types.CoroutineType
,inspect.iscoroutinefunction
andcollections.abc.Coroutine
/collections.abc.Awaitable
are always present.https://bugs.python.org/issue32166