Skip to content

Treat bare Callable as Callable[..., Any] #1505

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
May 8, 2016
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
5 changes: 5 additions & 0 deletions mypy/test/data/check-functions.test
Original file line number Diff line number Diff line change
Expand Up @@ -1531,6 +1531,11 @@ from typing import Callable, Any

def foo(f: Callable) -> bool:
return f()

def f1() -> bool:
return False

foo(f1)
[builtins fixtures/bool.py]

[case testFunctionNestedWithinWith]
Expand Down
5 changes: 3 additions & 2 deletions mypy/typeanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,13 @@ def visit_ellipsis_type(self, t: EllipsisType) -> Type:
def analyze_callable_type(self, t: UnboundType) -> Type:
fallback = self.builtin_type('builtins.function')
if len(t.args) == 0:
# Callable (bare)
# Callable (bare). Treat as Callable[..., Any].
return CallableType([AnyType(), AnyType()],
[nodes.ARG_STAR, nodes.ARG_STAR2],
[None, None],
ret_type=AnyType(),
fallback=fallback)
fallback=fallback,
is_ellipsis_args=True)
elif len(t.args) == 2:
ret_type = t.args[1].accept(self)
if isinstance(t.args[0], TypeList):
Expand Down