-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
what to do with an AsyncIterator that raises a NotImplementedError #10732
Comments
The easy workaround is to add a Line 771 in f98f782
|
thanks for your quick response, I'll do this to get rid of my |
I ran into this myself today. It's "fixed" in my code with the |
It's not really a bug, since you could totally have an async function that produces an AsyncIterator when awaited. Relevant: #5385 (comment) |
I'm really not sure I agree that it's not a bug. If I take a valid method signature in a parent class and copy it verbatim into a child class, I would expect mypy not to emit error messages about an incompatible signature. I had this, and mypy complained loudly about it:
The child method is declared identically, byte-for-byte, character-for-character the same as the parent, and mypy complained about them being incompatible. You really don't think that's an issue? |
Surprising, sure, but not a bug. The presence of yield very fundamentally changes the nature of the object at runtime. Another workaround that might make more sense to you:
|
Urk. Yeah, I see why that works. I tend to forget just how much Can't say I like the fact that this happens, though. It really violates intuition that if one thing appears to be |
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 anasync 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 anasync def
without anawait
(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:)
AsyncIterator
async def
function in a parent class that raises aNotImplementedError
AsyncIterator
async def
function in a child class. Ours does async iteration / await calls, so it has to beasync def
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.ini
(and other config files):The text was updated successfully, but these errors were encountered: