The undefined variable goes unnoticed
- Dominant language
- Python
- Stars
- 15.6k
- Forks
- 1.8k
- Avg merge
- 12h 13m
- Merged PRs (30d)
- 52
Description
## Environment data
- Pylance version: 2025.6.2
- OS and version: 6.6.87.2-microsoft-standard-WSL2 (Ubuntu)
- Python version (& distribution if applicable, e.g. Anaconda): Python 3.12.2
## Code Snippet
```python
counter += 1
```
ends up with correct:
"counter" is not defined [PyLance]
while
```python
for i in range(100):
counter += 1
```
PyLance does not report anything
It seems that PyLance does not care about undefined variables in nested loops.
## Expected behavior
The undefined variable in the nested loop is reported
## Actual behavior
The undefined variable goes unnoticed.
Contributor guide
Research direction
Start by reproducing the two snippets in the reported Pylance environment: the top-level increment should produce an undefined-variable diagnostic, while the increment inside the loop currently does not. Trace the undefined-variable analysis for loop bodies and add or update coverage for this case. Done means the nested-loop example reports the undefined variable without regressing the existing behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 42/100