Skip to content

Commit c375009

Browse files
authored
Fix crash on prefixed paramspec with deferral (#14569)
Fixes #14565 The fix looks simple, looks like an obvious omission.
1 parent 90168b8 commit c375009

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
@@ -716,13 +716,13 @@ def name_with_suffix(self) -> str:
716716
return n
717717

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

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

727727
def serialize(self) -> JsonDict:
728728
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)