Author uriyyo
Recipients chaim422, uriyyo
Date 2021-01-03.17:18:04
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1609694284.85.0.734642051513.issue42812@roundup.psfhosted.org>
In-reply-to
Content
`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.
History
Date User Action Args
2021-01-03 17:18:04uriyyosetrecipients: + uriyyo, chaim422
2021-01-03 17:18:04uriyyosetmessageid: <1609694284.85.0.734642051513.issue42812@roundup.psfhosted.org>
2021-01-03 17:18:04uriyyolinkissue42812 messages
2021-01-03 17:18:04uriyyocreate