Mag*_*Sec 6 python docstring pycharm keyword-argument epytext
是否可以获得 kwargs 的额外提示,这将为您提供预定义的可能关键字参数的示例?也许epytext不支持它?
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 ...
Run Code Online (Sandbox Code Playgroud)
如果我能在完成提示中得到这样的东西(对不起,我不得不删除图片),那就太好了:
一个 Quick Doku 看起来像这样:
我真的很喜欢将通用课程作为父母的全球课程。这使得重用更容易。所以这是一个小片段示例:
class common():
PERSON_DETAILS = dict( name = ' ',
age = 1,
connection = [] )
Run Code Online (Sandbox Code Playgroud)
使用稍微不同的 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()
Run Code Online (Sandbox Code Playgroud)
以下(已删除图片)显示了我作为完成提示获得的内容(完全正确),但是如果从 kwargs 中推出参数列表(如第一个示例中所示)会很棒:
我知道定义和自动完成提示的 docstring 实现是有限的,但也许有人知道在 PyCharm 中获得我想要的东西的不同方法。
小智 4
根据 Epytext 文档,您将能够通过使用来实现这一点@keyword。
@param字段应该用于记录任何显式参数(包括关键字参数)。@keyword字段只能用于非显式关键字参数:
另外,@kwarg p: ...和@kwparam p: ...是同义词。