【发布时间】:2020-05-18 23:32:25
【问题描述】:
我正在尝试silence mypy errors based on error codes。这是使用这样的东西完成的:
from foolib import foo # type: ignore[attr-defined]
我相信 PyCharm 将我的 type: ignore[code] cmets 解释为类型注释,并将 ignore 报告为未解决的引用。
此外,PyCharm 需要括号内的表达式。
mypy 我试图抑制的错误:
pylint_ignore.py:8: error: Skipping analyzing 'pylint.utils': found module but no type hints or library stubs [import]
是的,我知道我可以只说type: ignore,而不包括代码,或者指定忽略配置文件中的这个特定导入。但是,我想指定错误代码,因为我认为这是一个很好的功能。
我怎样才能让 PyCharm 不抱怨这个?
研究
This answer 到 How do I stop pyCharm from complaining about underscore strings?
帮我实现在Preferences --> Editor --> Inspections --> Python --> Unresolved references下,我可以添加一个完全限定的符号名来忽略。
我相信这是官方记录的here。
我尝试添加 *.ignore.*(因为我不想建立每个模块的忽略列表),但这不起作用。
如果这是正确的方法,你能帮我找出正确的语法吗?
版本
mypy==0.770
python==3.6.5
PyCharm PE 2020.1
【问题讨论】:
-
他们的错误跟踪器上的相关问题:https://youtrack.jetbrains.com/issue/PY-19917。但是没有关于如何抑制警告的信息。
-
谢谢@Georgy,我赞成这个问题!
标签: pycharm ide type-hinting mypy