我可以让 PyC​​harm 在一行中抑制特定警告吗? [英] Can I get PyCharm to suppress a particular warning on a single line?

查看:39
本文介绍了我可以让 PyC​​harm 在一行中抑制特定警告吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PyCharm 提供了一些关于代码风格、约定和逻辑陷阱的有用警告.如果我尝试提交带有警告(或错误)的代码,它还会提供通知.

PyCharm provides some helpful warnings on code style, conventions and logical gotchas. It also provides a notification if I try to commit code with warnings (or errors).

有时我有意识地忽略这些针对特定代码行的警告(出于各种原因,通常是考虑到第三方库的实现细节).我想抑制警告,但只是针对那条线(如果警告出现在我没有故意的不同行上,我想知道它!)

Sometimes I consciously ignore these warnings for particular lines of code (for various reasons, typically to account for implementation details of third-party libraries). I want to suppress the warning, but just for that line (if the warning crops up on a different line where I'm not being deliberate, I want to know about it!)

如何在 PyCharm 中做到这一点?(强烈推荐遵循通用的 Python 约定.)

How can I do that in PyCharm? (Following a universal Python convention strongly preferable.)

推荐答案

要禁止对特定代码行的 PyCharm 代码检查,您可以使用以下构造:

To suppress PyCharm code inspections for a particular line of code you can use the following construct:

# noinspection INSPECTION_NAME
your_line_of_code_to_suppress

您可以从 检查名称列表(它们非常具有描述性).

where the name of the inspection (INSPECTION_NAME above) you can take from the list of inspection names (they are pretty descriptive).

要显式抑制 pylint 命令行消息,您必须使用不同的注释/命令,如 描述在这里 (pylint 错误名称).

To suppress pylint command line messages explicitly you have to use different comments/commands, as described here (pylint error names).

这篇关于我可以让 PyC​​harm 在一行中抑制特定警告吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆