【问题标题】:Pycharm type-hinting in __init__ does not work__init__ 中的 Pycharm 类型提示不起作用
【发布时间】:2017-08-14 17:57:50
【问题描述】:

我正在使用 Python 2.7 和 PyCharm 社区版 2016.3.2。我有以下 sn-p 代码:

class ParentNode(node.Node):
    """ParentNode is a subclass of Node but also takes an additional child_nodes parameter.
    @type child_nodes: dict[str: child_node.ChildNode]
    """
    def __init__(self, name, node_type, FSPs, CTT_distributions, TMR_distributions,
                 prob_on_convoy, rep_rndstrm, child_nodes):
        """ParentNode is a subclass of Node but also takes an additional child_nodes parameter.
        @type child_nodes: dict[str: child_node.ChildNode]
        """
        node.Node.__init__(self, name, node_type, FSPs, CTT_distributions, TMR_distributions,
                           prob_on_convoy, rep_rndstrm)
        self.network_status = 'parent'
        self.child_nodes = child_nodes

问题是当我将鼠标悬停在self.child_nodes 或child_nodes 上时,推断的类型显示为Any 而不是Dict[str, ChildNode]。我不明白为什么我在文档字符串中的类型提示在这种情况下不起作用。

【问题讨论】:

    标签: python python-2.7 pycharm code-completion type-hinting


    【解决方案1】:

    替换

    dict[str: child_node.ChildNode]

    与

    dict[str, child_node.ChildNode]

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-26
      • 2013-07-21
      • 2018-03-31
      • 2015-11-23
      • 2017-11-30
      • 2016-03-22
      • 1970-01-01
      • 2022-01-24
      相关资源
      最近更新 更多