It is common pattern in Python extend functions and use **kwargs to pass all keyword arguments to the extended function.
i.e. take
class A:
def bar(self, *, a: int, b: str, c: float) -> str:
return f"{a}_{b}_{c}"
class B:
def bar(self, **kwargs):
return f"NEW_{super().bar(**kwargs)}"
def base_function(*, a: int, b: str, c: float) -> str:
return f"{a}_{b}_{c}"
def extension(**kwargs):
return f"NEW_{super().bar(**kwargs)}"
Now calling extension(no_existing="a") would lead to a TypeError, that could be detected by static type checkers.
How can I annotate my extension in order to detect this problem before I run my code?
This annotation would be also helpful for IDE's to give me the correct suggestions for extension.