Skip to content

"Incompatible with definition in base class" with generics #15952

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

Closed
eltoder opened this issue Aug 24, 2023 · 2 comments
Closed

"Incompatible with definition in base class" with generics #15952

eltoder opened this issue Aug 24, 2023 · 2 comments
Labels
bug mypy got something wrong

Comments

@eltoder
Copy link

eltoder commented Aug 24, 2023

To Reproduce

https://mypy-play.net/?mypy=latest&python=3.11&gist=fd4559c9942bc1991500fb402ca989f3

from typing import Generic, TypeVar

T = TypeVar("T")
U = TypeVar("U")

class A(Generic[T]):
    x: T

class B(Generic[U]):
    x: U

class C(A[T], B[T]):
    pass

Expected Behavior

I expect this to type check, since x in both bases are using exactly the same type after substitution of generic arguments. I'm guessing the compatibility check is performed before the substitution, but it should be after.

Actual Behavior

main.py:12: error: Definition of "x" in base class "A" is incompatible with definition in base class "B"  [misc]

Your Environment

  • Mypy version used: 1.5.1
  • Python version used: 3.11
@eltoder eltoder added the bug mypy got something wrong label Aug 24, 2023
@erictraut
Copy link

This appears to be a duplicate of #2875.

@eltoder
Copy link
Author

eltoder commented Aug 24, 2023

@erictraut thanks! Indeed, very similar to #2875 (comment), except in my case both classes are generic. Probably the same issue.

@eltoder eltoder closed this as completed Aug 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

2 participants