Skip to content

[red-knot] Properly handle gradual types in subtyping/equivalence relations #14524

@sharkdp

Description

@sharkdp

From https://typing.readthedocs.io/en/latest/spec/concepts.html#materialization:

Since Any represents an unknown static type, it does not represent any known single set of values (it represents an unknown set of values). Thus it is not in the domain of the subtype, supertype, or equivalence relations on static types described above.

But we currently return true for Type::Any.is_subtype_of(Type::Any).

The reason for that is that is_subtype_of relies on is_equivalent_to.

And is_equivalent_to doesn't model type equivalence for fully static types as defined here.

But rather something (but also not exactly) what would be the is-consistent-with definition for gradual types (for example, we currently have Any.is_equivalent_to(Any) but not Any.is_equivalent_to(Int), which would be required for is-consistent-with).

  • Fix subtyping for gradual types
  • Clarify what kind of equivalence is_equivalent_to implements and potentially make it more consistent with that definition
  • Make sure that this is the interpretation of is_equivalent_to that we want at all call sites.
  • Potentially introduce is_fully_static
  • Make sure we still handle assignability correctly.
  • Make sure we still simplify unions of Any.
  • Add new property test: non-fully-static types should never participate in subtyping

Metadata

Metadata

Assignees

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