首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >__init__中的Pycharm类型提示不起作用

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

Stack Overflow用户
提问于 2017-03-22 14:35:39
回答 1查看 440关注 0票数 0

我正在使用Python2.7和PyCharm Community 2016.3.2。我有以下代码片段:

代码语言:javascript
复制
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]。我不明白为什么我在docstring中的类型提示在这种情况下不起作用。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-03-24 16:35:42

替换

dict[str: child_node.ChildNode]

使用

dict[str, child_node.ChildNode]

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42954718

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档