Skip to content

[red-knot] Narrowing for while loops #14861

@sharkdp

Description

@sharkdp

We currently only narrow for if/elif, match and Boolean expressions. Narrowing for while loops should also be supported, for example:

def f(n: int) -> int | None: ...

n = 0

while (x := f(n)) is not None:
    reveal_type(x)
    n += 1

Metadata

Metadata

Assignees

Labels

tyMulti-file analysis & type inference

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions