[Python-ideas] Keyword for direct pass through of kwargs to super
mial.lohmann+pythonml at gmail.com
Fri May 25 20:06:40 EDT 2018
***Disclaimer: I am relatively new to Python***
I propose to add some mechanism that can automatically collect everything
what would normally be collected by **kwargs in the __init__ method and
directly pass it through to the super().__init__ call without being
accessible in the __init__ itself. This way the autocompletion/docstring
generation could safely ignore this argument which before would have showed
up as **kwargs.
I believe that this could greatly enhance the readability of automated
documentation and especially the autocomplete of an IDE.
I would like something like this to work:
@pass_through_kwargs # like this? Or maybe __init__(self,
def __init__(self, a_value):
super().__init__() # <- realize that nothing is passed in here
def __init__(self, some_value):
class MyClass(A, B):
Where the autocomplete of `A(` shows me just `A(a_value)`. The
pass_through_kwargs can safely be ignored, since it is not "a real input"
of A. It is automatically merged with the parameters of the `super(A,
self).__init__()` call. How exactly this should be done would have to be
discussed in more detail (I guess the actual values should probably
override the passed through ones).
With the current python version the code would have looked like
def __init__(self, a_value, **kwargs):
But the user could have had the false impression that additional kwargs
could be given when instantiating A. Obviously they are purely there for
getting the init in the MRO working with multiple inheritance.
One could also add something like pass_through_args as well but the
usability of that is probably much more limited.
Could this even work in theory? I guess it might be quite tricky since
`super().__init__` doesn't even have to be called. If that would be the
case: should it be called automatically if pass_through_kwargs were given
after the init is done?
By the way: Thank you all for this amazing language!
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas