ruff/crates/ty_python_semantic/src
Carl Meyer 089f5152f6
[ty] Fix mixed tuple subtyping (#18852)
## Summary

The code in the `Variable` branch of
`VariableLengthTupleSpec::has_relation_to` made the incorrect assumption
that if you zip two possibly-different-length iterators together and
iterate over the resulting zip iterator, the original two iterators will
only have their common elements consumed. But in fact, the zip iterator
detects that it is done when it receives a `None` from one iterator and
`Some()` element from the other iterator, which means that it consumes
one additional element from the longer iterator. This meant that we
failed to detect mismatched types on this extra consumed element,
because we never compared it to the variable type of the other tuple.

Use `zip_longest` from itertools as an alternative, which allows us to
combine all the handling into just two `zip_longest`, one for prefixes
and one for suffixes.

Marking this PR internal since it fixes a bug in a commit that wasn't
released yet.

## Test Plan

Added mdtests that failed before this fix and pass after it.
2025-06-21 13:09:23 -07:00
..
module_resolver [ty] Infer the Python version from `--python=<system installation>` on Unix (#18550) 2025-06-11 14:32:33 +00:00
semantic_index [ty] Use `HashTable` in `PlaceTable` (#18819) 2025-06-20 15:31:54 +02:00
types [ty] Fix mixed tuple subtyping (#18852) 2025-06-21 13:09:23 -07:00
util [ty] Homogeneous and mixed tuples (#18600) 2025-06-20 18:23:54 -04:00
ast_node_ref.rs [ty] AST garbage collection (#18482) 2025-06-13 08:40:11 -04:00
db.rs [ty] Allow overriding rules for specific files (#18648) 2025-06-15 14:27:39 +01:00
dunder_all.rs [ty] Add infrastructure for AST garbage collection (#18445) 2025-06-05 11:43:18 -04:00
lib.rs [ty] Pull types on synthesized Python files created by mdtest (#18539) 2025-06-12 10:32:17 +01:00
lint.rs [ty] Allow overriding rules for specific files (#18648) 2025-06-15 14:27:39 +01:00
list.rs Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
module_name.rs [ty] AST garbage collection (#18482) 2025-06-13 08:40:11 -04:00
node_key.rs [ty] AST garbage collection (#18482) 2025-06-13 08:40:11 -04:00
place.rs [ty] basic narrowing on attribute and subscript expressions (#17643) 2025-06-17 11:07:46 +02:00
program.rs [ty] Infer the Python version from `--python=<system installation>` on Unix (#18550) 2025-06-11 14:32:33 +00:00
pull_types.rs [ty] Pull types on synthesized Python files created by mdtest (#18539) 2025-06-12 10:32:17 +01:00
python_platform.rs Hug closing `}` when f-string expression has a format specifier (#18704) 2025-06-17 07:39:42 +02:00
semantic_index.rs [ty] Use `HashTable` in `PlaceTable` (#18819) 2025-06-20 15:31:54 +02:00
semantic_model.rs Revert "[ty] Offer "Did you mean...?" suggestions for unresolved `from` imports and unresolved attributes (#18705)" (#18721) 2025-06-17 15:48:09 +01:00
site_packages.rs [ty] Support `--python=<symlink to executable>` (#18827) 2025-06-21 20:28:47 +01:00
suppression.rs [ty] Allow overriding rules for specific files (#18648) 2025-06-15 14:27:39 +01:00
types.rs [ty] Homogeneous and mixed tuples (#18600) 2025-06-20 18:23:54 -04:00
unpack.rs [ty] Add infrastructure for AST garbage collection (#18445) 2025-06-05 11:43:18 -04:00