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

Fix async iterator body stripping #15491

Merged
merged 5 commits into from
Jun 23, 2023
Merged

Conversation

hauntsaninja
Copy link
Collaborator

Fixes #15489

and self.strip_function_bodies
and len(stack) == 1
and stack[0] == "F"
and not is_coroutine
Copy link
Member

Choose a reason for hiding this comment

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

We can strip if there is no yield right? Also IIUC this is the actual fix, while the change below is just a refactoring, right?

Copy link
Collaborator Author

@hauntsaninja hauntsaninja Jun 21, 2023

Choose a reason for hiding this comment

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

Change below isn't just refactoring, since the stripping below used to only happen in methods.

Copy link
Member

Choose a reason for hiding this comment

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

OK, wait, but then now the stripping in last part will occur even if stack[0] != "F", is it safe?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added that check, and fixed a bug I introduced in the logic for empty bodies

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@hauntsaninja
Copy link
Collaborator Author

I added the reporting repo to primer and hit update branch, so hopefully diff will show up.

@github-actions
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

vision (https://github.com/pytorch/vision): typechecking got 1.28x slower (38.1s -> 48.9s)
(Performance measurements are based on a single noisy sample)

aiohttp-devtools (https://github.com/aio-libs/aiohttp-devtools)
- aiohttp_devtools/runserver/watch.py:70: error: "Coroutine[Any, Any, AsyncGenerator[set[tuple[Change, str]], None]]" has no attribute "__aiter__" (not async iterable)  [attr-defined]
- aiohttp_devtools/runserver/watch.py:70: note: Maybe you forgot to use "await"?
- aiohttp_devtools/runserver/watch.py:147: error: "Coroutine[Any, Any, AsyncGenerator[set[tuple[Change, str]], None]]" has no attribute "__aiter__" (not async iterable)  [attr-defined]
- aiohttp_devtools/runserver/watch.py:147: note: Maybe you forgot to use "await"?

Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

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

Thanks for the fix!

@JukkaL JukkaL merged commit 2d8ad8e into python:master Jun 23, 2023
@hauntsaninja hauntsaninja deleted the async-fn-bod branch June 23, 2023 18:22
hauntsaninja added a commit that referenced this pull request Jun 24, 2023
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.

[1.4] Regression with AsyncGenerator
3 participants