Pycharm ** kwargs自动完成

Tar*_*nko 6 python pycharm python-3.x

嗨,我正在尝试使用** kwargs使pycharm的自动完成功能。为此,我使用epytext语法编写了一个doc字符串,该字符串可以用声明关键字参数,@keyword p:但是不起作用。

例

有人知道解决方法吗?谢谢。

PS我在PyCharm设置中更改了文档字符串格式。

ntr*_*bng -1

如果关键字参数提前已知(并且您需要文档字符串来解释它们),那么它们应该在函数参数中显式列出。@param然后可以用正常的&语法来描述每一个@type@keywords用于描述开发时未知的其余关键字参数。

例如:

class SomeClass:
  def __init__(self, some_kw=None, some_kw_1=None, **other_kwargs):
    """
    @param some_kw: A known-at-dev-time keyword argument
    @type some_kw: str
    @param some_kw_1: Another known-at-dev-time keyword argument
    @type some_kw_1: str
    @keyword other_kwargs: More kwargs that will be set on the instance
    """
    self.some_kw = some_kw
    self.some_kw_1 = some_kw_1
    for k, v in other_kwargs:
        setattr(self, k, v)

an_instance = SomeClass(some_kw="hello", other_kw="world")
print an_instance.some_kw
print an_instance.some_kw_1
print an_instance.other_kw
Run Code Online (Sandbox Code Playgroud)

输出

> "hello"
> None
> "world"
Run Code Online (Sandbox Code Playgroud)

  • 重点是不要让它们存在,而是让 PyC​​harm 向您推荐它们。 (3认同)