bpo-32166: Drop Python 3.4 code from asyncio#4612
Conversation
serhiy-storchaka
left a comment
There was a problem hiding this comment.
There is also a code related to Python < 3.5.
| 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.
Wouldn't the code look clearer if inline these definitions?
| if _CoroutineABC is not None: | ||
| _COROUTINE_TYPES += (_CoroutineABC,) | ||
| if _types_CoroutineType is not None: | ||
| # Prioritize native coroutine check to speed-up |
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. |
| # 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.
The second line of the comment has been lost.
| isinstance(res, CoroWrapper)): | ||
| res = yield from res | ||
| elif _AwaitableABC is not None: | ||
| elif Awaitable is not None: |
There was a problem hiding this comment.
Is Awaitable imported?
There was a problem hiding this comment.
Good catch. Fixed.
There was a problem hiding this comment.
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 :) |
|
|
||
|
|
||
| # Opcode of "yield from" instruction | ||
| _YIELD_FROM = opcode.opmap['YIELD_FROM'] |
There was a problem hiding this comment.
No. It was used for making a workaround for bug already fixed in Python 3.4
| isinstance(res, CoroWrapper)): | ||
| res = yield from res | ||
| elif _AwaitableABC is not None: | ||
| elif Awaitable is not None: |
There was a problem hiding this comment.
Isn't Awaitable is not None always true?
| _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.
In the current code the natural type types.GeneratorType is tested before the abstract type Coroutine.
There was a problem hiding this comment.
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.
But checking an instance of types.GeneratorType is much faster than running the Python code in collections.abc.Coroutine.__subclasshook__.
|
Redundant check for |
serhiy-storchaka
left a comment
There was a problem hiding this comment.
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. |
| # (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.
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.
If you don't trust me, please trust the tests ;-)
cpython/Lib/test/test_socket.py
Lines 5145 to 5146 in ef83806
There was a problem hiding this comment.
Thanks.
The call is removed.
NO! Such refactoring change must not be backport to prevent any risk of regression. |
vstinner
left a comment
There was a problem hiding this comment.
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.iscoroutinefunctionandcollections.abc.Coroutine/collections.abc.Awaitableare always present.https://bugs.python.org/issue32166