Skip to content

Commit 8dde577

Browse files
committed
address review
1 parent e2a21e2 commit 8dde577

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

crates/ty_python_semantic/resources/mdtest/call/function.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -724,14 +724,14 @@ def f3(coinflip: bool):
724724

725725
def f4(a=None, b=None, c=None, d=None, e=None): ...
726726

727-
my_args = (("a", "b"), ("c", "d"), ("e", "f"))
727+
my_args = ((1, 2), (3, 4), (5, 6))
728728

729729
for tup in my_args:
730730
f4(*tup, e=None) # fine
731731

732732
my_other_args = (
733-
("a", "b", "c", "d", "e"),
734-
("f", "g", "h", "i", "k"),
733+
(1, 2, 3, 4, 5),
734+
(6, 7, 8, 9, 10),
735735
)
736736

737737
for tup in my_other_args:

crates/ty_python_semantic/src/types/call/bind.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2313,6 +2313,12 @@ impl<'a, 'db> ArgumentMatcher<'a, 'db> {
23132313
argument: Argument<'a>,
23142314
argument_type: Option<Type<'db>>,
23152315
) -> Result<(), ()> {
2316+
// TODO: `Type::iterate` internally handles unions, but in a lossy way.
2317+
// It might be superior here to manually map over the union and call `try_iterate`
2318+
// on each element, similar to the way that `unpacker.rs` does in the `unpack_inner` method.
2319+
// It might be a bit of a refactor, though.
2320+
// See <https://github.com/astral-sh/ruff/pull/20377#issuecomment-3401380305>
2321+
// for more details. --Alex
23162322
let tuple = argument_type.map(|ty| ty.iterate(db));
23172323
let (mut argument_types, length, variable_element) = match tuple.as_ref() {
23182324
Some(tuple) => (

crates/ty_python_semantic/src/types/unpacker.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ impl<'db, 'ast> Unpacker<'db, 'ast> {
118118
};
119119
let mut unpacker = TupleUnpacker::new(self.db(), target_len);
120120

121+
// N.B. `Type::try_iterate` internally handles unions, but in a lossy way.
122+
// For our purposes here, we get better error messages and more precise inference
123+
// if we manually map over the union and call `try_iterate` on each union element.
124+
// See <https://github.com/astral-sh/ruff/pull/20377#issuecomment-3401380305>
125+
// for more discussion.
121126
let unpack_types = match value_ty {
122127
Type::Union(union_ty) => union_ty.elements(self.db()),
123128
_ => std::slice::from_ref(&value_ty),

0 commit comments

Comments
 (0)