我更喜欢在我声明参数的同一行记录每个参数(根据需要)以便应用DRY
如果我有这样的代码:
def foo(
flab_nickers, # a series of under garments to process
has_polka_dots=False,
needs_pressing=False # Whether the list of garments should all be pressed
):
...
Run Code Online (Sandbox Code Playgroud)
如何避免重复doc字符串中的参数并保留参数说明?
我想避免:
def foo(
flab_nickers, # a series of under garments to process
has_polka_dots=False,
needs_pressing=False # Whether the list of garments should all be pressed
):
'''Foo does whatever.
* flab_nickers - a series of under garments to process
* needs_pressing - Whether the list of garments should all be pressed.
[Default …Run Code Online (Sandbox Code Playgroud) 我使用了很多Pycharm docstring类型解析器来指定方法参数和返回的类型,属性或实例变量.如果它几乎一直在工作,我有一个关于告诉PyCharm我有一个函数或类作为参数/属性/ ...的问题.
这是一个简短的例子:
class Bar:
def __init__(self, bar):
"""
:type bar: str
"""
print bar
class Foo:
"""
:type my_class: Bar.__class__
"""
def __init__(self, cinstance=Bar):
"""
:type cinstance: Bar.__class__
"""
self.my_class = cinstance
def run(self):
# it should print an unexpected type warning, but it doesn't.
self.my_class(2)
Run Code Online (Sandbox Code Playgroud)
如果我只是把Bar而不是Bar.__class__,当然PyCharm告诉我,Bar不能打电话.那么如何告诉他我正在给他上课?
请注意,对于@classmethod装饰器,PyCharm没有任何问题可以理解我们正在谈论的是类而不是实例.
以下是我的尝试:


