Unused Variable warning in Visual Studio Code (Python)

Viewed 7303

Why do I get unused variable warning in Visual Studio Code, when there quite clearly is a use - just 3 lines below the offending variable declaration? Here the warning is given for variable

found_r_object_id_in_cara

the variable is referenced in an 'if' statement a few lines below the declaration.

enter image description here

2 Answers

Add these lines at the top of the program (Global declaration)

# pylint: disable=unused-variable
# pylint: enable=too-many-lines

This may help someone.

Are you using the variable in question after setting the value inside if loop, if not the warning is valid. Setting and unsetting without actual usage will generate warning. There are couple of ways to disable the warning ( although this one seems like legitimate).

you can put this above the line thats generating the warning:

#pylint: disable=unused-argument

Prefix the variable name with _ underscore

Related