Skip to content

Commit 3d5376f

Browse files
committed
Add overlapping type variables test case
This was originally written by @A5rocks in #11657. Related to #12590.
1 parent 20b0b9b commit 3d5376f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

test-data/unit/check-generics.test

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2504,3 +2504,23 @@ b: I[I[Any]]
25042504
reveal_type([a, b]) # N: Revealed type is "builtins.list[__main__.I[__main__.I[Any]]]"
25052505
reveal_type([b, a]) # N: Revealed type is "builtins.list[__main__.I[__main__.I[Any]]]"
25062506
[builtins fixtures/list.pyi]
2507+
2508+
[case testOverlappingTypeVarIds]
2509+
from typing import TypeVar, Generic
2510+
2511+
class A: ...
2512+
class B: ...
2513+
2514+
T = TypeVar("T", bound=A)
2515+
V = TypeVar("V", bound=B)
2516+
S = TypeVar("S")
2517+
2518+
class Whatever(Generic[T]):
2519+
def something(self: S) -> S:
2520+
return self
2521+
2522+
# the "V" here had the same id as "T" and so mypy used to think it could expand one into another.
2523+
# this test is here to make sure that doesn't happen!
2524+
class WhateverPartTwo(Whatever[A], Generic[V]):
2525+
def something(self: S) -> S:
2526+
return self

0 commit comments

Comments
 (0)