[issue42812] @overload-ing method of parent class without actual implementation

Yurii Karabas report at bugs.python.org
Sun Jan 3 12:55:40 EST 2021


Yurii Karabas <1998uriyyo at gmail.com> added the comment:

> What is better?

Sorry, I can't answer this question.

I am a regular python user and I just tried to help with your issue.

I believe we should wait for someone from core team to answer this question.


> In your example, does Child foo call Parent foo? Because the intent is to use the parent's foo method.

Sorry, I made a mistake, it definitely should call a parent method. A correct example will look like this:
```
class Parent:
    def foo(self, **kwargs):
        """Argument names of foo vary depending on the child class."""


class Child(Parent):
    def foo(self, a, b):
        super().foo(a=a, b=b)
```

But, the example above require more code to write, so a better option will be:
```
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)
```

I am not sure is it the perfect solution to solve your issue.

Let's wait for someone from core team, so we can hear their opinion.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42812>
_______________________________________


More information about the Python-bugs-list mailing list