diff --git a/mypy/subtypes.py b/mypy/subtypes.py index 753fa74b7744..98397d84c157 100644 --- a/mypy/subtypes.py +++ b/mypy/subtypes.py @@ -295,8 +295,9 @@ def visit_instance(self, left: Instance) -> bool: if call: return self._is_subtype(call, right) return False - else: - return False + if isinstance(right, TypeVarType) and right.values: + return any(self._is_subtype(left, r_val) for r_val in right.values) + return False def visit_type_var(self, left: TypeVarType) -> bool: right = self.right diff --git a/test-data/unit/check-typevar-values.test b/test-data/unit/check-typevar-values.test index 3f77996ec959..def2274670ba 100644 --- a/test-data/unit/check-typevar-values.test +++ b/test-data/unit/check-typevar-values.test @@ -631,3 +631,16 @@ def g(s: S) -> Callable[[S], None]: ... def f(x: S) -> None: h = g(x) h(x) + +[case testTypeVarWithValuesAndSuper] +from typing import Generic, TypeVar + +AnyStr = TypeVar('AnyStr', bytes, str) + +class Foo(Generic[AnyStr]): + def method1(self, s: AnyStr) -> None: + pass + +class Bar(Foo[AnyStr]): + def method1(self, s: AnyStr) -> None: + super().method1(s)