Yurii Karabas <[email protected]> added the comment:
`mypy` will produce an error on such code:
```
class Parent:
def foo(self, **kwargs):
"""Argument names of foo vary depending on the child class."""
class Child(Parent):
@overload
def foo(self, a, b):
pass
def foo(self, **kwargs):
return super().foo(**kwargs)
```
Result
```
temp.py:10: error: Single overload definition, multiple required
temp.py:10: error: Signature of "foo" incompatible with supertype "Parent"
Found 2 errors in 1 file (checked 1 source file)
```
In case if you want to add an overload for method I would recommend to use such
pattern:
```
class Parent:
def foo(self, **kwargs):
"""Argument names of foo vary depending on the child class."""
class Child(Parent):
@overload
def foo(self, a, b):
pass
@overload
def foo(self, **kwargs):
pass
def foo(self, **kwargs):
return super().foo(**kwargs)
```
So signature of `foo` will still match to parent class signature, but it will
also have an overloaded variant.
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue42812>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com