Skip to content

Commit 488548c

Browse files
committed
Merge branch 'pr/Akuli/12096' into paramspec-concatenate
2 parents 1cd8493 + 442ecca commit 488548c

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

mypy/subtypes.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,9 @@ def visit_instance(self, left: Instance) -> bool:
289289
if isinstance(tvar, TypeVarType):
290290
if not self.check_type_parameter(lefta, righta, tvar.variance):
291291
nominal = False
292+
elif isinstance(tvar, ParamSpecType):
293+
if not self.check_type_parameter(lefta, righta, COVARIANT):
294+
nominal = False
292295
else:
293296
if not self.check_type_parameter(lefta, righta, COVARIANT):
294297
nominal = False

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,3 +1026,26 @@ P = ParamSpec("P")
10261026

10271027
def x(f: Callable[Concatenate[int, Concatenate[int, P]], None]) -> None: ... # E: Nested Concatenates are invalid
10281028
[builtins fixtures/tuple.pyi]
1029+
1030+
[case testDecoratingClassesThatUseParamSpec]
1031+
from typing import Generic, TypeVar, Callable, Any
1032+
from typing_extensions import ParamSpec
1033+
1034+
_P = ParamSpec("_P")
1035+
_T = TypeVar("_T")
1036+
_F = TypeVar("_F", bound=Callable[..., Any])
1037+
1038+
def f(x: _F) -> _F: ...
1039+
1040+
@f # Should be ok
1041+
class OnlyParamSpec(Generic[_P]):
1042+
pass
1043+
1044+
@f # Should be ok
1045+
class MixedWithTypeVar1(Generic[_P, _T]):
1046+
pass
1047+
1048+
@f # Should be ok
1049+
class MixedWithTypeVar2(Generic[_T, _P]):
1050+
pass
1051+
[builtins fixtures/dict.pyi]

0 commit comments

Comments
 (0)