3

In python when creating a subclass we often pass necessary arguments to the superclass using the construction super().__init__(*args, **kwargs) like so:

class B(A):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

However, if I do this I will lose all argument hints and docstrings from superclass (A in this case) and will be left with *args and **kwargs.

When using decorators a similar problem is solved via functools.wraps. My question is is there similarly elegant solution to the situation with __init__ of a subclass? Maybe using functools.update_wrapper?

  • Asked in https://github.com/python/typing/discussions/1079#discussion-3878409 also. I'm surprised that this doesn't have a good solution from what I can see. – pelson Jun 02 '22 at 06:22
  • Also, possibly a dupe of https://stackoverflow.com/questions/14626279/inheritance-best-practice-args-kwargs-or-explicitly-specifying-parameters. – pelson Jun 02 '22 at 06:25

0 Answers0