Skip to content
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-39562: Allow executing asynchronous comprehensions in the asyncio REPL #18968

Merged
merged 5 commits into from
Mar 19, 2020

Conversation

isidentical
Copy link
Member

@isidentical isidentical commented Mar 12, 2020

https://bugs.python.org/issue39562

Allow executing asynchronous comprehensions on the top level when the
PyCF_ALLOW_TOP_LEVEL_AWAIT flag is given.

@Jackenmen
Copy link
Contributor

Jackenmen commented Mar 12, 2020

Does this also fix the async comprehension with await that was mentioned in the issue?
e.g.

[await asyncio.sleep(1, x) for x in range(5)]

I just noticed there's no test added for that and I don't know if these two cases differ under the hood.

@isidentical
Copy link
Member Author

Yes, it is! Will add a test.

>>> import asyncio
>>> [await asyncio.sleep(1, x) for x in range(5)]
[0, 1, 2, 3, 4]

@Jackenmen
Copy link
Contributor

Thanks for checking that :)

@isidentical isidentical requested review from 1st1 and pablogsal March 12, 2020 19:50
@isidentical
Copy link
Member Author

I'm not sure if this is an enhancement or a bugfix so should we backports this to the 3.8? @1st1 @pablogsal

@pablogsal
Copy link
Member

I think is a bug, this should be allowed the same way regular for loops are allowed so we need to backport this.

@pablogsal pablogsal changed the title bpo-39562: Run asynchronous comprehensions under asyncio repl bpo-39562: Allow executing asynchronous comprehensions in the asyncio REPL Mar 15, 2020
@pablogsal pablogsal self-assigned this Mar 15, 2020
@pablogsal pablogsal merged commit 9052f7a into python:master Mar 19, 2020
@miss-islington
Copy link
Contributor

Thanks @isidentical for the PR, and @pablogsal for merging it 🌮🎉.. I'm working now to backport this PR to: 3.8.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 19, 2020
… REPL (pythonGH-18968)

Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
(cherry picked from commit 9052f7a)

Co-authored-by: Batuhan Taşkaya <47358913+isidentical@users.noreply.github.com>
@bedevere-bot
Copy link

GH-19070 is a backport of this pull request to the 3.8 branch.

miss-islington added a commit that referenced this pull request Mar 19, 2020
… REPL (GH-18968)

Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
(cherry picked from commit 9052f7a)

Co-authored-by: Batuhan Taşkaya <47358913+isidentical@users.noreply.github.com>
int is_async_generator = 0;

outermost = (comprehension_ty) asdl_seq_GET(generators, 0);
if (IS_TOP_LEVEL_AWAIT(c)) {
c->u->u_ste->ste_coroutine = 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was over aggressive, it marks even non-async list comprehensions as coroutine, which breaks IPython/Jupyter. It should be marked as ste_coroutine only if await is somewhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants