@zzzen/pyright-internal 1.2.0-dev.20250209 → 1.2.0-dev.20250223
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 +4 -4
- package/dist/analyzer/backgroundAnalysisProgram.js.map +1 -1
- package/dist/analyzer/cacheManager.d.ts +5 -2
- package/dist/analyzer/cacheManager.js +1 -0
- package/dist/analyzer/cacheManager.js.map +1 -1
- package/dist/analyzer/checker.d.ts +1 -1
- package/dist/analyzer/checker.js +200 -247
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/constraintTracker.d.ts +2 -2
- package/dist/analyzer/constraintTracker.js +11 -5
- package/dist/analyzer/constraintTracker.js.map +1 -1
- package/dist/analyzer/constructorTransform.js +1 -1
- package/dist/analyzer/constructorTransform.js.map +1 -1
- package/dist/analyzer/constructors.js +3 -3
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/importResolver.d.ts +1 -1
- package/dist/analyzer/parseTreeUtils.d.ts +2 -1
- package/dist/analyzer/parseTreeUtils.js +12 -0
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/program.d.ts +1 -1
- package/dist/analyzer/program.js +17 -30
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/protocols.js +26 -11
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/service.d.ts +4 -3
- package/dist/analyzer/service.js +3 -1
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceFile.d.ts +11 -1
- package/dist/analyzer/sourceFile.js +6 -1
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/sourceFileInfoUtils.d.ts +1 -0
- package/dist/analyzer/sourceFileInfoUtils.js +12 -11
- package/dist/analyzer/sourceFileInfoUtils.js.map +1 -1
- package/dist/analyzer/tracePrinter.d.ts +1 -1
- package/dist/analyzer/tracePrinter.js +3 -2
- package/dist/analyzer/tracePrinter.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +248 -98
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +2 -0
- package/dist/analyzer/typeGuards.js +20 -3
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.d.ts +2 -0
- package/dist/analyzer/typePrinter.js +20 -0
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeUtils.js +3 -3
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typeWalker.js +1 -1
- package/dist/analyzer/typeWalker.js.map +1 -1
- package/dist/analyzer/typedDicts.js +6 -7
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +4 -1
- package/dist/analyzer/types.js +9 -4
- package/dist/analyzer/types.js.map +1 -1
- package/dist/backgroundAnalysisBase.d.ts +26 -4
- package/dist/backgroundAnalysisBase.js +14 -13
- package/dist/backgroundAnalysisBase.js.map +1 -1
- package/dist/backgroundThreadBase.d.ts +6 -2
- package/dist/backgroundThreadBase.js +7 -1
- package/dist/backgroundThreadBase.js.map +1 -1
- package/dist/common/cancellationUtils.d.ts +2 -0
- package/dist/common/cancellationUtils.js +19 -1
- package/dist/common/cancellationUtils.js.map +1 -1
- package/dist/common/fileSystem.d.ts +2 -0
- package/dist/common/fileSystem.js.map +1 -1
- package/dist/common/languageServerInterface.d.ts +3 -27
- package/dist/common/languageServerInterface.js.map +1 -1
- package/dist/common/realFileSystem.d.ts +2 -0
- package/dist/common/realFileSystem.js +8 -0
- package/dist/common/realFileSystem.js.map +1 -1
- package/dist/common/serviceKeys.d.ts +1 -1
- package/dist/common/serviceProviderExtensions.d.ts +1 -1
- package/dist/common/serviceProviderExtensions.js +2 -2
- package/dist/common/serviceProviderExtensions.js.map +1 -1
- package/dist/common/uri/uriMap.d.ts +17 -0
- package/dist/common/uri/uriMap.js +76 -0
- package/dist/common/uri/uriMap.js.map +1 -0
- package/dist/languageServerBase.d.ts +5 -4
- package/dist/languageServerBase.js +2 -0
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/completionProvider.js +1 -1
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/referencesProvider.js +9 -2
- package/dist/languageService/referencesProvider.js.map +1 -1
- package/dist/localization/localize.d.ts +4 -4
- package/dist/localization/localize.js +2 -1
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +7 -7
- package/dist/localization/package.nls.de.json +7 -7
- package/dist/localization/package.nls.en-us.json +5 -4
- package/dist/localization/package.nls.es.json +7 -7
- package/dist/localization/package.nls.fr.json +7 -7
- package/dist/localization/package.nls.it.json +7 -7
- package/dist/localization/package.nls.ja.json +7 -7
- package/dist/localization/package.nls.ko.json +7 -7
- package/dist/localization/package.nls.pl.json +7 -7
- package/dist/localization/package.nls.pt-br.json +7 -7
- package/dist/localization/package.nls.qps-ploc.json +3 -3
- package/dist/localization/package.nls.ru.json +7 -7
- package/dist/localization/package.nls.tr.json +7 -7
- package/dist/localization/package.nls.zh-cn.json +7 -7
- package/dist/localization/package.nls.zh-tw.json +7 -7
- package/dist/partialStubService.d.ts +26 -0
- package/dist/partialStubService.js +138 -0
- package/dist/partialStubService.js.map +1 -0
- package/dist/pyrightFileSystem.d.ts +1 -21
- package/dist/pyrightFileSystem.js +7 -137
- package/dist/pyrightFileSystem.js.map +1 -1
- package/dist/readonlyAugmentedFileSystem.d.ts +7 -4
- package/dist/readonlyAugmentedFileSystem.js +124 -60
- package/dist/readonlyAugmentedFileSystem.js.map +1 -1
- package/dist/server.d.ts +2 -2
- package/dist/server.js +3 -1
- package/dist/server.js.map +1 -1
- package/dist/tests/completions.test.js +23 -0
- package/dist/tests/completions.test.js.map +1 -1
- package/dist/tests/fourslash/completions.autoimport.shadow.fourslash.js +2 -2
- package/dist/tests/fourslash/completions.autoimport.shadow.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.wildcardimports.fourslash.js +2 -2
- package/dist/tests/fourslash/completions.wildcardimports.fourslash.js.map +1 -1
- package/dist/tests/fourslash/hover.wildcardimports.fourslash.js +2 -2
- package/dist/tests/fourslash/hover.wildcardimports.fourslash.js.map +1 -1
- package/dist/tests/fourslash/rename.typeParams.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/rename.typeParams.fourslash.js +27 -0
- package/dist/tests/fourslash/rename.typeParams.fourslash.js.map +1 -0
- package/dist/tests/fourslash/signature.docstrings.wildcardimports.fourslash.js +2 -2
- package/dist/tests/fourslash/signature.docstrings.wildcardimports.fourslash.js.map +1 -1
- package/dist/tests/harness/fourslash/testLanguageService.d.ts +2 -2
- package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.js +3 -1
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/harness/vfs/filesystem.d.ts +2 -0
- package/dist/tests/harness/vfs/filesystem.js +5 -2
- package/dist/tests/harness/vfs/filesystem.js.map +1 -1
- package/dist/tests/importResolver.test.js +8 -2
- package/dist/tests/importResolver.test.js.map +1 -1
- package/dist/tests/pyrightFileSystem.test.js +15 -8
- package/dist/tests/pyrightFileSystem.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +3 -3
- package/dist/tests/typeEvaluator5.test.js +1 -1
- package/dist/tests/typeEvaluator6.test.js +4 -0
- package/dist/tests/typeEvaluator6.test.js.map +1 -1
- package/dist/tests/typeEvaluator7.test.js +1 -1
- package/dist/tests/typeEvaluator8.test.js +2 -2
- package/dist/tests/typeEvaluator8.test.js.map +1 -1
- package/dist/types.d.ts +26 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +1 -1
@@ -86,6 +86,7 @@ const typeGuards_1 = require("./typeGuards");
|
|
86
86
|
const TypePrinter = __importStar(require("./typePrinter"));
|
87
87
|
const types_1 = require("./types");
|
88
88
|
const typeUtils_1 = require("./typeUtils");
|
89
|
+
const core_1 = require("../common/core");
|
89
90
|
// This table contains the names of several built-in types that
|
90
91
|
// are not subscriptable at runtime on older versions of Python.
|
91
92
|
// It lists the first version of Python where subscripting is
|
@@ -199,12 +200,23 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
199
200
|
const signatureTrackerStack = [];
|
200
201
|
let prefetched;
|
201
202
|
function runWithCancellationToken(token, callback) {
|
203
|
+
// Save the current token and restore it after the callback to support nested calls
|
204
|
+
const oldToken = cancellationToken;
|
205
|
+
let result = undefined;
|
202
206
|
try {
|
203
207
|
cancellationToken = token;
|
204
|
-
|
208
|
+
result = callback();
|
209
|
+
if (!(0, core_1.isThenable)(result)) {
|
210
|
+
return result;
|
211
|
+
}
|
212
|
+
return result.finally(() => {
|
213
|
+
cancellationToken = oldToken;
|
214
|
+
});
|
205
215
|
}
|
206
216
|
finally {
|
207
|
-
|
217
|
+
if (!(0, core_1.isThenable)(result)) {
|
218
|
+
cancellationToken = oldToken;
|
219
|
+
}
|
208
220
|
}
|
209
221
|
}
|
210
222
|
function checkForCancellation() {
|
@@ -590,7 +602,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
590
602
|
// Make sure the resulting type is assignable to the expected type.
|
591
603
|
if (!assignType(inferenceContext.expectedType, typeResult.type, diag,
|
592
604
|
/* constraints */ undefined, 0 /* AssignTypeFlags.Default */)) {
|
593
|
-
|
605
|
+
// Set the typeErrors to true, but first make a copy of the
|
606
|
+
// type result because the (non-error) version may already
|
607
|
+
// be cached.
|
608
|
+
typeResult = { ...typeResult, typeErrors: true };
|
594
609
|
typeResult.expectedTypeDiagAddendum = diag;
|
595
610
|
diag.addTextRange(node);
|
596
611
|
}
|
@@ -2554,6 +2569,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2554
2569
|
sourceEntryTypes.splice(unboundedIndex, 0, typeToReplicate);
|
2555
2570
|
}
|
2556
2571
|
}
|
2572
|
+
if (sourceEntryTypes.length > targetTypes.length) {
|
2573
|
+
// Remove elements to make the count match the target count.
|
2574
|
+
sourceEntryTypes.splice(unboundedIndex, 1);
|
2575
|
+
}
|
2557
2576
|
}
|
2558
2577
|
// If there's an unpack operator in the target and we have too many source elements,
|
2559
2578
|
// combine them to assign to the unpacked target.
|
@@ -7500,7 +7519,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7500
7519
|
}
|
7501
7520
|
else {
|
7502
7521
|
let tooManyPositionals = false;
|
7503
|
-
if (
|
7522
|
+
if (argList[argIndex].argCategory === 1 /* ArgCategory.UnpackedList */) {
|
7504
7523
|
// If this is an unpacked iterable, we will conservatively assume that it
|
7505
7524
|
// might have zero iterations unless we can tell from its type that it
|
7506
7525
|
// definitely has at least one iterable value.
|
@@ -7512,9 +7531,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7512
7531
|
argType.priv.tupleTypeArgs.length > 0) {
|
7513
7532
|
tooManyPositionals = true;
|
7514
7533
|
}
|
7515
|
-
else {
|
7516
|
-
matchedUnpackedListOfUnknownLength = true;
|
7517
|
-
}
|
7518
7534
|
}
|
7519
7535
|
else {
|
7520
7536
|
tooManyPositionals = true;
|
@@ -7603,6 +7619,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7603
7619
|
listElementType = getTypeOfIterator({ type: argType, isIncomplete: argTypeResult.isIncomplete },
|
7604
7620
|
/* isAsync */ false, errorNode,
|
7605
7621
|
/* emitNotIterableError */ false)?.type;
|
7622
|
+
if (paramInfo.param.category === 1 /* ParamCategory.ArgsList */) {
|
7623
|
+
matchedUnpackedListOfUnknownLength = true;
|
7624
|
+
}
|
7606
7625
|
}
|
7607
7626
|
const funcArg = listElementType
|
7608
7627
|
? {
|
@@ -8107,25 +8126,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8107
8126
|
const param = paramInfo.param;
|
8108
8127
|
if (param.category === 0 /* ParamCategory.Simple */ && param.name) {
|
8109
8128
|
const entry = paramMap.get(param.name);
|
8110
|
-
if (entry && entry.argsNeeded === 0 && entry.argsReceived === 0) {
|
8111
|
-
|
8112
|
-
|
8113
|
-
|
8114
|
-
|
8115
|
-
|
8116
|
-
|
8117
|
-
|
8118
|
-
|
8119
|
-
|
8120
|
-
|
8121
|
-
|
8122
|
-
|
8123
|
-
|
8124
|
-
errorNode,
|
8125
|
-
paramName: param.name,
|
8126
|
-
isParamNameSynthesized: types_1.FunctionParam.isNameSynthesized(param),
|
8127
|
-
});
|
8128
|
-
}
|
8129
|
+
if (entry && entry.argsNeeded === 0 && entry.argsReceived === 0 && paramInfo.defaultType) {
|
8130
|
+
validateArgTypeParams.push({
|
8131
|
+
paramCategory: param.category,
|
8132
|
+
paramType: paramInfo.type,
|
8133
|
+
requiresTypeVarMatching: true,
|
8134
|
+
argument: {
|
8135
|
+
argCategory: 0 /* ArgCategory.Simple */,
|
8136
|
+
typeResult: { type: paramInfo.defaultType },
|
8137
|
+
},
|
8138
|
+
isDefaultArg: true,
|
8139
|
+
errorNode,
|
8140
|
+
paramName: param.name,
|
8141
|
+
isParamNameSynthesized: types_1.FunctionParam.isNameSynthesized(param),
|
8142
|
+
});
|
8129
8143
|
}
|
8130
8144
|
}
|
8131
8145
|
});
|
@@ -8200,10 +8214,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8200
8214
|
}
|
8201
8215
|
let relevance = 0;
|
8202
8216
|
if (matchedUnpackedListOfUnknownLength) {
|
8203
|
-
//
|
8217
|
+
// Increase the relevance if we made assumptions about the length
|
8204
8218
|
// of an unpacked argument. This will favor overloads that
|
8205
8219
|
// associate this case with a *args parameter.
|
8206
|
-
relevance
|
8220
|
+
relevance++;
|
8207
8221
|
}
|
8208
8222
|
// Special-case the builtin isinstance and issubclass functions.
|
8209
8223
|
if (types_1.FunctionType.isBuiltIn(overload, ['isinstance', 'issubclass']) && validateArgTypeParams.length === 2) {
|
@@ -9245,6 +9259,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9245
9259
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeAliasTypeMustBeAssigned(), errorNode);
|
9246
9260
|
return undefined;
|
9247
9261
|
}
|
9262
|
+
const scope = ScopeUtils.getScopeForNode(errorNode);
|
9263
|
+
if (scope) {
|
9264
|
+
if (scope.type !== 3 /* ScopeType.Class */ && scope.type !== 4 /* ScopeType.Module */ && scope.type !== 5 /* ScopeType.Builtin */) {
|
9265
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeAliasTypeBadScope(), errorNode.parent.d.leftExpr);
|
9266
|
+
}
|
9267
|
+
}
|
9248
9268
|
const nameNode = errorNode.parent.d.leftExpr;
|
9249
9269
|
const firstArg = argList[0];
|
9250
9270
|
if (firstArg.valueExpression && firstArg.valueExpression.nodeType === 48 /* ParseNodeType.StringList */) {
|
@@ -10374,7 +10394,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10374
10394
|
: undefined, () => {
|
10375
10395
|
const returnTypeResult = getTypeOfExpression(node.d.expr,
|
10376
10396
|
/* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedReturnType));
|
10377
|
-
functionType.priv.inferredReturnType =
|
10397
|
+
functionType.priv.inferredReturnType = {
|
10398
|
+
type: returnTypeResult.type,
|
10399
|
+
};
|
10378
10400
|
if (returnTypeResult.isIncomplete) {
|
10379
10401
|
isIncomplete = true;
|
10380
10402
|
}
|
@@ -12253,16 +12275,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12253
12275
|
else if (arg.d.name.d.value === 'total' && !constArgValue) {
|
12254
12276
|
classType.shared.flags |= 32 /* ClassTypeFlags.CanOmitDictValues */;
|
12255
12277
|
}
|
12256
|
-
else if (arg.d.name.d.value === 'closed'
|
12278
|
+
else if (arg.d.name.d.value === 'closed' &&
|
12279
|
+
AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.enableExperimentalFeatures) {
|
12257
12280
|
if (constArgValue) {
|
12258
|
-
|
12259
|
-
|
12260
|
-
|
12261
|
-
|
12262
|
-
16 /* ClassTypeFlags.TypedDictEffectivelyClosed */;
|
12263
|
-
if (classType.shared.typedDictExtraItemsExpr) {
|
12264
|
-
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typedDictExtraItemsClosed(), classType.shared.typedDictExtraItemsExpr);
|
12265
|
-
}
|
12281
|
+
classType.shared.flags |=
|
12282
|
+
8 /* ClassTypeFlags.TypedDictMarkedClosed */ | 16 /* ClassTypeFlags.TypedDictEffectivelyClosed */;
|
12283
|
+
if (classType.shared.typedDictExtraItemsExpr) {
|
12284
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typedDictExtraItemsClosed(), classType.shared.typedDictExtraItemsExpr);
|
12266
12285
|
}
|
12267
12286
|
}
|
12268
12287
|
if (sawClosedOrExtraItems) {
|
@@ -12271,16 +12290,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12271
12290
|
sawClosedOrExtraItems = true;
|
12272
12291
|
}
|
12273
12292
|
}
|
12274
|
-
else if (arg.d.name.d.value === 'extra_items'
|
12275
|
-
|
12276
|
-
|
12277
|
-
|
12278
|
-
|
12279
|
-
|
12280
|
-
|
12281
|
-
|
12282
|
-
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typedDictExtraItemsClosed(), classType.shared.typedDictExtraItemsExpr);
|
12283
|
-
}
|
12293
|
+
else if (arg.d.name.d.value === 'extra_items' &&
|
12294
|
+
AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.enableExperimentalFeatures) {
|
12295
|
+
// Record a reference to the expression but don't evaluate it yet.
|
12296
|
+
// It may refer to the class itself.
|
12297
|
+
classType.shared.typedDictExtraItemsExpr = arg.d.valueExpr;
|
12298
|
+
classType.shared.flags |= 16 /* ClassTypeFlags.TypedDictEffectivelyClosed */;
|
12299
|
+
if (types_1.ClassType.isTypedDictMarkedClosed(classType)) {
|
12300
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typedDictExtraItemsClosed(), classType.shared.typedDictExtraItemsExpr);
|
12284
12301
|
}
|
12285
12302
|
if (sawClosedOrExtraItems) {
|
12286
12303
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typedDictExtraItemsClosed(), arg.d.valueExpr);
|
@@ -13534,7 +13551,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13534
13551
|
awaitableFunctionType.shared.declaredReturnType = createAwaitableReturnType(node, functionType.shared.declaredReturnType, types_1.FunctionType.isGenerator(functionType));
|
13535
13552
|
}
|
13536
13553
|
else {
|
13537
|
-
awaitableFunctionType.priv.inferredReturnType =
|
13554
|
+
awaitableFunctionType.priv.inferredReturnType = {
|
13555
|
+
type: createAwaitableReturnType(node, getInferredReturnType(functionType), types_1.FunctionType.isGenerator(functionType)),
|
13556
|
+
};
|
13538
13557
|
}
|
13539
13558
|
return awaitableFunctionType;
|
13540
13559
|
}
|
@@ -16595,8 +16614,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
16595
16614
|
}
|
16596
16615
|
// If the return type has already been lazily evaluated,
|
16597
16616
|
// don't bother computing it again.
|
16598
|
-
if (type.priv.inferredReturnType) {
|
16599
|
-
returnType = type.priv.inferredReturnType;
|
16617
|
+
if (type.priv.inferredReturnType && !type.priv.inferredReturnType.isIncomplete) {
|
16618
|
+
returnType = type.priv.inferredReturnType.type;
|
16600
16619
|
}
|
16601
16620
|
else {
|
16602
16621
|
// Don't bother inferring the return type of __init__ because it's
|
@@ -16643,9 +16662,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
16643
16662
|
}
|
16644
16663
|
returnType = (0, typeUtils_1.makeTypeVarsFree)(returnType, typeVarScopes);
|
16645
16664
|
// Cache the type for next time.
|
16646
|
-
|
16647
|
-
type.priv.inferredReturnType = returnType;
|
16648
|
-
}
|
16665
|
+
type.priv.inferredReturnType = { type: returnType, isIncomplete };
|
16649
16666
|
}
|
16650
16667
|
// If the type is partially unknown and the function has one or more unannotated
|
16651
16668
|
// params, try to analyze the function with the provided argument types and
|
@@ -16899,13 +16916,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
16899
16916
|
if (!(0, typedDicts_1.assignTypedDictToTypedDict)(evaluatorInterface, destType, srcType, diag, constraints, flags, recursionCount)) {
|
16900
16917
|
return false;
|
16901
16918
|
}
|
16902
|
-
if (types_1.ClassType.isFinal(destType) !== types_1.ClassType.isFinal(srcType)) {
|
16903
|
-
diag?.addMessage(localize_1.LocAddendum.typedDictFinalMismatch().format({
|
16904
|
-
sourceType: printType((0, typeUtils_1.convertToInstance)(srcType)),
|
16905
|
-
destType: printType((0, typeUtils_1.convertToInstance)(destType)),
|
16906
|
-
}));
|
16907
|
-
return false;
|
16908
|
-
}
|
16909
16919
|
// If invariance is being enforced, the two TypedDicts must be assignable to each other.
|
16910
16920
|
if ((flags & 1 /* AssignTypeFlags.Invariant */) !== 0) {
|
16911
16921
|
return (0, typedDicts_1.assignTypedDictToTypedDict)(evaluatorInterface, srcType, destType,
|
@@ -17648,6 +17658,23 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17648
17658
|
}
|
17649
17659
|
}
|
17650
17660
|
let concreteSrcType = makeTopLevelTypeVarsConcrete(srcType);
|
17661
|
+
// Handle the TypeForm special form. Add a special case for
|
17662
|
+
// type[T] to be assignable to TypeForm[T].
|
17663
|
+
if (types_1.ClassType.isBuiltIn(destType, 'TypeForm')) {
|
17664
|
+
const destTypeArg = destType.priv.typeArgs && destType.priv.typeArgs.length > 0
|
17665
|
+
? destType.priv.typeArgs[0]
|
17666
|
+
: types_1.UnknownType.create();
|
17667
|
+
let srcTypeArg;
|
17668
|
+
if ((0, types_1.isClassInstance)(concreteSrcType) && types_1.ClassType.isBuiltIn(concreteSrcType, 'type')) {
|
17669
|
+
srcTypeArg = concreteSrcType;
|
17670
|
+
}
|
17671
|
+
else if ((0, types_1.isInstantiableClass)(concreteSrcType)) {
|
17672
|
+
srcTypeArg = (0, typeUtils_1.convertToInstance)(concreteSrcType);
|
17673
|
+
}
|
17674
|
+
if (srcTypeArg) {
|
17675
|
+
return assignType(destTypeArg, srcTypeArg, diag, constraints, flags, recursionCount);
|
17676
|
+
}
|
17677
|
+
}
|
17651
17678
|
if ((0, types_1.isClass)(concreteSrcType) && types_1.TypeBase.isInstance(concreteSrcType)) {
|
17652
17679
|
// Handle the case where the source is an unpacked tuple.
|
17653
17680
|
if (!destType.priv.isUnpacked &&
|
@@ -17791,7 +17818,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17791
17818
|
const typeVarSignatures = [];
|
17792
17819
|
overloads.forEach((overload) => {
|
17793
17820
|
const overloadScopeId = (0, typeUtils_1.getTypeVarScopeId)(overload) ?? '';
|
17794
|
-
const constraintsClone = constraints?.cloneWithSignature(overloadScopeId);
|
17821
|
+
const constraintsClone = constraints?.cloneWithSignature([overloadScopeId]);
|
17795
17822
|
if (assignType(destType, overload, /* diag */ undefined, constraintsClone, flags, recursionCount)) {
|
17796
17823
|
filteredOverloads.push(overload);
|
17797
17824
|
if (constraintsClone) {
|
@@ -17950,6 +17977,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17950
17977
|
if ((0, types_1.isTypeSame)(srcType, destType, {}, recursionCount)) {
|
17951
17978
|
return true;
|
17952
17979
|
}
|
17980
|
+
if ((flags & 16 /* AssignTypeFlags.OverloadOverlap */) !== 0 &&
|
17981
|
+
srcType.priv.subtypes.some((subtype) => (0, types_1.isAnyOrUnknown)(subtype))) {
|
17982
|
+
return false;
|
17983
|
+
}
|
17953
17984
|
// Sort the subtypes so we have a deterministic order for unions.
|
17954
17985
|
let sortedSrcTypes = (0, typeUtils_1.sortTypes)(srcType.priv.subtypes);
|
17955
17986
|
let matchedSomeSubtypes = false;
|
@@ -18196,6 +18227,95 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18196
18227
|
/* diag */ undefined,
|
18197
18228
|
/* constraints */ undefined, 0 /* AssignTypeFlags.Default */, recursionCount));
|
18198
18229
|
}
|
18230
|
+
// Determines whether the two types are potentially comparable -- i.e.
|
18231
|
+
// their types overlap in such a way that it makes sense for them to
|
18232
|
+
// be compared with an == or != operator.
|
18233
|
+
function isTypeComparable(leftType, rightType) {
|
18234
|
+
if ((0, types_1.isAnyOrUnknown)(leftType) || (0, types_1.isAnyOrUnknown)(rightType)) {
|
18235
|
+
return true;
|
18236
|
+
}
|
18237
|
+
if ((0, types_1.isNever)(leftType) || (0, types_1.isNever)(rightType)) {
|
18238
|
+
return false;
|
18239
|
+
}
|
18240
|
+
if ((0, types_1.isModule)(leftType) || (0, types_1.isModule)(rightType)) {
|
18241
|
+
return (0, types_1.isTypeSame)(leftType, rightType, { ignoreConditions: true });
|
18242
|
+
}
|
18243
|
+
const isLeftCallable = (0, types_1.isFunction)(leftType) || (0, types_1.isOverloaded)(leftType);
|
18244
|
+
const isRightCallable = (0, types_1.isFunction)(rightType) || (0, types_1.isOverloaded)(rightType);
|
18245
|
+
if (isLeftCallable !== isRightCallable) {
|
18246
|
+
return false;
|
18247
|
+
}
|
18248
|
+
if ((0, types_1.isInstantiableClass)(leftType) || ((0, types_1.isClassInstance)(leftType) && types_1.ClassType.isBuiltIn(leftType, 'type'))) {
|
18249
|
+
if ((0, types_1.isInstantiableClass)(rightType) ||
|
18250
|
+
((0, types_1.isClassInstance)(rightType) && types_1.ClassType.isBuiltIn(rightType, 'type'))) {
|
18251
|
+
const genericLeftType = types_1.ClassType.specialize(leftType, /* typeArgs */ undefined);
|
18252
|
+
const genericRightType = types_1.ClassType.specialize(rightType, /* typeArgs */ undefined);
|
18253
|
+
if (assignType(genericLeftType, genericRightType) || assignType(genericRightType, genericLeftType)) {
|
18254
|
+
return true;
|
18255
|
+
}
|
18256
|
+
}
|
18257
|
+
// Does the class have an operator overload for eq?
|
18258
|
+
const metaclass = leftType.shared.effectiveMetaclass;
|
18259
|
+
if (metaclass && (0, types_1.isClass)(metaclass)) {
|
18260
|
+
if ((0, typeUtils_1.lookUpClassMember)(metaclass, '__eq__', 4 /* MemberAccessFlags.SkipObjectBaseClass */)) {
|
18261
|
+
return true;
|
18262
|
+
}
|
18263
|
+
}
|
18264
|
+
return false;
|
18265
|
+
}
|
18266
|
+
if ((0, types_1.isClassInstance)(leftType)) {
|
18267
|
+
if ((0, types_1.isClass)(rightType)) {
|
18268
|
+
const genericLeftType = types_1.ClassType.specialize(leftType, /* typeArgs */ undefined);
|
18269
|
+
const genericRightType = types_1.ClassType.specialize(rightType, /* typeArgs */ undefined);
|
18270
|
+
if (assignType(genericLeftType, genericRightType) || assignType(genericRightType, genericLeftType)) {
|
18271
|
+
return true;
|
18272
|
+
}
|
18273
|
+
// Assume that if the types are disjoint and built-in classes that they
|
18274
|
+
// will never be comparable.
|
18275
|
+
if (types_1.ClassType.isBuiltIn(leftType) && types_1.ClassType.isBuiltIn(rightType) && types_1.TypeBase.isInstance(rightType)) {
|
18276
|
+
// We need to be careful with bool and int literals because
|
18277
|
+
// they are comparable under certain circumstances.
|
18278
|
+
let boolType;
|
18279
|
+
let intType;
|
18280
|
+
if (types_1.ClassType.isBuiltIn(leftType, 'bool') && types_1.ClassType.isBuiltIn(rightType, 'int')) {
|
18281
|
+
boolType = leftType;
|
18282
|
+
intType = rightType;
|
18283
|
+
}
|
18284
|
+
else if (types_1.ClassType.isBuiltIn(rightType, 'bool') && types_1.ClassType.isBuiltIn(leftType, 'int')) {
|
18285
|
+
boolType = rightType;
|
18286
|
+
intType = leftType;
|
18287
|
+
}
|
18288
|
+
if (boolType && intType) {
|
18289
|
+
const intVal = intType.priv?.literalValue;
|
18290
|
+
if (intVal === undefined) {
|
18291
|
+
return true;
|
18292
|
+
}
|
18293
|
+
if (intVal !== 0 && intVal !== 1) {
|
18294
|
+
return false;
|
18295
|
+
}
|
18296
|
+
const boolVal = boolType.priv?.literalValue;
|
18297
|
+
if (boolVal === undefined) {
|
18298
|
+
return true;
|
18299
|
+
}
|
18300
|
+
return boolVal === (intVal === 1);
|
18301
|
+
}
|
18302
|
+
return false;
|
18303
|
+
}
|
18304
|
+
}
|
18305
|
+
// Does the class have an operator overload for eq?
|
18306
|
+
const eqMethod = (0, typeUtils_1.lookUpClassMember)(types_1.ClassType.cloneAsInstantiable(leftType), '__eq__', 4 /* MemberAccessFlags.SkipObjectBaseClass */);
|
18307
|
+
if (eqMethod) {
|
18308
|
+
// If this is a synthesized method for a dataclass, we can assume
|
18309
|
+
// that other dataclass types will not be comparable.
|
18310
|
+
if (types_1.ClassType.isDataClass(leftType) && eqMethod.symbol.getSynthesizedType()) {
|
18311
|
+
return false;
|
18312
|
+
}
|
18313
|
+
return true;
|
18314
|
+
}
|
18315
|
+
return false;
|
18316
|
+
}
|
18317
|
+
return true;
|
18318
|
+
}
|
18199
18319
|
function assignToUnionType(destType, srcType, diag, constraints, flags, recursionCount) {
|
18200
18320
|
// If we need to enforce invariance, the source needs to be compatible
|
18201
18321
|
// with all subtypes in the dest, unless those subtypes are subclasses
|
@@ -18378,17 +18498,26 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18378
18498
|
for (const mroClass of objType.shared.mro) {
|
18379
18499
|
if ((0, types_1.isClass)(mroClass) && types_1.ClassType.isProtocolClass(mroClass)) {
|
18380
18500
|
for (const field of types_1.ClassType.getSymbolTable(mroClass)) {
|
18381
|
-
|
18382
|
-
|
18383
|
-
|
18384
|
-
|
18385
|
-
|
18386
|
-
|
18387
|
-
|
18388
|
-
|
18389
|
-
|
18501
|
+
const fieldName = field[0];
|
18502
|
+
const fieldSymbol = field[1];
|
18503
|
+
// We're expecting a __call__ method. We will also ignore a
|
18504
|
+
// __slots__ definition, which is (by convention) ignored for
|
18505
|
+
// protocol matching.
|
18506
|
+
if (fieldName === '__call__' || fieldName === '__slots__') {
|
18507
|
+
continue;
|
18508
|
+
}
|
18509
|
+
if (fieldSymbol.isIgnoredForProtocolMatch()) {
|
18510
|
+
continue;
|
18511
|
+
}
|
18512
|
+
let fieldIsPartOfFunction = false;
|
18513
|
+
if (prefetched?.functionClass && (0, types_1.isClass)(prefetched.functionClass)) {
|
18514
|
+
if (types_1.ClassType.getSymbolTable(prefetched.functionClass).has(field[0])) {
|
18515
|
+
fieldIsPartOfFunction = true;
|
18390
18516
|
}
|
18391
18517
|
}
|
18518
|
+
if (!fieldIsPartOfFunction) {
|
18519
|
+
return undefined;
|
18520
|
+
}
|
18392
18521
|
}
|
18393
18522
|
}
|
18394
18523
|
}
|
@@ -18539,6 +18668,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18539
18668
|
const destPositionalCount = destParamDetails.firstKeywordOnlyIndex ?? destParamDetails.params.length;
|
18540
18669
|
const srcPositionalCount = srcParamDetails.firstKeywordOnlyIndex ?? srcParamDetails.params.length;
|
18541
18670
|
const positionalsToMatch = Math.min(destPositionalCount, srcPositionalCount);
|
18671
|
+
const skippedPosParamIndices = [];
|
18542
18672
|
// Match positional parameters.
|
18543
18673
|
for (let paramIndex = 0; paramIndex < positionalsToMatch; paramIndex++) {
|
18544
18674
|
if (paramIndex === 0 &&
|
@@ -18550,6 +18680,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18550
18680
|
}
|
18551
18681
|
// Skip over the *args parameter since it's handled separately below.
|
18552
18682
|
if (paramIndex === destParamDetails.argsIndex) {
|
18683
|
+
if (!(0, types_1.isUnpackedTypeVarTuple)(destParamDetails.params[destParamDetails.argsIndex].type)) {
|
18684
|
+
skippedPosParamIndices.push(paramIndex);
|
18685
|
+
}
|
18553
18686
|
continue;
|
18554
18687
|
}
|
18555
18688
|
const destParam = destParamDetails.params[paramIndex];
|
@@ -18642,7 +18775,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18642
18775
|
canAssign = false;
|
18643
18776
|
}
|
18644
18777
|
if (destPositionalCount < srcPositionalCount && !targetIncludesParamSpec) {
|
18778
|
+
// Add any remaining positional parameter indices to the list that
|
18779
|
+
// need to be validated.
|
18645
18780
|
for (let i = destPositionalCount; i < srcPositionalCount; i++) {
|
18781
|
+
skippedPosParamIndices.push(i);
|
18782
|
+
}
|
18783
|
+
for (const i of skippedPosParamIndices) {
|
18646
18784
|
// If the dest has an *args parameter, make sure it can accept the remaining
|
18647
18785
|
// positional arguments in the source.
|
18648
18786
|
if (destParamDetails.argsIndex !== undefined) {
|
@@ -19747,37 +19885,48 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
19747
19885
|
// is the type used to reference the member.
|
19748
19886
|
function partiallySpecializeBoundMethod(baseType, memberType, diag, recursionCount, firstParamType, stripFirstParam = true) {
|
19749
19887
|
const constraints = new constraintTracker_1.ConstraintTracker();
|
19750
|
-
if (firstParamType
|
19751
|
-
|
19752
|
-
|
19753
|
-
|
19754
|
-
memberTypeFirstParamType
|
19755
|
-
|
19756
|
-
|
19757
|
-
|
19758
|
-
|
19759
|
-
|
19760
|
-
|
19761
|
-
|
19762
|
-
|
19763
|
-
|
19888
|
+
if (firstParamType) {
|
19889
|
+
if (memberType.shared.parameters.length > 0) {
|
19890
|
+
const memberTypeFirstParam = memberType.shared.parameters[0];
|
19891
|
+
const memberTypeFirstParamType = types_1.FunctionType.getParamType(memberType, 0);
|
19892
|
+
if ((0, types_1.isTypeVar)(memberTypeFirstParamType) &&
|
19893
|
+
memberTypeFirstParamType.shared.boundType &&
|
19894
|
+
(0, types_1.isClassInstance)(memberTypeFirstParamType.shared.boundType) &&
|
19895
|
+
types_1.ClassType.isProtocolClass(memberTypeFirstParamType.shared.boundType)) {
|
19896
|
+
// Handle the protocol class specially. Some protocol classes
|
19897
|
+
// contain references to themselves or their subclasses, so if
|
19898
|
+
// we attempt to call assignType, we'll risk infinite recursion.
|
19899
|
+
// Instead, we'll assume it's assignable.
|
19900
|
+
constraints.setBounds(memberTypeFirstParamType, types_1.TypeBase.isInstantiable(memberTypeFirstParamType)
|
19901
|
+
? (0, typeUtils_1.convertToInstance)(firstParamType)
|
19902
|
+
: firstParamType);
|
19903
|
+
}
|
19904
|
+
else {
|
19905
|
+
const subDiag = diag?.createAddendum();
|
19906
|
+
if (!assignType(memberTypeFirstParamType, firstParamType, subDiag?.createAddendum(), constraints, 8192 /* AssignTypeFlags.AllowUnspecifiedTypeArgs */, recursionCount)) {
|
19907
|
+
if (memberTypeFirstParam.name &&
|
19908
|
+
!types_1.FunctionParam.isNameSynthesized(memberTypeFirstParam) &&
|
19909
|
+
types_1.FunctionParam.isTypeDeclared(memberTypeFirstParam)) {
|
19910
|
+
if (subDiag) {
|
19911
|
+
subDiag.addMessage(localize_1.LocMessage.bindTypeMismatch().format({
|
19912
|
+
type: printType(firstParamType),
|
19913
|
+
methodName: memberType.shared.name || '<anonymous>',
|
19914
|
+
paramName: memberTypeFirstParam.name,
|
19915
|
+
}));
|
19916
|
+
}
|
19917
|
+
return undefined;
|
19918
|
+
}
|
19919
|
+
}
|
19920
|
+
}
|
19764
19921
|
}
|
19765
19922
|
else {
|
19766
19923
|
const subDiag = diag?.createAddendum();
|
19767
|
-
if (
|
19768
|
-
|
19769
|
-
|
19770
|
-
|
19771
|
-
if (subDiag) {
|
19772
|
-
subDiag.addMessage(localize_1.LocMessage.bindTypeMismatch().format({
|
19773
|
-
type: printType(firstParamType),
|
19774
|
-
methodName: memberType.shared.name || '<anonymous>',
|
19775
|
-
paramName: memberTypeFirstParam.name,
|
19776
|
-
}));
|
19777
|
-
}
|
19778
|
-
return undefined;
|
19779
|
-
}
|
19924
|
+
if (subDiag) {
|
19925
|
+
subDiag.addMessage(localize_1.LocMessage.bindParamMissing().format({
|
19926
|
+
methodName: memberType.shared.name || '<anonymous>',
|
19927
|
+
}));
|
19780
19928
|
}
|
19929
|
+
return undefined;
|
19781
19930
|
}
|
19782
19931
|
}
|
19783
19932
|
// Get the effective return type, which will have the side effect of lazily
|
@@ -20104,6 +20253,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
20104
20253
|
getCallSignatureInfo,
|
20105
20254
|
getAbstractSymbols,
|
20106
20255
|
narrowConstrainedTypeVar,
|
20256
|
+
isTypeComparable,
|
20107
20257
|
assignType,
|
20108
20258
|
validateOverrideMethod,
|
20109
20259
|
validateCallArgs,
|