Skip to content

[ty] Ban multiple unpacked variadic tuples in a tuple specialization#22884

Merged
AlexWaygood merged 2 commits intomainfrom
alex/two-starred-tuples
Jan 27, 2026
Merged

[ty] Ban multiple unpacked variadic tuples in a tuple specialization#22884
AlexWaygood merged 2 commits intomainfrom
alex/two-starred-tuples

Conversation

@AlexWaygood
Copy link
Member

@AlexWaygood AlexWaygood commented Jan 27, 2026

Summary

The spec states that while this is allowed:

tuple[*tuple[int, ...], *tuple[str]]

and this is allowed:

from typing import TypeVarTuple

Ts = TypeVarTuple("Ts")

tuple[*Ts, *tuple[str]]

none of these are, because multiple variadic tuples cannot be unpacked in the context of a single tuple specialization:

tuple[*tuple[int, ...], *tuple[str, ...]]
tuple[*tuple[int, ...], str, *tuple[bytes, ...]]
tuple[*Ts, *Ts]
tuple[*Ts, *tuple[int, ...]]

This PR adds the missing diagnostics.

Test Plan

snapshots and mdtests

@AlexWaygood AlexWaygood added the ty Multi-file analysis & type inference label Jan 27, 2026
@astral-sh-bot
Copy link

astral-sh-bot bot commented Jan 27, 2026

Typing conformance results improved 🎉

The percentage of diagnostics emitted that were expected errors increased from 78.84% to 78.95%. The percentage of expected errors that received a diagnostic increased from 69.42% to 69.88%.

Summary

Metric Old New Diff Outcome
True Positives 749 754 +5 ⏫ (✅)
False Positives 201 201 +0
False Negatives 330 325 -5 ⏬ (✅)
Total Diagnostics 950 955 +5
Precision 78.84% 78.95% +0.11% ⏫ (✅)
Recall 69.42% 69.88% +0.46% ⏫ (✅)

True positives added

Details
Location Name Message
generics_typevartuple_specialization.py:121:7 invalid-type-form Multiple unpacked variadic tuples are not allowed in a tuple specialization
generics_typevartuple_specialization.py:122:7 invalid-type-form Multiple unpacked variadic tuples are not allowed in a tuple specialization
tuples_unpacked.py:40:5 invalid-type-form Multiple unpacked variadic tuples are not allowed in a tuple specialization
tuples_unpacked.py:41:5 invalid-type-form Multiple unpacked variadic tuples are not allowed in a tuple specialization
tuples_unpacked.py:51:9 invalid-type-form Multiple unpacked variadic tuples are not allowed in a tuple specialization

@astral-sh-bot
Copy link

astral-sh-bot bot commented Jan 27, 2026

mypy_primer results

Changes were detected when running on open source projects
scikit-build-core (https://github.com/scikit-build/scikit-build-core)
+ src/scikit_build_core/build/wheel.py:99:20: error[no-matching-overload] No overload of bound method `__init__` matches arguments
- Found 46 diagnostics
+ Found 47 diagnostics

core (https://github.com/home-assistant/core)
+ homeassistant/util/variance.py:47:12: error[invalid-return-type] Return type does not match returned value: expected `(**_P@ignore_variance) -> _R@ignore_variance`, found `_Wrapped[_P@ignore_variance, int | _R@ignore_variance | float | datetime, _P@ignore_variance, _R@ignore_variance | int | float | datetime]`
- Found 14488 diagnostics
+ Found 14489 diagnostics

No memory usage changes detected ✅

@AlexWaygood AlexWaygood force-pushed the alex/two-starred-tuples branch 2 times, most recently from 7cfca5a to 9dd669f Compare January 27, 2026 14:32
@AlexWaygood AlexWaygood changed the title [ty] Ban multiple starred expressions in a tuple specializatoin [ty] Ban multiple unpacked variadic tuples in a tuple specialization Jan 27, 2026
@AlexWaygood AlexWaygood marked this pull request as ready for review January 27, 2026 14:36
diagnostic.annotate(
self.context
.secondary(element)
.message("Second unpacked variadict tuple"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
.message("Second unpacked variadict tuple"),
.message("Second unpacked variadic tuple"),

Copy link
Member Author

@AlexWaygood AlexWaygood Jan 27, 2026

Choose a reason for hiding this comment

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

beat you to it :P

@AlexWaygood AlexWaygood enabled auto-merge (squash) January 27, 2026 16:42
@AlexWaygood AlexWaygood merged commit 72fd386 into main Jan 27, 2026
48 checks passed
@AlexWaygood AlexWaygood deleted the alex/two-starred-tuples branch January 27, 2026 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants