Matt
Matt

Reputation: 5168

VSCode python interpreter warning on built-in functions

I am using VSCode within a dev container but the python interpreter is raising warnings about undefined variables for built-in functions such as len, range, str, and super.

Undefined variable: 'range' Python(undefined-variable)

What could cause this? What other diagnostic information would be useful? enter image description here

Edit: Added the version I am using. enter image description here

Upvotes: 6

Views: 2850

Answers (2)

Angia
Angia

Reputation: 335

I use VS Code as well, and i have a similar issue str is not defined - pylance, according to internet, this issue appears when you set a variable with name str, or refer to a function/class before declaring it. However i do not have either of this situation.

In the end I navigated to "Extensions"-"Pylance" in VS Code, chose to "Switch to Pre-Release Version", then clicked "Reload Required". After reloading, this issue did not seem to appear. Then I switched back by clicking "Switch to Release Version", then reload again, the issue also does not seem to appear anymore. I think it's the reloading Pylance doing the trick.

Upvotes: 4

Brett Cannon
Brett Cannon

Reputation: 16080

Please make sure you have have an up-to-date copy of the Microsoft language server installed or consider using the beta version by setting "python.analysis.downloadChannel": "beta". If that doesn't work then please report the bug to https://github.com/microsoft/python-language-server with example code showing the problem.

Upvotes: 0

Related Questions