Skip to content

Suggest typing.Callable when using callable as type #12204

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
Feb 17, 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/typeanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,8 @@ def analyze_unbound_type_without_type_info(self, t: UnboundType, sym: SymbolTabl
message = 'Function "{}" is not valid as a type'
if name == 'builtins.any':
notes.append('Perhaps you meant "typing.Any" instead of "any"?')
elif name == 'builtins.callable':
notes.append('Perhaps you meant "typing.Callable" instead of "callable"?')
else:
notes.append('Perhaps you need "Callable[...]" or a callback protocol?')
elif isinstance(sym.node, MypyFile):
Expand Down
5 changes: 5 additions & 0 deletions test-data/unit/check-functions.test
Original file line number Diff line number Diff line change
Expand Up @@ -2610,3 +2610,8 @@ reveal_type(foo()) # N: Revealed type is "None"
def a(b: any): pass # E: Function "builtins.any" is not valid as a type \
# N: Perhaps you meant "typing.Any" instead of "any"?
[builtins fixtures/any.pyi]

[case testCallableArgument]
def a(b: callable): pass # E: Function "builtins.callable" is not valid as a type \
# N: Perhaps you meant "typing.Callable" instead of "callable"?
[builtins fixtures/callable.pyi]