diff --git a/mypy/checkexpr.py b/mypy/checkexpr.py index f1b8ebcaf54cd..d630f4d766200 100644 --- a/mypy/checkexpr.py +++ b/mypy/checkexpr.py @@ -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) diff --git a/mypy/test/data/check-dynamic-typing.test b/mypy/test/data/check-dynamic-typing.test index 4c65fc912bb9a..c58e1d57306c0 100644 --- a/mypy/test/data/check-dynamic-typing.test +++ b/mypy/test/data/check-dynamic-typing.test @@ -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] diff --git a/mypy/test/data/typexport-basic.test b/mypy/test/data/typexport-basic.test index 643fc2dab47d6..b284a35cdc1e2 100644 --- a/mypy/test/data/typexport-basic.test +++ b/mypy/test/data/typexport-basic.test @@ -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 @@ -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 @@ -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] @@ -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