@zzzen/pyright-internal 1.2.0-dev.20241215 → 1.2.0-dev.20241222
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/analysis.js +1 -1
- package/dist/analyzer/analysis.js.map +1 -1
- package/dist/analyzer/analyzerNodeInfo.js +17 -18
- package/dist/analyzer/analyzerNodeInfo.js.map +1 -1
- package/dist/analyzer/backgroundAnalysisProgram.js +18 -35
- package/dist/analyzer/backgroundAnalysisProgram.js.map +1 -1
- package/dist/analyzer/binder.js +38 -55
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.js +146 -185
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.js +24 -31
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +23 -24
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constraintTracker.js +1 -2
- package/dist/analyzer/constraintTracker.js.map +1 -1
- package/dist/analyzer/constructorTransform.js +10 -12
- package/dist/analyzer/constructorTransform.js.map +1 -1
- package/dist/analyzer/constructors.js +14 -19
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.js +27 -26
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/declarationUtils.js +8 -11
- package/dist/analyzer/declarationUtils.js.map +1 -1
- package/dist/analyzer/decorators.js +2 -3
- package/dist/analyzer/decorators.js.map +1 -1
- package/dist/analyzer/docStringConversion.js +6 -8
- package/dist/analyzer/docStringConversion.js.map +1 -1
- package/dist/analyzer/enums.js +12 -13
- package/dist/analyzer/enums.js.map +1 -1
- package/dist/analyzer/functionTransform.js +1 -2
- package/dist/analyzer/functionTransform.js.map +1 -1
- package/dist/analyzer/importResolver.js +18 -27
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/importStatementUtils.js +4 -5
- package/dist/analyzer/importStatementUtils.js.map +1 -1
- package/dist/analyzer/namedTuples.js +6 -7
- package/dist/analyzer/namedTuples.js.map +1 -1
- package/dist/analyzer/operations.js +14 -17
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/packageTypeVerifier.js +35 -39
- package/dist/analyzer/packageTypeVerifier.js.map +1 -1
- package/dist/analyzer/parameterUtils.js +5 -7
- package/dist/analyzer/parameterUtils.js.map +1 -1
- package/dist/analyzer/parentDirectoryCache.js +8 -9
- package/dist/analyzer/parentDirectoryCache.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.js +30 -44
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/parseTreeWalker.js +2 -3
- package/dist/analyzer/parseTreeWalker.js.map +1 -1
- package/dist/analyzer/patternMatching.js +11 -20
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.js +29 -40
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/properties.js +7 -8
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/protocols.js +21 -23
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/pythonPathUtils.js +1 -1
- package/dist/analyzer/pythonPathUtils.js.map +1 -1
- package/dist/analyzer/scope.js +10 -10
- package/dist/analyzer/scope.js.map +1 -1
- package/dist/analyzer/service.js +32 -47
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceFile.js +21 -26
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/sourceFileInfo.js +2 -3
- package/dist/analyzer/sourceFileInfo.js.map +1 -1
- package/dist/analyzer/sourceFileInfoUtils.js +5 -5
- package/dist/analyzer/sourceFileInfoUtils.js.map +1 -1
- package/dist/analyzer/sourceMapper.js +19 -30
- package/dist/analyzer/sourceMapper.js.map +1 -1
- package/dist/analyzer/testWalker.js +1 -2
- package/dist/analyzer/testWalker.js.map +1 -1
- package/dist/analyzer/tracePrinter.js +7 -9
- package/dist/analyzer/tracePrinter.js.map +1 -1
- package/dist/analyzer/tuples.js +11 -13
- package/dist/analyzer/tuples.js.map +1 -1
- package/dist/analyzer/typeCacheUtils.js +5 -6
- package/dist/analyzer/typeCacheUtils.js.map +1 -1
- package/dist/analyzer/typeDocStringUtils.js +7 -11
- package/dist/analyzer/typeDocStringUtils.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +618 -776
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +1 -1
- package/dist/analyzer/typeEvaluatorWithTracker.js +2 -2
- package/dist/analyzer/typeEvaluatorWithTracker.js.map +1 -1
- package/dist/analyzer/typeGuards.js +26 -36
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.js +15 -24
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeStubWriter.js +1 -2
- package/dist/analyzer/typeStubWriter.js.map +1 -1
- package/dist/analyzer/typeUtils.js +65 -94
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typeWalker.js +4 -8
- package/dist/analyzer/typeWalker.js.map +1 -1
- package/dist/analyzer/typedDicts.js +39 -46
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.js +64 -103
- package/dist/analyzer/types.js.map +1 -1
- package/dist/backgroundAnalysis.js +2 -3
- package/dist/backgroundAnalysis.js.map +1 -1
- package/dist/backgroundAnalysisBase.js +9 -10
- package/dist/backgroundAnalysisBase.js.map +1 -1
- package/dist/backgroundThreadBase.js +6 -7
- package/dist/backgroundThreadBase.js.map +1 -1
- package/dist/commands/createTypeStub.js +1 -1
- package/dist/commands/createTypeStub.js.map +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js +3 -3
- package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
- package/dist/commands/quickActionCommand.js +1 -1
- package/dist/commands/quickActionCommand.js.map +1 -1
- package/dist/common/asyncInitialization.js +1 -1
- package/dist/common/chokidarFileWatcherProvider.js +2 -4
- package/dist/common/chokidarFileWatcherProvider.js.map +1 -1
- package/dist/common/configOptions.js +6 -9
- package/dist/common/configOptions.js.map +1 -1
- package/dist/common/console.js +1 -2
- package/dist/common/console.js.map +1 -1
- package/dist/common/core.js +2 -2
- package/dist/common/core.js.map +1 -1
- package/dist/common/crypto.js +1 -1
- package/dist/common/crypto.js.map +1 -1
- package/dist/common/diagnostic.js +3 -5
- package/dist/common/diagnostic.js.map +1 -1
- package/dist/common/envVarUtils.js +1 -1
- package/dist/common/envVarUtils.js.map +1 -1
- package/dist/common/extensibility.d.ts +1 -0
- package/dist/common/extensibility.js.map +1 -1
- package/dist/common/fileSystem.d.ts +1 -0
- package/dist/common/fileSystem.js.map +1 -1
- package/dist/common/fullAccessHost.js +5 -5
- package/dist/common/fullAccessHost.js.map +1 -1
- package/dist/common/host.js +1 -1
- package/dist/common/host.js.map +1 -1
- package/dist/common/logTracker.js +1 -1
- package/dist/common/logTracker.js.map +1 -1
- package/dist/common/lspUtils.js +1 -2
- package/dist/common/lspUtils.js.map +1 -1
- package/dist/common/progressReporter.js +1 -2
- package/dist/common/progressReporter.js.map +1 -1
- package/dist/common/realFileSystem.js +2 -3
- package/dist/common/realFileSystem.js.map +1 -1
- package/dist/common/serviceProvider.js +1 -1
- package/dist/common/serviceProvider.js.map +1 -1
- package/dist/common/textEditTracker.js +4 -6
- package/dist/common/textEditTracker.js.map +1 -1
- package/dist/common/tomlUtils.js +3 -1
- package/dist/common/tomlUtils.js.map +1 -1
- package/dist/common/uri/baseUri.js +1 -1
- package/dist/common/uri/baseUri.js.map +1 -1
- package/dist/common/uri/emptyUri.js +1 -1
- package/dist/common/uri/emptyUri.js.map +1 -1
- package/dist/common/uri/fileUri.js +2 -2
- package/dist/common/uri/fileUri.js.map +1 -1
- package/dist/common/uri/memoization.js +1 -1
- package/dist/common/uri/memoization.js.map +1 -1
- package/dist/common/uri/uri.js +2 -3
- package/dist/common/uri/uri.js.map +1 -1
- package/dist/common/uri/uriUtils.js +6 -8
- package/dist/common/uri/uriUtils.js.map +1 -1
- package/dist/common/uri/webUri.js +2 -2
- package/dist/common/uri/webUri.js.map +1 -1
- package/dist/common/workspaceEditUtils.js +10 -15
- package/dist/common/workspaceEditUtils.js.map +1 -1
- package/dist/languageServerBase.js +34 -42
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/analyzerServiceExecutor.js +8 -10
- package/dist/languageService/analyzerServiceExecutor.js.map +1 -1
- package/dist/languageService/autoImporter.js +16 -19
- package/dist/languageService/autoImporter.js.map +1 -1
- package/dist/languageService/callHierarchyProvider.js +6 -11
- package/dist/languageService/callHierarchyProvider.js.map +1 -1
- package/dist/languageService/completionProvider.js +81 -106
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/completionProviderUtils.js +3 -3
- package/dist/languageService/completionProviderUtils.js.map +1 -1
- package/dist/languageService/definitionProvider.js +6 -9
- package/dist/languageService/definitionProvider.js.map +1 -1
- package/dist/languageService/documentSymbolCollector.js +32 -32
- package/dist/languageService/documentSymbolCollector.js.map +1 -1
- package/dist/languageService/dynamicFeature.js +1 -2
- package/dist/languageService/dynamicFeature.js.map +1 -1
- package/dist/languageService/hoverProvider.js +17 -23
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/referencesProvider.js +4 -9
- package/dist/languageService/referencesProvider.js.map +1 -1
- package/dist/languageService/renameProvider.js +2 -4
- package/dist/languageService/renameProvider.js.map +1 -1
- package/dist/languageService/signatureHelpProvider.js +11 -15
- package/dist/languageService/signatureHelpProvider.js.map +1 -1
- package/dist/languageService/tooltipUtils.js +15 -17
- package/dist/languageService/tooltipUtils.js.map +1 -1
- package/dist/localization/localize.js +3 -3
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +6 -0
- package/dist/localization/package.nls.de.json +6 -0
- package/dist/localization/package.nls.en-us.json +8 -8
- package/dist/localization/package.nls.es.json +6 -0
- package/dist/localization/package.nls.fr.json +7 -1
- package/dist/localization/package.nls.it.json +6 -0
- package/dist/localization/package.nls.ja.json +6 -0
- package/dist/localization/package.nls.ko.json +6 -0
- package/dist/localization/package.nls.pl.json +6 -0
- package/dist/localization/package.nls.pt-br.json +6 -0
- package/dist/localization/package.nls.qps-ploc.json +6 -0
- package/dist/localization/package.nls.ru.json +6 -0
- package/dist/localization/package.nls.tr.json +6 -0
- package/dist/localization/package.nls.zh-cn.json +6 -0
- package/dist/localization/package.nls.zh-tw.json +6 -0
- package/dist/parser/parser.js +30 -38
- package/dist/parser/parser.js.map +1 -1
- package/dist/parser/tokenizer.js +8 -13
- package/dist/parser/tokenizer.js.map +1 -1
- package/dist/pprof/profiler.js +3 -3
- package/dist/pprof/profiler.js.map +1 -1
- package/dist/pyright.js +5 -7
- package/dist/pyright.js.map +1 -1
- package/dist/pyrightFileSystem.js +4 -5
- package/dist/pyrightFileSystem.js.map +1 -1
- package/dist/readonlyAugmentedFileSystem.js +3 -5
- package/dist/readonlyAugmentedFileSystem.js.map +1 -1
- package/dist/server.js +1 -1
- package/dist/server.js.map +1 -1
- package/dist/tests/chainedSourceFiles.test.js +3 -3
- package/dist/tests/chainedSourceFiles.test.js.map +1 -1
- package/dist/tests/classDeclaration.test.js +7 -10
- package/dist/tests/classDeclaration.test.js.map +1 -1
- package/dist/tests/completions.test.js +3 -3
- package/dist/tests/completions.test.js.map +1 -1
- package/dist/tests/config.test.js +10 -15
- package/dist/tests/config.test.js.map +1 -1
- package/dist/tests/diagnosticOverrides.test.js +4 -6
- package/dist/tests/diagnosticOverrides.test.js.map +1 -1
- package/dist/tests/envVarUtils.test.js +9 -12
- package/dist/tests/envVarUtils.test.js.map +1 -1
- package/dist/tests/harness/fourslash/testLanguageService.js +1 -1
- package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.js +45 -60
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/harness/fourslash/workspaceEditTestUtils.js +6 -7
- package/dist/tests/harness/fourslash/workspaceEditTestUtils.js.map +1 -1
- package/dist/tests/harness/vfs/filesystem.js +3 -3
- package/dist/tests/harness/vfs/filesystem.js.map +1 -1
- package/dist/tests/importResolver.test.js +6 -7
- package/dist/tests/importResolver.test.js.map +1 -1
- package/dist/tests/importStatementUtils.test.js +2 -2
- package/dist/tests/importStatementUtils.test.js.map +1 -1
- package/dist/tests/ipythonMode.test.js +11 -12
- package/dist/tests/ipythonMode.test.js.map +1 -1
- package/dist/tests/languageServer.test.js +1 -2
- package/dist/tests/languageServer.test.js.map +1 -1
- package/dist/tests/lsp/languageServer.js +10 -14
- package/dist/tests/lsp/languageServer.js.map +1 -1
- package/dist/tests/lsp/languageServerTestUtils.js +10 -14
- package/dist/tests/lsp/languageServerTestUtils.js.map +1 -1
- package/dist/tests/parseTreeUtils.test.js +7 -7
- package/dist/tests/parseTreeUtils.test.js.map +1 -1
- package/dist/tests/parser.test.js +2 -2
- package/dist/tests/parser.test.js.map +1 -1
- package/dist/tests/service.test.js +2 -3
- package/dist/tests/service.test.js.map +1 -1
- package/dist/tests/sourceFile.test.js +2 -3
- package/dist/tests/sourceFile.test.js.map +1 -1
- package/dist/tests/sourceMapperUtils.test.js +3 -4
- package/dist/tests/sourceMapperUtils.test.js.map +1 -1
- package/dist/tests/testState.test.js +3 -6
- package/dist/tests/testState.test.js.map +1 -1
- package/dist/tests/testStateUtils.js +3 -4
- package/dist/tests/testStateUtils.js.map +1 -1
- package/dist/tests/textEditUtil.test.js +2 -2
- package/dist/tests/textEditUtil.test.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +1 -1
- package/dist/tests/typePrinter.test.js +1 -2
- package/dist/tests/typePrinter.test.js.map +1 -1
- package/dist/tests/workspaceEditUtils.test.js +3 -5
- package/dist/tests/workspaceEditUtils.test.js.map +1 -1
- package/dist/workspaceFactory.js +2 -3
- package/dist/workspaceFactory.js.map +1 -1
- package/package.json +1 -1
package/dist/analyzer/checker.js
CHANGED
@@ -203,7 +203,6 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
203
203
|
return false;
|
204
204
|
}
|
205
205
|
visitFunction(node) {
|
206
|
-
var _a, _b, _c;
|
207
206
|
if (node.d.typeParams) {
|
208
207
|
this.walk(node.d.typeParams);
|
209
208
|
}
|
@@ -222,14 +221,13 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
222
221
|
const paramDetails = (0, parameterUtils_1.getParamListDetails)(functionTypeResult.functionType);
|
223
222
|
// Report any unknown or missing parameter types.
|
224
223
|
node.d.params.forEach((param, index) => {
|
225
|
-
var _a;
|
226
224
|
if (param.d.name) {
|
227
225
|
if (param.d.category === 0 /* ParamCategory.Simple */ && index >= paramDetails.positionOnlyParamCount) {
|
228
226
|
keywordNames.add(param.d.name.d.value);
|
229
227
|
}
|
230
228
|
// Determine whether this is a P.args parameter.
|
231
229
|
if (param.d.category === 1 /* ParamCategory.ArgsList */) {
|
232
|
-
const annotationExpr =
|
230
|
+
const annotationExpr = param.d.annotation ?? param.d.annotationComment;
|
233
231
|
if (annotationExpr &&
|
234
232
|
annotationExpr.nodeType === 35 /* ParseNodeType.MemberAccess */ &&
|
235
233
|
annotationExpr.d.member.d.value === 'args') {
|
@@ -248,7 +246,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
248
246
|
}
|
249
247
|
// Allow unknown and missing param types if the param is named '_'.
|
250
248
|
if (param.d.name && param.d.name.d.value !== '_') {
|
251
|
-
const paramIndex = functionTypeResult.functionType.shared.parameters.findIndex((p) =>
|
249
|
+
const paramIndex = functionTypeResult.functionType.shared.parameters.findIndex((p) => p.name === param.d.name?.d.value);
|
252
250
|
if (paramIndex >= 0) {
|
253
251
|
const functionTypeParam = functionTypeResult.functionType.shared.parameters[paramIndex];
|
254
252
|
const paramType = types_1.FunctionType.getParamType(functionTypeResult.functionType, paramIndex);
|
@@ -299,7 +297,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
299
297
|
if (overlappingEntries.size > 0) {
|
300
298
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.overlappingKeywordArgs().format({
|
301
299
|
names: [...overlappingEntries.values()].join(', '),
|
302
|
-
}),
|
300
|
+
}), node.d.params[kwargsIndex].d.annotation ?? node.d.params[kwargsIndex]);
|
303
301
|
}
|
304
302
|
}
|
305
303
|
}
|
@@ -314,15 +312,15 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
314
312
|
return false;
|
315
313
|
});
|
316
314
|
if (paramSpecParams.length === 1 && paramSpecParams[0].name) {
|
317
|
-
const paramNode = node.d.params.find((param) =>
|
318
|
-
const annotationNode =
|
315
|
+
const paramNode = node.d.params.find((param) => param.d.name?.d.value === paramSpecParams[0].name);
|
316
|
+
const annotationNode = paramNode?.d.annotation ?? paramNode?.d.annotationComment;
|
319
317
|
if (annotationNode) {
|
320
318
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.paramSpecArgsKwargsUsage(), annotationNode);
|
321
319
|
}
|
322
320
|
}
|
323
321
|
// If this is a stub, ensure that the return type is specified.
|
324
322
|
if (this._fileInfo.isStubFile) {
|
325
|
-
const returnAnnotation = node.d.returnAnnotation ||
|
323
|
+
const returnAnnotation = node.d.returnAnnotation || node.d.funcAnnotationComment?.d.returnAnnotation;
|
326
324
|
if (!returnAnnotation) {
|
327
325
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnknownParameterType, localize_1.LocMessage.returnTypeUnknown(), node.d.name);
|
328
326
|
}
|
@@ -407,7 +405,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
407
405
|
// This signifies an incomplete stub file that obscures type errors.
|
408
406
|
if (this._fileInfo.isStubFile && node.d.name.d.value === '__getattr__') {
|
409
407
|
const scope = (0, scopeUtils_1.getScopeForNode)(node);
|
410
|
-
if (
|
408
|
+
if (scope?.type === 4 /* ScopeType.Module */) {
|
411
409
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompleteStub, localize_1.LocMessage.stubUsesGetAttr(), node.d.name);
|
412
410
|
}
|
413
411
|
}
|
@@ -465,13 +463,12 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
465
463
|
return false;
|
466
464
|
}
|
467
465
|
visitCall(node) {
|
468
|
-
var _a;
|
469
466
|
this._validateIsInstanceCall(node);
|
470
467
|
this._validateIllegalDefaultParamInitializer(node);
|
471
468
|
this._validateStandardCollectionInstantiation(node);
|
472
469
|
if (this._fileInfo.diagnosticRuleSet.reportUnusedCallResult !== 'none' ||
|
473
470
|
this._fileInfo.diagnosticRuleSet.reportUnusedCoroutine !== 'none') {
|
474
|
-
if (
|
471
|
+
if (node.parent?.nodeType === 47 /* ParseNodeType.StatementList */) {
|
475
472
|
const isRevealTypeCall = node.d.leftExpr.nodeType === 38 /* ParseNodeType.Name */ && node.d.leftExpr.d.value === 'reveal_type';
|
476
473
|
const returnType = this._evaluator.getType(node);
|
477
474
|
if (!isRevealTypeCall && returnType && this._isTypeValidForUnusedValueTest(returnType)) {
|
@@ -487,9 +484,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
487
484
|
return true;
|
488
485
|
}
|
489
486
|
visitAwait(node) {
|
490
|
-
var _a;
|
491
487
|
if (this._fileInfo.diagnosticRuleSet.reportUnusedCallResult !== 'none') {
|
492
|
-
if (
|
488
|
+
if (node.parent?.nodeType === 47 /* ParseNodeType.StatementList */ && node.d.expr.nodeType === 9 /* ParseNodeType.Call */) {
|
493
489
|
const returnType = this._evaluator.getType(node);
|
494
490
|
if (returnType && this._isTypeValidForUnusedValueTest(returnType)) {
|
495
491
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnusedCallResult, localize_1.LocMessage.unusedCallResult().format({
|
@@ -548,7 +544,6 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
548
544
|
return true;
|
549
545
|
}
|
550
546
|
visitReturn(node) {
|
551
|
-
var _a, _b, _c, _d, _e, _f;
|
552
547
|
let returnTypeResult;
|
553
548
|
let returnType;
|
554
549
|
const enclosingFunctionNode = ParseTreeUtils.getEnclosingFunction(node);
|
@@ -556,7 +551,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
556
551
|
? this._evaluator.getDeclaredReturnType(enclosingFunctionNode)
|
557
552
|
: undefined;
|
558
553
|
if (node.d.expr) {
|
559
|
-
returnTypeResult =
|
554
|
+
returnTypeResult = this._evaluator.getTypeResult(node.d.expr) ?? { type: types_1.UnknownType.create() };
|
560
555
|
}
|
561
556
|
else {
|
562
557
|
// There is no return expression, so "None" is assumed.
|
@@ -564,15 +559,15 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
564
559
|
}
|
565
560
|
returnType = returnTypeResult.type;
|
566
561
|
// If this type is a special form, use the special form instead.
|
567
|
-
if (
|
562
|
+
if (returnType.props?.specialForm) {
|
568
563
|
returnType = returnType.props.specialForm;
|
569
564
|
}
|
570
565
|
// If the enclosing function is async and a generator, the return
|
571
566
|
// statement is not allowed to have an argument. A syntax error occurs
|
572
567
|
// at runtime in this case.
|
573
|
-
if (
|
568
|
+
if (enclosingFunctionNode?.d.isAsync && node.d.expr) {
|
574
569
|
const functionDecl = AnalyzerNodeInfo.getDeclaration(enclosingFunctionNode);
|
575
|
-
if (
|
570
|
+
if (functionDecl?.type === 5 /* DeclarationType.Function */ && functionDecl.isGenerator) {
|
576
571
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.returnInAsyncGenerator(), node.d.expr);
|
577
572
|
}
|
578
573
|
}
|
@@ -622,31 +617,29 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
622
617
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportReturnType, localize_1.LocMessage.returnTypeMismatch().format({
|
623
618
|
exprType: this._evaluator.printType(returnType),
|
624
619
|
returnType: this._evaluator.printType(declaredReturnType),
|
625
|
-
}) + diagAddendum.getString(),
|
620
|
+
}) + diagAddendum.getString(), node.d.expr ?? node, returnTypeResult.expectedTypeDiagAddendum?.getEffectiveTextRange());
|
626
621
|
}
|
627
622
|
}
|
628
623
|
}
|
629
624
|
if ((0, types_1.isUnknown)(returnType)) {
|
630
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnknownVariableType, localize_1.LocMessage.returnTypeUnknown(),
|
625
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnknownVariableType, localize_1.LocMessage.returnTypeUnknown(), node.d.expr ?? node);
|
631
626
|
}
|
632
627
|
else if ((0, typeUtils_1.isPartlyUnknown)(returnType)) {
|
633
628
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnknownVariableType, localize_1.LocMessage.returnTypePartiallyUnknown().format({
|
634
629
|
returnType: this._evaluator.printType(returnType, { expandTypeAlias: true }),
|
635
|
-
}),
|
630
|
+
}), node.d.expr ?? node);
|
636
631
|
}
|
637
632
|
}
|
638
633
|
return true;
|
639
634
|
}
|
640
635
|
visitYield(node) {
|
641
|
-
var _a;
|
642
636
|
const yieldTypeResult = node.d.expr
|
643
637
|
? this._evaluator.getTypeResult(node.d.expr)
|
644
638
|
: { type: this._evaluator.getNoneType() };
|
645
|
-
this._validateYieldType(node,
|
639
|
+
this._validateYieldType(node, yieldTypeResult?.type ?? types_1.UnknownType.create(), yieldTypeResult?.expectedTypeDiagAddendum);
|
646
640
|
return true;
|
647
641
|
}
|
648
642
|
visitYieldFrom(node) {
|
649
|
-
var _a, _b, _c, _d;
|
650
643
|
const yieldFromType = this._evaluator.getType(node.d.expr) || types_1.UnknownType.create();
|
651
644
|
let yieldType;
|
652
645
|
let sendType;
|
@@ -656,7 +649,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
656
649
|
}
|
657
650
|
else {
|
658
651
|
yieldType =
|
659
|
-
|
652
|
+
this._evaluator.getTypeOfIterable({ type: yieldFromType }, /* isAsync */ false, node)?.type ??
|
653
|
+
types_1.UnknownType.create();
|
660
654
|
// Does the iterator return a Generator? If so, get the yield type from it.
|
661
655
|
// If the iterator doesn't return a Generator, use the iterator return type
|
662
656
|
// directly.
|
@@ -667,7 +661,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
667
661
|
}
|
668
662
|
else {
|
669
663
|
yieldType =
|
670
|
-
|
664
|
+
this._evaluator.getTypeOfIterator({ type: yieldFromType }, /* isAsync */ false, node)?.type ??
|
665
|
+
types_1.UnknownType.create();
|
671
666
|
}
|
672
667
|
}
|
673
668
|
this._validateYieldType(node, yieldType, /* expectedDiagAddendum */ undefined, sendType);
|
@@ -754,7 +749,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
754
749
|
if (baseType) {
|
755
750
|
(0, typeUtils_1.doForEachSubtype)(baseType, (subtype) => {
|
756
751
|
const tupleType = (0, typeUtils_1.getSpecializedTupleType)(subtype);
|
757
|
-
if (!(0, types_1.isClassInstance)(subtype) || !
|
752
|
+
if (!(0, types_1.isClassInstance)(subtype) || !tupleType?.priv.tupleTypeArgs || (0, typeUtils_1.isUnboundedTupleClass)(tupleType)) {
|
758
753
|
return;
|
759
754
|
}
|
760
755
|
const tupleLength = tupleType.priv.tupleTypeArgs.length;
|
@@ -940,12 +935,11 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
940
935
|
return false;
|
941
936
|
}
|
942
937
|
visitMemberAccess(node) {
|
943
|
-
var _a;
|
944
938
|
const typeResult = this._evaluator.getTypeResult(node.d.member);
|
945
|
-
const type =
|
939
|
+
const type = typeResult?.type ?? types_1.UnknownType.create();
|
946
940
|
const leftExprType = this._evaluator.getType(node.d.leftExpr);
|
947
941
|
this._reportDeprecatedUseForType(node.d.member, type, leftExprType && (0, types_1.isModule)(leftExprType) && leftExprType.priv.moduleName === 'typing');
|
948
|
-
if (typeResult
|
942
|
+
if (typeResult?.memberAccessDeprecationInfo) {
|
949
943
|
this._reportDeprecatedUseForMemberAccess(node.d.member, typeResult.memberAccessDeprecationInfo);
|
950
944
|
}
|
951
945
|
this._conditionallyReportPrivateUsage(node.d.member);
|
@@ -986,11 +980,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
986
980
|
return true;
|
987
981
|
}
|
988
982
|
visitImportFromAs(node) {
|
989
|
-
var _a, _b, _c;
|
990
983
|
if (this._fileInfo.isStubFile) {
|
991
984
|
return false;
|
992
985
|
}
|
993
|
-
const decls =
|
986
|
+
const decls = this._evaluator.getDeclInfoForNameNode(node.d.name)?.decls;
|
994
987
|
if (!decls) {
|
995
988
|
return false;
|
996
989
|
}
|
@@ -1000,7 +993,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1000
993
|
continue;
|
1001
994
|
}
|
1002
995
|
const resolvedAlias = this._evaluator.resolveAliasDeclaration(decl, /* resolveLocalNames */ true);
|
1003
|
-
const resolvedAliasUri = resolvedAlias
|
996
|
+
const resolvedAliasUri = resolvedAlias?.uri;
|
1004
997
|
if (!resolvedAliasUri || !(0, sourceMapper_1.isStubFile)(resolvedAliasUri)) {
|
1005
998
|
continue;
|
1006
999
|
}
|
@@ -1012,14 +1005,14 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1012
1005
|
break;
|
1013
1006
|
}
|
1014
1007
|
let isImportFromTyping = false;
|
1015
|
-
if (
|
1008
|
+
if (node.parent?.nodeType === 25 /* ParseNodeType.ImportFrom */) {
|
1016
1009
|
if (node.parent.d.module.d.leadingDots === 0 && node.parent.d.module.d.nameParts.length === 1) {
|
1017
1010
|
if (node.parent.d.module.d.nameParts[0].d.value === 'typing') {
|
1018
1011
|
isImportFromTyping = true;
|
1019
1012
|
}
|
1020
1013
|
}
|
1021
1014
|
}
|
1022
|
-
const type = this._evaluator.getType(
|
1015
|
+
const type = this._evaluator.getType(node.d.alias ?? node.d.name);
|
1023
1016
|
this._reportDeprecatedUseForType(node.d.name, type, isImportFromTyping);
|
1024
1017
|
return false;
|
1025
1018
|
}
|
@@ -1037,10 +1030,9 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1037
1030
|
return true;
|
1038
1031
|
}
|
1039
1032
|
visitTypeParameter(node) {
|
1040
|
-
var _a, _b, _c, _d;
|
1041
1033
|
// Verify that there are no live type variables with the same
|
1042
1034
|
// name in outer scopes.
|
1043
|
-
let curNode =
|
1035
|
+
let curNode = node.parent?.parent?.parent;
|
1044
1036
|
let foundDuplicate = false;
|
1045
1037
|
while (curNode) {
|
1046
1038
|
const typeVarScopeNode = ParseTreeUtils.getTypeVarScopeNode(curNode);
|
@@ -1048,15 +1040,15 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1048
1040
|
break;
|
1049
1041
|
}
|
1050
1042
|
if (typeVarScopeNode.nodeType === 10 /* ParseNodeType.Class */) {
|
1051
|
-
const classType =
|
1052
|
-
if (classType
|
1043
|
+
const classType = this._evaluator.getTypeOfClass(typeVarScopeNode)?.classType;
|
1044
|
+
if (classType?.shared.typeParams.some((param) => param.shared.name === node.d.name.d.value)) {
|
1053
1045
|
foundDuplicate = true;
|
1054
1046
|
break;
|
1055
1047
|
}
|
1056
1048
|
}
|
1057
1049
|
else if (typeVarScopeNode.nodeType === 31 /* ParseNodeType.Function */) {
|
1058
|
-
const functionType =
|
1059
|
-
if (functionType
|
1050
|
+
const functionType = this._evaluator.getTypeOfFunction(typeVarScopeNode)?.functionType;
|
1051
|
+
if (functionType?.shared.typeParams.some((param) => param.shared.name === node.d.name.d.value)) {
|
1060
1052
|
foundDuplicate = true;
|
1061
1053
|
break;
|
1062
1054
|
}
|
@@ -1144,7 +1136,6 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1144
1136
|
let isTypeBool = true;
|
1145
1137
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
1146
1138
|
this._evaluator.mapSubtypesExpandTypeVars(operandType, /* options */ undefined, (expandedSubtype) => {
|
1147
|
-
var _a;
|
1148
1139
|
if ((0, types_1.isAnyOrUnknown)(expandedSubtype)) {
|
1149
1140
|
return undefined;
|
1150
1141
|
}
|
@@ -1153,8 +1144,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1153
1144
|
return undefined;
|
1154
1145
|
}
|
1155
1146
|
// Invoke the __bool__ method on the type.
|
1156
|
-
const boolReturnType =
|
1157
|
-
/* inferenceContext */ undefined)
|
1147
|
+
const boolReturnType = this._evaluator.getTypeOfMagicMethodCall(expandedSubtype, '__bool__', [], node,
|
1148
|
+
/* inferenceContext */ undefined)?.type;
|
1158
1149
|
if (!boolReturnType || (0, types_1.isAnyOrUnknown)(boolReturnType)) {
|
1159
1150
|
return undefined;
|
1160
1151
|
}
|
@@ -1209,7 +1200,6 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1209
1200
|
}
|
1210
1201
|
}
|
1211
1202
|
_reportUnusedExpression(node) {
|
1212
|
-
var _a, _b;
|
1213
1203
|
if (this._fileInfo.diagnosticRuleSet.reportUnusedExpression === 'none') {
|
1214
1204
|
return;
|
1215
1205
|
}
|
@@ -1235,9 +1225,9 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1235
1225
|
}
|
1236
1226
|
if (reportAsUnused &&
|
1237
1227
|
this._fileInfo.ipythonMode === sourceFile_1.IPythonMode.CellDocs &&
|
1238
|
-
|
1228
|
+
node.parent?.nodeType === 47 /* ParseNodeType.StatementList */ &&
|
1239
1229
|
node.parent.d.statements[node.parent.d.statements.length - 1] === node &&
|
1240
|
-
|
1230
|
+
node.parent.parent?.nodeType === 36 /* ParseNodeType.Module */ &&
|
1241
1231
|
node.parent.parent.d.statements[node.parent.parent.d.statements.length - 1] === node.parent) {
|
1242
1232
|
// Exclude an expression at the end of a notebook cell, as that is treated as
|
1243
1233
|
// the cell's value.
|
@@ -1465,7 +1455,6 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1465
1455
|
// If the function is a generator, validates that its annotated return type
|
1466
1456
|
// is appropriate for a generator.
|
1467
1457
|
_validateGeneratorReturnType(node, functionType) {
|
1468
|
-
var _a;
|
1469
1458
|
if (!types_1.FunctionType.isGenerator(functionType)) {
|
1470
1459
|
return;
|
1471
1460
|
}
|
@@ -1501,7 +1490,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1501
1490
|
? localize_1.LocMessage.generatorAsyncReturnType()
|
1502
1491
|
: localize_1.LocMessage.generatorSyncReturnType();
|
1503
1492
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, errorMessage.format({ yieldType: this._evaluator.printType(types_1.AnyType.create()) }) +
|
1504
|
-
diagAddendum.getString(),
|
1493
|
+
diagAddendum.getString(), node.d.returnAnnotation ?? node.d.name);
|
1505
1494
|
}
|
1506
1495
|
}
|
1507
1496
|
// Determines whether the specified type is one that should trigger
|
@@ -1532,7 +1521,6 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1532
1521
|
}
|
1533
1522
|
}
|
1534
1523
|
const nameWalker = new ParseTreeUtils.NameNodeWalker((nameNode, subscriptIndex, baseExpression) => {
|
1535
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
1536
1524
|
const nameType = this._evaluator.getType(nameNode);
|
1537
1525
|
``;
|
1538
1526
|
if (nameType && (0, types_1.isTypeVar)(nameType) && !types_1.TypeVarType.isSelf(nameType)) {
|
@@ -1550,13 +1538,13 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1550
1538
|
// exempt it from the check because the type alias may repeat
|
1551
1539
|
// the TypeVar multiple times.
|
1552
1540
|
const baseType = this._evaluator.getType(baseExpression);
|
1553
|
-
const aliasInfo =
|
1554
|
-
if (
|
1541
|
+
const aliasInfo = baseType?.props?.typeAliasInfo;
|
1542
|
+
if (aliasInfo?.shared.typeParams && subscriptIndex < aliasInfo.shared.typeParams.length) {
|
1555
1543
|
isExempt = true;
|
1556
1544
|
}
|
1557
1545
|
}
|
1558
1546
|
const existingEntry = localTypeVarUsage.get(nameType.shared.name);
|
1559
|
-
const isParamTypeWithEllipsisUsage =
|
1547
|
+
const isParamTypeWithEllipsisUsage = curParamNode?.d.defaultValue?.nodeType === 21 /* ParseNodeType.Ellipsis */;
|
1560
1548
|
if (!existingEntry) {
|
1561
1549
|
localTypeVarUsage.set(nameType.shared.name, {
|
1562
1550
|
nodes: [nameNode],
|
@@ -1564,7 +1552,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1564
1552
|
paramTypeUsageCount: curParamNode !== undefined ? 1 : 0,
|
1565
1553
|
paramTypeWithEllipsisUsageCount: isParamTypeWithEllipsisUsage ? 1 : 0,
|
1566
1554
|
returnTypeUsageCount: curParamNode === undefined ? 1 : 0,
|
1567
|
-
paramWithEllipsis: isParamTypeWithEllipsisUsage ?
|
1555
|
+
paramWithEllipsis: isParamTypeWithEllipsisUsage ? curParamNode?.d.name?.d.value : undefined,
|
1568
1556
|
isExempt,
|
1569
1557
|
});
|
1570
1558
|
}
|
@@ -1575,7 +1563,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1575
1563
|
if (isParamTypeWithEllipsisUsage) {
|
1576
1564
|
existingEntry.paramTypeWithEllipsisUsageCount += 1;
|
1577
1565
|
if (!existingEntry.paramWithEllipsis) {
|
1578
|
-
existingEntry.paramWithEllipsis =
|
1566
|
+
existingEntry.paramWithEllipsis = curParamNode?.d.name?.d.value;
|
1579
1567
|
}
|
1580
1568
|
}
|
1581
1569
|
}
|
@@ -1588,7 +1576,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1588
1576
|
// this constructor method?
|
1589
1577
|
if (constructorClass && nameType.priv.scopeId === constructorClass.shared.typeVarScopeId) {
|
1590
1578
|
const existingEntry = classTypeVarUsage.get(nameType.shared.name);
|
1591
|
-
const isParamTypeWithEllipsisUsage =
|
1579
|
+
const isParamTypeWithEllipsisUsage = curParamNode?.d.defaultValue?.nodeType === 21 /* ParseNodeType.Ellipsis */;
|
1592
1580
|
const isExempt = !!nameType.shared.isDefaultExplicit;
|
1593
1581
|
if (!existingEntry) {
|
1594
1582
|
classTypeVarUsage.set(nameType.shared.name, {
|
@@ -1597,7 +1585,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1597
1585
|
paramTypeUsageCount: curParamNode !== undefined ? 1 : 0,
|
1598
1586
|
paramTypeWithEllipsisUsageCount: isParamTypeWithEllipsisUsage ? 1 : 0,
|
1599
1587
|
returnTypeUsageCount: 0,
|
1600
|
-
paramWithEllipsis: isParamTypeWithEllipsisUsage ?
|
1588
|
+
paramWithEllipsis: isParamTypeWithEllipsisUsage ? curParamNode?.d.name?.d.value : undefined,
|
1601
1589
|
isExempt,
|
1602
1590
|
});
|
1603
1591
|
}
|
@@ -1608,7 +1596,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1608
1596
|
if (isParamTypeWithEllipsisUsage) {
|
1609
1597
|
existingEntry.paramTypeWithEllipsisUsageCount += 1;
|
1610
1598
|
if (!existingEntry.paramWithEllipsis) {
|
1611
|
-
existingEntry.paramWithEllipsis =
|
1599
|
+
existingEntry.paramWithEllipsis = curParamNode?.d.name?.d.value;
|
1612
1600
|
}
|
1613
1601
|
}
|
1614
1602
|
}
|
@@ -1642,7 +1630,6 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1642
1630
|
}
|
1643
1631
|
}
|
1644
1632
|
localTypeVarUsage.forEach((usage) => {
|
1645
|
-
var _a;
|
1646
1633
|
// Report error for local type variable that appears only once.
|
1647
1634
|
if (usage.nodes.length === 1 && !usage.isExempt) {
|
1648
1635
|
let altTypeText;
|
@@ -1690,14 +1677,13 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1690
1677
|
diag.addMessage(localize_1.LocAddendum.typeVarUnsolvableRemedy());
|
1691
1678
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeVarUse, localize_1.LocMessage.typeVarPossiblyUnsolvable().format({
|
1692
1679
|
name: usage.nodes[0].d.value,
|
1693
|
-
param:
|
1680
|
+
param: usage.paramWithEllipsis ?? '',
|
1694
1681
|
}) + diag.getString(), usage.nodes[0]);
|
1695
1682
|
}
|
1696
1683
|
});
|
1697
1684
|
// Report error for a class type variable that appears only within
|
1698
1685
|
// constructor parameters that have default values. These may go unsolved.
|
1699
1686
|
classTypeVarUsage.forEach((usage) => {
|
1700
|
-
var _a;
|
1701
1687
|
if (usage.paramTypeWithEllipsisUsageCount > 0 &&
|
1702
1688
|
usage.paramTypeUsageCount === usage.paramTypeWithEllipsisUsageCount &&
|
1703
1689
|
!usage.isExempt) {
|
@@ -1705,14 +1691,13 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1705
1691
|
diag.addMessage(localize_1.LocAddendum.typeVarUnsolvableRemedy());
|
1706
1692
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeVarUse, localize_1.LocMessage.typeVarPossiblyUnsolvable().format({
|
1707
1693
|
name: usage.nodes[0].d.value,
|
1708
|
-
param:
|
1694
|
+
param: usage.paramWithEllipsis ?? '',
|
1709
1695
|
}) + diag.getString(), usage.nodes[0]);
|
1710
1696
|
}
|
1711
1697
|
});
|
1712
1698
|
}
|
1713
1699
|
// Validates that overloads use @staticmethod and @classmethod consistently.
|
1714
1700
|
_validateOverloadAttributeConsistency(node, functionType) {
|
1715
|
-
var _a, _b, _c, _d, _e, _f;
|
1716
1701
|
// Don't bother with the check if it's suppressed.
|
1717
1702
|
if (this._fileInfo.diagnosticRuleSet.reportInconsistentOverload === 'none') {
|
1718
1703
|
return;
|
@@ -1745,12 +1730,12 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1745
1730
|
if (staticMethodCount > 0 && staticMethodCount < totalMethods) {
|
1746
1731
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInconsistentOverload, localize_1.LocMessage.overloadStaticMethodInconsistent().format({
|
1747
1732
|
name: node.d.name.d.value,
|
1748
|
-
}),
|
1733
|
+
}), overloads[0]?.shared.declaration?.node.d.name ?? node.d.name);
|
1749
1734
|
}
|
1750
1735
|
if (classMethodCount > 0 && classMethodCount < totalMethods) {
|
1751
1736
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInconsistentOverload, localize_1.LocMessage.overloadClassMethodInconsistent().format({
|
1752
1737
|
name: node.d.name.d.value,
|
1753
|
-
}),
|
1738
|
+
}), overloads[0]?.shared.declaration?.node.d.name ?? node.d.name);
|
1754
1739
|
}
|
1755
1740
|
}
|
1756
1741
|
// Validates that overloads do not overlap with inconsistent return results.
|
@@ -1795,15 +1780,14 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1795
1780
|
// earlier overload. Typeshed stubs contain type: ignore comments on these
|
1796
1781
|
// lines, so it is important for us to report them in the same manner.
|
1797
1782
|
_findNodeForOverload(functionNode, overloadType) {
|
1798
|
-
|
1799
|
-
const decls = (_a = this._evaluator.getDeclInfoForNameNode(functionNode.d.name)) === null || _a === void 0 ? void 0 : _a.decls;
|
1783
|
+
const decls = this._evaluator.getDeclInfoForNameNode(functionNode.d.name)?.decls;
|
1800
1784
|
if (!decls) {
|
1801
1785
|
return undefined;
|
1802
1786
|
}
|
1803
1787
|
for (const decl of decls) {
|
1804
1788
|
if (decl.type === 5 /* DeclarationType.Function */) {
|
1805
1789
|
const functionType = this._evaluator.getTypeOfFunction(decl.node);
|
1806
|
-
if (
|
1790
|
+
if (functionType?.functionType === overloadType) {
|
1807
1791
|
return decl.node;
|
1808
1792
|
}
|
1809
1793
|
}
|
@@ -1811,7 +1795,6 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1811
1795
|
return undefined;
|
1812
1796
|
}
|
1813
1797
|
_isOverlappingOverload(functionType, prevOverload, partialOverlap) {
|
1814
|
-
var _a, _b, _c;
|
1815
1798
|
// According to precedent, the __get__ method is special-cased and is
|
1816
1799
|
// exempt from overlapping overload checks. It's not clear why this is
|
1817
1800
|
// the case, but for consistency with other type checkers, we'll honor
|
@@ -1824,14 +1807,14 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1824
1807
|
if (partialOverlap) {
|
1825
1808
|
flags |= 32 /* AssignTypeFlags.PartialOverloadOverlap */;
|
1826
1809
|
}
|
1827
|
-
const functionNode =
|
1810
|
+
const functionNode = functionType.shared.declaration?.node;
|
1828
1811
|
if (functionNode) {
|
1829
1812
|
const liveTypeVars = ParseTreeUtils.getTypeVarScopesForNode(functionNode);
|
1830
1813
|
functionType = (0, typeUtils_1.makeTypeVarsBound)(functionType, liveTypeVars);
|
1831
1814
|
}
|
1832
1815
|
// Use the parent node of the declaration in this case so we don't transform
|
1833
1816
|
// function-local type variables into bound type variables.
|
1834
|
-
const prevOverloadNode =
|
1817
|
+
const prevOverloadNode = prevOverload.shared.declaration?.node?.parent;
|
1835
1818
|
if (prevOverloadNode) {
|
1836
1819
|
const liveTypeVars = ParseTreeUtils.getTypeVarScopesForNode(prevOverloadNode);
|
1837
1820
|
prevOverload = (0, typeUtils_1.makeTypeVarsBound)(prevOverload, liveTypeVars);
|
@@ -1845,16 +1828,15 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1845
1828
|
// of the same arguments as the overload and return a type that is consistent
|
1846
1829
|
// with the overload's return type.
|
1847
1830
|
_validateOverloadImplementation(overload, implementation, diag) {
|
1848
|
-
var _a, _b, _c, _d, _e;
|
1849
1831
|
const constraints = new constraintTracker_1.ConstraintTracker();
|
1850
1832
|
let implBound = implementation;
|
1851
1833
|
let overloadBound = overload;
|
1852
|
-
const implNode =
|
1834
|
+
const implNode = implementation.shared.declaration?.node?.parent;
|
1853
1835
|
if (implNode) {
|
1854
1836
|
const liveScopeIds = ParseTreeUtils.getTypeVarScopesForNode(implNode);
|
1855
1837
|
implBound = (0, typeUtils_1.makeTypeVarsBound)(implementation, liveScopeIds);
|
1856
1838
|
}
|
1857
|
-
const overloadNode =
|
1839
|
+
const overloadNode = overload.shared.declaration?.node;
|
1858
1840
|
if (overloadNode) {
|
1859
1841
|
const liveScopeIds = ParseTreeUtils.getTypeVarScopesForNode(overloadNode);
|
1860
1842
|
overloadBound = (0, typeUtils_1.makeTypeVarsBound)(overload, liveScopeIds);
|
@@ -1862,8 +1844,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1862
1844
|
// First check the parameters to see if they are assignable.
|
1863
1845
|
let isConsistent = this._evaluator.assignType(overloadBound, implBound, diag, constraints, 64 /* AssignTypeFlags.SkipReturnTypeCheck */ | 2 /* AssignTypeFlags.Contravariant */ | 512 /* AssignTypeFlags.SkipSelfClsTypeCheck */);
|
1864
1846
|
// Now check the return types.
|
1865
|
-
const overloadReturnType = this._evaluator.solveAndApplyConstraints(
|
1866
|
-
const implReturnType = this._evaluator.solveAndApplyConstraints(
|
1847
|
+
const overloadReturnType = this._evaluator.solveAndApplyConstraints(types_1.FunctionType.getEffectiveReturnType(overloadBound) ?? this._evaluator.getInferredReturnType(overloadBound), constraints);
|
1848
|
+
const implReturnType = this._evaluator.solveAndApplyConstraints(types_1.FunctionType.getEffectiveReturnType(implBound) ?? this._evaluator.getInferredReturnType(implBound), constraints);
|
1867
1849
|
const returnDiag = new diagnostic_1.DiagnosticAddendum();
|
1868
1850
|
if (!(0, types_1.isNever)(overloadReturnType) &&
|
1869
1851
|
!this._evaluator.assignType(implReturnType, overloadReturnType, returnDiag.createAddendum(), constraints, 0 /* AssignTypeFlags.Default */)) {
|
@@ -1871,7 +1853,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1871
1853
|
sourceType: this._evaluator.printType(overloadReturnType),
|
1872
1854
|
destType: this._evaluator.printType(implReturnType),
|
1873
1855
|
}));
|
1874
|
-
diag
|
1856
|
+
diag?.addAddendum(returnDiag);
|
1875
1857
|
isConsistent = false;
|
1876
1858
|
}
|
1877
1859
|
return isConsistent;
|
@@ -2050,8 +2032,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2050
2032
|
});
|
2051
2033
|
}
|
2052
2034
|
_validateSymbolTables() {
|
2053
|
-
|
2054
|
-
const dependentFileInfo = (_a = this._dependentFiles) === null || _a === void 0 ? void 0 : _a.map((p) => AnalyzerNodeInfo.getFileInfo(p.parseTree));
|
2035
|
+
const dependentFileInfo = this._dependentFiles?.map((p) => AnalyzerNodeInfo.getFileInfo(p.parseTree));
|
2055
2036
|
for (const scopedNode of this._scopedNodes) {
|
2056
2037
|
const scope = AnalyzerNodeInfo.getScope(scopedNode);
|
2057
2038
|
if (scope) {
|
@@ -2072,7 +2053,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2072
2053
|
for (const paramList of this._typeParamLists) {
|
2073
2054
|
const typeParamScope = AnalyzerNodeInfo.getScope(paramList);
|
2074
2055
|
for (const param of paramList.d.params) {
|
2075
|
-
const symbol = typeParamScope
|
2056
|
+
const symbol = typeParamScope?.symbolTable.get(param.d.name.d.value);
|
2076
2057
|
if (!symbol) {
|
2077
2058
|
// This can happen if the code is unreachable.
|
2078
2059
|
return;
|
@@ -2162,7 +2143,6 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2162
2143
|
}
|
2163
2144
|
// Verify that all overload signatures are assignable to implementation signature.
|
2164
2145
|
types_1.OverloadedType.getOverloads(type).forEach((overload, index) => {
|
2165
|
-
var _a, _b, _c, _d;
|
2166
2146
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
2167
2147
|
if (implementation &&
|
2168
2148
|
(0, types_1.isFunction)(implementation) &&
|
@@ -2173,7 +2153,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2173
2153
|
index: index + 1,
|
2174
2154
|
}) + diag.getString(), implementation.shared.declaration.node.d.name);
|
2175
2155
|
if (diagnostic && overload.shared.declaration) {
|
2176
|
-
diagnostic.addRelatedInfo(localize_1.LocAddendum.overloadSignature(),
|
2156
|
+
diagnostic.addRelatedInfo(localize_1.LocAddendum.overloadSignature(), overload.shared.declaration?.uri ?? primaryDecl.uri, overload.shared.declaration?.range ?? primaryDecl.range);
|
2177
2157
|
}
|
2178
2158
|
}
|
2179
2159
|
}
|
@@ -2212,9 +2192,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2212
2192
|
return;
|
2213
2193
|
}
|
2214
2194
|
decls.forEach((decl) => {
|
2215
|
-
var _a;
|
2216
2195
|
if (decl !== finalImportDecl) {
|
2217
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.finalReassigned().format({ name }), (
|
2196
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.finalReassigned().format({ name }), (0, declarationUtils_1.getNameNodeForDeclaration)(decl) ?? decl.node);
|
2218
2197
|
}
|
2219
2198
|
});
|
2220
2199
|
}
|
@@ -2233,8 +2212,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2233
2212
|
}
|
2234
2213
|
const decls = symbol.getDeclarations();
|
2235
2214
|
decls.forEach((decl) => {
|
2236
|
-
|
2237
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.finalReassigned().format({ name }), (_a = (0, declarationUtils_1.getNameNodeForDeclaration)(decl)) !== null && _a !== void 0 ? _a : decl.node);
|
2215
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.finalReassigned().format({ name }), (0, declarationUtils_1.getNameNodeForDeclaration)(decl) ?? decl.node);
|
2238
2216
|
});
|
2239
2217
|
}
|
2240
2218
|
// If a variable is marked Final, it should receive only one assigned value.
|
@@ -2246,7 +2224,6 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2246
2224
|
let sawFinal = false;
|
2247
2225
|
let sawAssignment = false;
|
2248
2226
|
decls.forEach((decl) => {
|
2249
|
-
var _a;
|
2250
2227
|
if (this._evaluator.isFinalVariableDeclaration(decl)) {
|
2251
2228
|
if (sawFinal) {
|
2252
2229
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.finalRedeclaration().format({ name }), decl.node);
|
@@ -2264,7 +2241,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2264
2241
|
// the assignment is within an `__init__` method, so ignore class
|
2265
2242
|
// scopes here.
|
2266
2243
|
const classOrFunc = ParseTreeUtils.getEnclosingClassOrFunction(decl.node);
|
2267
|
-
if (
|
2244
|
+
if (classOrFunc?.nodeType === 31 /* ParseNodeType.Function */) {
|
2268
2245
|
exemptAssignment = true;
|
2269
2246
|
}
|
2270
2247
|
}
|
@@ -2279,7 +2256,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2279
2256
|
reportRedeclaration = true;
|
2280
2257
|
}
|
2281
2258
|
if (reportRedeclaration) {
|
2282
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.finalReassigned().format({ name }), (
|
2259
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.finalReassigned().format({ name }), (0, declarationUtils_1.getNameNodeForDeclaration)(decl) ?? decl.node);
|
2283
2260
|
}
|
2284
2261
|
});
|
2285
2262
|
// If it's not a stub file, an assignment must be provided.
|
@@ -2326,7 +2303,6 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2326
2303
|
}
|
2327
2304
|
}
|
2328
2305
|
_reportIncompatibleDeclarations(name, symbol) {
|
2329
|
-
var _a, _b, _c, _d;
|
2330
2306
|
// If there's one or more declaration with a declared type,
|
2331
2307
|
// all other declarations should match. The only exception is
|
2332
2308
|
// for functions that have an overload.
|
@@ -2433,13 +2409,13 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2433
2409
|
}
|
2434
2410
|
}
|
2435
2411
|
else if (otherDecl.type === 5 /* DeclarationType.Function */) {
|
2436
|
-
const primaryType =
|
2412
|
+
const primaryType = this._evaluator.getTypeForDeclaration(primaryDecl)?.type;
|
2437
2413
|
let duplicateIsOk = false;
|
2438
2414
|
// If the return type has not yet been inferred, do so now.
|
2439
2415
|
if (primaryType && (0, types_1.isFunction)(primaryType)) {
|
2440
2416
|
this._evaluator.getInferredReturnType(primaryType);
|
2441
2417
|
}
|
2442
|
-
const otherType =
|
2418
|
+
const otherType = this._evaluator.getTypeForDeclaration(otherDecl)?.type;
|
2443
2419
|
const suite1 = ParseTreeUtils.getEnclosingSuite(primaryDecl.node);
|
2444
2420
|
const suite2 = ParseTreeUtils.getEnclosingSuite(otherDecl.node);
|
2445
2421
|
// Allow same-signature overrides in cases where the declarations
|
@@ -2483,12 +2459,12 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2483
2459
|
}
|
2484
2460
|
}
|
2485
2461
|
else if (otherDecl.type === 1 /* DeclarationType.Variable */) {
|
2486
|
-
const primaryType =
|
2462
|
+
const primaryType = this._evaluator.getTypeForDeclaration(primaryDecl)?.type;
|
2487
2463
|
if (otherDecl.typeAnnotationNode) {
|
2488
2464
|
if (otherDecl.node.nodeType === 38 /* ParseNodeType.Name */) {
|
2489
2465
|
let duplicateIsOk = false;
|
2490
2466
|
// It's OK if they both have the same declared type.
|
2491
|
-
const otherType =
|
2467
|
+
const otherType = this._evaluator.getTypeForDeclaration(otherDecl)?.type;
|
2492
2468
|
if (primaryType && otherType && (0, types_1.isTypeSame)(primaryType, otherType)) {
|
2493
2469
|
duplicateIsOk = true;
|
2494
2470
|
}
|
@@ -2534,7 +2510,6 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2534
2510
|
});
|
2535
2511
|
}
|
2536
2512
|
_conditionallyReportUnusedDeclaration(decl, isPrivate) {
|
2537
|
-
var _a;
|
2538
2513
|
let diagnosticLevel;
|
2539
2514
|
let nameNode;
|
2540
2515
|
let message;
|
@@ -2569,7 +2544,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2569
2544
|
const importFrom = decl.node.parent;
|
2570
2545
|
// For statements of the form "from y import x as x", don't mark "x" as
|
2571
2546
|
// unaccessed because it's assumed to be re-exported.
|
2572
|
-
const isReexport =
|
2547
|
+
const isReexport = decl.node.d.alias?.d.value === decl.node.d.name.d.value;
|
2573
2548
|
// If this is a __future__ import, it's OK for the import symbol to be unaccessed.
|
2574
2549
|
const isFuture = importFrom.d.module.d.nameParts.length === 1 &&
|
2575
2550
|
importFrom.d.module.d.nameParts[0].d.value === '__future__';
|
@@ -2793,10 +2768,9 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2793
2768
|
_isTypeSupportedTypeForIsInstance(type, isInstanceCheck, diag) {
|
2794
2769
|
let isSupported = true;
|
2795
2770
|
(0, typeUtils_1.doForEachSubtype)(type, (subtype) => {
|
2796
|
-
var _a, _b;
|
2797
2771
|
subtype = this._evaluator.makeTopLevelTypeVarsConcrete(subtype);
|
2798
2772
|
subtype = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(subtype);
|
2799
|
-
if (
|
2773
|
+
if (subtype.props?.specialForm && types_1.ClassType.isBuiltIn(subtype.props.specialForm, 'TypeAliasType')) {
|
2800
2774
|
diag.addMessage(localize_1.LocAddendum.typeAliasInstanceCheck());
|
2801
2775
|
isSupported = false;
|
2802
2776
|
return;
|
@@ -2846,7 +2820,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2846
2820
|
diag.addMessage(localize_1.LocAddendum.newTypeClassNotAllowed());
|
2847
2821
|
isSupported = false;
|
2848
2822
|
}
|
2849
|
-
else if (
|
2823
|
+
else if (subtype.props?.specialForm &&
|
2850
2824
|
(0, types_1.isClassInstance)(subtype.props.specialForm) &&
|
2851
2825
|
types_1.ClassType.isBuiltIn(subtype.props.specialForm, 'Annotated')) {
|
2852
2826
|
diag.addMessage(localize_1.LocAddendum.annotatedNotAllowed());
|
@@ -2927,7 +2901,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2927
2901
|
}
|
2928
2902
|
}
|
2929
2903
|
_reportDeprecatedUseForOperation(node, typeResult) {
|
2930
|
-
const deprecationInfo = typeResult
|
2904
|
+
const deprecationInfo = typeResult?.magicMethodDeprecationInfo;
|
2931
2905
|
if (!deprecationInfo) {
|
2932
2906
|
return;
|
2933
2907
|
}
|
@@ -2937,7 +2911,6 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2937
2911
|
}), deprecationInfo.deprecatedMessage);
|
2938
2912
|
}
|
2939
2913
|
_reportDeprecatedUseForType(node, type, isImportFromTyping = false) {
|
2940
|
-
var _a, _b, _c;
|
2941
2914
|
if (!type) {
|
2942
2915
|
return;
|
2943
2916
|
}
|
@@ -3044,10 +3017,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3044
3017
|
this._reportDeprecatedDiagnostic(node, errorMessage, deprecatedMessage);
|
3045
3018
|
}
|
3046
3019
|
if (this._fileInfo.diagnosticRuleSet.deprecateTypingAliases) {
|
3047
|
-
const deprecatedForm =
|
3020
|
+
const deprecatedForm = deprecatedSymbols_1.deprecatedAliases.get(node.d.value) ?? deprecatedSymbols_1.deprecatedSpecialForms.get(node.d.value);
|
3048
3021
|
if (deprecatedForm) {
|
3049
3022
|
if (((0, types_1.isInstantiableClass)(type) && type.shared.fullName === deprecatedForm.fullName) ||
|
3050
|
-
|
3023
|
+
type.props?.typeAliasInfo?.shared.fullName === deprecatedForm.fullName) {
|
3051
3024
|
if (pythonVersion_1.PythonVersion.isGreaterOrEqualTo(this._fileInfo.executionEnvironment.pythonVersion, deprecatedForm.version)) {
|
3052
3025
|
if (!deprecatedForm.typingImportOnly || isImportFromTyping) {
|
3053
3026
|
this._reportDeprecatedDiagnostic(node, localize_1.LocMessage.deprecatedType().format({
|
@@ -3122,17 +3095,16 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3122
3095
|
}
|
3123
3096
|
}
|
3124
3097
|
_conditionallyReportShadowedImport(node) {
|
3125
|
-
var _a, _b;
|
3126
3098
|
if (this._fileInfo.diagnosticRuleSet.reportShadowedImports === 'none') {
|
3127
3099
|
return;
|
3128
3100
|
}
|
3129
3101
|
// Skip this check for relative imports.
|
3130
3102
|
const nodeModule = node.nodeType === 26 /* ParseNodeType.ImportFromAs */
|
3131
|
-
?
|
3132
|
-
?
|
3103
|
+
? node.parent?.nodeType === 25 /* ParseNodeType.ImportFrom */
|
3104
|
+
? node.parent?.d.module
|
3133
3105
|
: undefined
|
3134
3106
|
: node.d.module;
|
3135
|
-
if (nodeModule
|
3107
|
+
if (nodeModule?.d.leadingDots) {
|
3136
3108
|
return;
|
3137
3109
|
}
|
3138
3110
|
// Otherwise use the name to determine if a match for a stdlib module.
|
@@ -3175,7 +3147,6 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3175
3147
|
}
|
3176
3148
|
}
|
3177
3149
|
_conditionallyReportPrivateUsage(node) {
|
3178
|
-
var _a, _b, _c;
|
3179
3150
|
if (this._fileInfo.diagnosticRuleSet.reportPrivateUsage === 'none') {
|
3180
3151
|
return;
|
3181
3152
|
}
|
@@ -3184,7 +3155,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3184
3155
|
return;
|
3185
3156
|
}
|
3186
3157
|
// Ignore privates in named arguments.
|
3187
|
-
if (
|
3158
|
+
if (node.parent?.nodeType === 1 /* ParseNodeType.Argument */ && node.parent.d.name === node) {
|
3188
3159
|
return;
|
3189
3160
|
}
|
3190
3161
|
const nameValue = node.d.value;
|
@@ -3198,8 +3169,9 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3198
3169
|
// Get the declarations for this name node, but filter out
|
3199
3170
|
// any variable declarations that are bound using nonlocal
|
3200
3171
|
// or global explicit bindings.
|
3201
|
-
const declarations =
|
3202
|
-
.getDeclInfoForNameNode(node)
|
3172
|
+
const declarations = this._evaluator
|
3173
|
+
.getDeclInfoForNameNode(node)
|
3174
|
+
?.decls?.filter((decl) => decl.type !== 1 /* DeclarationType.Variable */ || !decl.isExplicitBinding);
|
3203
3175
|
let primaryDeclaration = declarations && declarations.length > 0 ? declarations[declarations.length - 1] : undefined;
|
3204
3176
|
if (!primaryDeclaration || primaryDeclaration.node === node) {
|
3205
3177
|
return;
|
@@ -3307,7 +3279,6 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3307
3279
|
});
|
3308
3280
|
}
|
3309
3281
|
_validateTypeGuardFunction(node, functionType, isMethod) {
|
3310
|
-
var _a;
|
3311
3282
|
const returnType = functionType.shared.declaredReturnType;
|
3312
3283
|
if (!returnType) {
|
3313
3284
|
return;
|
@@ -3345,7 +3316,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3345
3316
|
const paramType = (0, typeUtils_1.makeTypeVarsBound)(types_1.FunctionType.getParamType(functionType, paramIndex), scopeIds);
|
3346
3317
|
// Verify that the typeGuardType is a narrower type than the paramType.
|
3347
3318
|
if (!this._evaluator.assignType(paramType, typeGuardType)) {
|
3348
|
-
const returnAnnotation = node.d.returnAnnotation ||
|
3319
|
+
const returnAnnotation = node.d.returnAnnotation || node.d.funcAnnotationComment?.d.returnAnnotation;
|
3349
3320
|
if (returnAnnotation) {
|
3350
3321
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeIsReturnType().format({
|
3351
3322
|
type: this._evaluator.printType(paramType),
|
@@ -3356,11 +3327,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3356
3327
|
}
|
3357
3328
|
}
|
3358
3329
|
_validateDunderSignatures(node, functionType, isMethod) {
|
3359
|
-
var _a;
|
3360
3330
|
const functionName = functionType.shared.name;
|
3361
3331
|
// Is this an '__init__' method? Verify that it returns None.
|
3362
3332
|
if (isMethod && functionName === '__init__') {
|
3363
|
-
const returnAnnotation = node.d.returnAnnotation ||
|
3333
|
+
const returnAnnotation = node.d.returnAnnotation || node.d.funcAnnotationComment?.d.returnAnnotation;
|
3364
3334
|
const declaredReturnType = functionType.shared.declaredReturnType;
|
3365
3335
|
if (returnAnnotation && declaredReturnType) {
|
3366
3336
|
if (!(0, typeUtils_1.isNoneInstance)(declaredReturnType) && !(0, types_1.isNever)(declaredReturnType)) {
|
@@ -3378,13 +3348,12 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3378
3348
|
}
|
3379
3349
|
}
|
3380
3350
|
_validateFunctionReturn(node, functionType) {
|
3381
|
-
var _a;
|
3382
3351
|
// Stub files are allowed not to return an actual value,
|
3383
3352
|
// so skip this if it's a stub file.
|
3384
3353
|
if (this._fileInfo.isStubFile) {
|
3385
3354
|
return;
|
3386
3355
|
}
|
3387
|
-
const returnAnnotation = node.d.returnAnnotation ||
|
3356
|
+
const returnAnnotation = node.d.returnAnnotation || node.d.funcAnnotationComment?.d.returnAnnotation;
|
3388
3357
|
if (returnAnnotation) {
|
3389
3358
|
const functionNeverReturns = !this._evaluator.isAfterNodeReachable(node);
|
3390
3359
|
const implicitlyReturnsNone = this._evaluator.isAfterNodeReachable(node.d.suite);
|
@@ -3426,7 +3395,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3426
3395
|
if (!isEmptySuite) {
|
3427
3396
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportReturnType, localize_1.LocMessage.returnMissing().format({
|
3428
3397
|
returnType: this._evaluator.printType(declaredReturnType),
|
3429
|
-
}) +
|
3398
|
+
}) + diagAddendum?.getString(), returnAnnotation);
|
3430
3399
|
}
|
3431
3400
|
}
|
3432
3401
|
}
|
@@ -3503,7 +3472,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3503
3472
|
let newMemberTypeResult = (0, constructors_1.getBoundNewMethod)(this._evaluator, node.d.name, classType,
|
3504
3473
|
/* diag */ undefined, 4 /* MemberAccessFlags.SkipObjectBaseClass */);
|
3505
3474
|
// If this __new__ comes from a built-in class like Enum, we'll ignore it.
|
3506
|
-
if (newMemberTypeResult
|
3475
|
+
if (newMemberTypeResult?.classType) {
|
3507
3476
|
if ((0, types_1.isClass)(newMemberTypeResult.classType) && types_1.ClassType.isBuiltIn(newMemberTypeResult.classType)) {
|
3508
3477
|
newMemberTypeResult = undefined;
|
3509
3478
|
}
|
@@ -3511,13 +3480,12 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3511
3480
|
let initMemberTypeResult = (0, constructors_1.getBoundInitMethod)(this._evaluator, node.d.name, types_1.ClassType.cloneAsInstance(classType),
|
3512
3481
|
/* diag */ undefined, 4 /* MemberAccessFlags.SkipObjectBaseClass */);
|
3513
3482
|
// If this __init__ comes from a built-in class like Enum, we'll ignore it.
|
3514
|
-
if (initMemberTypeResult
|
3483
|
+
if (initMemberTypeResult?.classType) {
|
3515
3484
|
if ((0, types_1.isClass)(initMemberTypeResult.classType) && types_1.ClassType.isBuiltIn(initMemberTypeResult.classType)) {
|
3516
3485
|
initMemberTypeResult = undefined;
|
3517
3486
|
}
|
3518
3487
|
}
|
3519
3488
|
types_1.ClassType.getSymbolTable(classType).forEach((symbol, name) => {
|
3520
|
-
var _a;
|
3521
3489
|
// Determine whether this is an enum member. We ignore the presence
|
3522
3490
|
// of an annotation in this case because the runtime does. From a
|
3523
3491
|
// type checking perspective, if the runtime treats the assignment
|
@@ -3556,7 +3524,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3556
3524
|
const declNode = decls[0].node;
|
3557
3525
|
const assignedValueType = symbolType.priv.literalValue.itemType;
|
3558
3526
|
const assignmentNode = ParseTreeUtils.getParentNodeOfType(declNode, 3 /* ParseNodeType.Assignment */);
|
3559
|
-
const errorNode =
|
3527
|
+
const errorNode = assignmentNode?.d.rightExpr ?? declNode;
|
3560
3528
|
// Validate the __new__ and __init__ methods if present.
|
3561
3529
|
if (newMemberTypeResult || initMemberTypeResult) {
|
3562
3530
|
if (!(0, types_1.isAnyOrUnknown)(assignedValueType)) {
|
@@ -3647,15 +3615,14 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3647
3615
|
// Verify that the parameter types match.
|
3648
3616
|
let paramIndex = 1;
|
3649
3617
|
initOnlySymbolMap.forEach((symbol, fieldName) => {
|
3650
|
-
var _a, _b;
|
3651
3618
|
if (paramIndex >= paramListDetails.params.length) {
|
3652
3619
|
return;
|
3653
3620
|
}
|
3654
3621
|
const param = paramListDetails.params[paramIndex].param;
|
3655
|
-
const paramNode = postInitNode.d.params.find((node) =>
|
3656
|
-
const annotationNode =
|
3622
|
+
const paramNode = postInitNode.d.params.find((node) => node.d.name?.d.value === param.name);
|
3623
|
+
const annotationNode = paramNode?.d.annotation ?? paramNode?.d.annotationComment;
|
3657
3624
|
if (types_1.FunctionParam.isTypeDeclared(param) && annotationNode) {
|
3658
|
-
const fieldType =
|
3625
|
+
const fieldType = this._evaluator.getDeclaredTypeOfSymbol(symbol)?.type;
|
3659
3626
|
const paramType = types_1.FunctionType.getParamType(postInitType, paramListDetails.params[paramIndex].index);
|
3660
3627
|
const assignTypeDiag = new diagnostic_1.DiagnosticAddendum();
|
3661
3628
|
if (fieldType && !this._evaluator.assignType(paramType, fieldType, assignTypeDiag)) {
|
@@ -3746,7 +3713,6 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3746
3713
|
// If the symbol is assigned (or at least declared) within the
|
3747
3714
|
// class body or within the __init__ method, it can be ignored.
|
3748
3715
|
if (decls.find((decl) => {
|
3749
|
-
var _a, _b, _c;
|
3750
3716
|
const containingClass = ParseTreeUtils.getEnclosingClassOrFunction(decl.node);
|
3751
3717
|
if (!containingClass) {
|
3752
3718
|
return true;
|
@@ -3754,11 +3720,11 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3754
3720
|
if (containingClass.nodeType === 10 /* ParseNodeType.Class */) {
|
3755
3721
|
// If this is part of an assignment statement, assume it has been
|
3756
3722
|
// initialized as a class variable.
|
3757
|
-
if (
|
3723
|
+
if (decl.node.parent?.nodeType === 3 /* ParseNodeType.Assignment */) {
|
3758
3724
|
return true;
|
3759
3725
|
}
|
3760
|
-
if (
|
3761
|
-
|
3726
|
+
if (decl.node.parent?.nodeType === 54 /* ParseNodeType.TypeAnnotation */ &&
|
3727
|
+
decl.node.parent.parent?.nodeType === 3 /* ParseNodeType.Assignment */) {
|
3762
3728
|
return true;
|
3763
3729
|
}
|
3764
3730
|
// If this is part of a dataclass, a class handled by a dataclass_transform,
|
@@ -3802,7 +3768,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3802
3768
|
}
|
3803
3769
|
// Dataclass fields are typically exempted from this check because
|
3804
3770
|
// they have synthesized __init__ methods that initialize these variables.
|
3805
|
-
const dcEntry = dataClassEntries
|
3771
|
+
const dcEntry = dataClassEntries?.find((entry) => entry.name === name);
|
3806
3772
|
if (dcEntry) {
|
3807
3773
|
if (dcEntry.includeInInit) {
|
3808
3774
|
return;
|
@@ -4140,7 +4106,6 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4140
4106
|
}
|
4141
4107
|
}
|
4142
4108
|
_validateMultipleInheritanceOverride(overriddenClassAndSymbol, overrideClassAndSymbol, childClassType, memberName, errorNode) {
|
4143
|
-
var _a, _b, _c, _d;
|
4144
4109
|
if (!(0, types_1.isClass)(overriddenClassAndSymbol.classType) || !(0, types_1.isClass)(overrideClassAndSymbol.classType)) {
|
4145
4110
|
return;
|
4146
4111
|
}
|
@@ -4210,7 +4175,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4210
4175
|
// rule is disabled.
|
4211
4176
|
if (this._fileInfo.diagnosticRuleSet.reportIncompatibleVariableOverride !== 'none') {
|
4212
4177
|
const primaryDecl = (0, symbolUtils_1.getLastTypedDeclarationForSymbol)(overriddenClassAndSymbol.symbol);
|
4213
|
-
let isInvariant =
|
4178
|
+
let isInvariant = primaryDecl?.type === 1 /* DeclarationType.Variable */ && !primaryDecl.isFinal;
|
4214
4179
|
// If the entry is a member of a frozen dataclass, it is immutable,
|
4215
4180
|
// so it does not need to be invariant.
|
4216
4181
|
if (types_1.ClassType.isDataClassFrozen(overriddenClassAndSymbol.classType) &&
|
@@ -4223,17 +4188,21 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4223
4188
|
let overriddenTDEntry;
|
4224
4189
|
if (overriddenClassAndSymbol.classType.shared.typedDictEntries) {
|
4225
4190
|
overriddenTDEntry =
|
4226
|
-
|
4227
|
-
|
4191
|
+
overriddenClassAndSymbol.classType.shared.typedDictEntries.knownItems.get(memberName) ??
|
4192
|
+
overriddenClassAndSymbol.classType.shared.typedDictEntries.extraItems ??
|
4193
|
+
(0, typedDicts_1.getEffectiveExtraItemsEntryType)(this._evaluator, overriddenClassAndSymbol.classType);
|
4194
|
+
if (overriddenTDEntry?.isReadOnly) {
|
4228
4195
|
isInvariant = false;
|
4229
4196
|
}
|
4230
4197
|
}
|
4231
4198
|
let overrideTDEntry;
|
4232
4199
|
if (overrideClassAndSymbol.classType.shared.typedDictEntries) {
|
4233
4200
|
overrideTDEntry =
|
4234
|
-
|
4201
|
+
overrideClassAndSymbol.classType.shared.typedDictEntries.knownItems.get(memberName) ??
|
4202
|
+
overrideClassAndSymbol.classType.shared.typedDictEntries.extraItems ??
|
4203
|
+
(0, typedDicts_1.getEffectiveExtraItemsEntryType)(this._evaluator, overrideClassAndSymbol.classType);
|
4235
4204
|
}
|
4236
|
-
if (!this._evaluator.assignType(overriddenType, childOverrideType
|
4205
|
+
if (!this._evaluator.assignType(overriddenType, childOverrideType ?? overrideType,
|
4237
4206
|
/* diag */ undefined,
|
4238
4207
|
/* constraints */ undefined, isInvariant ? 1 /* AssignTypeFlags.Invariant */ : 0 /* AssignTypeFlags.Default */)) {
|
4239
4208
|
diag = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompatibleVariableOverride, localize_1.LocMessage.baseClassVariableTypeIncompatible().format({
|
@@ -4283,9 +4252,9 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4283
4252
|
}
|
4284
4253
|
_validateMultipleInheritancePropertyOverride(overriddenClassType, overrideClassType, overriddenSymbolType, overrideSymbolType, overrideSymbol, memberName, errorNode) {
|
4285
4254
|
const propMethodInfo = [
|
4286
|
-
['fget', (c) =>
|
4287
|
-
['fset', (c) =>
|
4288
|
-
['fdel', (c) =>
|
4255
|
+
['fget', (c) => c.priv.fgetInfo?.methodType],
|
4256
|
+
['fset', (c) => c.priv.fsetInfo?.methodType],
|
4257
|
+
['fdel', (c) => c.priv.fdelInfo?.methodType],
|
4289
4258
|
];
|
4290
4259
|
propMethodInfo.forEach((info) => {
|
4291
4260
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
@@ -4367,12 +4336,11 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4367
4336
|
return;
|
4368
4337
|
}
|
4369
4338
|
overloads.forEach((overload) => {
|
4370
|
-
var _a;
|
4371
4339
|
const decl = overload.shared.declaration;
|
4372
4340
|
if (types_1.FunctionType.isAbstractMethod(overload) && decl) {
|
4373
4341
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInconsistentOverload, localize_1.LocMessage.overloadAbstractImplMismatch().format({
|
4374
4342
|
name: overload.shared.name,
|
4375
|
-
}), (
|
4343
|
+
}), (0, declarationUtils_1.getNameNodeForDeclaration)(decl) ?? decl.node);
|
4376
4344
|
}
|
4377
4345
|
});
|
4378
4346
|
return;
|
@@ -4384,11 +4352,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4384
4352
|
// abstract or not abstract.
|
4385
4353
|
const isFirstOverloadAbstract = types_1.FunctionType.isAbstractMethod(overloads[0]);
|
4386
4354
|
overloads.slice(1).forEach((overload, index) => {
|
4387
|
-
var _a;
|
4388
4355
|
if (types_1.FunctionType.isAbstractMethod(overload) !== isFirstOverloadAbstract && overload.shared.declaration) {
|
4389
4356
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInconsistentOverload, localize_1.LocMessage.overloadAbstractMismatch().format({
|
4390
4357
|
name: overload.shared.name,
|
4391
|
-
}), (
|
4358
|
+
}), (0, declarationUtils_1.getNameNodeForDeclaration)(overload.shared.declaration) ?? overload.shared.declaration.node);
|
4392
4359
|
}
|
4393
4360
|
});
|
4394
4361
|
}
|
@@ -4400,11 +4367,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4400
4367
|
// implementation is not, report an error.
|
4401
4368
|
if (!types_1.FunctionType.isFinal(implementation)) {
|
4402
4369
|
overloads.forEach((overload) => {
|
4403
|
-
|
4404
|
-
if (types_1.FunctionType.isFinal(overload) && ((_a = overload.shared.declaration) === null || _a === void 0 ? void 0 : _a.node)) {
|
4370
|
+
if (types_1.FunctionType.isFinal(overload) && overload.shared.declaration?.node) {
|
4405
4371
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInconsistentOverload, localize_1.LocMessage.overloadFinalInconsistencyImpl().format({
|
4406
4372
|
name: overload.shared.name,
|
4407
|
-
}), (
|
4373
|
+
}), (0, declarationUtils_1.getNameNodeForDeclaration)(overload.shared.declaration) ?? overload.shared.declaration.node);
|
4408
4374
|
}
|
4409
4375
|
});
|
4410
4376
|
}
|
@@ -4412,12 +4378,11 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4412
4378
|
}
|
4413
4379
|
if (overloads.length > 0 && !types_1.FunctionType.isFinal(overloads[0])) {
|
4414
4380
|
overloads.slice(1).forEach((overload, index) => {
|
4415
|
-
|
4416
|
-
if (types_1.FunctionType.isFinal(overload) && ((_a = overload.shared.declaration) === null || _a === void 0 ? void 0 : _a.node)) {
|
4381
|
+
if (types_1.FunctionType.isFinal(overload) && overload.shared.declaration?.node) {
|
4417
4382
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInconsistentOverload, localize_1.LocMessage.overloadFinalInconsistencyNoImpl().format({
|
4418
4383
|
name: overload.shared.name,
|
4419
4384
|
index: index + 2,
|
4420
|
-
}), (
|
4385
|
+
}), (0, declarationUtils_1.getNameNodeForDeclaration)(overload.shared.declaration) ?? overload.shared.declaration.node);
|
4421
4386
|
}
|
4422
4387
|
});
|
4423
4388
|
}
|
@@ -4538,7 +4503,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4538
4503
|
if (!baseClassAndSymbol) {
|
4539
4504
|
continue;
|
4540
4505
|
}
|
4541
|
-
firstOverride = firstOverride
|
4506
|
+
firstOverride = firstOverride ?? baseClassAndSymbol;
|
4542
4507
|
this._validateBaseClassOverride(baseClassAndSymbol, symbol, validateType ? typeOfSymbol : types_1.AnyType.create(), classType, name);
|
4543
4508
|
}
|
4544
4509
|
if (!firstOverride) {
|
@@ -4571,7 +4536,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4571
4536
|
overrideFunction = overrideType.priv.fgetInfo.methodType;
|
4572
4537
|
}
|
4573
4538
|
}
|
4574
|
-
if (!
|
4539
|
+
if (!overrideFunction?.shared.declaration || types_1.FunctionType.isOverridden(overrideFunction)) {
|
4575
4540
|
return;
|
4576
4541
|
}
|
4577
4542
|
// Constructors are exempt.
|
@@ -4617,7 +4582,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4617
4582
|
overrideFunction = overrideType.priv.fgetInfo.methodType;
|
4618
4583
|
}
|
4619
4584
|
}
|
4620
|
-
if (!
|
4585
|
+
if (!overrideFunction?.shared.declaration || !types_1.FunctionType.isOverridden(overrideFunction)) {
|
4621
4586
|
return;
|
4622
4587
|
}
|
4623
4588
|
// If the declaration for the override function is not the same as the
|
@@ -4629,7 +4594,6 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4629
4594
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.overriddenMethodNotFound().format({ name: funcNode.d.name.d.value }), funcNode.d.name);
|
4630
4595
|
}
|
4631
4596
|
_validateBaseClassOverride(baseClassAndSymbol, overrideSymbol, overrideType, childClassType, memberName) {
|
4632
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
4633
4597
|
if (!(0, types_1.isInstantiableClass)(baseClassAndSymbol.classType)) {
|
4634
4598
|
return;
|
4635
4599
|
}
|
@@ -4705,7 +4669,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4705
4669
|
const diag = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompatibleMethodOverride, localize_1.LocMessage.incompatibleMethodOverride().format({
|
4706
4670
|
name: memberName,
|
4707
4671
|
className: baseClass.shared.name,
|
4708
|
-
}) + diagAddendum.getString(), (
|
4672
|
+
}) + diagAddendum.getString(), (0, declarationUtils_1.getNameNodeForDeclaration)(decl) ?? decl.node);
|
4709
4673
|
const origDecl = (0, symbolUtils_1.getLastTypedDeclarationForSymbol)(baseClassAndSymbol.symbol);
|
4710
4674
|
if (diag && origDecl) {
|
4711
4675
|
diag.addRelatedInfo(localize_1.LocAddendum.overriddenMethod(), origDecl.uri, origDecl.range);
|
@@ -4726,7 +4690,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4726
4690
|
name: memberName,
|
4727
4691
|
className: baseClass.shared.name,
|
4728
4692
|
type: this._evaluator.printType(overrideType),
|
4729
|
-
}), (
|
4693
|
+
}), (0, declarationUtils_1.getNameNodeForDeclaration)(lastDecl) ?? lastDecl.node);
|
4730
4694
|
const origDecl = (0, symbolUtils_1.getLastTypedDeclarationForSymbol)(baseClassAndSymbol.symbol);
|
4731
4695
|
if (diag && origDecl) {
|
4732
4696
|
diag.addRelatedInfo(localize_1.LocAddendum.overriddenMethod(), origDecl.uri, origDecl.range);
|
@@ -4744,7 +4708,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4744
4708
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompatibleMethodOverride, localize_1.LocMessage.propertyOverridden().format({
|
4745
4709
|
name: memberName,
|
4746
4710
|
className: baseClass.shared.name,
|
4747
|
-
}), (
|
4711
|
+
}), (0, declarationUtils_1.getNameNodeForDeclaration)(lastDecl) ?? lastDecl.node);
|
4748
4712
|
}
|
4749
4713
|
}
|
4750
4714
|
else {
|
@@ -4761,7 +4725,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4761
4725
|
const primaryDecl = decls[0];
|
4762
4726
|
// Verify that the override type is assignable to (same or narrower than)
|
4763
4727
|
// the declared type of the base symbol.
|
4764
|
-
let isInvariant =
|
4728
|
+
let isInvariant = primaryDecl?.type === 1 /* DeclarationType.Variable */ && !primaryDecl.isFinal;
|
4765
4729
|
// If the entry is a member of a frozen dataclass, it is immutable,
|
4766
4730
|
// so it does not need to be invariant.
|
4767
4731
|
if (types_1.ClassType.isDataClassFrozen(baseClass) && baseClass.shared.dataClassEntries) {
|
@@ -4775,14 +4739,18 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4775
4739
|
if (!overrideSymbol.isIgnoredForProtocolMatch()) {
|
4776
4740
|
if (baseClass.shared.typedDictEntries) {
|
4777
4741
|
overriddenTDEntry =
|
4778
|
-
|
4779
|
-
|
4742
|
+
baseClass.shared.typedDictEntries.knownItems.get(memberName) ??
|
4743
|
+
baseClass.shared.typedDictEntries.extraItems ??
|
4744
|
+
(0, typedDicts_1.getEffectiveExtraItemsEntryType)(this._evaluator, baseClass);
|
4745
|
+
if (overriddenTDEntry?.isReadOnly) {
|
4780
4746
|
isInvariant = false;
|
4781
4747
|
}
|
4782
4748
|
}
|
4783
4749
|
if (childClassType.shared.typedDictEntries) {
|
4784
4750
|
overrideTDEntry =
|
4785
|
-
|
4751
|
+
childClassType.shared.typedDictEntries.knownItems.get(memberName) ??
|
4752
|
+
childClassType.shared.typedDictEntries.extraItems ??
|
4753
|
+
(0, typedDicts_1.getEffectiveExtraItemsEntryType)(this._evaluator, childClassType);
|
4786
4754
|
}
|
4787
4755
|
}
|
4788
4756
|
let diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
@@ -4799,7 +4767,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4799
4767
|
const diag = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompatibleVariableOverride, localize_1.LocMessage.symbolOverridden().format({
|
4800
4768
|
name: memberName,
|
4801
4769
|
className: baseClass.shared.name,
|
4802
|
-
}) + diagAddendum.getString(), (
|
4770
|
+
}) + diagAddendum.getString(), (0, declarationUtils_1.getNameNodeForDeclaration)(lastDecl) ?? lastDecl.node);
|
4803
4771
|
const origDecl = (0, symbolUtils_1.getLastTypedDeclarationForSymbol)(baseClassAndSymbol.symbol);
|
4804
4772
|
if (diag && origDecl) {
|
4805
4773
|
diag.addRelatedInfo(localize_1.LocAddendum.overriddenSymbol(), origDecl.uri, origDecl.range);
|
@@ -4820,14 +4788,14 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4820
4788
|
const message = overrideTDEntry.isRequired
|
4821
4789
|
? localize_1.LocMessage.typedDictFieldRequiredRedefinition
|
4822
4790
|
: localize_1.LocMessage.typedDictFieldNotRequiredRedefinition;
|
4823
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, message().format({ name: memberName }), (
|
4791
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, message().format({ name: memberName }), (0, declarationUtils_1.getNameNodeForDeclaration)(lastDecl) ?? lastDecl.node);
|
4824
4792
|
}
|
4825
4793
|
// Make sure that the derived class isn't marking a previously writable
|
4826
4794
|
// entry as read-only.
|
4827
4795
|
if (!overriddenTDEntry.isReadOnly && overrideTDEntry.isReadOnly) {
|
4828
4796
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typedDictFieldReadOnlyRedefinition().format({
|
4829
4797
|
name: memberName,
|
4830
|
-
}), (
|
4798
|
+
}), (0, declarationUtils_1.getNameNodeForDeclaration)(lastDecl) ?? lastDecl.node);
|
4831
4799
|
}
|
4832
4800
|
}
|
4833
4801
|
// Verify that there is not a Final mismatch.
|
@@ -4837,7 +4805,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4837
4805
|
const diag = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompatibleVariableOverride, localize_1.LocMessage.variableFinalOverride().format({
|
4838
4806
|
name: memberName,
|
4839
4807
|
className: baseClass.shared.name,
|
4840
|
-
}), (
|
4808
|
+
}), (0, declarationUtils_1.getNameNodeForDeclaration)(lastDecl) ?? lastDecl.node);
|
4841
4809
|
if (diag) {
|
4842
4810
|
diag.addRelatedInfo(localize_1.LocAddendum.overriddenSymbol(), overrideFinalVarDecl.uri, overrideFinalVarDecl.range);
|
4843
4811
|
}
|
@@ -4869,7 +4837,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4869
4837
|
const diag = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompatibleVariableOverride, unformattedMessage.format({
|
4870
4838
|
name: memberName,
|
4871
4839
|
className: baseClass.shared.name,
|
4872
|
-
}), (
|
4840
|
+
}), (0, declarationUtils_1.getNameNodeForDeclaration)(lastDecl) ?? lastDecl.node);
|
4873
4841
|
const origDecl = (0, symbolUtils_1.getLastTypedDeclarationForSymbol)(baseClassAndSymbol.symbol);
|
4874
4842
|
if (diag && origDecl) {
|
4875
4843
|
diag.addRelatedInfo(localize_1.LocAddendum.overriddenSymbol(), origDecl.uri, origDecl.range);
|
@@ -4881,12 +4849,11 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4881
4849
|
}
|
4882
4850
|
_validatePropertyOverride(baseClassType, childClassType, baseType, childType, overrideSymbol, memberName) {
|
4883
4851
|
const propMethodInfo = [
|
4884
|
-
['fget', (c) =>
|
4885
|
-
['fset', (c) =>
|
4886
|
-
['fdel', (c) =>
|
4852
|
+
['fget', (c) => c.priv.fgetInfo?.methodType],
|
4853
|
+
['fset', (c) => c.priv.fsetInfo?.methodType],
|
4854
|
+
['fdel', (c) => c.priv.fdelInfo?.methodType],
|
4887
4855
|
];
|
4888
4856
|
propMethodInfo.forEach((info) => {
|
4889
|
-
var _a, _b;
|
4890
4857
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
4891
4858
|
const [methodName, methodAccessor] = info;
|
4892
4859
|
const baseClassPropMethod = methodAccessor(baseType);
|
@@ -4908,7 +4875,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4908
4875
|
const diag = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompatibleMethodOverride, localize_1.LocMessage.propertyOverridden().format({
|
4909
4876
|
name: memberName,
|
4910
4877
|
className: baseClassType.shared.name,
|
4911
|
-
}) + diagAddendum.getString(), (
|
4878
|
+
}) + diagAddendum.getString(), (0, declarationUtils_1.getNameNodeForDeclaration)(lastDecl) ?? lastDecl.node);
|
4912
4879
|
const origDecl = baseClassMethodType.shared.declaration;
|
4913
4880
|
if (diag && origDecl) {
|
4914
4881
|
diag.addRelatedInfo(localize_1.LocAddendum.overriddenMethod(), origDecl.uri, origDecl.range);
|
@@ -4944,7 +4911,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4944
4911
|
return;
|
4945
4912
|
}
|
4946
4913
|
const lastSymbolDecl = symbolDecls[symbolDecls.length - 1];
|
4947
|
-
diagLocation = (
|
4914
|
+
diagLocation = (0, declarationUtils_1.getNameNodeForDeclaration)(lastSymbolDecl) ?? lastSymbolDecl.node;
|
4948
4915
|
}
|
4949
4916
|
const diag = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompatibleMethodOverride, localize_1.LocMessage.propertyOverridden().format({
|
4950
4917
|
name: memberName,
|
@@ -5104,7 +5071,6 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5104
5071
|
// Validates that the annotated type of a "self" or "cls" parameter is
|
5105
5072
|
// compatible with the type of the class that contains it.
|
5106
5073
|
_validateClsSelfParamType(node, functionType, classType, isCls) {
|
5107
|
-
var _a;
|
5108
5074
|
if (node.d.params.length < 1 || functionType.shared.parameters.length < 1) {
|
5109
5075
|
return;
|
5110
5076
|
}
|
@@ -5112,7 +5078,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5112
5078
|
// the type will be inferred.d.typeAnnotation
|
5113
5079
|
const paramInfo = functionType.shared.parameters[0];
|
5114
5080
|
const paramType = types_1.FunctionType.getParamType(functionType, 0);
|
5115
|
-
const paramAnnotation =
|
5081
|
+
const paramAnnotation = node.d.params[0].d.annotation ?? node.d.params[0].d.annotationComment;
|
5116
5082
|
if (!paramAnnotation || !paramInfo.name) {
|
5117
5083
|
return;
|
5118
5084
|
}
|
@@ -5121,11 +5087,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5121
5087
|
// according to the typing spec.
|
5122
5088
|
if (functionType.shared.name === '__init__' && functionType.shared.methodClass) {
|
5123
5089
|
const typeVars = (0, typeUtils_1.getTypeVarArgsRecursive)(paramType);
|
5124
|
-
if (typeVars.some((typeVar) =>
|
5125
|
-
|
5126
|
-
return typeVar.priv.scopeId === ((_a = functionType.shared.methodClass) === null || _a === void 0 ? void 0 : _a.shared.typeVarScopeId) &&
|
5127
|
-
!types_1.TypeVarType.isSelf(typeVar);
|
5128
|
-
})) {
|
5090
|
+
if (typeVars.some((typeVar) => typeVar.priv.scopeId === functionType.shared.methodClass?.shared.typeVarScopeId &&
|
5091
|
+
!types_1.TypeVarType.isSelf(typeVar))) {
|
5129
5092
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeVarUse, localize_1.LocMessage.initMethodSelfParamTypeVar(), paramAnnotation);
|
5130
5093
|
}
|
5131
5094
|
}
|
@@ -5177,7 +5140,6 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5177
5140
|
// Determines whether a yield or yield from node is compatible with the
|
5178
5141
|
// return type annotation of the containing function.
|
5179
5142
|
_validateYieldType(node, yieldType, expectedDiagAddendum, sendType) {
|
5180
|
-
var _a, _b, _c, _d;
|
5181
5143
|
const enclosingFunctionNode = ParseTreeUtils.getEnclosingFunction(node);
|
5182
5144
|
if (!enclosingFunctionNode || !enclosingFunctionNode.d.returnAnnotation) {
|
5183
5145
|
return;
|
@@ -5213,7 +5175,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5213
5175
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.noReturnContainsYield(), node);
|
5214
5176
|
return;
|
5215
5177
|
}
|
5216
|
-
const generatorTypeArgs = [yieldType, sendType
|
5178
|
+
const generatorTypeArgs = [yieldType, sendType ?? types_1.UnknownType.create(), types_1.UnknownType.create()];
|
5217
5179
|
const specializedGenerator = types_1.ClassType.cloneAsInstance(types_1.ClassType.specialize(generatorType, generatorTypeArgs));
|
5218
5180
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
5219
5181
|
if (!this._evaluator.assignType(declaredReturnType, specializedGenerator, diagAddendum)) {
|
@@ -5221,7 +5183,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5221
5183
|
? localize_1.LocMessage.generatorAsyncReturnType()
|
5222
5184
|
: localize_1.LocMessage.generatorSyncReturnType();
|
5223
5185
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportReturnType, errorMessage.format({ yieldType: this._evaluator.printType(yieldType) }) +
|
5224
|
-
(
|
5186
|
+
(expectedDiagAddendum?.getString() ?? diagAddendum.getString()), node.d.expr ?? node, expectedDiagAddendum?.getEffectiveTextRange() ?? node.d.expr ?? node);
|
5225
5187
|
}
|
5226
5188
|
}
|
5227
5189
|
// Determines whether any of the except statements are unreachable because
|
@@ -5230,7 +5192,6 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5230
5192
|
let sawUnknownExceptionType = false;
|
5231
5193
|
const exceptionTypesSoFar = [];
|
5232
5194
|
node.d.exceptClauses.forEach((except) => {
|
5233
|
-
var _a, _b;
|
5234
5195
|
if (sawUnknownExceptionType || except.d.isExceptGroup || !except.d.typeExpr) {
|
5235
5196
|
return;
|
5236
5197
|
}
|
@@ -5249,10 +5210,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5249
5210
|
typesOfThisExcept.push(exceptionType);
|
5250
5211
|
}
|
5251
5212
|
else if ((0, types_1.isClassInstance)(exceptionType)) {
|
5252
|
-
const iterableType =
|
5213
|
+
const iterableType = this._evaluator.getTypeOfIterator({ type: exceptionType },
|
5253
5214
|
/* isAsync */ false,
|
5254
5215
|
/* errorNode */ except.d.typeExpr,
|
5255
|
-
/* emitNotIterableError */ false)
|
5216
|
+
/* emitNotIterableError */ false)?.type ?? types_1.UnknownType.create();
|
5256
5217
|
(0, typeUtils_1.doForEachSubtype)(iterableType, (subtype) => {
|
5257
5218
|
if ((0, types_1.isAnyOrUnknown)(subtype)) {
|
5258
5219
|
sawUnknownExceptionType = true;
|