Skip to content

Skip arg count checks for dynamic functions. #1433

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 4 commits into from
Apr 25, 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
6 changes: 1 addition & 5 deletions mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,7 @@ def visit_call_expr(self, e: CallExpr) -> Type:
# It's really a special form that only looks like a call.
return self.accept(e.analyzed, self.chk.type_context[-1])
self.try_infer_partial_type(e)
self.accept(e.callee)
# Access callee type directly, since accept may return the Any type
# even if the type is known (in a dynamically typed function). This
# way we get a more precise callee in dynamically typed functions.
callee_type = self.chk.type_map[e.callee]
callee_type = self.accept(e.callee)
if (self.chk.disallow_untyped_calls and
self.chk.typing_mode_full() and
isinstance(callee_type, CallableType)
Expand Down
22 changes: 22 additions & 0 deletions mypy/test/data/check-dynamic-typing.test
Original file line number Diff line number Diff line change
Expand Up @@ -655,3 +655,25 @@ class A(B):
x()
[out]
main: note: In class "A":


-- Don't complain about too few/many arguments in dynamic functions
-- ----------------------------------------------------------------

[case testTooManyArgsInDynamic]
def f() -> None: pass
def g():
f(1) # Silent
[out]

[case testTooFewArgsInDynamic]
def f(a: int) -> None: pass
def g():
f() # Silent
[out]

[case testJustRightInDynamic]
def f(a: int) -> None: pass
def g():
f('') # Silent
[out]
12 changes: 6 additions & 6 deletions mypy/test/data/typexport-basic.test
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ def f():
def g(a: object) -> object: pass
o = None # type: object
[out]
CallExpr(3) : builtins.object
CallExpr(3) : Any
NameExpr(3) : def (a: builtins.object) -> builtins.object
NameExpr(3) : builtins.object

Expand Down Expand Up @@ -549,8 +549,8 @@ def f():
A()
class A(Generic[T]): pass
[out]
CallExpr(4) : A[Any]
NameExpr(4) : def () -> A[Any]
CallExpr(4) : Any
NameExpr(4) : def [T] () -> A[T`-1]

[case testGenericCallInDynamicallyTypedFunction2]
from typing import TypeVar, Generic
Expand All @@ -560,8 +560,8 @@ def f():
class A(Generic[T]):
def __init__(self, x: T) -> None: pass
[out]
CallExpr(4) : A[Any]
NameExpr(4) : def (x: Any) -> A[Any]
CallExpr(4) : Any
NameExpr(4) : def [T] (x: T`-1) -> A[T`-1]
NameExpr(4) : def () -> Any

[case testGenericCallInDynamicallyTypedFunction3]
Expand All @@ -572,7 +572,7 @@ def f():
def g(x: t) -> t: pass
[out]
CallExpr(4) : Any
NameExpr(4) : def (x: Any) -> Any
NameExpr(4) : def [t] (x: t`-1) -> t`-1


-- Generic types and type inference
Expand Down