Skip to content

(🐞) false narrowing with reassignment in loop #11612

Closed
@KotlinIsland

Description

@KotlinIsland
a: int | None
a = None
for i in range(10):
    reveal_type(a)  # "None" and also "int | None"
    if a:
        print(a)  # error: unreachable
    a = i

Also:

a = None
for b in [1, 2]:
    if a is None:
        a = b
        continue
    print("hi")  # false unreachable error

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-reachabilityDetecting unreachable codetopic-type-narrowingConditional type narrowing / binder

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions