Skip to content

Regression in 1.1.405 involving loops #11321

@Molkree

Description

@Molkree

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

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
Broken in 1.1.405
Still broken in 1.1.408 (latest version as of today)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions