Skip to content

Commit

Permalink
Fix crash on deferred value constrained TypeVar (python#14642)
Browse files Browse the repository at this point in the history
  • Loading branch information
hauntsaninja authored and ilinum committed Feb 8, 2023
1 parent bc18017 commit a7b124a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 6 additions & 2 deletions mypy/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 9 additions & 0 deletions test-data/unit/check-typevar-values.test
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...

0 comments on commit a7b124a

Please sign in to comment.