diff --git a/mypy/constraints.py b/mypy/constraints.py index 9a6d87575bdc..4d9527733375 100644 --- a/mypy/constraints.py +++ b/mypy/constraints.py @@ -571,6 +571,8 @@ def visit_instance(self, template: Instance) -> List[Constraint]: if not actual.values: return infer_constraints(template, actual.upper_bound, self.direction) return [] + elif isinstance(actual, ParamSpecType): + return infer_constraints(template, actual.upper_bound, self.direction) else: return [] diff --git a/test-data/unit/check-parameter-specification.test b/test-data/unit/check-parameter-specification.test index 4dae32978263..682ce93cb7ea 100644 --- a/test-data/unit/check-parameter-specification.test +++ b/test-data/unit/check-parameter-specification.test @@ -1066,16 +1066,21 @@ def run_job(job: Job[...]) -> T: ... [builtins fixtures/tuple.pyi] [case testTupleAndDictOperationsOnParamSpecArgsAndKwargs] -from typing import Callable +from typing import Callable, Iterator, Iterable, TypeVar, Tuple from typing_extensions import ParamSpec P = ParamSpec('P') +T = TypeVar('T') +def enumerate(x: Iterable[T]) -> Iterator[Tuple[int, T]]: ... def func(callback: Callable[P, str]) -> Callable[P, str]: def inner(*args: P.args, **kwargs: P.kwargs) -> str: reveal_type(args[5]) # N: Revealed type is "builtins.object" for a in args: reveal_type(a) # N: Revealed type is "builtins.object" + for idx, a in enumerate(args): + reveal_type(idx) # N: Revealed type is "builtins.int" + reveal_type(a) # N: Revealed type is "builtins.object" b = 'foo' in args reveal_type(b) # N: Revealed type is "builtins.bool" reveal_type(args.count(42)) # N: Revealed type is "builtins.int"