Skip to content

mypy seems to lose the type of an async AsyncIterator function that overrides a superclass #12662

@zzzeek

Description

@zzzeek

Getting this both with 0.942 as well as latest master:

from typing import AsyncIterator from typing import Sequence class AsyncResultWorking: "a class with two async methods." async def _some_impl(self) -> str: ... async def partitions(self) -> AsyncIterator[str]: ... class AsyncResultBroken: """a class with the identical two async methods as AsyncResultWorking,  but the 'partitions' method is now implemented.""" async def _some_impl(self) -> str: ... async def partitions(self) -> AsyncIterator[str]: while True: partition = await self._some_impl() if partition: yield partition else: break class AsyncResultSubclassWorking(AsyncResultWorking): """subclassing the working class is fine""" async def partitions(self) -> AsyncIterator[str]: ... class AsyncResultSubclassBroken(AsyncResultBroken): """subclassing the broken class expresses confusion over the  'partitions' method signature.   """ async def partitions(self) -> AsyncIterator[str]: ...

error:

test3.py:43: error: Return type "Coroutine[Any, Any, AsyncIterator[str]]" of "partitions" incompatible with return type "AsyncIterator[str]" in supertype "AsyncResultBroken" [override] Found 1 error in 1 file (checked 1 source file) 

if you remove the implementation from AsyncResultBroken.partitions, then it passes. So, I'm wondering am I not using AsyncIterator correctly? but if I'm not, neither mypy nor pyright are saying anything. Also, even if the method body of partitions were wrong, the signatures match exactly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions