From 49c9f1db999345e78b81d36ba1366761cbfbf08d Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Thu, 4 Jan 2024 19:18:27 -0500 Subject: [PATCH] handle TypeVarTuple and ParamSpec for PEP 695 --- pyflakes/checker.py | 2 ++ pyflakes/test/test_type_annotations.py | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/pyflakes/checker.py b/pyflakes/checker.py index 43fd2d8e..754ab30c 100644 --- a/pyflakes/checker.py +++ b/pyflakes/checker.py @@ -2192,6 +2192,8 @@ def TYPEVAR(self, node): self.handleNodeStore(node) self.handle_annotation_always_deferred(node.bound, node) + PARAMSPEC = TYPEVARTUPLE = handleNodeStore + def TYPEALIAS(self, node): self.handleNode(node.name, node) with self._type_param_scope(node): diff --git a/pyflakes/test/test_type_annotations.py b/pyflakes/test/test_type_annotations.py index 2353e81e..4c8b998f 100644 --- a/pyflakes/test/test_type_annotations.py +++ b/pyflakes/test/test_type_annotations.py @@ -780,3 +780,20 @@ class C[T](list[T]): pass T # not accessible afterwards """, m.UndefinedName, m.UndefinedName) + + @skipIf(version_info < (3, 12), 'new in Python 3.12') + def test_type_parameters_TypeVarTuple(self): + self.flakes(""" + def f[*T](*args: *T) -> None: ... + """) + + @skipIf(version_info < (3, 12), 'new in Python 3.12') + def test_type_parameters_ParamSpec(self): + self.flakes(""" + from typing import Callable + + def f[R, **P](f: Callable[P, R]) -> Callable[P, R]: + def g(*args: P.args, **kwargs: P.kwargs) -> R: + return f(*args, **kwargs) + return g + """)