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

Functions returning AsyncIterator shouldn't be async def #298

Open
JelleZijlstra opened this issue Oct 21, 2022 · 7 comments
Open

Functions returning AsyncIterator shouldn't be async def #298

JelleZijlstra opened this issue Oct 21, 2022 · 7 comments
Assignees

Comments

@JelleZijlstra
Copy link
Collaborator

See python/typeshed#8960.

@AlexWaygood
Copy link
Collaborator

Does pyright also misinterpret async def functions in stubs that return AsyncIterator? Is this just a weirdness with stubs? If so, maybe we should open an issue over at https://github.com/python/typing to document this weirdness as well.

@JelleZijlstra
Copy link
Collaborator Author

I don't think mypy's behavior is incorrect here, but documenting this gotcha is a good idea.

@AlexWaygood
Copy link
Collaborator

AlexWaygood commented Oct 21, 2022

I was using the word "misinterpret" in a highly confusing way, to mean "misinterprets what the author of the stub meant to convey" rather than "did something incorrect". Bad choice of words from me :)

@JelleZijlstra
Copy link
Collaborator Author

Sorry for misinterpreting you!

@AlexWaygood
Copy link
Collaborator

@JelleZijlstra do you fancy tackling this? I'm pretty sure the code changes should be trivial, but I'm not sure I have a precise enough understanding of the problem to be able to write a good error message here.

@JelleZijlstra JelleZijlstra self-assigned this Oct 25, 2022
@Dreamsorcerer
Copy link

I answered a question on Stackoverflow about this confusion. Feel free to link to it or copy any of the contents:
https://stackoverflow.com/questions/68905848/how-to-correctly-specify-type-hints-with-asyncgenerator-and-asynccontextmanager/68911014#68911014

@hauntsaninja
Copy link
Collaborator

For what it's worth, I documented this behaviour at https://mypy.readthedocs.io/en/latest/more_types.html#asynchronous-iterators a couple weeks ago

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

No branches or pull requests

4 participants