标签:kwargs pycharm docstring python 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 ...
如果我会在完成提示中得到类似的信息,那就太好了(很抱歉,我不得不删除图片):
>>自我,姓名,年龄,人脉
惠特快速Doku看起来像这样:
>无图像*
我真的很喜欢有全球班,有普通班的父母.这使得重用变得更加容易.因此,这是一个小片段示例:
class common():
PERSON_DETAILS = dict( name = ' ',
age = 1,
connection = [] )
与定义的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()
下面的图片(删除的图片)显示了我作为完成提示得到的信息(完全正确),但是从kwargs中推出一个变元列表将是很棒的(就像第一个示例一样):
>>自我,虚假
我知道定义和自动完成提示的文档字符串实现是有限的,但是也许有人知道以其他方式在PyCharm中获得我想要的东西.
解决方法:
According to the Epytext documentation,您将可以使用@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:
另外,@kwarg p:…和@kwparam p:…是同义词.
标签:kwargs,pycharm,docstring,python,epytext 来源: https://codeday.me/bug/20191028/1955756.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。