From a7b124adae759dc336108c5cb70680e55d29095b Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Wed, 8 Feb 2023 11:51:53 -0800 Subject: [PATCH] Fix crash on deferred value constrained TypeVar (#14642) Fixes #14631 --- mypy/types.py | 8 ++++++-- test-data/unit/check-typevar-values.test | 9 +++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/mypy/types.py b/mypy/types.py index b4710a95164c..60145cf44527 100644 --- a/mypy/types.py +++ b/mypy/types.py @@ -587,12 +587,16 @@ def accept(self, visitor: TypeVisitor[T]) -> T: return visitor.visit_type_var(self) def __hash__(self) -> int: - return hash((self.id, self.upper_bound)) + return hash((self.id, self.upper_bound, tuple(self.values))) def __eq__(self, other: object) -> bool: if not isinstance(other, TypeVarType): return NotImplemented - return self.id == other.id and self.upper_bound == other.upper_bound + return ( + self.id == other.id + and self.upper_bound == other.upper_bound + and self.values == other.values + ) def serialize(self) -> JsonDict: assert not self.id.is_meta_var() diff --git a/test-data/unit/check-typevar-values.test b/test-data/unit/check-typevar-values.test index d5a94f96fae7..a4a4d68bd9fe 100644 --- a/test-data/unit/check-typevar-values.test +++ b/test-data/unit/check-typevar-values.test @@ -702,3 +702,12 @@ class Indexable: [builtins fixtures/tuple.pyi] [builtins fixtures/classmethod.pyi] + +[case testTypeVarWithValueDeferral] +from typing import TypeVar, Callable + +T = TypeVar("T", "A", "B") +Func = Callable[[], T] + +class A: ... +class B: ...