Skip to content

Commit 0c99585

Browse files
ilinumhauntsaninja
andauthored
[backport] Fix crash on deferred value constrained TypeVar (#14642) (#14655)
Fixes #14631 Co-authored-by: Shantanu <[email protected]>
1 parent b562f53 commit 0c99585

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
@@ -587,12 +587,16 @@ def accept(self, visitor: TypeVisitor[T]) -> T:
587587
return visitor.visit_type_var(self)
588588

589589
def __hash__(self) -> int:
590-
return hash((self.id, self.upper_bound))
590+
return hash((self.id, self.upper_bound, tuple(self.values)))
591591

592592
def __eq__(self, other: object) -> bool:
593593
if not isinstance(other, TypeVarType):
594594
return NotImplemented
595-
return self.id == other.id and self.upper_bound == other.upper_bound
595+
return (
596+
self.id == other.id
597+
and self.upper_bound == other.upper_bound
598+
and self.values == other.values
599+
)
596600

597601
def serialize(self) -> JsonDict:
598602
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)