Skip to content

[red-knot] Incorrect control flow modelling in if-elif chains #15033

@sharkdp

Description

@sharkdp

We currently infer a type of Literal[1, 2, 4] in the following example, but 1 is not a possible value of x. And 3 is a possible value for x.

def check(x: int) -> bool: ...

if check(x := 1):
    x = 2
elif check(x := 3):
    x = 4

reveal_type(x)  # revealed: Literal[1, 2, 4]; should be Literal[2, 3, 4]

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtyMulti-file analysis & type inference

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions