Skip to content

Commit 319980b

Browse files
ilinumilevkivskyi
andauthored
[1.0 backport] Fix crash on prefixed paramspec with deferral (#14569) (#14586)
Fixes #14565 The fix looks simple, looks like an obvious omission. Co-authored-by: Ivan Levkivskyi <levkivskyi@gmail.com>
1 parent 61d6cad commit 319980b

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

mypy/types.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -713,13 +713,13 @@ def name_with_suffix(self) -> str:
713713
return n
714714

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

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

724724
def serialize(self) -> JsonDict:
725725
assert not self.id.is_meta_var()

test-data/unit/check-parameter-specification.test

+15
Original file line numberDiff line numberDiff line change
@@ -1456,3 +1456,18 @@ class C(Generic[T]): ...
14561456
C[Callable[P, int]]() # E: The first argument to Callable must be a list of types, parameter specification, or "..." \
14571457
# N: See https://mypy.readthedocs.io/en/stable/kinds_of_types.html#callable-types-and-lambdas
14581458
[builtins fixtures/paramspec.pyi]
1459+
1460+
[case testConcatDeferralNoCrash]
1461+
from typing import Callable, TypeVar
1462+
from typing_extensions import Concatenate, ParamSpec
1463+
1464+
P = ParamSpec("P")
1465+
T = TypeVar("T", bound="Defer")
1466+
1467+
Alias = Callable[P, bool]
1468+
Concat = Alias[Concatenate[T, P]]
1469+
1470+
def test(f: Concat[T, ...]) -> None: ...
1471+
1472+
class Defer: ...
1473+
[builtins fixtures/paramspec.pyi]

0 commit comments

Comments
 (0)