@zzzen/pyright-internal 1.2.0-dev.20230205 → 1.2.0-dev.20230219
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyzer/backgroundAnalysisProgram.d.ts +1 -0
- package/dist/analyzer/backgroundAnalysisProgram.js +5 -0
- package/dist/analyzer/backgroundAnalysisProgram.js.map +1 -1
- package/dist/analyzer/checker.js +8 -5
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/commentUtils.d.ts +6 -1
- package/dist/analyzer/commentUtils.js +100 -25
- package/dist/analyzer/commentUtils.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +83 -67
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/dataClasses.js +9 -2
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/declaration.d.ts +1 -0
- package/dist/analyzer/declaration.js.map +1 -1
- package/dist/analyzer/importStatementUtils.d.ts +1 -0
- package/dist/analyzer/importStatementUtils.js +14 -1
- package/dist/analyzer/importStatementUtils.js.map +1 -1
- package/dist/analyzer/parameterUtils.d.ts +2 -0
- package/dist/analyzer/parameterUtils.js +20 -0
- package/dist/analyzer/parameterUtils.js.map +1 -0
- package/dist/analyzer/parseTreeUtils.d.ts +6 -2
- package/dist/analyzer/parseTreeUtils.js +52 -14
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/parseTreeWalker.d.ts +1 -1
- package/dist/analyzer/patternMatching.js +25 -5
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.d.ts +9 -2
- package/dist/analyzer/program.js +106 -8
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/service.d.ts +1 -4
- package/dist/analyzer/service.js +16 -36
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceFile.d.ts +4 -0
- package/dist/analyzer/sourceFile.js +82 -16
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/testWalker.js +23 -15
- package/dist/analyzer/testWalker.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +122 -71
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +2 -1
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typePrinter.d.ts +2 -1
- package/dist/analyzer/typePrinter.js +13 -0
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +1 -1
- package/dist/analyzer/typeUtils.js +189 -142
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typeVarContext.d.ts +31 -14
- package/dist/analyzer/typeVarContext.js +158 -79
- package/dist/analyzer/typeVarContext.js.map +1 -1
- package/dist/analyzer/types.d.ts +2 -1
- package/dist/analyzer/types.js +1 -0
- package/dist/analyzer/types.js.map +1 -1
- package/dist/backgroundAnalysisBase.d.ts +2 -1
- package/dist/backgroundAnalysisBase.js +15 -1
- package/dist/backgroundAnalysisBase.js.map +1 -1
- package/dist/backgroundThreadBase.js +1 -0
- package/dist/backgroundThreadBase.js.map +1 -1
- package/dist/common/commandLineOptions.d.ts +2 -0
- package/dist/common/commandLineOptions.js.map +1 -1
- package/dist/common/configOptions.d.ts +3 -0
- package/dist/common/configOptions.js +10 -1
- package/dist/common/configOptions.js.map +1 -1
- package/dist/common/core.d.ts +2 -0
- package/dist/common/core.js +9 -1
- package/dist/common/core.js.map +1 -1
- package/dist/common/diagnostic.d.ts +15 -3
- package/dist/common/diagnostic.js +13 -4
- package/dist/common/diagnostic.js.map +1 -1
- package/dist/common/editAction.d.ts +1 -0
- package/dist/common/editAction.js +8 -0
- package/dist/common/editAction.js.map +1 -1
- package/dist/common/extensibility.d.ts +34 -11
- package/dist/common/extensibility.js +63 -18
- package/dist/common/extensibility.js.map +1 -1
- package/dist/common/pathUtils.d.ts +3 -0
- package/dist/common/pathUtils.js +18 -0
- package/dist/common/pathUtils.js.map +1 -1
- package/dist/common/textEditUtils.d.ts +26 -9
- package/dist/common/textEditUtils.js +218 -41
- package/dist/common/textEditUtils.js.map +1 -1
- package/dist/common/textRangeCollection.d.ts +1 -0
- package/dist/common/textRangeCollection.js +54 -20
- package/dist/common/textRangeCollection.js.map +1 -1
- package/dist/languageServerBase.d.ts +3 -0
- package/dist/languageServerBase.js +90 -1
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/analyzerServiceExecutor.js +1 -0
- package/dist/languageService/analyzerServiceExecutor.js.map +1 -1
- package/dist/languageService/completionProvider.js +13 -7
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/definitionProvider.js +1 -1
- package/dist/languageService/definitionProvider.js.map +1 -1
- package/dist/languageService/documentSymbolCollector.js +1 -1
- package/dist/languageService/documentSymbolCollector.js.map +1 -1
- package/dist/languageService/hoverProvider.js +10 -6
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/importAdder.d.ts +4 -0
- package/dist/languageService/importAdder.js +50 -13
- package/dist/languageService/importAdder.js.map +1 -1
- package/dist/languageService/insertionPointUtils.js +28 -7
- package/dist/languageService/insertionPointUtils.js.map +1 -1
- package/dist/languageService/renameModuleProvider.d.ts +12 -10
- package/dist/languageService/renameModuleProvider.js +240 -229
- package/dist/languageService/renameModuleProvider.js.map +1 -1
- package/dist/languageService/signatureHelpProvider.js +20 -3
- package/dist/languageService/signatureHelpProvider.js.map +1 -1
- package/dist/languageService/tooltipUtils.js +1 -1
- package/dist/languageService/tooltipUtils.js.map +1 -1
- package/dist/localization/localize.d.ts +10 -1
- package/dist/localization/localize.js +6 -1
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.en-us.json +8 -2
- package/dist/tests/checker.test.js +5 -0
- package/dist/tests/checker.test.js.map +1 -1
- package/dist/tests/fourslash/completions.params.fourslash.js +37 -0
- package/dist/tests/fourslash/completions.params.fourslash.js.map +1 -1
- package/dist/tests/fourslash/hover.inferred.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.inferred.fourslash.js +24 -0
- package/dist/tests/fourslash/hover.inferred.fourslash.js.map +1 -0
- package/dist/tests/fourslash/signature.complicated.fourslash.js +31 -1
- package/dist/tests/fourslash/signature.complicated.fourslash.js.map +1 -1
- package/dist/tests/hoverProvider.test.js +27 -0
- package/dist/tests/hoverProvider.test.js.map +1 -1
- package/dist/tests/importAdder.test.js +39 -2
- package/dist/tests/importAdder.test.js.map +1 -1
- package/dist/tests/insertionPointUtils.test.js +70 -3
- package/dist/tests/insertionPointUtils.test.js.map +1 -1
- package/dist/tests/{updateSymbolReference.test.d.ts → moveSymbol.importAdder.test.d.ts} +0 -0
- package/dist/tests/moveSymbol.importAdder.test.js +139 -0
- package/dist/tests/moveSymbol.importAdder.test.js.map +1 -0
- package/dist/tests/moveSymbol.insertion.test.d.ts +1 -0
- package/dist/tests/moveSymbol.insertion.test.js +360 -0
- package/dist/tests/moveSymbol.insertion.test.js.map +1 -0
- package/dist/tests/moveSymbol.misc.test.d.ts +1 -0
- package/dist/tests/moveSymbol.misc.test.js +37 -0
- package/dist/tests/moveSymbol.misc.test.js.map +1 -0
- package/dist/tests/moveSymbol.updateReference.test.d.ts +1 -0
- package/dist/tests/{updateSymbolReference.test.js → moveSymbol.updateReference.test.js} +235 -158
- package/dist/tests/moveSymbol.updateReference.test.js.map +1 -0
- package/dist/tests/parseTreeUtils.test.js +36 -13
- package/dist/tests/parseTreeUtils.test.js.map +1 -1
- package/dist/tests/renameModuleTestUtils.js +9 -3
- package/dist/tests/renameModuleTestUtils.js.map +1 -1
- package/dist/tests/testStateUtils.d.ts +2 -0
- package/dist/tests/testStateUtils.js +25 -22
- package/dist/tests/testStateUtils.js.map +1 -1
- package/dist/tests/textEditUtil.test.d.ts +1 -0
- package/dist/tests/textEditUtil.test.js +107 -0
- package/dist/tests/textEditUtil.test.js.map +1 -0
- package/dist/tests/typeEvaluator1.test.js +4 -0
- package/dist/tests/typeEvaluator1.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +2 -2
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +10 -2
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/workspaceMap.d.ts +0 -1
- package/dist/workspaceMap.js +0 -11
- package/dist/workspaceMap.js.map +1 -1
- package/package.json +1 -1
- package/dist/tests/updateSymbolReference.test.js.map +0 -1
@@ -1354,8 +1354,8 @@ function setTypeArgumentsRecursive(destType, srcType, typeVarContext, recursionC
|
|
1354
1354
|
setTypeArgumentsRecursive(destType.details.declaredReturnType, srcType, typeVarContext, recursionCount);
|
1355
1355
|
}
|
1356
1356
|
if (destType.details.paramSpec) {
|
1357
|
-
// Fill in an empty signature for a ParamSpec
|
1358
|
-
if (!typeVarContext.
|
1357
|
+
// Fill in an empty signature for a ParamSpec.
|
1358
|
+
if (!typeVarContext.getPrimarySignature().getTypeVar(destType.details.paramSpec)) {
|
1359
1359
|
const newFunction = types_1.FunctionType.createInstance('', '', '', 32768 /* SkipArgsKwargsCompatibilityCheck */ | 65536 /* ParamSpecValue */);
|
1360
1360
|
types_1.FunctionType.addDefaultParameters(newFunction);
|
1361
1361
|
typeVarContext.setTypeVarType(destType.details.paramSpec, newFunction);
|
@@ -1369,7 +1369,7 @@ function setTypeArgumentsRecursive(destType, srcType, typeVarContext, recursionC
|
|
1369
1369
|
});
|
1370
1370
|
break;
|
1371
1371
|
case 10 /* TypeVar */:
|
1372
|
-
if (!typeVarContext.
|
1372
|
+
if (!typeVarContext.getPrimarySignature().getTypeVar(destType)) {
|
1373
1373
|
typeVarContext.setTypeVarType(destType, srcType);
|
1374
1374
|
}
|
1375
1375
|
break;
|
@@ -2370,7 +2370,12 @@ class TypeVarTransformer {
|
|
2370
2370
|
const newOverloads = [];
|
2371
2371
|
type.overloads.forEach((entry) => {
|
2372
2372
|
const replacementType = this._transformTypeVarsInFunctionType(entry, recursionCount);
|
2373
|
-
|
2373
|
+
if ((0, types_1.isFunction)(replacementType)) {
|
2374
|
+
newOverloads.push(replacementType);
|
2375
|
+
}
|
2376
|
+
else {
|
2377
|
+
newOverloads.push(...replacementType.overloads);
|
2378
|
+
}
|
2374
2379
|
if (replacementType !== entry) {
|
2375
2380
|
requiresUpdate = true;
|
2376
2381
|
}
|
@@ -2393,6 +2398,11 @@ class TypeVarTransformer {
|
|
2393
2398
|
transformUnionSubtype(preTransform, postTransform, recursionCount) {
|
2394
2399
|
return postTransform;
|
2395
2400
|
}
|
2401
|
+
doForEachSignatureContext(callback) {
|
2402
|
+
// By default, simply return the result of the callback. Subclasses
|
2403
|
+
// can override this method as they see fit.
|
2404
|
+
return callback();
|
2405
|
+
}
|
2396
2406
|
_transformGenericTypeAlias(type, recursionCount) {
|
2397
2407
|
if (!type.typeAliasInfo || !type.typeAliasInfo.typeParameters || !type.typeAliasInfo.typeArguments) {
|
2398
2408
|
return type;
|
@@ -2511,148 +2521,156 @@ class TypeVarTransformer {
|
|
2511
2521
|
/* includeSubclasses */ undefined, newTupleTypeArgs);
|
2512
2522
|
}
|
2513
2523
|
_transformTypeVarsInFunctionType(sourceType, recursionCount) {
|
2514
|
-
|
2515
|
-
|
2516
|
-
|
2517
|
-
|
2518
|
-
|
2519
|
-
|
2520
|
-
|
2521
|
-
|
2522
|
-
|
2523
|
-
|
2524
|
-
|
2525
|
-
|
2526
|
-
|
2527
|
-
|
2528
|
-
|
2529
|
-
|
2530
|
-
|
2531
|
-
|
2532
|
-
|
2533
|
-
|
2534
|
-
|
2535
|
-
|
2536
|
-
|
2537
|
-
|
2538
|
-
|
2539
|
-
(
|
2540
|
-
(
|
2541
|
-
|
2542
|
-
|
2543
|
-
|
2544
|
-
|
2545
|
-
|
2546
|
-
|
2547
|
-
|
2524
|
+
return this.doForEachSignatureContext(() => {
|
2525
|
+
let functionType = sourceType;
|
2526
|
+
// Handle functions with a parameter specification in a special manner.
|
2527
|
+
if (functionType.details.paramSpec) {
|
2528
|
+
const paramSpec = this.transformParamSpec(functionType.details.paramSpec, recursionCount);
|
2529
|
+
if (paramSpec) {
|
2530
|
+
functionType = types_1.FunctionType.cloneForParamSpec(functionType, paramSpec);
|
2531
|
+
}
|
2532
|
+
}
|
2533
|
+
const declaredReturnType = types_1.FunctionType.getSpecializedReturnType(functionType);
|
2534
|
+
const specializedReturnType = declaredReturnType
|
2535
|
+
? this.apply(declaredReturnType, recursionCount)
|
2536
|
+
: undefined;
|
2537
|
+
let typesRequiredSpecialization = declaredReturnType !== specializedReturnType;
|
2538
|
+
const specializedParameters = {
|
2539
|
+
parameterTypes: [],
|
2540
|
+
returnType: specializedReturnType,
|
2541
|
+
};
|
2542
|
+
// Does this function end with *args: P.args, **args: P.kwargs? If so, we'll
|
2543
|
+
// modify the function and replace these parameters with the signature captured
|
2544
|
+
// by the ParamSpec.
|
2545
|
+
if (functionType.details.parameters.length >= 2) {
|
2546
|
+
const argsParam = functionType.details.parameters[functionType.details.parameters.length - 2];
|
2547
|
+
const kwargsParam = functionType.details.parameters[functionType.details.parameters.length - 1];
|
2548
|
+
const argsParamType = types_1.FunctionType.getEffectiveParameterType(functionType, functionType.details.parameters.length - 2);
|
2549
|
+
const kwargsParamType = types_1.FunctionType.getEffectiveParameterType(functionType, functionType.details.parameters.length - 1);
|
2550
|
+
if (argsParam.category === 1 /* VarArgList */ &&
|
2551
|
+
kwargsParam.category === 2 /* VarArgDictionary */ &&
|
2552
|
+
(0, types_1.isParamSpec)(argsParamType) &&
|
2553
|
+
(0, types_1.isParamSpec)(kwargsParamType) &&
|
2554
|
+
(0, types_1.isTypeSame)(argsParamType, kwargsParamType)) {
|
2555
|
+
const paramSpecType = this.transformParamSpec(argsParamType, recursionCount);
|
2556
|
+
if (paramSpecType) {
|
2557
|
+
if (paramSpecType.details.parameters.length > 0 ||
|
2558
|
+
paramSpecType.details.paramSpec === undefined ||
|
2559
|
+
!(0, types_1.isTypeSame)(argsParamType, paramSpecType.details.paramSpec)) {
|
2560
|
+
functionType = types_1.FunctionType.cloneForParamSpecApplication(functionType, paramSpecType);
|
2561
|
+
}
|
2548
2562
|
}
|
2549
2563
|
}
|
2550
2564
|
}
|
2551
|
-
|
2552
|
-
|
2553
|
-
|
2554
|
-
|
2555
|
-
|
2556
|
-
|
2557
|
-
|
2558
|
-
|
2559
|
-
|
2560
|
-
|
2561
|
-
|
2562
|
-
|
2563
|
-
|
2564
|
-
|
2565
|
-
|
2566
|
-
|
2565
|
+
let variadicParamIndex;
|
2566
|
+
let variadicTypesToUnpack;
|
2567
|
+
const specializedDefaultArgs = [];
|
2568
|
+
const wasTransformingTypeArg = this._isTransformingTypeArg;
|
2569
|
+
this._isTransformingTypeArg = true;
|
2570
|
+
for (let i = 0; i < functionType.details.parameters.length; i++) {
|
2571
|
+
const paramType = types_1.FunctionType.getEffectiveParameterType(functionType, i);
|
2572
|
+
const specializedType = this.apply(paramType, recursionCount);
|
2573
|
+
specializedParameters.parameterTypes.push(specializedType);
|
2574
|
+
// Do we need to specialize the default argument type for this parameter?
|
2575
|
+
let defaultArgType = types_1.FunctionType.getEffectiveParameterDefaultArgType(functionType, i);
|
2576
|
+
if (defaultArgType) {
|
2577
|
+
const specializedArgType = this.apply(defaultArgType, recursionCount);
|
2578
|
+
if (specializedArgType !== defaultArgType) {
|
2579
|
+
defaultArgType = specializedArgType;
|
2580
|
+
typesRequiredSpecialization = true;
|
2581
|
+
}
|
2582
|
+
}
|
2583
|
+
specializedDefaultArgs.push(defaultArgType);
|
2584
|
+
if (variadicParamIndex === undefined &&
|
2585
|
+
(0, types_1.isVariadicTypeVar)(paramType) &&
|
2586
|
+
functionType.details.parameters[i].category === 1 /* VarArgList */) {
|
2587
|
+
variadicParamIndex = i;
|
2588
|
+
if ((0, types_1.isClassInstance)(specializedType) &&
|
2589
|
+
isTupleClass(specializedType) &&
|
2590
|
+
specializedType.isUnpacked) {
|
2591
|
+
variadicTypesToUnpack = specializedType.tupleTypeArguments;
|
2592
|
+
}
|
2593
|
+
}
|
2594
|
+
if (paramType !== specializedType) {
|
2567
2595
|
typesRequiredSpecialization = true;
|
2568
2596
|
}
|
2569
2597
|
}
|
2570
|
-
|
2571
|
-
if (
|
2572
|
-
(
|
2573
|
-
|
2574
|
-
|
2575
|
-
if ((0, types_1.isClassInstance)(specializedType) && isTupleClass(specializedType) && specializedType.isUnpacked) {
|
2576
|
-
variadicTypesToUnpack = specializedType.tupleTypeArguments;
|
2598
|
+
let specializedInferredReturnType;
|
2599
|
+
if (functionType.inferredReturnType) {
|
2600
|
+
specializedInferredReturnType = this.apply(functionType.inferredReturnType, recursionCount);
|
2601
|
+
if (specializedInferredReturnType !== functionType.inferredReturnType) {
|
2602
|
+
typesRequiredSpecialization = true;
|
2577
2603
|
}
|
2578
2604
|
}
|
2579
|
-
|
2580
|
-
|
2581
|
-
|
2582
|
-
|
2583
|
-
|
2584
|
-
|
2585
|
-
|
2586
|
-
|
2587
|
-
|
2588
|
-
|
2589
|
-
|
2590
|
-
|
2591
|
-
|
2592
|
-
|
2593
|
-
|
2594
|
-
|
2595
|
-
|
2596
|
-
|
2597
|
-
|
2598
|
-
|
2599
|
-
|
2600
|
-
|
2601
|
-
|
2602
|
-
|
2603
|
-
|
2604
|
-
|
2605
|
-
|
2606
|
-
|
2607
|
-
|
2608
|
-
|
2609
|
-
|
2610
|
-
|
2611
|
-
category: unpackedType.isUnbounded ? 1 /* VarArgList */ : 0 /* Simple */,
|
2612
|
-
name: `__p${newFunctionType.details.parameters.length}`,
|
2613
|
-
isNameSynthesized: true,
|
2614
|
-
type: unpackedType.type,
|
2615
|
-
hasDeclaredType: true,
|
2605
|
+
this._isTransformingTypeArg = wasTransformingTypeArg;
|
2606
|
+
if (!typesRequiredSpecialization) {
|
2607
|
+
return functionType;
|
2608
|
+
}
|
2609
|
+
if (specializedDefaultArgs.some((t) => t !== undefined)) {
|
2610
|
+
specializedParameters.parameterDefaultArgs = specializedDefaultArgs;
|
2611
|
+
}
|
2612
|
+
// If there was no unpacked variadic type variable, we're done.
|
2613
|
+
if (!variadicTypesToUnpack) {
|
2614
|
+
return types_1.FunctionType.cloneForSpecialization(functionType, specializedParameters, specializedInferredReturnType);
|
2615
|
+
}
|
2616
|
+
// Unpack the tuple and synthesize a new function in the process.
|
2617
|
+
const newFunctionType = types_1.FunctionType.createSynthesizedInstance('', functionType.details.flags);
|
2618
|
+
let insertKeywordOnlySeparator = false;
|
2619
|
+
let swallowPositionOnlySeparator = false;
|
2620
|
+
specializedParameters.parameterTypes.forEach((paramType, index) => {
|
2621
|
+
if (index === variadicParamIndex) {
|
2622
|
+
let sawUnboundedEntry = false;
|
2623
|
+
// Unpack the tuple into individual parameters.
|
2624
|
+
variadicTypesToUnpack.forEach((unpackedType) => {
|
2625
|
+
types_1.FunctionType.addParameter(newFunctionType, {
|
2626
|
+
category: unpackedType.isUnbounded
|
2627
|
+
? 1 /* VarArgList */
|
2628
|
+
: 0 /* Simple */,
|
2629
|
+
name: `__p${newFunctionType.details.parameters.length}`,
|
2630
|
+
isNameSynthesized: true,
|
2631
|
+
type: unpackedType.type,
|
2632
|
+
hasDeclaredType: true,
|
2633
|
+
});
|
2634
|
+
if (unpackedType.isUnbounded) {
|
2635
|
+
sawUnboundedEntry = true;
|
2636
|
+
}
|
2616
2637
|
});
|
2617
|
-
if (
|
2618
|
-
|
2638
|
+
if (sawUnboundedEntry) {
|
2639
|
+
swallowPositionOnlySeparator = true;
|
2640
|
+
}
|
2641
|
+
else {
|
2642
|
+
insertKeywordOnlySeparator = true;
|
2619
2643
|
}
|
2620
|
-
});
|
2621
|
-
if (sawUnboundedEntry) {
|
2622
|
-
swallowPositionOnlySeparator = true;
|
2623
2644
|
}
|
2624
2645
|
else {
|
2625
|
-
|
2626
|
-
|
2627
|
-
|
2628
|
-
|
2629
|
-
|
2630
|
-
|
2631
|
-
|
2632
|
-
|
2633
|
-
|
2634
|
-
insertKeywordOnlySeparator
|
2635
|
-
|
2636
|
-
|
2637
|
-
|
2638
|
-
|
2639
|
-
|
2640
|
-
|
2641
|
-
|
2642
|
-
|
2643
|
-
|
2644
|
-
|
2645
|
-
|
2646
|
-
|
2647
|
-
|
2648
|
-
}
|
2649
|
-
if (param.category !== 0 /* Simple */ || param.name || !swallowPositionOnlySeparator) {
|
2650
|
-
types_1.FunctionType.addParameter(newFunctionType, param);
|
2646
|
+
const param = { ...functionType.details.parameters[index] };
|
2647
|
+
if (param.category === 1 /* VarArgList */ && !param.name) {
|
2648
|
+
insertKeywordOnlySeparator = false;
|
2649
|
+
}
|
2650
|
+
else if (param.category === 2 /* VarArgDictionary */) {
|
2651
|
+
insertKeywordOnlySeparator = false;
|
2652
|
+
}
|
2653
|
+
// Insert a keyword-only separator parameter if we previously
|
2654
|
+
// unpacked a variadic TypeVar.
|
2655
|
+
if (param.category === 0 /* Simple */ && param.name && insertKeywordOnlySeparator) {
|
2656
|
+
types_1.FunctionType.addParameter(newFunctionType, {
|
2657
|
+
category: 1 /* VarArgList */,
|
2658
|
+
type: types_1.UnknownType.create(),
|
2659
|
+
});
|
2660
|
+
insertKeywordOnlySeparator = false;
|
2661
|
+
}
|
2662
|
+
param.type = paramType;
|
2663
|
+
if (param.name && param.isNameSynthesized) {
|
2664
|
+
param.name = `__p${newFunctionType.details.parameters.length}`;
|
2665
|
+
}
|
2666
|
+
if (param.category !== 0 /* Simple */ || param.name || !swallowPositionOnlySeparator) {
|
2667
|
+
types_1.FunctionType.addParameter(newFunctionType, param);
|
2668
|
+
}
|
2651
2669
|
}
|
2652
|
-
}
|
2670
|
+
});
|
2671
|
+
newFunctionType.details.declaredReturnType = specializedParameters.returnType;
|
2672
|
+
return newFunctionType;
|
2653
2673
|
});
|
2654
|
-
newFunctionType.details.declaredReturnType = specializedParameters.returnType;
|
2655
|
-
return newFunctionType;
|
2656
2674
|
}
|
2657
2675
|
}
|
2658
2676
|
// For a TypeVar with a default type, validates whether the default type is using
|
@@ -2688,15 +2706,17 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
2688
2706
|
this._isSolvingDefaultType = false;
|
2689
2707
|
}
|
2690
2708
|
transformTypeVar(typeVar, recursionCount) {
|
2709
|
+
var _a;
|
2710
|
+
const signatureContext = this._typeVarContext.getSignatureContext((_a = this._activeTypeVarSignatureContextIndex) !== null && _a !== void 0 ? _a : 0);
|
2691
2711
|
// If the type variable is unrelated to the scopes we're solving,
|
2692
2712
|
// don't transform that type variable.
|
2693
2713
|
if (typeVar.scopeId && this._typeVarContext.hasSolveForScope(typeVar.scopeId)) {
|
2694
|
-
let replacement =
|
2714
|
+
let replacement = signatureContext.getTypeVarType(typeVar, !!this._options.useNarrowBoundOnly);
|
2695
2715
|
// If there was no narrow bound but there is a wide bound that
|
2696
2716
|
// contains literals, we'll use the wide bound even if "useNarrowBoundOnly"
|
2697
2717
|
// is specified.
|
2698
2718
|
if (!replacement && !!this._options.useNarrowBoundOnly) {
|
2699
|
-
const wideType =
|
2719
|
+
const wideType = signatureContext.getTypeVarType(typeVar);
|
2700
2720
|
if (wideType) {
|
2701
2721
|
if (containsLiteralType(wideType, /* includeTypeArgs */ true)) {
|
2702
2722
|
replacement = wideType;
|
@@ -2730,11 +2750,11 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
2730
2750
|
}
|
2731
2751
|
// If we're solving a default type, handle type variables with no scope ID.
|
2732
2752
|
if (this._isSolvingDefaultType && !typeVar.scopeId) {
|
2733
|
-
const replacementEntry =
|
2753
|
+
const replacementEntry = signatureContext
|
2734
2754
|
.getTypeVars()
|
2735
2755
|
.find((entry) => entry.typeVar.details.name === typeVar.details.name);
|
2736
2756
|
if (replacementEntry) {
|
2737
|
-
return
|
2757
|
+
return signatureContext.getTypeVarType(replacementEntry.typeVar);
|
2738
2758
|
}
|
2739
2759
|
if (typeVar.details.defaultType) {
|
2740
2760
|
return this.apply(typeVar.details.defaultType, recursionCount);
|
@@ -2743,11 +2763,11 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
2743
2763
|
}
|
2744
2764
|
// If we're solving a default type, handle type variables with no scope ID.
|
2745
2765
|
if (this._isSolvingDefaultType && !typeVar.scopeId) {
|
2746
|
-
const replacementEntry =
|
2766
|
+
const replacementEntry = signatureContext
|
2747
2767
|
.getTypeVars()
|
2748
2768
|
.find((entry) => entry.typeVar.details.name === typeVar.details.name);
|
2749
2769
|
if (replacementEntry) {
|
2750
|
-
return
|
2770
|
+
return signatureContext.getTypeVarType(replacementEntry.typeVar);
|
2751
2771
|
}
|
2752
2772
|
if (typeVar.details.defaultType) {
|
2753
2773
|
return this.apply(typeVar.details.defaultType, recursionCount);
|
@@ -2781,6 +2801,7 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
2781
2801
|
return postTransform;
|
2782
2802
|
}
|
2783
2803
|
transformTupleTypeVar(typeVar) {
|
2804
|
+
var _a;
|
2784
2805
|
if (!typeVar.scopeId || !this._typeVarContext.hasSolveForScope(typeVar.scopeId)) {
|
2785
2806
|
const defaultType = typeVar.details.defaultType;
|
2786
2807
|
if (defaultType && (0, types_1.isClassInstance)(defaultType) && defaultType.tupleTypeArguments) {
|
@@ -2788,16 +2809,19 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
2788
2809
|
}
|
2789
2810
|
return undefined;
|
2790
2811
|
}
|
2791
|
-
|
2812
|
+
const signatureContext = this._typeVarContext.getSignatureContext((_a = this._activeTypeVarSignatureContextIndex) !== null && _a !== void 0 ? _a : 0);
|
2813
|
+
return signatureContext.getTupleTypeVar(typeVar);
|
2792
2814
|
}
|
2793
2815
|
transformParamSpec(paramSpec, recursionCount) {
|
2816
|
+
var _a;
|
2817
|
+
const signatureContext = this._typeVarContext.getSignatureContext((_a = this._activeTypeVarSignatureContextIndex) !== null && _a !== void 0 ? _a : 0);
|
2794
2818
|
// If we're solving a default type, handle param specs with no scope ID.
|
2795
2819
|
if (this._isSolvingDefaultType && !paramSpec.scopeId) {
|
2796
|
-
const replacementEntry =
|
2820
|
+
const replacementEntry = signatureContext
|
2797
2821
|
.getTypeVars()
|
2798
2822
|
.find((entry) => entry.typeVar.details.name === paramSpec.details.name);
|
2799
2823
|
if (replacementEntry) {
|
2800
|
-
return
|
2824
|
+
return signatureContext.getParamSpecType(replacementEntry.typeVar);
|
2801
2825
|
}
|
2802
2826
|
if (paramSpec.details.defaultType) {
|
2803
2827
|
return convertTypeToParamSpecValue(this.apply(paramSpec.details.defaultType, recursionCount));
|
@@ -2807,7 +2831,7 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
2807
2831
|
if (!paramSpec.scopeId || !this._typeVarContext.hasSolveForScope(paramSpec.scopeId)) {
|
2808
2832
|
return undefined;
|
2809
2833
|
}
|
2810
|
-
const transformedParamSpec =
|
2834
|
+
const transformedParamSpec = signatureContext.getParamSpecType(paramSpec);
|
2811
2835
|
if (transformedParamSpec) {
|
2812
2836
|
return transformedParamSpec;
|
2813
2837
|
}
|
@@ -2821,6 +2845,29 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
2821
2845
|
}
|
2822
2846
|
return undefined;
|
2823
2847
|
}
|
2848
|
+
doForEachSignatureContext(callback) {
|
2849
|
+
const signatureContexts = this._typeVarContext.getSignatureContexts();
|
2850
|
+
// Handle the common case where there are not multiple signature contexts.
|
2851
|
+
if (signatureContexts.length <= 1) {
|
2852
|
+
return callback();
|
2853
|
+
}
|
2854
|
+
// Loop through all of the signature contexts in the type var context
|
2855
|
+
// to create an overload type.
|
2856
|
+
const overloadTypes = signatureContexts.map((_, index) => {
|
2857
|
+
this._activeTypeVarSignatureContextIndex = index;
|
2858
|
+
return callback();
|
2859
|
+
});
|
2860
|
+
this._activeTypeVarSignatureContextIndex = undefined;
|
2861
|
+
const filteredOverloads = [];
|
2862
|
+
doForEachSubtype((0, types_1.combineTypes)(overloadTypes), (subtype) => {
|
2863
|
+
(0, debug_1.assert)((0, types_1.isFunction)(subtype));
|
2864
|
+
filteredOverloads.push(subtype);
|
2865
|
+
});
|
2866
|
+
if (filteredOverloads.length === 1) {
|
2867
|
+
return filteredOverloads[0];
|
2868
|
+
}
|
2869
|
+
return types_1.OverloadedFunctionType.create(filteredOverloads);
|
2870
|
+
}
|
2824
2871
|
_solveDefaultType(defaultType, recursionCount) {
|
2825
2872
|
const wasSolvingDefaultType = this._isSolvingDefaultType;
|
2826
2873
|
this._isSolvingDefaultType = true;
|