From 3d5376f0297a9ecb22b9931b7f1bc0d3215231d7 Mon Sep 17 00:00:00 2001 From: Jukka Lehtosalo Date: Tue, 19 Apr 2022 11:52:27 +0100 Subject: [PATCH] Add overlapping type variables test case This was originally written by @A5rocks in #11657. Related to #12590. --- test-data/unit/check-generics.test | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test-data/unit/check-generics.test b/test-data/unit/check-generics.test index 9c5f3a332dab..6a89f6fb200c 100644 --- a/test-data/unit/check-generics.test +++ b/test-data/unit/check-generics.test @@ -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