-
-
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
The generic type of an inner function cannot be made to match the generic type of an enclosing function #8696
Comments
Ugh! This is a bad error message, and pretty confusing. I think that the issue here is that the inner function binds those type variables separately (but maybe it shouldn't?), which is why there is a type mismatch: they are different |
@msullivan Thanks for taking a look. I ended up redesigning this, so it's not a priority for me anymore. Out of curiosity, how should I have annotated this? However, thank you, MyPy people, for the great project. It's really useful! |
Sorry for resuming this old issue but I just stumbled in (what I believe is) this same situation and I could not find a solution. My code is:
and, while running mypy command (version 0.910), I got:
I admit I am not completely sure it is the same issue as the one reported by @NeilGirdhar and that @msullivan suggested being due to the fact that "they are different T type", but it seemed so and I couldn't find a way to change my code to avoid this error. |
@NicolaDonelli Did you try inheriting from from abc import abstractmethod
from typing import TypeVar, Iterable, Iterator, Generic
from collections.abc import Iterable
T = TypeVar('T')
class MyABC(Iterable[T], Generic[T]):
@property
@abstractmethod
def items(self) -> Iterable[T]: ...
def __iter__(self) -> Iterator[T]:
yield from self.items It may be worth considering filing an issue to improve the error message for this case. |
@NeilGirdhar, nope I didn't try before and effectively your proposed solution works like a charm, thanks a lot! For what it takes the issue about the error message, would you prefer me to open it or you'd prefer to open it yourself? |
You're very welcome.
I'm not opening it. |
Looks like the error message is fixed! |
With the following example:
MyPy 0.910 says:
The text was updated successfully, but these errors were encountered: