Skip to content

Commit

Permalink
Suggest typing.Callable when using callable as type (#12204)
Browse files Browse the repository at this point in the history
  • Loading branch information
siiptuo authored Feb 17, 2022
1 parent 3158677 commit d02db50
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
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]

0 comments on commit d02db50

Please sign in to comment.