ruff
807a8a7a - [red-knot] Acknowledge that `T & anything` is assignable to `T` (#17413)

Commit
157 days ago
[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
Author
Parents
Loading