-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Incompatible definition of generic field on multiple base classes #9031
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
Comments
Yeah, this is a mypy bug. Likely related to #7724 |
Still happening with mypy 0.960 :( |
I think I just encountered a modified version of this in django-stubs: typeddjango/django-stubs#1227 . Due to the structure of the classes we are trying to type, the attribute is defined as generic in both base classes, and passed as a type parameter to each: from typing import Generic, TypeVar
T = TypeVar("T", int, str)
class A(Generic[T]):
foo: T
class B(Generic[T]):
foo: T
class C(Generic[T], B[T], A[T]):
pass
c: C[int] = C()
reveal_type(A().foo)
reveal_type(B().foo)
reveal_type(c.foo) |
I just ran into the same issue. I don't see it explicitly mentioned above, but one workaround is to explicitly type the attribute in the concrete class (if that's an option; i.e. if the type is resolved in the class definition rather than the variable declaration); e.g. from typing import Generic, TypeVar
T = TypeVar('T')
class A(Generic[T]):
value: T
class B(Generic[T]):
value: T
class C(A[int], B[int]):
value: int |
Mypy 1.15 includes fix for <python/mypy#9031>, allowing several "type: ignore" comments to be removed.
Mypy 1.15 includes fix for <python/mypy#9031>, allowing several "type: ignore" comments to be removed.
Mypy 1.15 includes fix for <python/mypy#9031>, allowing several "type: ignore" comments to be removed.
* Upgrade mypy to 1.15 Mypy 1.15 includes fix for <python/mypy#9031>, allowing several "type: ignore" comments to be removed. * Add type annotations to DataTree.pipe tests * More precisely type `pipe` methods. In addition, enhance mypy job configuration to support running it locally via `act`. Fixes #9997 * Pin mypy to 1.15 in CI * Revert mypy CI job changes * Add pytest-mypy-plugin and typestub packages * Add pytest-mypy-plugins to all conda env files * Remove dup pandas-stubs dep * Revert pre-commit config changes * Place mypy tests behind pytest mypy marker * Set default pytest numprocesses to 4 * Ignore pytest-mypy-plugins for min version check
[BUG] Edited for a clearer example
Given this code:
I get this output:
I couldn't find what
builtins.int*
. The code makes sense though, right?The text was updated successfully, but these errors were encountered: