mirror of
https://github.com/astral-sh/ruff
synced 2026-01-10 16:15:19 -05:00
This PR updates the constraint implication type relationship to work on compound types as well. (A compound type is a non-atomic type, like `list[T]`.) The goal of constraint implication is to check whether the requirements of a constraint imply that a particular subtyping relationship holds. Before, we were only checking atomic typevars. That would let us verify that the constraint set `T ≤ bool` implies that `T` is always a subtype of `int`. (In this case, the lhs of the subtyping check, `T`, is an atomic typevar.) But we weren't recursing into compound types, to look for nested occurrences of typevars. That means that we weren't able to see that `T ≤ bool` implies that `Covariant[T]` is always a subtype of `Covariant[int]`. Doing this recursion means that we have to carry the constraint set along with us as we recurse into types as part of `has_relation_to`, by adding constraint implication as a new `TypeRelation` variant. (Before it was just a method on `ConstraintSet`.) --------- Co-authored-by: David Peter <sharkdp@users.noreply.github.com>
Markdown files within the mdtest/ subdirectory are tests of type inference and type checking;
executed by the tests/mdtest.rs integration test.
See crates/ty_test/README.md for documentation of this test format.