ruff/crates/red_knot_python_semantic/resources/mdtest/generics
Douglas Creager 807a8a7a29
[red-knot] Acknowledge that T & anything is assignable to T (#17413)
This reworks the assignability/subtyping relations a bit to handle
typevars better:

1. For the most part, types are not assignable to typevars, since
there's no guarantee what type the typevar will be specialized to.

2. An intersection is an exception, if it contains the typevar itself as
one of the positive elements. This should fall out from the other
clauses automatically, since a typevar is assignable to itself, and an
intersection is assignable to something if any positive element is
assignable to that something.

3. Constrained typevars are an exception, since they must be specialized
to _exactly_ one of the constraints, not to a _subtype_ of a constraint.
If a type is assignable to every constraint, then the type is also
assignable to the constrained typevar.

We already had a special case for (3), but the ordering of it relative
to the intersection clauses meant we weren't catching (2) correctly. To
fix this, we keep the special case for (3), but fall through to the
other match arms for non-constrained typevars and if the special case
isn't true for a constrained typevar.

Closes https://github.com/astral-sh/ruff/issues/17364
2025-04-15 16:34:07 -04:00
..
classes.md red_knot_python_semantic: replace one use of "old" secondary diagnostic messages 2025-04-10 13:21:00 -04:00
functions.md red_knot_python_semantic: remove the "old" secondary message type 2025-04-10 13:21:00 -04:00
legacy.md Use python.typing.org for typing documentation links (#17323) 2025-04-09 20:38:20 +02:00
pep695.md [red-knot] Acknowledge that T & anything is assignable to T (#17413) 2025-04-15 16:34:07 -04:00
scoping.md [red-knot] improve function/bound method type display (#17294) 2025-04-14 15:56:18 -07:00