@zzzen/pyright-internal 1.2.0-dev.20230409 → 1.2.0-dev.20230423
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/binder.js +1 -3
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.js +22 -0
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/commentUtils.d.ts +1 -1
- package/dist/analyzer/commentUtils.js +18 -3
- package/dist/analyzer/commentUtils.js.map +1 -1
- package/dist/analyzer/constructorTransform.js +112 -49
- package/dist/analyzer/constructorTransform.js.map +1 -1
- package/dist/analyzer/declarationUtils.js +2 -1
- package/dist/analyzer/declarationUtils.js.map +1 -1
- package/dist/analyzer/docStringConversion.js +2 -3
- package/dist/analyzer/docStringConversion.js.map +1 -1
- package/dist/analyzer/enums.d.ts +1 -1
- package/dist/analyzer/enums.js +114 -55
- package/dist/analyzer/enums.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.js +9 -4
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/patternMatching.d.ts +6 -2
- package/dist/analyzer/patternMatching.js +109 -2
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.d.ts +9 -7
- package/dist/analyzer/program.js +106 -46
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/service.d.ts +2 -2
- package/dist/analyzer/service.js +6 -6
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceFile.d.ts +1 -3
- package/dist/analyzer/sourceFile.js +1 -9
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/sourceMapper.js +1 -1
- package/dist/analyzer/sourceMapper.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +147 -38
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +4 -3
- package/dist/analyzer/typeEvaluatorTypes.js +0 -2
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.d.ts +2 -0
- package/dist/analyzer/typeGuards.js +172 -175
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.d.ts +1 -1
- package/dist/analyzer/typePrinter.js +21 -18
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeUtils.js +13 -13
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/types.d.ts +2 -1
- package/dist/analyzer/types.js +20 -4
- package/dist/analyzer/types.js.map +1 -1
- package/dist/common/configOptions.d.ts +1 -1
- package/dist/common/configOptions.js +3 -3
- package/dist/common/configOptions.js.map +1 -1
- package/dist/common/extensibility.d.ts +7 -4
- package/dist/common/extensibility.js.map +1 -1
- package/dist/common/fullAccessHost.d.ts +2 -1
- package/dist/common/fullAccessHost.js +11 -1
- package/dist/common/fullAccessHost.js.map +1 -1
- package/dist/common/host.d.ts +3 -2
- package/dist/common/host.js +1 -1
- package/dist/common/host.js.map +1 -1
- package/dist/languageServerBase.js +3 -2
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/autoImporter.d.ts +1 -1
- package/dist/languageService/autoImporter.js +2 -2
- package/dist/languageService/autoImporter.js.map +1 -1
- package/dist/languageService/callHierarchyProvider.js +17 -4
- package/dist/languageService/callHierarchyProvider.js.map +1 -1
- package/dist/languageService/completionProvider.js +259 -93
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/completionProviderUtils.js +11 -3
- package/dist/languageService/completionProviderUtils.js.map +1 -1
- package/dist/languageService/documentSymbolCollector.js +1 -1
- package/dist/languageService/documentSymbolCollector.js.map +1 -1
- package/dist/languageService/hoverProvider.d.ts +28 -28
- package/dist/languageService/hoverProvider.js +151 -118
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/importAdder.d.ts +13 -2
- package/dist/languageService/importAdder.js +73 -26
- package/dist/languageService/importAdder.js.map +1 -1
- package/dist/languageService/indentationUtils.js +9 -4
- package/dist/languageService/indentationUtils.js.map +1 -1
- package/dist/languageService/insertionPointUtils.js +2 -2
- package/dist/languageService/insertionPointUtils.js.map +1 -1
- package/dist/localization/localize.d.ts +2 -0
- package/dist/localization/localize.js +2 -0
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.en-us.json +2 -0
- package/dist/tests/checker.test.js +1 -1
- package/dist/tests/completions.test.js +412 -0
- package/dist/tests/completions.test.js.map +1 -1
- package/dist/tests/docStringConversion.test.js +11 -1
- package/dist/tests/docStringConversion.test.js.map +1 -1
- package/dist/tests/fourslash/completions.inherited.function.docFromStub.fourslash.js +1 -1
- package/dist/tests/fourslash/completions.inherited.function.docFromStub.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.override2.fourslash.js +16 -1
- package/dist/tests/fourslash/completions.override2.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.variableDocStrings.fourslash.js +1 -1
- package/dist/tests/fourslash/completions.variableDocStrings.fourslash.js.map +1 -1
- package/dist/tests/fourslash/fourslash.d.ts +11 -1
- package/dist/tests/fourslash/hover.docstring.overloads.fourslash.js +2 -2
- package/dist/tests/fourslash/hover.docstring.overloads.fourslash.js.map +1 -1
- package/dist/tests/fourslash/hover.variable.docString.fourslash.js +1 -1
- package/dist/tests/fourslash/hover.variable.docString.fourslash.js.map +1 -1
- package/dist/tests/fourslash/showcallhierarchy.incomingCalls.aliasedFunction.fourslash.js +5 -6
- package/dist/tests/fourslash/showcallhierarchy.incomingCalls.aliasedFunction.fourslash.js.map +1 -1
- package/dist/tests/fourslash/showcallhierarchy.incomingCalls.aliasedVariable.fourslash.js +1 -4
- package/dist/tests/fourslash/showcallhierarchy.incomingCalls.aliasedVariable.fourslash.js.map +1 -1
- package/dist/tests/fourslash/showcallhierarchy.incomingCalls.function.fourslash.js +10 -9
- package/dist/tests/fourslash/showcallhierarchy.incomingCalls.function.fourslash.js.map +1 -1
- package/dist/tests/fourslash/showcallhierarchy.outgoingCalls.aliasedFunction1.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/showcallhierarchy.outgoingCalls.aliasedFunction1.fourslash.js +54 -0
- package/dist/tests/fourslash/showcallhierarchy.outgoingCalls.aliasedFunction1.fourslash.js.map +1 -0
- package/dist/tests/fourslash/showcallhierarchy.outgoingCalls.aliasedFunction2.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/showcallhierarchy.outgoingCalls.aliasedFunction2.fourslash.js +46 -0
- package/dist/tests/fourslash/showcallhierarchy.outgoingCalls.aliasedFunction2.fourslash.js.map +1 -0
- package/dist/tests/fourslash/showcallhierarchy.outgoingCalls.function.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/showcallhierarchy.outgoingCalls.function.fourslash.js +39 -0
- package/dist/tests/fourslash/showcallhierarchy.outgoingCalls.function.fourslash.js.map +1 -0
- package/dist/tests/harness/fourslash/fourSlashParser.js +1 -1
- package/dist/tests/harness/fourslash/fourSlashParser.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.d.ts +6 -1
- package/dist/tests/harness/fourslash/testState.js +38 -6
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/harness/testHost.js +1 -1
- package/dist/tests/harness/testHost.js.map +1 -1
- package/dist/tests/harness/vfs/factory.js +2 -2
- package/dist/tests/harness/vfs/factory.js.map +1 -1
- package/dist/tests/harness/vfs/filesystem.js +26 -25
- package/dist/tests/harness/vfs/filesystem.js.map +1 -1
- package/dist/tests/hoverProvider.test.js +6 -0
- package/dist/tests/hoverProvider.test.js.map +1 -1
- package/dist/tests/importAdder.test.js +69 -1
- package/dist/tests/importAdder.test.js.map +1 -1
- package/dist/tests/indentationUtils.ptvs.test.js +2 -2
- package/dist/tests/indentationUtils.ptvs.test.js.map +1 -1
- package/dist/tests/indentationUtils.test.js +18 -0
- package/dist/tests/indentationUtils.test.js.map +1 -1
- package/dist/tests/moveSymbol.insertion.test.js +25 -4
- package/dist/tests/moveSymbol.insertion.test.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +8 -0
- package/dist/tests/typeEvaluator1.test.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +4 -0
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +10 -0
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +5 -1
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typePrinter.test.js +5 -0
- package/dist/tests/typePrinter.test.js.map +1 -1
- package/dist/workspaceFactory.js +1 -1
- package/dist/workspaceFactory.js.map +1 -1
- package/package.json +1 -1
@@ -751,9 +751,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
751
751
|
if ((flags & 1 /* ConvertEllipsisToAny */) !== 0) {
|
752
752
|
typeResult = { type: types_1.AnyType.create(/* isEllipsis */ true) };
|
753
753
|
}
|
754
|
-
else if ((flags & 512 /* ConvertEllipsisToUnknown */) !== 0) {
|
755
|
-
typeResult = { type: types_1.UnknownType.create() };
|
756
|
-
}
|
757
754
|
else {
|
758
755
|
const ellipsisType = getBuiltInObject(node, 'ellipsis') || types_1.AnyType.create();
|
759
756
|
typeResult = { type: ellipsisType };
|
@@ -5295,7 +5292,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5295
5292
|
}
|
5296
5293
|
function getTypeOfCall(node, inferenceContext, flags) {
|
5297
5294
|
var _a;
|
5298
|
-
|
5295
|
+
let baseTypeResult;
|
5296
|
+
// Handle immediate calls of lambdas specially.
|
5297
|
+
if (node.leftExpression.nodeType === 30 /* Lambda */) {
|
5298
|
+
baseTypeResult = getTypeOfLambdaForCall(node, inferenceContext);
|
5299
|
+
}
|
5300
|
+
else {
|
5301
|
+
baseTypeResult = getTypeOfExpression(node.leftExpression, 2 /* DoNotSpecialize */);
|
5302
|
+
}
|
5299
5303
|
const argList = node.arguments.map((arg) => {
|
5300
5304
|
const functionArg = {
|
5301
5305
|
valueExpression: arg.valueExpression,
|
@@ -5386,6 +5390,57 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5386
5390
|
}
|
5387
5391
|
return typeResult;
|
5388
5392
|
}
|
5393
|
+
// This function is used in cases where a lambda is defined and immediately
|
5394
|
+
// called. In this case, we can't use normal bidirectional type inference
|
5395
|
+
// to determine the lambda's type. It needs to be inferred from the argument
|
5396
|
+
// types instead.
|
5397
|
+
function getTypeOfLambdaForCall(node, inferenceContext) {
|
5398
|
+
(0, debug_1.assert)(node.leftExpression.nodeType === 30 /* Lambda */);
|
5399
|
+
const expectedType = types_1.FunctionType.createSynthesizedInstance('');
|
5400
|
+
expectedType.details.declaredReturnType = inferenceContext
|
5401
|
+
? inferenceContext.expectedType
|
5402
|
+
: types_1.UnknownType.create();
|
5403
|
+
let isArgTypeIncomplete = false;
|
5404
|
+
node.arguments.forEach((arg, index) => {
|
5405
|
+
const argTypeResult = getTypeOfExpression(arg.valueExpression);
|
5406
|
+
if (argTypeResult.isIncomplete) {
|
5407
|
+
isArgTypeIncomplete = true;
|
5408
|
+
}
|
5409
|
+
types_1.FunctionType.addParameter(expectedType, {
|
5410
|
+
category: 0 /* Simple */,
|
5411
|
+
name: `p${index.toString()}`,
|
5412
|
+
type: argTypeResult.type,
|
5413
|
+
hasDeclaredType: true,
|
5414
|
+
});
|
5415
|
+
});
|
5416
|
+
// If the lambda's param list ends with a "/" positional parameter separator,
|
5417
|
+
// add a corresponding separator to the expected type.
|
5418
|
+
const lambdaParams = node.leftExpression.parameters;
|
5419
|
+
if (lambdaParams.length > 0) {
|
5420
|
+
const lastParam = lambdaParams[lambdaParams.length - 1];
|
5421
|
+
if (lastParam.category === 0 /* Simple */ && !lastParam.name) {
|
5422
|
+
types_1.FunctionType.addParameter(expectedType, {
|
5423
|
+
category: 0 /* Simple */,
|
5424
|
+
name: '',
|
5425
|
+
type: types_1.UnknownType.create(),
|
5426
|
+
});
|
5427
|
+
}
|
5428
|
+
}
|
5429
|
+
function getLambdaType() {
|
5430
|
+
return getTypeOfExpression(node.leftExpression, 2 /* DoNotSpecialize */, (0, typeUtils_1.makeInferenceContext)(expectedType));
|
5431
|
+
}
|
5432
|
+
// If one or more of the arguments are incomplete, use speculative mode
|
5433
|
+
// for the lambda evaluation because it may need to be reevaluated once
|
5434
|
+
// the arg types are complete.
|
5435
|
+
let typeResult = isArgTypeIncomplete || speculativeTypeTracker.isSpeculative(node) || (inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.isTypeIncomplete)
|
5436
|
+
? useSpeculativeMode(node.leftExpression, getLambdaType)
|
5437
|
+
: getLambdaType();
|
5438
|
+
// If bidirectional type inference failed, use normal type inference instead.
|
5439
|
+
if (typeResult.typeErrors) {
|
5440
|
+
typeResult = getTypeOfExpression(node.leftExpression, 2 /* DoNotSpecialize */);
|
5441
|
+
}
|
5442
|
+
return typeResult;
|
5443
|
+
}
|
5389
5444
|
function getTypeOfAssertType(node, inferenceContext) {
|
5390
5445
|
if (node.arguments.length !== 2 ||
|
5391
5446
|
node.arguments[0].argumentCategory !== 0 /* Simple */ ||
|
@@ -5662,6 +5717,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5662
5717
|
const argTypeOverride = expandedArgTypes[expandedTypesIndex];
|
5663
5718
|
const hasArgTypeOverride = argTypeOverride.some((a) => a !== undefined);
|
5664
5719
|
let possibleMatchResults = [];
|
5720
|
+
let possibleMatchInvolvesIncompleteUnknown = false;
|
5665
5721
|
isDefinitiveMatchFound = false;
|
5666
5722
|
for (let overloadIndex = 0; overloadIndex < argParamMatches.length; overloadIndex++) {
|
5667
5723
|
const overload = argParamMatches[overloadIndex].overload;
|
@@ -5709,8 +5765,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5709
5765
|
argResults: (_b = callResult.argResults) !== null && _b !== void 0 ? _b : [],
|
5710
5766
|
};
|
5711
5767
|
matchedOverloads.push(matchedOverloadInfo);
|
5712
|
-
if (callResult.
|
5768
|
+
if (callResult.anyOrUnknownArgument) {
|
5713
5769
|
possibleMatchResults.push(matchedOverloadInfo);
|
5770
|
+
if ((0, typeUtils_1.isIncompleteUnknown)(callResult.anyOrUnknownArgument)) {
|
5771
|
+
possibleMatchInvolvesIncompleteUnknown = true;
|
5772
|
+
}
|
5714
5773
|
}
|
5715
5774
|
else {
|
5716
5775
|
returnTypes.push(callResult.returnType);
|
@@ -5752,7 +5811,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5752
5811
|
});
|
5753
5812
|
dedupedMatchResults = dedupedMatchResults.filter((t) => !(0, types_1.isNever)(t));
|
5754
5813
|
const combinedTypes = (0, types_1.combineTypes)(dedupedMatchResults);
|
5755
|
-
returnTypes.push(dedupedMatchResults.length > 1
|
5814
|
+
returnTypes.push(dedupedMatchResults.length > 1
|
5815
|
+
? types_1.UnknownType.createPossibleType(combinedTypes, possibleMatchInvolvesIncompleteUnknown)
|
5816
|
+
: combinedTypes);
|
5756
5817
|
}
|
5757
5818
|
}
|
5758
5819
|
if (!matchedOverload) {
|
@@ -5777,7 +5838,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5777
5838
|
}
|
5778
5839
|
return {
|
5779
5840
|
argumentErrors: finalCallResult.argumentErrors,
|
5780
|
-
|
5841
|
+
anyOrUnknownArgument: finalCallResult.anyOrUnknownArgument,
|
5781
5842
|
returnType: (0, types_1.combineTypes)(returnTypes),
|
5782
5843
|
isTypeIncomplete,
|
5783
5844
|
specializedInitSelfType: finalCallResult.specializedInitSelfType,
|
@@ -6038,7 +6099,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6038
6099
|
if (expectedCallResult.isTypeIncomplete) {
|
6039
6100
|
isTypeIncomplete = true;
|
6040
6101
|
}
|
6041
|
-
overloadsUsedForCall.push(...expectedCallResult.overloadsUsedForCall);
|
6042
6102
|
}
|
6043
6103
|
}
|
6044
6104
|
if (!returnType) {
|
@@ -6134,6 +6194,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6134
6194
|
}
|
6135
6195
|
else if (!newReturnType) {
|
6136
6196
|
newReturnType = callResult.returnType;
|
6197
|
+
if (overloadsUsedForCall.length === 0) {
|
6198
|
+
overloadsUsedForCall.push(...callResult.overloadsUsedForCall);
|
6199
|
+
}
|
6137
6200
|
// If the constructor returned an object whose type matches the class of
|
6138
6201
|
// the original type being constructed, use the return type in case it was
|
6139
6202
|
// specialized. If it doesn't match, we'll fall back on the assumption that
|
@@ -6528,7 +6591,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6528
6591
|
return types_1.AnyType.create();
|
6529
6592
|
}
|
6530
6593
|
if ((0, types_1.isClass)(unexpandedSubtype) && (0, enums_1.isKnownEnumType)(className)) {
|
6531
|
-
return (_d = (0, enums_1.createEnumType)(errorNode, expandedSubtype, argList)) !== null && _d !== void 0 ? _d : types_1.UnknownType.create();
|
6594
|
+
return ((_d = (0, enums_1.createEnumType)(evaluatorInterface, errorNode, expandedSubtype, argList)) !== null && _d !== void 0 ? _d : types_1.UnknownType.create());
|
6532
6595
|
}
|
6533
6596
|
if (className === 'TypedDict') {
|
6534
6597
|
return (0, typedDicts_1.createTypedDictType)(evaluatorInterface, errorNode, expandedSubtype, argList);
|
@@ -7575,7 +7638,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7575
7638
|
let isTypeIncomplete = matchResults.isTypeIncomplete;
|
7576
7639
|
let argumentErrors = false;
|
7577
7640
|
let specializedInitSelfType;
|
7578
|
-
let
|
7641
|
+
let anyOrUnknownArgument;
|
7579
7642
|
const typeCondition = (0, typeUtils_1.getTypeCondition)(type);
|
7580
7643
|
if (type.boundTypeVarScopeId) {
|
7581
7644
|
// If the function was bound to a class or object and was a constructor, a
|
@@ -7647,7 +7710,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7647
7710
|
// times.
|
7648
7711
|
const argResult = validateArgType(argParam, typeVarContext, signatureTracker, { type, isIncomplete: matchResults.isTypeIncomplete }, skipUnknownArgCheck,
|
7649
7712
|
/* skipOverloadArg */ i === 0,
|
7650
|
-
/*
|
7713
|
+
/* isFirstPass */ passCount > 1 && i === 0, typeCondition);
|
7651
7714
|
if (argResult.isTypeIncomplete) {
|
7652
7715
|
isTypeIncomplete = true;
|
7653
7716
|
}
|
@@ -7673,7 +7736,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7673
7736
|
var _a;
|
7674
7737
|
const argResult = validateArgType(argParam, typeVarContext, signatureTracker, { type, isIncomplete: matchResults.isTypeIncomplete }, skipUnknownArgCheck,
|
7675
7738
|
/* skipOverloadArg */ false,
|
7676
|
-
/*
|
7739
|
+
/* isFirstPass */ false, typeCondition);
|
7677
7740
|
argResults.push(argResult);
|
7678
7741
|
if (!argResult.isCompatible) {
|
7679
7742
|
argumentErrors = true;
|
@@ -7685,7 +7748,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7685
7748
|
condition = (_a = types_1.TypeCondition.combine(condition, argResult.condition)) !== null && _a !== void 0 ? _a : [];
|
7686
7749
|
}
|
7687
7750
|
if ((0, types_1.isAnyOrUnknown)(argResult.argType)) {
|
7688
|
-
|
7751
|
+
anyOrUnknownArgument = anyOrUnknownArgument
|
7752
|
+
? (0, typeUtils_1.preserveUnknown)(argResult.argType, anyOrUnknownArgument)
|
7753
|
+
: argResult.argType;
|
7689
7754
|
}
|
7690
7755
|
if (type.details.paramSpec) {
|
7691
7756
|
if (argParam.argument.argumentCategory === 1 /* UnpackedList */) {
|
@@ -7803,7 +7868,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7803
7868
|
return {
|
7804
7869
|
argumentErrors,
|
7805
7870
|
argResults,
|
7806
|
-
|
7871
|
+
anyOrUnknownArgument,
|
7807
7872
|
returnType: specializedReturnType,
|
7808
7873
|
isTypeIncomplete,
|
7809
7874
|
activeParam: matchResults.activeParam,
|
@@ -7811,19 +7876,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7811
7876
|
overloadsUsedForCall: argumentErrors ? [] : [type],
|
7812
7877
|
};
|
7813
7878
|
}
|
7814
|
-
function adjustCallableReturnType(
|
7879
|
+
function adjustCallableReturnType(returnType) {
|
7815
7880
|
// If the return type includes a generic Callable type, set the type var
|
7816
7881
|
// scope to a wildcard to allow these type vars to be solved. This won't
|
7817
7882
|
// work with overloads or unions of callables. It's intended for a
|
7818
7883
|
// specific use case. We may need to make this more sophisticated in
|
7819
7884
|
// the future.
|
7820
|
-
if ((0, types_1.isFunction)(
|
7821
|
-
|
7822
|
-
...type.details,
|
7823
|
-
typeVarScopeId: types_1.WildcardTypeVarScopeId,
|
7824
|
-
};
|
7885
|
+
if ((0, types_1.isFunction)(returnType) && !returnType.details.name) {
|
7886
|
+
return types_1.FunctionType.cloneWithNewTypeVarScopeId(returnType, types_1.WildcardTypeVarScopeId);
|
7825
7887
|
}
|
7826
|
-
return
|
7888
|
+
return returnType;
|
7827
7889
|
}
|
7828
7890
|
// Tries to assign the call arguments to the function parameter
|
7829
7891
|
// list and reports any mismatches in types or counts. Returns the
|
@@ -7895,6 +7957,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7895
7957
|
const argsParam = paramSpecParams.find((paramInfo) => paramInfo.category === 1 /* VarArgList */);
|
7896
7958
|
const kwargsParam = paramSpecParams.find((paramInfo) => paramInfo.category === 2 /* VarArgDictionary */);
|
7897
7959
|
const signatureTracker = new typeUtils_1.UniqueSignatureTracker();
|
7960
|
+
let sawUnpackedListArgument = false;
|
7961
|
+
let sawUnpackedDictArgument = false;
|
7898
7962
|
argList.forEach((arg) => {
|
7899
7963
|
var _a;
|
7900
7964
|
if (arg.argumentCategory === 0 /* Simple */) {
|
@@ -7945,15 +8009,30 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7945
8009
|
/* functionType */ undefined,
|
7946
8010
|
/* skipUnknownArgCheck */ false,
|
7947
8011
|
/* skipOverloadArg */ false,
|
7948
|
-
/*
|
8012
|
+
/* isFirstPass */ false, conditionFilter);
|
7949
8013
|
if (!argResult.isCompatible) {
|
7950
8014
|
reportedArgError = true;
|
7951
8015
|
}
|
7952
8016
|
}
|
7953
8017
|
}
|
8018
|
+
else if (arg.argumentCategory === 1 /* UnpackedList */) {
|
8019
|
+
sawUnpackedListArgument = true;
|
8020
|
+
// See if there is an *args parameter.
|
8021
|
+
const argsParam = paramSpecParams.find((param) => param.category === 1 /* VarArgList */ && param.name);
|
8022
|
+
if (argsParam && paramMap.has(argsParam.name)) {
|
8023
|
+
// TODO - validate args type
|
8024
|
+
paramMap.delete(argsParam.name);
|
8025
|
+
}
|
8026
|
+
}
|
7954
8027
|
else {
|
7955
|
-
|
7956
|
-
|
8028
|
+
sawUnpackedDictArgument = true;
|
8029
|
+
(0, debug_1.assert)(arg.argumentCategory === 2 /* UnpackedDictionary */);
|
8030
|
+
// See if there is an *kwargs parameter.
|
8031
|
+
const kwargsParam = paramSpecParams.find((param) => param.category === 2 /* VarArgDictionary */);
|
8032
|
+
if (kwargsParam && paramMap.has(kwargsParam.name)) {
|
8033
|
+
// TODO - validate kwargs type
|
8034
|
+
paramMap.delete(kwargsParam.name);
|
8035
|
+
}
|
7957
8036
|
}
|
7958
8037
|
});
|
7959
8038
|
// Report any missing parameters.
|
@@ -7964,7 +8043,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7964
8043
|
const paramInfo = paramMap.get(name);
|
7965
8044
|
return paramInfo.category === 0 /* Simple */ && !paramInfo.hasDefault;
|
7966
8045
|
});
|
7967
|
-
if (unassignedParams.length > 0 &&
|
8046
|
+
if (unassignedParams.length > 0 &&
|
8047
|
+
!paramSpecType.details.paramSpec &&
|
8048
|
+
!sawUnpackedListArgument &&
|
8049
|
+
!sawUnpackedDictArgument) {
|
7968
8050
|
const missingParamNames = unassignedParams.map((p) => `"${p}"`).join(', ');
|
7969
8051
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, unassignedParams.length === 1
|
7970
8052
|
? localize_1.Localizer.Diagnostic.argMissingForParam().format({ name: missingParamNames })
|
@@ -7977,7 +8059,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7977
8059
|
}
|
7978
8060
|
return !reportedArgError;
|
7979
8061
|
}
|
7980
|
-
function validateArgType(argParam, typeVarContext, signatureTracker, typeResult, skipUnknownCheck, skipOverloadArg,
|
8062
|
+
function validateArgType(argParam, typeVarContext, signatureTracker, typeResult, skipUnknownCheck, skipOverloadArg, isFirstPass, conditionFilter) {
|
7981
8063
|
var _a;
|
7982
8064
|
let argType;
|
7983
8065
|
let expectedTypeDiag;
|
@@ -7986,16 +8068,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7986
8068
|
const functionName = typeResult === null || typeResult === void 0 ? void 0 : typeResult.type.details.name;
|
7987
8069
|
if (argParam.argument.valueExpression) {
|
7988
8070
|
// If the param type is a "bare" TypeVar, don't use it as an expected
|
7989
|
-
// type. This causes problems for cases where the the
|
7990
|
-
// result can influence the type of the TypeVar, such as in
|
8071
|
+
// type during the first pass. This causes problems for cases where the the
|
8072
|
+
// call expression result can influence the type of the TypeVar, such as in
|
7991
8073
|
// the expression "min(1, max(2, 0.5))". We set useNarrowBoundOnly
|
7992
8074
|
// to true if this is the first pass through the parameter list because
|
7993
8075
|
// a wide bound on a TypeVar (if a narrow bound has not yet been established)
|
7994
8076
|
// will unnecessarily constrain the expected type.
|
7995
8077
|
let expectedType;
|
7996
|
-
if (!
|
8078
|
+
if (!isFirstPass ||
|
8079
|
+
!(0, types_1.isTypeVar)(argParam.paramType) ||
|
7997
8080
|
argParam.paramType.scopeId !== (typeResult === null || typeResult === void 0 ? void 0 : typeResult.type.details.typeVarScopeId)) {
|
7998
|
-
expectedType = (0, typeUtils_1.applySolvedTypeVars)(argParam.paramType, typeVarContext, {
|
8081
|
+
expectedType = (0, typeUtils_1.applySolvedTypeVars)(argParam.paramType, typeVarContext, {
|
8082
|
+
useNarrowBoundOnly: isFirstPass,
|
8083
|
+
});
|
7999
8084
|
}
|
8000
8085
|
// If the expected type is unknown, don't use an expected type. Instead,
|
8001
8086
|
// use default rules for evaluating the expression type.
|
@@ -9923,8 +10008,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9923
10008
|
});
|
9924
10009
|
// Determine the minimum number of parameters that are required to
|
9925
10010
|
// satisfy the lambda.
|
9926
|
-
const minLambdaParamCount = node.parameters.filter((param) => param.category === 0 /* Simple */ && param.defaultValue === undefined).length;
|
9927
|
-
const maxLambdaParamCount = node.parameters.filter((param) => param.category === 0 /* Simple */).length;
|
10011
|
+
const minLambdaParamCount = node.parameters.filter((param) => param.category === 0 /* Simple */ && !!param.name && param.defaultValue === undefined).length;
|
10012
|
+
const maxLambdaParamCount = node.parameters.filter((param) => param.category === 0 /* Simple */ && !!param.name).length;
|
9928
10013
|
// Remove any expected subtypes that don't satisfy the minimum
|
9929
10014
|
// parameter count requirement.
|
9930
10015
|
expectedFunctionTypes = expectedFunctionTypes.filter((functionType) => {
|
@@ -11103,7 +11188,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11103
11188
|
let flags = 0 /* None */;
|
11104
11189
|
if (fileInfo.isStubFile) {
|
11105
11190
|
// An assignment of ellipsis means "Any" within a type stub file.
|
11106
|
-
flags |=
|
11191
|
+
flags |= 1 /* ConvertEllipsisToAny */;
|
11107
11192
|
}
|
11108
11193
|
if (node.rightExpression.nodeType === 38 /* Name */ ||
|
11109
11194
|
node.rightExpression.nodeType === 35 /* MemberAccess */) {
|
@@ -13166,11 +13251,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13166
13251
|
if (functionDecl === null || functionDecl === void 0 ? void 0 : functionDecl.isGenerator) {
|
13167
13252
|
const inferredYieldTypes = [];
|
13168
13253
|
let useAwaitableGenerator = false;
|
13254
|
+
let isYieldResultUsed = false;
|
13169
13255
|
if (functionDecl.yieldStatements) {
|
13170
13256
|
functionDecl.yieldStatements.forEach((yieldNode) => {
|
13171
|
-
var _a;
|
13257
|
+
var _a, _b;
|
13172
13258
|
if (isNodeReachable(yieldNode)) {
|
13173
13259
|
if (yieldNode.nodeType === 61 /* YieldFrom */) {
|
13260
|
+
isYieldResultUsed = true;
|
13174
13261
|
const iteratorTypeResult = getTypeOfExpression(yieldNode.expression);
|
13175
13262
|
if ((0, types_1.isClassInstance)(iteratorTypeResult.type) &&
|
13176
13263
|
types_1.ClassType.isBuiltIn(iteratorTypeResult.type, 'Coroutine')) {
|
@@ -13185,6 +13272,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13185
13272
|
}
|
13186
13273
|
}
|
13187
13274
|
else {
|
13275
|
+
// If the yield expression is not by itself in a statement list,
|
13276
|
+
// assume that its result is consumed.
|
13277
|
+
if (((_b = yieldNode === null || yieldNode === void 0 ? void 0 : yieldNode.parent) === null || _b === void 0 ? void 0 : _b.nodeType) !== 47 /* StatementList */) {
|
13278
|
+
isYieldResultUsed = true;
|
13279
|
+
}
|
13188
13280
|
if (yieldNode.expression) {
|
13189
13281
|
const yieldType = getTypeOfExpression(yieldNode.expression).type;
|
13190
13282
|
inferredYieldTypes.push(yieldType !== null && yieldType !== void 0 ? yieldType : types_1.UnknownType.create());
|
@@ -13205,10 +13297,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13205
13297
|
const generatorType = getTypingType(node, useAwaitableGenerator ? 'AwaitableGenerator' : 'Generator');
|
13206
13298
|
if (generatorType && (0, types_1.isInstantiableClass)(generatorType)) {
|
13207
13299
|
const typeArgs = [];
|
13300
|
+
// The "send type" for the generator (the second type argument) is
|
13301
|
+
// not generally inferrable, but we can assume that it's Any
|
13302
|
+
// if the function never uses the value and Unknown if it does.
|
13303
|
+
// This eliminates any "partially unknown" errors in strict mode
|
13304
|
+
// in the common case.
|
13305
|
+
const sendType = isYieldResultUsed ? types_1.UnknownType.create() : types_1.AnyType.create();
|
13306
|
+
typeArgs.push(inferredYieldType, sendType, (0, types_1.isNever)(inferredReturnType) ? types_1.NoneType.createInstance() : inferredReturnType);
|
13208
13307
|
if (useAwaitableGenerator) {
|
13209
13308
|
typeArgs.push(types_1.AnyType.create());
|
13210
13309
|
}
|
13211
|
-
typeArgs.push(inferredYieldType, types_1.NoneType.createInstance(), (0, types_1.isNever)(inferredReturnType) ? types_1.NoneType.createInstance() : inferredReturnType);
|
13212
13310
|
inferredReturnType = types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneForSpecialization(generatorType, typeArgs,
|
13213
13311
|
/* isTypeArgumentExplicit */ true));
|
13214
13312
|
}
|
@@ -13736,7 +13834,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13736
13834
|
nodeToEvaluate = parent;
|
13737
13835
|
continue;
|
13738
13836
|
}
|
13739
|
-
// The left expression of a call or member access expression is not contextual.
|
13837
|
+
// The left expression of a call or member access expression is not generally contextual.
|
13740
13838
|
if (parent.nodeType === 9 /* Call */ || parent.nodeType === 35 /* MemberAccess */) {
|
13741
13839
|
if (nodeToEvaluate === parent.leftExpression) {
|
13742
13840
|
// Handle the special case where the LHS is a call to super().
|
@@ -13746,6 +13844,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13746
13844
|
nodeToEvaluate = parent;
|
13747
13845
|
continue;
|
13748
13846
|
}
|
13847
|
+
// Handle the special case where the LHS is a call to a lambda.
|
13848
|
+
if (parent.nodeType === 9 /* Call */ && nodeToEvaluate.nodeType === 30 /* Lambda */) {
|
13849
|
+
nodeToEvaluate = parent;
|
13850
|
+
continue;
|
13851
|
+
}
|
13749
13852
|
flags = 2 /* DoNotSpecialize */;
|
13750
13853
|
break;
|
13751
13854
|
}
|
@@ -15423,8 +15526,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15423
15526
|
const resolvedDecl = (_a = resolveAliasDeclaration(decl,
|
15424
15527
|
/* resolveLocalNames */ true,
|
15425
15528
|
/* allowExternallyHiddenAccess */ AnalyzerNodeInfo.getFileInfo(decl.node).isStubFile)) !== null && _a !== void 0 ? _a : decl;
|
15426
|
-
const isExplicitTypeAlias = isExplicitTypeAliasDeclaration(
|
15427
|
-
const isTypeAlias = isExplicitTypeAlias || isPossibleTypeAliasOrTypedDict(
|
15529
|
+
const isExplicitTypeAlias = isExplicitTypeAliasDeclaration(resolvedDecl);
|
15530
|
+
const isTypeAlias = isExplicitTypeAlias || isPossibleTypeAliasOrTypedDict(resolvedDecl);
|
15428
15531
|
if (isExplicitTypeAlias) {
|
15429
15532
|
sawExplicitTypeAlias = true;
|
15430
15533
|
}
|
@@ -18608,6 +18711,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18608
18711
|
if (options === null || options === void 0 ? void 0 : options.useTypingUnpack) {
|
18609
18712
|
flags |= 512 /* UseTypingUnpack */;
|
18610
18713
|
}
|
18714
|
+
if (options === null || options === void 0 ? void 0 : options.printUnknownWithAny) {
|
18715
|
+
flags |= 1 /* PrintUnknownWithAny */;
|
18716
|
+
}
|
18717
|
+
if (options === null || options === void 0 ? void 0 : options.omitTypeArgumentsIfUnknown) {
|
18718
|
+
flags |= 2 /* OmitTypeArgumentsIfUnknown */;
|
18719
|
+
}
|
18611
18720
|
return TypePrinter.printType(type, flags, getFunctionEffectiveReturnType);
|
18612
18721
|
}
|
18613
18722
|
// Calls back into the parser to parse the contents of a string literal.
|