Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[red-knot] Narrowing for while loops #14861

Closed
sharkdp opened this issue Dec 9, 2024 · 0 comments · Fixed by #14947
Closed

[red-knot] Narrowing for while loops #14861

sharkdp opened this issue Dec 9, 2024 · 0 comments · Fixed by #14947
Assignees
Labels
red-knot Multi-file analysis & type inference

Comments

@sharkdp
Copy link
Contributor

sharkdp commented Dec 9, 2024

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
@sharkdp sharkdp added the red-knot Multi-file analysis & type inference label Dec 9, 2024
@sharkdp sharkdp self-assigned this Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
red-knot Multi-file analysis & type inference
Projects
None yet
1 participant