Regression in 1.1.405 involving loops
- Dominant language
- Python
- Stars
- 15.6k
- Forks
- 1.8k
- Avg merge
- 12h 13m
- Merged PRs (30d)
- 52
Description
**Describe the bug**
A clear and concise description of the behavior you are seeing and the expected behavior along with steps to reproduce it.
Pyright seems to be confused about variable type when modifying said variable inside the loop.
In this example, `lines` should infer as `list[str]`.
**Code or Screenshots**
```python
lines = ["ab", "bc", "ac", "ca"] # lines: list[str]
while lines: # lines: list[str] | list[str | Unknown]
print(lines) # lines: list[str] | list[Unknown]
lines = [x for x in lines[1:]] # x: str | Unknown
```
Working fine in [1.1.404](https://pyright-play.net/?pyrightVersion=1.1.404&strict=true&code=DYSwdgpgzgBAvDA2gIgIYCNkBobPQY211UJ2X1WQF0AoAdwAsRgIZRIoAuGmXmABwBO4AC4AKdtACUPPpNgJEADxgAzAPaCYK8G3DREARk5VaQA)
Broken in [1.1.405](https://pyright-play.net/?pyrightVersion=1.1.405&strict=true&code=DYSwdgpgzgBAvDA2gIgIYCNkBobPQY211UJ2X1WQF0AoAdwAsRgIZRIoAuGmXmABwBO4AC4AKdtACUPPpNgJEADxgAzAPaCYK8G3DREARk5VaQA)
Still broken in [1.1.408](https://pyright-play.net/?pyrightVersion=1.1.408&strict=true&code=DYSwdgpgzgBAvDA2gIgIYCNkBobPQY211UJ2X1WQF0AoAdwAsRgIZRIoAuGmXmABwBO4AC4AKdtACUPPpNgJEADxgAzAPaCYK8G3DREARk5VaQA) (latest version as of today)
Contributor guide
Research direction
Start with the provided Pyright Playground reproducer in strict mode and compare its behavior between versions 1.1.404, 1.1.405, and 1.1.408. Trace the loop variable type inference involved in the example; done means lines remains list[str] throughout the loop without Unknown widening.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100