Is is possible to get an additional hint for kwargs, which will give you examples of predefined possible keyword arguments? Maybe epytext is not supporting it?
class Person():
def __init__(self, **kwargs):
"""
@param name: Name
@type name: str
@param age: Age
@type age: int
@param connections: Connections to other persons
@type connections: [Person]
.
.
. # I know this is not working
"""
self.name = kwargs[name] if name in kwargs
self.age = kwargs[age] if age in kwargs
# and so on ...
Would be great if I'll get something like this in the completion hint (sorry I had to remove the pictures):
Whith a Quick Doku looking like this:
I really like to have global classes with common classes as parents. That makes it much easier for reuse. So here is a little snippet example:
class common():
PERSON_DETAILS = dict( name = ' ',
age = 1,
connection = [] )
With a bit different defined class of Person:
class Person(common):
def setDetail(self, **kwargs):
"""
Set some detail information about the person.
"""
argErrors = []
for arg, value in kwargs.iteritems():
if arg in self.PERSON_DETAILS:
if type(value)==type(self.PERSON_DETAILS[arg]):
self.doSomething() # I don't want to go deeper here
else:
raise ValueError("setDetails(%s) the type of '%s' needs to be %s, %s found" % (arg,arg,type(self.PERSON_DETAILS[arg]),type(value)))
else:
raise TypeError("setDetails() got an unexpected keyword argument '%s'" %arg )
person = Person()
person.setDetails()
The following (picture removed) shows what I get as completion hint (which is totally right), but it would be great to have a rolled out argument list from kwargs (like in the first example):
I know that the docstring implementation for definitions and auto completion hints are limited, but maybe someone knows a different way to get what I want in PyCharm.
Place the caret somewhere within the function you want to document. Press Alt+Enter to show the available intention actions. PyCharm generates documentation comment stub according to docstring format, selected in the Python Integrated Tools page.
Press Ctrl+Alt+S and go to Editor | General |Smart Keys. Select the Insert type placeholders checkbox in the Smart Keys page of the editor settings. Place the caret at the function name, and press Alt+Enter . In the list of intention actions that opens, choose Insert documentation string stub.
Declaring Docstrings: The docstrings are declared using ”'triple single quotes”' or “””triple double quotes””” just below the class, method or function declaration. All functions should have a docstring.
kwargs. get() retrieves a keyword argument passed to a function. The first argument is the keyword and the second is the default value if there was no argument provided for the keyword.
According to the Epytext documentation, you will be able to achieve this by using @keyword
.
@param
fields should be used to document any explicit parameter (including the keyword parameter).@keyword
fields should only be used for non-explicit keyword parameters:
Also, @kwarg p: ...
and @kwparam p: ...
are synonyms.
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