Skip to content

[red-knot] support narrowing on an assignment expression in a predicate #17437

@carljm

Description

@carljm

We narrow in the first case below but not the second (playground):

def maybe_int() -> int | None:
    return 1

def _():
    x = maybe_int()
    if x is not None:
        reveal_type(x)

    if (y := maybe_int()) is not None:
        reveal_type(y)

Anywhere we would narrow on a test against a Name, we should narrow in the same way if that name is the target of an assignment expression in the same test.

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedContributions especially welcometyMulti-file analysis & type inference

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions