【问题标题】:Type hints with forward references [duplicate]带有前向引用的类型提示[重复]
【发布时间】:2022-01-17 23:03:20
【问题描述】:

我正在实现这样的树

class A:
    children: List[A]

但是在 PyCharm 中我得到 Unresolved reference 'A' 。有解决办法吗?

【问题讨论】:

    标签: python python-3.x pycharm annotations


    【解决方案1】:

    你可以使用字符串:

    class A:
        children: List['A']
    

    这是Forward references的文档

    【讨论】:

      猜你喜欢
      • 2019-09-28
      • 2016-06-17
      • 2016-07-04
      • 2020-10-27
      • 2020-01-26
      • 2018-05-26
      • 2016-07-11
      • 2020-12-09
      相关资源
      最近更新 更多