From 5c718ba415c9ac96df9772db4b9ee3c444c54749 Mon Sep 17 00:00:00 2001 From: Hana Joo Date: Fri, 25 Apr 2025 08:54:57 -0700 Subject: [PATCH] Implement the body of INTRINSIC_TYPEVARTUPLE, but this change does not actually support the typing.TypeVarTuple feature. This is only to fail gracefully when we see this construct, mark anything to unsolvable and move on. PiperOrigin-RevId: 751437007 --- pytype/tests/test_typevar1.py | 14 ++++++++++++++ pytype/vm.py | 8 +++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/pytype/tests/test_typevar1.py b/pytype/tests/test_typevar1.py index 608f202b5..3ab55fc0c 100644 --- a/pytype/tests/test_typevar1.py +++ b/pytype/tests/test_typevar1.py @@ -147,6 +147,20 @@ class A(Generic[T, S]): """, ) + @test_utils.skipBeforePy((3, 12), "PEP 695 - 3.12 feature") + def test_unused_typevar_pep695_type_var_tuple(self): + errors = self.CheckWithErrors(""" + type Tup[*Ts] = ( # not-supported-yet[e1] + tuple[int, *Ts] ) # invalid-annotation[e2] + """) + self.assertErrorRegexes( + errors, + { + "e1": "Using TypeVarTuple in Generics is not supported yet", + "e2": "Invalid type annotation '' \nNot a type", + }, + ) + @test_utils.skipBeforePy((3, 12), "PEP 695 - 3.12 feature") def test_unused_typevar_pep695_class_both_generic_and_base(self): errors = self.CheckWithErrors(""" diff --git a/pytype/vm.py b/pytype/vm.py index 2c3259d53..6bde39e08 100644 --- a/pytype/vm.py +++ b/pytype/vm.py @@ -3917,7 +3917,13 @@ def byte_INTRINSIC_PARAMSPEC(self, state): return state def byte_INTRINSIC_TYPEVARTUPLE(self, state): - # TODO: b/350910471 - Implement to support PEP 695 + # We don't even support importing typing.TypeVarTuple so do the minimal to + # consume all the parameters, put any on the stack and move on. + self.ctx.errorlog.not_supported_yet( + self.frames, "Using TypeVarTuple in Generics is" + ) + state, _ = state.pop() + state = state.push(self.ctx.convert.unsolvable.to_variable(state.node)) return state def byte_INTRINSIC_SUBSCRIPT_GENERIC(self, state):