Skip to content

Commit 4a4c415

Browse files
committed
Skip arg count checks for dynamic functions. (#1433)
1 parent 490a8e6 commit 4a4c415

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

mypy/checkexpr.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,7 @@ def visit_call_expr(self, e: CallExpr) -> Type:
132132
# It's really a special form that only looks like a call.
133133
return self.accept(e.analyzed, self.chk.type_context[-1])
134134
self.try_infer_partial_type(e)
135-
self.accept(e.callee)
136-
# Access callee type directly, since accept may return the Any type
137-
# even if the type is known (in a dynamically typed function). This
138-
# way we get a more precise callee in dynamically typed functions.
139-
callee_type = self.chk.type_map[e.callee]
135+
callee_type = self.accept(e.callee)
140136
if (self.chk.disallow_untyped_calls and
141137
self.chk.typing_mode_full() and
142138
isinstance(callee_type, CallableType)

mypy/test/data/check-dynamic-typing.test

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,3 +655,25 @@ class A(B):
655655
x()
656656
[out]
657657
main: note: In class "A":
658+
659+
660+
-- Don't complain about too few/many arguments in dynamic functions
661+
-- ----------------------------------------------------------------
662+
663+
[case testTooManyArgsInDynamic]
664+
def f() -> None: pass
665+
def g():
666+
f(1) # Silent
667+
[out]
668+
669+
[case testTooFewArgsInDynamic]
670+
def f(a: int) -> None: pass
671+
def g():
672+
f() # Silent
673+
[out]
674+
675+
[case testJustRightInDynamic]
676+
def f(a: int) -> None: pass
677+
def g():
678+
f('') # Silent
679+
[out]

mypy/test/data/typexport-basic.test

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ def f():
510510
def g(a: object) -> object: pass
511511
o = None # type: object
512512
[out]
513-
CallExpr(3) : builtins.object
513+
CallExpr(3) : Any
514514
NameExpr(3) : def (a: builtins.object) -> builtins.object
515515
NameExpr(3) : builtins.object
516516

@@ -549,8 +549,8 @@ def f():
549549
A()
550550
class A(Generic[T]): pass
551551
[out]
552-
CallExpr(4) : A[Any]
553-
NameExpr(4) : def () -> A[Any]
552+
CallExpr(4) : Any
553+
NameExpr(4) : def [T] () -> A[T`-1]
554554

555555
[case testGenericCallInDynamicallyTypedFunction2]
556556
from typing import TypeVar, Generic
@@ -560,8 +560,8 @@ def f():
560560
class A(Generic[T]):
561561
def __init__(self, x: T) -> None: pass
562562
[out]
563-
CallExpr(4) : A[Any]
564-
NameExpr(4) : def (x: Any) -> A[Any]
563+
CallExpr(4) : Any
564+
NameExpr(4) : def [T] (x: T`-1) -> A[T`-1]
565565
NameExpr(4) : def () -> Any
566566

567567
[case testGenericCallInDynamicallyTypedFunction3]
@@ -572,7 +572,7 @@ def f():
572572
def g(x: t) -> t: pass
573573
[out]
574574
CallExpr(4) : Any
575-
NameExpr(4) : def (x: Any) -> Any
575+
NameExpr(4) : def [t] (x: t`-1) -> t`-1
576576

577577

578578
-- Generic types and type inference

0 commit comments

Comments
 (0)