PyCQA / flake8-pyi

A plugin for Flake8 that provides specializations for type hinting stub files
MIT License
73 stars 23 forks source link

Functions returning AsyncIterator shouldn't be `async def` #298

Open JelleZijlstra opened 1 year ago

JelleZijlstra commented 1 year ago

See python/typeshed#8960.

AlexWaygood commented 1 year ago

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 commented 1 year ago

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

AlexWaygood commented 1 year ago

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 commented 1 year ago

Sorry for misinterpreting you!

AlexWaygood commented 1 year ago

@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.

Dreamsorcerer commented 1 year ago

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 commented 1 year ago

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