Skip to content

handle sealed types #245

@carljm

Description

@carljm

Some types have a finite number of possible inhabitants. Examples include builtins.bool (the inhabitants are Literal[True] and Literal[False]) and enum types. For such types, we should consider the union of all possible inhabitants as equivalent to the type itself (so for example Literal[True, False]) is equivalent to builtins.bool). We should also take this equivalence into account when resolving negated intersections (so for example builtins.bool & ~Literal[True] is equivalent to Literal[False]; practically this will come up in type narrowing.)

Tasks here, in the order we'll likely get to them:

  • resolve Literal[True] | Literal[False] to builtins.bool
  • resolve builtins.bool back to Literal[True] | Literal[False] when intersection eliminates a type inhabitant
  • extend the above handling to enum types, when we add them

Metadata

Metadata

Assignees

No one assigned

    Labels

    type propertiessubtyping, assignability, equivalence, and more

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions