Skip to content

Improve error message for an invalid callable type #4213

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
Nov 15, 2017
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: 1 addition & 1 deletion mypy/typeanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ def analyze_callable_type(self, t: UnboundType) -> Type:
self.fail('The first argument to Callable must be a list of types or "..."', t)
return AnyType(TypeOfAny.from_error)
else:
self.fail('Invalid function type', t)
self.fail('Please use "Callable[[<parameters>], <return type>]" or "Callable"', t)
return AnyType(TypeOfAny.from_error)
assert isinstance(ret, CallableType)
return ret.accept(self)
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/check-generics.test
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ class Node(Generic[T]):
def __init__(self, x: T) -> None:
...

BadC = Callable[T] # E: Invalid function type
BadC = Callable[T] # E: Please use "Callable[[<parameters>], <return type>]" or "Callable"

C = Callable[..., T]
C2 = Callable[[T, T], Node[T]]
Expand Down
4 changes: 2 additions & 2 deletions test-data/unit/semanal-errors.test
Original file line number Diff line number Diff line change
Expand Up @@ -819,8 +819,8 @@ y = None # type: Callable[int]
z = None # type: Callable[int, int, int]
[out]
main:2: error: The first argument to Callable must be a list of types or "..."
main:3: error: Invalid function type
main:4: error: Invalid function type
main:3: error: Please use "Callable[[<parameters>], <return type>]" or "Callable"
main:4: error: Please use "Callable[[<parameters>], <return type>]" or "Callable"

[case testAbstractGlobalFunction]
import typing
Expand Down