Skip to content

Commit

Permalink
[1.0 backport] Fix crash on prefixed paramspec with deferral (#14569) (
Browse files Browse the repository at this point in the history
…#14586)

Fixes #14565

The fix looks simple, looks like an obvious omission.

Co-authored-by: Ivan Levkivskyi <levkivskyi@gmail.com>
  • Loading branch information
ilinum and ilevkivskyi committed Feb 2, 2023
1 parent 61d6cad commit 319980b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions mypy/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,13 +713,13 @@ def name_with_suffix(self) -> str:
return n

def __hash__(self) -> int:
return hash((self.id, self.flavor))
return hash((self.id, self.flavor, self.prefix))

def __eq__(self, other: object) -> bool:
if not isinstance(other, ParamSpecType):
return NotImplemented
# Upper bound can be ignored, since it's determined by flavor.
return self.id == other.id and self.flavor == other.flavor
return self.id == other.id and self.flavor == other.flavor and self.prefix == other.prefix

def serialize(self) -> JsonDict:
assert not self.id.is_meta_var()
Expand Down
15 changes: 15 additions & 0 deletions test-data/unit/check-parameter-specification.test
Original file line number Diff line number Diff line change
Expand Up @@ -1456,3 +1456,18 @@ class C(Generic[T]): ...
C[Callable[P, int]]() # E: The first argument to Callable must be a list of types, parameter specification, or "..." \
# N: See https://mypy.readthedocs.io/en/stable/kinds_of_types.html#callable-types-and-lambdas
[builtins fixtures/paramspec.pyi]

[case testConcatDeferralNoCrash]
from typing import Callable, TypeVar
from typing_extensions import Concatenate, ParamSpec

P = ParamSpec("P")
T = TypeVar("T", bound="Defer")

Alias = Callable[P, bool]
Concat = Alias[Concatenate[T, P]]

def test(f: Concat[T, ...]) -> None: ...

class Defer: ...
[builtins fixtures/paramspec.pyi]

0 comments on commit 319980b

Please sign in to comment.