是否可以让MyPy检查至少一个联合项目中存在属性(而不是每个联合项目)?
我正在尝试将mypy
应用于已经具有类型注释的大型代码库(由Pycharm检查)。运行mypy
时,我会得到一个bazzilion错误,例如:
error: Item "Bar" of "Union[Foo, Bar]" has no attribute "foo_func"
这是因为mypy
检查属性foo_func
每个都存在 工会成员,如下所述: https://mypy.readthedocs.io/en/stable/error_code_list.html#check-check-that-att-tribute-exists-in-each-each-each-union-item-union-union-union-union-attr 。
为了避免被这样的错误消息超载,我想修改mypy
的行为,以便检查属性foo_func
至少在 中存在一个 工会成员。
当然,我可以在代码中添加断言以告诉mypy
哪个对象是专门输入对象的。但是目前,我只是在寻找一种修改mypy
本身的行为的方法。
这可能吗?
I'm trying to apply mypy
on a large codebase that already has type annotations (which are checked by PyCharm). When running mypy
, I get a bazzilion errors like:
error: Item "Bar" of "Union[Foo, Bar]" has no attribute "foo_func"
This is because mypy
checks that the attribute foo_func
exists in each union member, as described here:
https://mypy.readthedocs.io/en/stable/error_code_list.html#check-that-attribute-exists-in-each-union-item-union-attr.
To avoid being overloaded with error messages like this, I want to modify the behavior of mypy
such that it checks that the attribute foo_func
exists in at least one union member.
Of course, I can add assertions in the code to tell mypy
which type the object specifically is. But for now, I'm just looking for a way to modify the behavior of mypy
itself.
Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试添加Inline评论
#忽略:[UNIOM-ATTR]
在我的情况下try to add inline comment
# ignore: [union-attr]
in my case like