Skip to content

[red-knot] add support for more type narrowing forms #13694

@carljm

Description

@carljm

This is not an exhaustive list of what we'll eventually want to support, it's just a starter list of some useful ones that aren't currently blocked by other type system features that aren't implemented yet.

(Supporting narrowing on x.attr or x[sub] expression forms is out of scope for this issue.)

Implementation for these lives in crates/red_knot_python_semantic/src/types/narrow.rs.

These cases we may want eventually, but we are deferring for now (please don't add support for these right now):

  • x == None (not sound for most x, don't want to do it unless driven by real use cases)
  • x == T (where T is any literal type) -- not sound for most x; need real use cases (maybe TypedDicts are a use case?)
  • x != T (where T is any literal type) -- use cases not clear yet; could result in complex-but-useless intersections

Sub-issues

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