Can I get PyCharm to suppress a particular warning on a single line?(我可以让 PyCharm 在一行中抑制特定警告吗?)
问题描述
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).
这篇关于我可以让 PyCharm 在一行中抑制特定警告吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:我可以让 PyCharm 在一行中抑制特定警告吗?
基础教程推荐
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
- 尝试制作WhatsApp机器人 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
