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?
I thought maybe it was related to waz
not being a "private" (underscore) variable, but it just doesn’t make sense…
2
Answers
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."
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
Global variables without an underscore are considered public, so it might be used when imported from somewhere else.