Skip to content

[red-knot] x != 0 is wrongly inferred as Literal[True] if type of x is any subtype of ~Literal[0] #17360

@MatthewMckee4

Description

@MatthewMckee4

Summary

From type_api.md

from knot_extensions import static_assert

def f(x: int) -> None:
    if x != 0:
        static_assert(x != 0)

This test is incorrect. An explanation by example thanks to @AlexWaygood

We cannot make any assumptions about int & ~Literal[0] here. I'm not yet sure where this error comes from.

Version

No response

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