__init__中的Pycharm类型提示不起作用

时间:2017-03-22 14:35:40

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

我正在使用Python 2.7和PyCharm Community Edition 2016.3.2。我有以下代码片段:

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_nodeschild_nodes上时,推断的类型会显示为Any,而不是Dict[str, ChildNode]。我不明白为什么我在文档字符串中的输入在这种情况下不起作用。

1 个答案:

答案 0 :(得分:1)

替换

def weight_variable(shape,dtype=np.float32,partition_info=None): n = np.prod(shape) w = (np.random.randn(n) * np.sqrt(2./n)).astype(np.float32) return tf.Variable(w.reshape(shape),trainable=True)

dict[str: child_node.ChildNode]