Skip to content

Commit e09dc31

Browse files
rwbartonGuido van Rossum
authored and
Guido van Rossum
committed
Treat bare Callable as Callable[..., Any] (#1505)
The old definition of Callable was the type of a function defined as def f(*args: Any, **kwargs: Any) -> Any: ... which is not the form of a general function, only one that can accept an arbitrary number of arguments. Fixes #1501.
1 parent e843a34 commit e09dc31

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

mypy/test/data/check-functions.test

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,6 +1531,11 @@ from typing import Callable, Any
15311531

15321532
def foo(f: Callable) -> bool:
15331533
return f()
1534+
1535+
def f1() -> bool:
1536+
return False
1537+
1538+
foo(f1)
15341539
[builtins fixtures/bool.py]
15351540

15361541
[case testFunctionNestedWithinWith]

mypy/typeanal.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,13 @@ def visit_ellipsis_type(self, t: EllipsisType) -> Type:
210210
def analyze_callable_type(self, t: UnboundType) -> Type:
211211
fallback = self.builtin_type('builtins.function')
212212
if len(t.args) == 0:
213-
# Callable (bare)
213+
# Callable (bare). Treat as Callable[..., Any].
214214
return CallableType([AnyType(), AnyType()],
215215
[nodes.ARG_STAR, nodes.ARG_STAR2],
216216
[None, None],
217217
ret_type=AnyType(),
218-
fallback=fallback)
218+
fallback=fallback,
219+
is_ellipsis_args=True)
219220
elif len(t.args) == 2:
220221
ret_type = t.args[1].accept(self)
221222
if isinstance(t.args[0], TypeList):

0 commit comments

Comments
 (0)