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
10 changes: 5 additions & 5 deletions mypy/constraints.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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]