Skip to content

Commit

Permalink
Fixed a bug that led to a false positive error when specializing a ty…
Browse files Browse the repository at this point in the history
…pe alias consisting of a callable parameterized by a TypeVarTuple. This partially addresses microsoft#6317.
  • Loading branch information
erictraut committed Nov 3, 2023
1 parent 841a79e commit fb67700
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/pyright-internal/src/analyzer/typeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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]]:
...

0 comments on commit fb67700

Please sign in to comment.