Skip to content
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

Generic classes with nested generic classes can't have different TypeVars #5551

Closed
euresti opened this issue Sep 1, 2018 · 4 comments · Fixed by #12652
Closed

Generic classes with nested generic classes can't have different TypeVars #5551

euresti opened this issue Sep 1, 2018 · 4 comments · Fixed by #12652
Assignees
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code priority-1-normal topic-type-variables

Comments

@euresti
Copy link
Contributor

euresti commented Sep 1, 2018

Looking at the following example

from typing import TypeVar, Generic

class C(Generic[T]):
    def __init__(self, t: T) -> None:
        self.t = t

    class F(Generic[K]):
        def __init__(self, k: K) -> None:
            self.k = k

        def foo(self) -> K:
            return self.k

C.F(17).foo()
C("").F(17).foo()  # error: Argument 1 to "F" has incompatible type "int"; expected "str"

reveal_type(C.F)  # 'def [K] (k: K`1) -> foo.C.F[K`1]'  All Good
reveal_type(C("").F)  # 'def [K] (k: builtins.str*) -> foo.C.F[builtins.str*]'   What?

Seems like specifying the T seems to crush K somehow.

@euresti
Copy link
Contributor Author

euresti commented Sep 1, 2018

I don't have any code that does this. I was just testing out a fix for #5542 and came across this issue.

@ilevkivskyi
Copy link
Member

Yes, there are still some weird clashes that can happen. I would say we need to "fix" #4814 soon.

@ilevkivskyi ilevkivskyi added bug mypy got something wrong topic-type-variables priority-1-normal false-positive mypy gave an error on correct code labels Sep 1, 2018
@AlexWaygood
Copy link
Member

@JelleZijlstra, this appears to be another one that was fixed by #12590. Reckon we should add another test case?

@JelleZijlstra
Copy link
Member

Yes, this seems good to test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code priority-1-normal topic-type-variables
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants