Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

PS: This is not a duplicate, as I understand this warn. I am just asking how to disable it in 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)

like image 518
u2gilles Avatar asked Mar 14 '19 05:03

u2gilles


1 Answers

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)
like image 75
Jacob Lee Avatar answered Oct 09 '22 04:10

Jacob Lee