[英]Pycharm - Disable 'Local variable 'xxx' might be referenced before assignment'
In pycharm, I would like to disable the following inspection warn: "Local variable 'xxx' might be referenced before assignment" but I can't find it in settings/inspections.在 pycharm 中,我想禁用以下检查警告:“局部变量 'xxx' 可能在赋值之前被引用”,但我在设置/检查中找不到它。
PS: This is not a duplicate, as I understand this warn. PS:这不是重复的,因为我理解这个警告。 I am just asking how to disable it in pycharm.
我只是问如何在 pycharm 中禁用它。
Update: Please find below an example of what I mean更新:请在下面找到我的意思的例子
cond = True
def add1(x):
return x+1
if cond:
a = 1
if cond:
b = add1(a) # the warn is on the 'a'
Solution:解决方案:
"Unbound local variable" inspection. “未绑定局部变量”检查。 (cf. Lomtrur answer below)
(参见下面的 Lomtrur 回答)
You can disable it locally by putting the following comment on the line preceding the warning:您可以通过在警告之前的行中添加以下注释来在本地禁用它:
# noinspection PyUnboundLocalVariable
It will only apply to that instance.它仅适用于该实例。
If you put that bit of code right before the function or method declaration, it will suppress the message for the entire function or method.如果将那段代码放在函数或方法声明之前,它将抑制整个函数或方法的消息。
In your case在你的情况下
if cond:
# noinspection PyUnboundLocalVariable
b = add1(a)
Place the cursor immediately after a
.立即将光标后
a
。 It should have a colored background or be underlined to show that this is where the warning is.它应该具有彩色背景或带有下划线以表明这是警告所在的位置。 Then press
Alt+Enter
to open the context menu.然后按
Alt+Enter
打开上下文菜单。 This should show you what the inspection is and also give the option to disable it.这应该向您显示检查是什么,并提供禁用它的选项。 (PyCharm 2018.2.5 Professional Edition)
(PyCharm 2018.2.5 专业版)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.