Skip to content

Fix bug in constraints solver regarding ParamSpec upper bounds #12938

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 4, 2022
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
2 changes: 2 additions & 0 deletions mypy/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 []

Expand Down
7 changes: 6 additions & 1 deletion test-data/unit/check-parameter-specification.test
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down