skip to Main Content

In below screenshot when hovering over the grayed out variables Pylance (correctly!) says they are not accessed, e.g.; "_baz" is not accessed Pylance. My question is about waz, which is clearly not accessed in either tabs, still not grayed out. Why isn’t it grayed out?

enter image description here

I thought maybe it was related to waz not being a "private" (underscore) variable, but it just doesn’t make sense…

2

Answers


  1. In Visual Studio Code even when you use pylance the unused variable will not be grayed out. although when you add the underscore(_) it grays out because it’s private.
    Here are some pictures showing that:

    first picture: Look at the unused available "art" and the unused private variable "_waz"

    "

    second Picture: "When I use the variable ‘_waz’, the text is displayed in color."

    Look here at "_waz" when I use it's coloured

    Brief: to gray out a variable you have to make it private by putting an underscore or use it as a parameter, else the variables will be displayed in color.

    That answer is referenced by my experience in using Pylance for 3 years

    Login or Signup to reply.
  2. Global variables without an underscore are considered public, so it might be used when imported from somewhere else.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search