Message384285
`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. |
|
Date |
User |
Action |
Args |
2021-01-03 17:18:04 | uriyyo | set | recipients:
+ uriyyo, chaim422 |
2021-01-03 17:18:04 | uriyyo | set | messageid: <1609694284.85.0.734642051513.issue42812@roundup.psfhosted.org> |
2021-01-03 17:18:04 | uriyyo | link | issue42812 messages |
2021-01-03 17:18:04 | uriyyo | create | |
|