mypy fails to consider the case where *args or **kwds contains zero elements · Issue #4001 · python/mypy (original) (raw)

Minimum repro:

This gives the following errors:

Too many arguments for "object"
Too many arguments for "object"

I think this is valid code and should pass the type check.

Context: I encountered this when I tried to write a multiple inheritance model where each class is passing arguments to the next parent (in terms of MRO):

class A(object): def init(self, a_arg: int, **kwds: Any) -> None: super().init(**kwds)

class B(object): def init(self, b_arg: int, **kwds: Any) -> None: super().init(**kwds)

class C(A, B): def init(self, c_arg: int, **kwds: Any) -> None: super().init(**kwds)

C(a_arg=1, b_arg=2, c_arg=3)

This code runs fine but gives three type errors saying:

Too many arguments for "init" of "object"

You cannot expect a static derivation order due to the dynamic nature of MRO, so it's hard to avoid this error from happening.