5

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

5
  • a) don't post pictures of code b) do you USE the variable anywhere or just set it to a value and not touch it Commented Mar 4, 2020 at 17:30
  • 3
    You're getting the warning because the variable is unused i.e you don't you don't use the value - you just set it Commented Mar 4, 2020 at 17:41
  • Please do not share information as images unless absolutely necessary. See: meta.stackoverflow.com/questions/303812/…, idownvotedbecau.se/imageofcode, idownvotedbecau.se/imageofanexception. Commented Mar 4, 2020 at 18:19
  • I use it in an if statement on line 131 Commented Mar 5, 2020 at 11:16
  • I added pictures to show the IDE identifying the unused variable Commented Mar 5, 2020 at 11:32

2 Answers 2

7

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

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

This may help someone.

Sign up to request clarification or add additional context in comments.

1 Comment

This is great. Now is there a way to do this in settings? I could not find it in vsc 1.49.2
5

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.