Skip to content

what to do with an AsyncIterator that raises a NotImplementedError #10732

@iscai-msft

Description

@iscai-msft

Bug Report

(A clear and concise description of what the bug is.)
mypy doesn't seem to be fully a NotImplementedError in a parent class. In my parent class, I have an async def iter_x function that raises this error, and this function is actually implemented in subsequent child classes. It seems that mypy thinks the paren'ts iter function function is a coroutine because it's an async def without an await (gotten from this issue comment). As such, I get the following error: Return type "AsyncIterator[bytes]" of "iter_x" incompatible with return type "Coroutine[Any, Any, AsyncIterator[bytes]]" in supertype "X".

To Reproduce

(Write your steps here:)

  1. Create an AsyncIterator async def function in a parent class that raises a NotImplementedError
  2. Implement the AsyncIterator async def function in a child class. Ours does async iteration / await calls, so it has to be async def
  3. Run mypy and you should get an error similar to Return type "AsyncIterator[bytes]" of "iter_x" incompatible with return type "Coroutine[Any, Any, AsyncIterator[bytes]]" in supertype "X"

Expected Behavior

(Write what you thought would happen.)
My expected behavior is that mypy would fully listen to NotImplementedError, and not make assumptions about the base method being a coroutine because of it's lack of an "await"

Actual Behavior

mypy thinks the parent class' method is a coroutine because it's an async def AsyncIterator without a yield (following this issue comment)

(Write what happened.)

Your Environment

  • Mypy version used: 0.782
  • Mypy command-line flags: mypy
  • Mypy configuration options from mypy.ini (and other config files):
  • Python version used: 3.9
  • Operating system and version: Mac OS 11.4

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