Pylance incorrectly tagging ReportUndefinedVariable
when using global
keyword
#526
Labels
bug
Something isn't working
fixed in next version (main)
A fix has been implemented and will appear in an upcoming version
Environment data
Expected behaviour
When using the
global
keyword anywhere, PyLance should recognize that is a variable declaration.Actual behaviour
Using the
global
keyword itself creates the erroneousreportUndefinedVariable
error.Logs
Logs seem irrelevant for this, but I can capture them if needed.
Code Snippet / Additional information
I tried to make this example as generic as possible, but also showing a valid case for the otherwise frowned upon
global
keyword. I might want to access protected secrets in a way that keeps them out of version control, but flags me, the user, when things go wrong.In PyLance, the line
global MY_SECRET
generates the error"MY_SECRET" is not defined [Pylance (reportUndefinedVariable)]
. This is obviously not an error. But I would argue that there are cases, such as shown above, where it isn't even bad practice.The text was updated successfully, but these errors were encountered: