Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions mypy/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,10 @@ def visit_unpack_type(self, template: UnpackType) -> List[Constraint]:
raise NotImplementedError

def visit_parameters(self, template: Parameters) -> List[Constraint]:
# constraining Any against C[P] turns into infer_against_any([P], Any)
# ... which seems like the only case this can happen. Better to fail loudly.
if isinstance(self.actual, AnyType):
return self.infer_against_any(template.arg_types, self.actual)
raise RuntimeError("Parameters cannot be constrained to")

# Non-leaf types
Expand Down
14 changes: 14 additions & 0 deletions test-data/unit/check-parameter-specification.test
Original file line number Diff line number Diff line change
Expand Up @@ -1026,3 +1026,17 @@ P = ParamSpec("P")

def x(f: Callable[Concatenate[int, Concatenate[int, P]], None]) -> None: ... # E: Nested Concatenates are invalid
[builtins fixtures/tuple.pyi]

[case testPropagatedAnyConstraintsAreOK]
from typing import Any, Callable, Generic, TypeVar
from typing_extensions import ParamSpec

T = TypeVar("T")
P = ParamSpec("P")

def callback(func: Callable[[Any], Any]) -> None: ...
class Job(Generic[P]): ...

@callback
def run_job(job: Job[...]) -> T: ...
[builtins fixtures/tuple.pyi]