Open JelleZijlstra opened 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.
I don't think mypy's behavior is incorrect here, but documenting this gotcha is a good idea.
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 :)
Sorry for misinterpreting you!
@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.
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
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
See python/typeshed#8960.