Skip to content
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

Fix inferring constraints from param spec callable against Any #11725

Merged
merged 1 commit into from Dec 15, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions mypy/constraints.py
Expand Up @@ -581,12 +581,12 @@ def visit_callable_type(self, template: CallableType) -> List[Constraint]:
if param_spec is None:
# FIX what if generic
res = self.infer_against_any(template.arg_types, self.actual)
res.extend(infer_constraints(template.ret_type, any_type, self.direction))
return res
else:
return [Constraint(param_spec.id,
SUBTYPE_OF,
callable_with_ellipsis(any_type, any_type, template.fallback))]
res = [Constraint(param_spec.id,
SUBTYPE_OF,
callable_with_ellipsis(any_type, any_type, template.fallback))]
res.extend(infer_constraints(template.ret_type, any_type, self.direction))
return res
elif isinstance(self.actual, Overloaded):
return self.infer_against_overloaded(self.actual, template)
elif isinstance(self.actual, TypeType):
Expand Down
28 changes: 28 additions & 0 deletions test-data/unit/check-parameter-specification.test
Expand Up @@ -378,3 +378,31 @@ class C(Generic[P, P2]):
def m4(self, x: int) -> None:
pass
[builtins fixtures/dict.pyi]

[case testParamSpecOverUnannotatedDecorator]
from typing import Callable, Iterator, TypeVar, ContextManager, Any
from typing_extensions import ParamSpec

from nonexistent import deco2 # type: ignore

T = TypeVar("T")
P = ParamSpec("P")
T_co = TypeVar("T_co", covariant=True)

class CM(ContextManager[T_co]):
def __call__(self, func: T) -> T: ...

def deco1(
func: Callable[P, Iterator[T]]) -> Callable[P, CM[T]]: ...

@deco1
@deco2
def f():
pass

reveal_type(f) # N: Revealed type is "def (*Any, **Any) -> __main__.CM[Any]"

with f() as x:
pass
[builtins fixtures/dict.pyi]
[typing fixtures/typing-full.pyi]