Consider the following code:
class A:
def __init__(self, foo=None):
pass
class B(A):
def __init__(self, bar=None, **kwargs):
super().__init__(**kwargs)
When I start typing B(, PyCharm helpfully shows bar in the autocomplete windows, quick doc, etc. However, it does not show foo.
I have resorted to making foo an explicit argument of class B, but this gets highly repetitive since I have a lot of such arguments. I would like to avoid doing so while still having PyCharm show me all the arguments.
How can I make PyCharm do this?
Short anwser is you can't. This is due to the fact that PyCharm does not not run your code while you type. Python is a dynamic language with multi inheritance, it would be difficult for IDE to check for all parameters in all base classes, especially due the fact that unlike in Java call to the base class __init__() function can be omitted.
Also note that this fragment:
class B(A):
def __init__(self, bar=None, **kwargs):
super().__init__(**kwargs)
Enforces that foo can only be passed as keyword argument not a positional one, while class A allows it to be passed as positional argument.
However, if typing is an issue i would suggest ctrl+O which is a shortcut to override. If you do it in an empty class it will create an __init__() method with arguments from the base class and a call to super. If the documentation is an issue just write a docstring for the method
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With