Skip to content

Commit

Permalink
Add overlapping type variables test case (#12623)
Browse files Browse the repository at this point in the history
This was originally written by @A5rocks in #11657.

Related to #12590.
  • Loading branch information
JukkaL authored Apr 20, 2022
1 parent cf146f4 commit 0bcca59
Showing 1 changed file with 20 additions and 0 deletions.
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

0 comments on commit 0bcca59

Please sign in to comment.