Skip to content

fix Passing an unpacked tuple of types as type arguments to the type parameters [T, *Ts] gets error #2363#2364

Open
asukaminato0721 wants to merge 2 commits intofacebook:mainfrom
asukaminato0721:2363
Open

fix Passing an unpacked tuple of types as type arguments to the type parameters [T, *Ts] gets error #2363#2364
asukaminato0721 wants to merge 2 commits intofacebook:mainfrom
asukaminato0721:2363

Conversation

@asukaminato0721
Copy link
Contributor

Summary

Fixes #2363

Expand unpacked tuple type arguments before specialization so Cls[*tuple[...]] and Cls[Unpack[tuple[...]]] can fill leading type parameters.

Test Plan

Added a regression test covering concrete tuple unpacking into [T, *Ts]

@meta-cla meta-cla bot added the cla signed label Feb 9, 2026
@github-actions

This comment has been minimized.

@asukaminato0721 asukaminato0721 marked this pull request as ready for review February 9, 2026 08:20
Copilot AI review requested due to automatic review settings February 9, 2026 08:20
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes #2363 by allowing unpacked concrete tuple type arguments (via *tuple[...] or Unpack[tuple[...]]) to expand into multiple type arguments before class/type specialization, so they can correctly bind leading type parameters like [T, *Ts].

Changes:

  • Expand unpacked tuple type arguments in create_targs before matching them to TParams.
  • Add a regression test covering concrete tuple unpacking into [T, *Ts].

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
pyrefly/lib/alt/class/targs.rs Expands unpacked tuple type arguments prior to specialization to allow them to fill multiple parameters.
pyrefly/lib/test/type_var_tuple.rs Adds a regression test ensuring Cls[*tuple[...]] and Cls[Unpack[tuple[...]]] work with [T, *Ts].

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Type::Unpack(box Type::Tuple(Tuple::Concrete(elts))) => {
expanded.extend(elts);
}
Type::Unpack(box Type::Tuple(Tuple::Unpacked(box (prefix, middle, suffix)))) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

i think we should have a test case for this

@yangdanny97
Copy link
Contributor

also, it might be good to fix the conformance bug while we're at it

fn expand_unpacked_targs(&self, targs: Vec<Type>) -> Vec<Type> {
let mut expanded = Vec::with_capacity(targs.len());
for arg in targs {
match arg {
Copy link
Contributor

Choose a reason for hiding this comment

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

how should we handle Unpack[*tuple[T, ...]]?

@yangdanny97 yangdanny97 self-assigned this Feb 9, 2026
@github-actions

This comment has been minimized.

@github-actions
Copy link

github-actions bot commented Feb 9, 2026

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@migeed-z
Copy link
Contributor

migeed-z commented Feb 9, 2026

@yangdanny97 @asukaminato0721 Is this PR supposed to address this test?

from typing import TypeVar, TypeVarTuple, assert_type

T1 = TypeVar("T1")
Ts = TypeVarTuple("Ts")

TA9 = tuple[*Ts, T1]
TA10 = TA9[*tuple[int, ...]]  # E: Unpacked argument cannot be used for type parameter T1

def func11(a: TA10, b: TA9[*tuple[int, ...], str]):
    assert_type(a, tuple[*tuple[int, ...], int])  # E: assert_type(tuple[Any], tuple[*tuple[int, ...], int]) failed
    assert_type(b, tuple[*tuple[int, ...], str])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Passing an unpacked tuple of types as type arguments to the type parameters [T, *Ts] gets error

3 participants