Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 1 addition & 1 deletion mypy/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ def visit_callable_type(self, template: CallableType) -> list[Constraint]:
arg_types=cactual.arg_types[prefix_len:],
arg_kinds=cactual.arg_kinds[prefix_len:],
arg_names=cactual.arg_names[prefix_len:],
ret_type=NoneType(),
ret_type=UninhabitedType(),
),
)
)
Expand Down
23 changes: 23 additions & 0 deletions test-data/unit/check-parameter-specification.test
Original file line number Diff line number Diff line change
Expand Up @@ -1296,3 +1296,26 @@ class C(Generic[P]):

reveal_type(bar(C(fn=foo, x=1))) # N: Revealed type is "__main__.C[[x: builtins.int]]"
[builtins fixtures/paramspec.pyi]

[case testParamSpecClassConstructor]
from typing import ParamSpec, Callable
Comment thread
VincentVanlaer marked this conversation as resolved.

P = ParamSpec("P")

class SomeClass:
def __init__(self, a: str) -> None:
pass

def func(t: Callable[P, SomeClass], val: Callable[P, SomeClass]) -> None:
pass

def constructor(a: str) -> SomeClass:
return SomeClass(a)

def wrong_constructor(a: bool) -> SomeClass:
return SomeClass("a")

func(SomeClass, constructor)
func(SomeClass, wrong_constructor) # E: Argument 1 to "func" has incompatible type "Type[SomeClass]"; expected "Callable[[VarArg(None), KwArg(None)], SomeClass]" \
# E: Argument 2 to "func" has incompatible type "Callable[[bool], SomeClass]"; expected "Callable[[VarArg(None), KwArg(None)], SomeClass]"
[builtins fixtures/paramspec.pyi]