Skip to content

Conversation

@MatthewMckee4
Copy link
Contributor

Summary

Resolves astral-sh/ty#2202.

Both of the following snippets are still not covered.

I'm not sure if these are completely unreachable, or I just can't think of a case to test them.

But the two new added tests add more coverage.

(TupleSpecBuilder::Fixed(_), TupleSpec::Fixed(_)) => None,
.or_else(|| {
    self_built.resize(db, var.len()).ok().and_then(|resized| {
        TupleSpecBuilder::from(&resized).intersect(db, other)
    })
})

Test Plan

cargo nextest run -p ty_python_semantic -- mdtest::loops

@MatthewMckee4 MatthewMckee4 changed the title Add tests for variable-length tuple iteration [ty] Add tests for variable-length tuple iteration Feb 1, 2026
@AlexWaygood AlexWaygood added testing Related to testing Ruff itself ty Multi-file analysis & type inference labels Feb 1, 2026
@sharkdp sharkdp self-assigned this Feb 3, 2026
@carljm carljm removed their request for review February 3, 2026 19:47
Copy link
Contributor

@sharkdp sharkdp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

I'm not sure if these are completely unreachable, or I just can't think of a case to test them.

I believe they are unreachable at the moment, but it looks to me like it doesn't hurt to leave the "dead" code in place (as opposed to adding unreachable!(…) or similar), just in case the function gets called in a different way in the future.

@sharkdp sharkdp enabled auto-merge (squash) February 5, 2026 15:47
@sharkdp sharkdp merged commit 77637e8 into astral-sh:main Feb 5, 2026
40 checks passed
@AlexWaygood
Copy link
Member

I think that's correct. I suppose we could add test coverage for the unreachable branches with a Rust unit test in tuple.rs, but it might not be worth it

@AlexWaygood
Copy link
Member

It would also be great if we could add tests for how these intersections of tuples behave when they're unpacked. When we have a test that just uses them in a for loop, all we see is the union of all the elements in the tuple spec

@MatthewMckee4 MatthewMckee4 deleted the tuple-iter-cov branch February 5, 2026 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

testing Related to testing Ruff itself ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve test coverage for iterating over intersections of tuples

3 participants