Skip to content

Commit d02db50

Browse files
authored
Suggest typing.Callable when using callable as type (#12204)
1 parent 3158677 commit d02db50

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

mypy/typeanal.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,8 @@ def analyze_unbound_type_without_type_info(self, t: UnboundType, sym: SymbolTabl
494494
message = 'Function "{}" is not valid as a type'
495495
if name == 'builtins.any':
496496
notes.append('Perhaps you meant "typing.Any" instead of "any"?')
497+
elif name == 'builtins.callable':
498+
notes.append('Perhaps you meant "typing.Callable" instead of "callable"?')
497499
else:
498500
notes.append('Perhaps you need "Callable[...]" or a callback protocol?')
499501
elif isinstance(sym.node, MypyFile):

test-data/unit/check-functions.test

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2610,3 +2610,8 @@ reveal_type(foo()) # N: Revealed type is "None"
26102610
def a(b: any): pass # E: Function "builtins.any" is not valid as a type \
26112611
# N: Perhaps you meant "typing.Any" instead of "any"?
26122612
[builtins fixtures/any.pyi]
2613+
2614+
[case testCallableArgument]
2615+
def a(b: callable): pass # E: Function "builtins.callable" is not valid as a type \
2616+
# N: Perhaps you meant "typing.Callable" instead of "callable"?
2617+
[builtins fixtures/callable.pyi]

0 commit comments

Comments
 (0)