【问题标题】:Python 2 type code-completion in JetBrains?JetBrains 中的 Python 2 类型代码完成?
【发布时间】:2019-01-16 14:37:05
【问题描述】:
class A:
  """
  A

  Attributes:
      type (int): type field
      required ([str]): required field
  """

  type = None  # type: str
  required = None  # type: [str]

  def __init__(self, type, required):
    """
    The constructor for A class.

    Parameters:
       type (int): type field
       required ([str]): required field
    """

    self.type = type
    self.required = required

适用于字符串:

但不列出:

【问题讨论】:

    标签: python python-2.7 pycharm python-sphinx docstring


    【解决方案1】:

    你想要的答案是# type: list[str]

    【讨论】:

      【解决方案2】:

      我相当确定这是因为,在 python 中,您声明了一个 list 就像 blah = [] 一样;您也不需要提供数据类型。

      所以将required ([str]): required field 更改为required (list): required field,它应该可以工作。

      【讨论】:

      • 嗯,这行得通。是的,我猜 Python 列表都支持多种类型。尽管如此,将其限制为单一/联合类型还是有用的,这样A().required[0]. 将解析相关的方法/属性。
      • @AT 是的,那将非常有用。另外,如果它有效,那么你能接受这个答案吗? :)
      • 我投了赞成票。 - 希望在接受之前等待键入列表值问题的答案得到解决。 - 现在要尝试几种不同的文档语法。
      • @AT 等等,这是什么问题??我以为您只是想修复 self.required 变量的类型...
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-02-14
      • 1970-01-01
      • 1970-01-01
      • 2011-04-20
      • 2011-10-12
      • 2011-10-15
      • 2015-01-07
      相关资源
      最近更新 更多