-
-
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
'got "C[T]", expected "C[T]"' with staticmethod #16668
Labels
bug
mypy got something wrong
Comments
The error message is confusing because the type variable T = TypeVar('T')
S = TypeVar('S')
class C(Generic[T]):
@staticmethod
def get() -> T: ...
def func(x: S) -> S:
return C[S].get() # E: Incompatible return value type (got "T", expected "S") [return-value] Generally you'd use T = TypeVar('T')
class C(Generic[T]):
@classmethod
def c(cls: 'type[C[T]]') -> 'C[T]':
return cls()
def f(t: T) -> C[T]:
return C[T].c() |
kourbou
added a commit
to kourbou/mypy
that referenced
this issue
Dec 16, 2023
`add_class_tvars` correctly instantiates type variables for class methods but not for static methods. Check if the analyzed member is a static method in `analyze_class_attribute_access` and substitute the type variable in the return type in `add_class_tvars` accordingly. Fixes python#16668.
kourbou
added a commit
to kourbou/mypy
that referenced
this issue
Dec 16, 2023
`add_class_tvars` correctly instantiates type variables for class methods but not for static methods. Check if the analyzed member is a static method in `analyze_class_attribute_access` and substitute the type variable in the return type in `add_class_tvars` accordingly. Fixes python#16668.
kourbou
added a commit
to kourbou/mypy
that referenced
this issue
Dec 16, 2023
`add_class_tvars` correctly instantiates type variables for class methods but not for static methods. Check if the analyzed member is a static method in `analyze_class_attribute_access` and substitute the type variable in the return type in `add_class_tvars` accordingly. Fixes python#16668.
kourbou
added a commit
to kourbou/mypy
that referenced
this issue
Dec 16, 2023
`add_class_tvars` correctly instantiates type variables for class methods but not for static methods. Check if the analyzed member is a static method in `analyze_class_attribute_access` and substitute the type variable in the return type in `add_class_tvars` accordingly. Fixes python#16668.
hauntsaninja
pushed a commit
that referenced
this issue
Dec 17, 2023
`add_class_tvars` correctly instantiates type variables in the return type for class methods but not for static methods. Check if the analyzed member is a static method in `analyze_class_attribute_access` and substitute the type variable in the return type in `add_class_tvars` accordingly. Fixes #16668.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bug Report
In the below playground link, mypy gives this error:
I think the program should pass type checking (it does with Pyright), but if there is some problem with it I'm not understanding, at least the error message should be better.
To Reproduce
https://mypy-play.net/?mypy=latest&python=3.12&gist=bcfed78680f130f0b4d87886bb196af7
Your Environment
mypy.ini
(and other config files): -The text was updated successfully, but these errors were encountered: