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

Add overlapping type variables test case #12623

Merged
merged 1 commit into from
Apr 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions test-data/unit/check-generics.test
Original file line number Diff line number Diff line change
Expand Up @@ -2504,3 +2504,23 @@ b: I[I[Any]]
reveal_type([a, b]) # N: Revealed type is "builtins.list[__main__.I[__main__.I[Any]]]"
reveal_type([b, a]) # N: Revealed type is "builtins.list[__main__.I[__main__.I[Any]]]"
[builtins fixtures/list.pyi]

[case testOverlappingTypeVarIds]
from typing import TypeVar, Generic

class A: ...
class B: ...

T = TypeVar("T", bound=A)
V = TypeVar("V", bound=B)
S = TypeVar("S")

class Whatever(Generic[T]):
def something(self: S) -> S:
return self

# the "V" here had the same id as "T" and so mypy used to think it could expand one into another.
# this test is here to make sure that doesn't happen!
class WhateverPartTwo(Whatever[A], Generic[V]):
def something(self: S) -> S:
return self