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