ruff
a4f873df - [ty] Preserve exact numeric types in covariant collections (#27311)

Commit
92 days ago
[ty] Preserve exact numeric types in covariant collections (#27311) ## Summary Fixes astral-sh/ty#4111. Collection inference promotes exact runtime `float` and `complex` elements to their numeric-tower unions, which can introduce types that violate a covariant `Sequence` or `Iterable` context. Preserve the original inferred element when it satisfies that context but the promoted type does not. This fixes the original `Sequence[str | Just[float]]` false positive without changing `Just` protocol matching, invariant collection inference, or ordinary mutable-list numeric widening. ## Test plan Added focused bidirectional mdtests covering exact-float `Sequence` and `Iterable` contexts, exact-complex sequence contexts, the original `Just[float]` union, tuples, invariant and explicitly annotated lists, rejection of actual integer and float mismatches, and preserved widening for mutable float lists. The full `ty_python_semantic` test suite and all applicable file-scoped repository hooks pass.
Author
Parents
Loading