Skip to content

[ty] Infer TypeVarTuple arguments from variadic calls - #27535

Draft
charliermarsh wants to merge 1 commit into
charlie/ty-4172-validate-unpacked-callsfrom
charlie/ty-4172-infer-variadic-typevartuple
Draft

[ty] Infer TypeVarTuple arguments from variadic calls#27535
charliermarsh wants to merge 1 commit into
charlie/ty-4172-validate-unpacked-callsfrom
charlie/ty-4172-infer-variadic-typevartuple

Conversation

@charliermarsh

Copy link
Copy Markdown
Member

Summary

Follow-up to #27516.

Previously, we inferred Unknown for a TypeVarTuple appearing directly in a variadic parameter, even when its argument types and tuple shape were known:

def collect[*Ts](*args: *Ts) -> tuple[*Ts]: ...

def caller(i: int, s: str) -> None:
    reveal_type(collect())      # tuple[()]
    reveal_type(collect(i, s))  # tuple[int, str]

We now infer the complete argument sequence as a single tuple, preserving fixed prefixes and suffixes, starred tuple shapes, generic constructors, and both PEP 695 and legacy declarations.

Calls requiring joint inference through callbacks or other parameters, forwarded tuple unions, and conflicting contextual return types retain their existing behavior.

The number of passing typing-conformance files increases from 104 to 106.

@astral-sh-bot astral-sh-bot Bot added the ty Multi-file analysis & type inference label Aug 6, 2026
@astral-sh-bot

astral-sh-bot Bot commented Aug 6, 2026

Copy link
Copy Markdown

Typing conformance results improved 🎉

The percentage of diagnostics emitted that were expected errors increased from 96.97% to 97.35%. The percentage of expected errors that received a diagnostic held steady at 93.24%. The number of fully passing files improved from 104/133 to 106/133.

Summary

How are test cases classified?

Each test case represents one expected error annotation or a group of annotations sharing a tag. Counts are per test case, not per diagnostic — multiple diagnostics on the same line count as one. Required annotations (E) are true positives when ty flags the expected location and false negatives when it does not. Optional annotations (E?) are true positives when flagged but true negatives (not false negatives) when not. Tagged annotations (E[tag]) require ty to flag exactly one of the tagged lines; tagged multi-annotations (E[tag+]) allow any number up to the tag count. Flagging unexpected locations counts as a false positive.

Metric Old New Diff Outcome
True Positives 993 993 +0
False Positives 31 27 -4 ⏬ (✅)
False Negatives 72 72 +0
Total Diagnostics 1066 1062 -4
Precision 96.97% 97.35% +0.38% ⏫ (✅)
Recall 93.24% 93.24% +0.00%
Passing Files 104/133 106/133 +2 ⏫ (✅)

Test file breakdown

2 files altered
File True Positives False Positives False Negatives Status
generics_typevartuple_args.py 8 0 (-3) ✅ 0 ✅ Newly Passing 🎉
generics_typevartuple_callable.py 1 0 (-1) ✅ 0 ✅ Newly Passing 🎉
Total (all files) 993 27 (-4) ✅ 72 106/133

False positives removed (4)

4 diagnostics
Test case Diff

generics_typevartuple_args.py:29

-error[type-assertion-failure] Type `tuple[Unknown, ...]` does not match asserted type `tuple[int, str]`

generics_typevartuple_args.py:31

-error[type-assertion-failure] Type `tuple[Unknown, ...]` does not match asserted type `tuple[()]`

generics_typevartuple_args.py:32

-error[type-assertion-failure] Type `tuple[Unknown, ...]` does not match asserted type `tuple[int, str]`

generics_typevartuple_callable.py:50

-error[type-assertion-failure] Type `tuple[int | float | complex, *tuple[Unknown, ...]]` does not match asserted type `tuple[int | float | complex, str, int | float]`

@astral-sh-bot

astral-sh-bot Bot commented Aug 6, 2026

Copy link
Copy Markdown

Memory usage report

Memory usage unchanged ✅

@astral-sh-bot

astral-sh-bot Bot commented Aug 6, 2026

Copy link
Copy Markdown

ecosystem-analyzer results

No diagnostic changes detected ✅

Flaky changes detected. This PR summary excludes flaky changes; see the HTML report for details.

Full report with detailed diff (timing results)

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.

1 participant