2017-03-22 2 views
0

Ich benutze Python 2.7 und PyCharm Community Edition 2016.3.2. Ich habe den folgenden Code-Snippet:Pycharm Typ-Hinting in __init__ funktioniert nicht

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 

Das Problem ist, dass, wenn ich über self.child_nodes oder child_nodes schweben, der abgeleitete Typ wird als Any statt Dict[str, ChildNode] gezeigt. Ich verstehe nicht, warum die Schreibschrift, die ich im Docstring habe, in diesem Fall nicht funktioniert.

Antwort

1

ersetzen

dict[str: child_node.ChildNode]

mit

dict[str, child_node.ChildNode]

Verwandte Themen