From fb677002afba986957f31e02c8bcf02c3cfeb52d Mon Sep 17 00:00:00 2001 From: Eric Traut <eric@traut.com> Date: Fri, 3 Nov 2023 09:24:25 -0700 Subject: [PATCH] Fixed a bug that led to a false positive error when specializing a type alias consisting of a callable parameterized by a TypeVarTuple. This partially addresses #6317. --- packages/pyright-internal/src/analyzer/typeUtils.ts | 4 +++- .../src/tests/samples/variadicTypeVar6.py | 9 ++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/pyright-internal/src/analyzer/typeUtils.ts b/packages/pyright-internal/src/analyzer/typeUtils.ts index 5bd553737885..3a4ef3d6c924 100644 --- a/packages/pyright-internal/src/analyzer/typeUtils.ts +++ b/packages/pyright-internal/src/analyzer/typeUtils.ts @@ -3791,7 +3791,9 @@ class TypeVarTransformer { } // Unpack the tuple and synthesize a new function in the process. - const newFunctionType = FunctionType.createSynthesizedInstance('', functionType.details.flags); + const newFunctionType = TypeBase.isInstantiable(functionType) + ? FunctionType.createInstantiable(functionType.details.flags | FunctionTypeFlags.SynthesizedMethod) + : FunctionType.createSynthesizedInstance('', functionType.details.flags); let insertKeywordOnlySeparator = false; let swallowPositionOnlySeparator = false; diff --git a/packages/pyright-internal/src/tests/samples/variadicTypeVar6.py b/packages/pyright-internal/src/tests/samples/variadicTypeVar6.py index 07d839d392cf..05b28b2059d5 100644 --- a/packages/pyright-internal/src/tests/samples/variadicTypeVar6.py +++ b/packages/pyright-internal/src/tests/samples/variadicTypeVar6.py @@ -3,7 +3,7 @@ # pyright: reportMissingModuleSource=false, reportMissingTypeArgument=true -from typing import Generic, TypeVar, Union +from typing import Callable, Generic, TypeVar, Union from typing_extensions import TypeVarTuple, Unpack _Xs = TypeVarTuple("_Xs") @@ -76,3 +76,10 @@ def func2(x: Alias6[float, bool], y: Alias6, z: Alias6[()]): reveal_type(y, expected_text="tuple[int, Unknown]") reveal_type(z, expected_text="tuple[int]") + + +Alias7 = Callable[[Unpack[_Xs]], None] + + +def func3(cb: Alias7[int, Unpack[_Xs]]) -> tuple[Unpack[_Xs]]: + ...