I looks like mypy drops all keyword arguments of the __call__ function of a class and recognises only positional arguments.
Code example:
class Formatter:
def __call__(
self,
message: str,
*, # same behaviour with and without
bold: bool = False,
) -> str:
if bold:
message = f"** {message} **"
return message
formatter = Formatter()
print(formatter("test", bold=True))
Mypy error:
test.py:13: error: Unexpected keyword argument "bold" for "__call__" of "Formatter"
Yes, confirmed and seems specific to __call__.
Adding __call__ to MAGIC_METHODS_ALLOWING_KWARGS in sharedparse.py fixes the issue. I wonder why it is not there now, do older versions of Python not allow kwargs in __call__?
I assume it was just an oversight. Do the tests pass with that one change? Then it's worth adding a test specifically for __call__ with kwargs and push a PR.
OK, here is the PR https://github.com/python/mypy/pull/3245
Most helpful comment
Yes, confirmed and seems specific to
__call__.