【发布时间】:2022-12-05 07:23:13
【问题描述】:
在我的项目中,我使用的是Fava。 Fava,正在使用Beancount。通过在mypy.ini 中设置mypy_path,我已经将Mypy 配置为在本地读取存根。 Mypy 能够读取配置。到目前为止,一切都很好。
考虑我的这个功能
1 def get_units(postings: list[Posting]):
2 numbers = []
3 for posting in postings:
4 numbers.append(posting.units.number)
5 return numbers
当我运行mypy src时,出现以下错误
report.py:4 error: Item "type" of "Union[Amount, Type[MISSING]]" has no attribute "number" [union-attr]
当我检查定义的存根 here 时,我可以看到 units 的类型是 Amount。现在,Amount 正在从其父级 _Amount 继承 number。回到Fava 中的存根,我可以看到类型here。
我的问题是为什么 mypy 找不到属性 number 尽管它是在存根中定义的?
【问题讨论】: