Skip to content

Commit 786c7b0

Browse files
authored
Fix crash on deferred value constrained TypeVar (#14642)
Fixes #14631
1 parent 6b56dc0 commit 786c7b0

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

mypy/types.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -590,12 +590,16 @@ def accept(self, visitor: TypeVisitor[T]) -> T:
590590
return visitor.visit_type_var(self)
591591

592592
def __hash__(self) -> int:
593-
return hash((self.id, self.upper_bound))
593+
return hash((self.id, self.upper_bound, tuple(self.values)))
594594

595595
def __eq__(self, other: object) -> bool:
596596
if not isinstance(other, TypeVarType):
597597
return NotImplemented
598-
return self.id == other.id and self.upper_bound == other.upper_bound
598+
return (
599+
self.id == other.id
600+
and self.upper_bound == other.upper_bound
601+
and self.values == other.values
602+
)
599603

600604
def serialize(self) -> JsonDict:
601605
assert not self.id.is_meta_var()

test-data/unit/check-typevar-values.test

+9
Original file line numberDiff line numberDiff line change
@@ -702,3 +702,12 @@ class Indexable:
702702

703703
[builtins fixtures/tuple.pyi]
704704
[builtins fixtures/classmethod.pyi]
705+
706+
[case testTypeVarWithValueDeferral]
707+
from typing import TypeVar, Callable
708+
709+
T = TypeVar("T", "A", "B")
710+
Func = Callable[[], T]
711+
712+
class A: ...
713+
class B: ...

0 commit comments

Comments
 (0)