Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
6 tasks
sharkdp opened this issue Nov 22, 2024 · 0 comments
Open
6 tasks
Assignees
Labels
bug Something isn't working red-knot Multi-file analysis & type inference

Comments

@sharkdp
Copy link
Contributor

sharkdp commented Nov 22, 2024

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.
@sharkdp sharkdp added bug Something isn't working red-knot Multi-file analysis & type inference labels Nov 22, 2024
@sharkdp sharkdp self-assigned this Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working red-knot Multi-file analysis & type inference
Projects
None yet
Development

No branches or pull requests

1 participant