@zzzen/pyright-internal 1.2.0-dev.20240707 → 1.2.0-dev.20240721
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/analyzerNodeInfo.js +74 -46
- package/dist/analyzer/analyzerNodeInfo.js.map +1 -1
- package/dist/analyzer/binder.js +506 -512
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.js +672 -655
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.d.ts +5 -3
- package/dist/analyzer/codeFlowEngine.js +112 -103
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/codeFlowTypes.js +30 -28
- package/dist/analyzer/codeFlowTypes.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +70 -66
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constructorTransform.d.ts +1 -2
- package/dist/analyzer/constructorTransform.js +26 -27
- package/dist/analyzer/constructorTransform.js.map +1 -1
- package/dist/analyzer/constructors.d.ts +2 -2
- package/dist/analyzer/constructors.js +95 -190
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.js +110 -179
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/declarationUtils.js +14 -15
- package/dist/analyzer/declarationUtils.js.map +1 -1
- package/dist/analyzer/decorators.js +78 -79
- package/dist/analyzer/decorators.js.map +1 -1
- package/dist/analyzer/enums.js +70 -56
- package/dist/analyzer/enums.js.map +1 -1
- package/dist/analyzer/functionTransform.js +8 -18
- package/dist/analyzer/functionTransform.js.map +1 -1
- package/dist/analyzer/importResolver.d.ts +2 -1
- package/dist/analyzer/importResolver.js +40 -29
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/importStatementUtils.js +27 -27
- package/dist/analyzer/importStatementUtils.js.map +1 -1
- package/dist/analyzer/namedTuples.js +33 -59
- package/dist/analyzer/namedTuples.js.map +1 -1
- package/dist/analyzer/operations.js +194 -145
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/packageTypeVerifier.js +66 -62
- package/dist/analyzer/packageTypeVerifier.js.map +1 -1
- package/dist/analyzer/parameterUtils.d.ts +4 -4
- package/dist/analyzer/parameterUtils.js +30 -47
- package/dist/analyzer/parameterUtils.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.d.ts +1 -0
- package/dist/analyzer/parseTreeUtils.js +294 -272
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/parseTreeWalker.js +76 -76
- package/dist/analyzer/parseTreeWalker.js.map +1 -1
- package/dist/analyzer/patternMatching.js +178 -145
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.js +1 -1
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/properties.js +82 -147
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/protocols.js +29 -25
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/sourceFile.js +3 -3
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/sourceMapper.js +20 -19
- package/dist/analyzer/sourceMapper.js.map +1 -1
- package/dist/analyzer/staticExpressions.js +83 -84
- package/dist/analyzer/staticExpressions.js.map +1 -1
- package/dist/analyzer/testWalker.js +15 -3
- package/dist/analyzer/testWalker.js.map +1 -1
- package/dist/analyzer/tracePrinter.js +20 -20
- package/dist/analyzer/tracePrinter.js.map +1 -1
- package/dist/analyzer/typeDocStringUtils.js +25 -25
- package/dist/analyzer/typeDocStringUtils.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +2443 -2350
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +13 -9
- package/dist/analyzer/typeEvaluatorTypes.js +7 -1
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +212 -215
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.js +118 -115
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeStubWriter.js +104 -103
- package/dist/analyzer/typeStubWriter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +30 -15
- package/dist/analyzer/typeUtils.js +534 -436
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typeVarContext.js +8 -8
- package/dist/analyzer/typeVarContext.js.map +1 -1
- package/dist/analyzer/typeWalker.js +13 -10
- package/dist/analyzer/typeWalker.js.map +1 -1
- package/dist/analyzer/typedDicts.js +97 -199
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +152 -106
- package/dist/analyzer/types.js +695 -496
- package/dist/analyzer/types.js.map +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js +34 -34
- package/dist/commands/dumpFileDebugInfoCommand.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 +6 -4
- package/dist/common/fullAccessHost.js.map +1 -1
- package/dist/common/realFileSystem.d.ts +1 -0
- package/dist/common/realFileSystem.js +4 -0
- package/dist/common/realFileSystem.js.map +1 -1
- package/dist/common/textEditTracker.js +14 -14
- package/dist/common/textEditTracker.js.map +1 -1
- package/dist/languageService/autoImporter.js +10 -10
- package/dist/languageService/autoImporter.js.map +1 -1
- package/dist/languageService/callHierarchyProvider.js +23 -23
- package/dist/languageService/callHierarchyProvider.js.map +1 -1
- package/dist/languageService/completionProvider.js +153 -151
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/definitionProvider.d.ts +1 -1
- package/dist/languageService/definitionProvider.js +3 -1
- package/dist/languageService/definitionProvider.js.map +1 -1
- package/dist/languageService/documentSymbolCollector.js +19 -19
- package/dist/languageService/documentSymbolCollector.js.map +1 -1
- package/dist/languageService/hoverProvider.js +36 -27
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/importSorter.js +8 -8
- package/dist/languageService/importSorter.js.map +1 -1
- package/dist/languageService/referencesProvider.d.ts +10 -4
- package/dist/languageService/referencesProvider.js +30 -18
- package/dist/languageService/referencesProvider.js.map +1 -1
- package/dist/languageService/renameProvider.js +21 -4
- package/dist/languageService/renameProvider.js.map +1 -1
- package/dist/languageService/signatureHelpProvider.d.ts +1 -1
- package/dist/languageService/signatureHelpProvider.js +6 -6
- package/dist/languageService/signatureHelpProvider.js.map +1 -1
- package/dist/languageService/symbolIndexer.js +3 -3
- package/dist/languageService/symbolIndexer.js.map +1 -1
- package/dist/languageService/tooltipUtils.js +13 -13
- package/dist/languageService/tooltipUtils.js.map +1 -1
- package/dist/localization/localize.d.ts +4 -3
- package/dist/localization/localize.js +2 -1
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +0 -1
- package/dist/localization/package.nls.de.json +0 -1
- package/dist/localization/package.nls.en-us.json +2 -1
- package/dist/localization/package.nls.es.json +0 -1
- package/dist/localization/package.nls.fr.json +0 -1
- package/dist/localization/package.nls.it.json +0 -1
- package/dist/localization/package.nls.ja.json +0 -1
- package/dist/localization/package.nls.ko.json +0 -1
- package/dist/localization/package.nls.pl.json +0 -1
- package/dist/localization/package.nls.pt-br.json +0 -1
- package/dist/localization/package.nls.qps-ploc.json +0 -1
- package/dist/localization/package.nls.ru.json +0 -1
- package/dist/localization/package.nls.tr.json +0 -1
- package/dist/localization/package.nls.zh-cn.json +0 -1
- package/dist/localization/package.nls.zh-tw.json +0 -1
- package/dist/parser/parseNodes.d.ts +471 -402
- package/dist/parser/parseNodes.js +629 -356
- package/dist/parser/parseNodes.js.map +1 -1
- package/dist/parser/parser.d.ts +1 -0
- package/dist/parser/parser.js +345 -300
- package/dist/parser/parser.js.map +1 -1
- package/dist/tests/classDeclaration.test.js +14 -14
- package/dist/tests/classDeclaration.test.js.map +1 -1
- package/dist/tests/fourslash/rename.args.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/rename.args.fourslash.js +71 -0
- package/dist/tests/fourslash/rename.args.fourslash.js.map +1 -0
- package/dist/tests/harness/vfs/filesystem.d.ts +3 -2
- package/dist/tests/harness/vfs/filesystem.js +6 -2
- package/dist/tests/harness/vfs/filesystem.js.map +1 -1
- package/dist/tests/importResolver.test.js +4 -3
- package/dist/tests/importResolver.test.js.map +1 -1
- package/dist/tests/parseTreeUtils.test.js +5 -5
- package/dist/tests/parseTreeUtils.test.js.map +1 -1
- package/dist/tests/parser.test.js +8 -8
- package/dist/tests/parser.test.js.map +1 -1
- package/dist/tests/sourceMapperUtils.test.js +7 -7
- package/dist/tests/sourceMapperUtils.test.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +17 -0
- package/dist/tests/typeEvaluator1.test.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +4 -0
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +8 -3
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +10 -6
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator6.test.js +6 -2
- package/dist/tests/typeEvaluator6.test.js.map +1 -1
- package/dist/tests/typeEvaluator7.test.js +7 -3
- package/dist/tests/typeEvaluator7.test.js.map +1 -1
- package/dist/tests/typePrinter.test.js +14 -39
- package/dist/tests/typePrinter.test.js.map +1 -1
- package/package.json +1 -1
package/dist/analyzer/checker.js
CHANGED
@@ -105,7 +105,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
105
105
|
if (codeComplexity > typeEvaluator_1.maxCodeComplexity) {
|
106
106
|
this._evaluator.addDiagnosticForTextRange(this._fileInfo, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.codeTooComplexToAnalyze(), { start: 0, length: 0 });
|
107
107
|
}
|
108
|
-
this._walkStatementsAndReportUnreachable(this._moduleNode.statements);
|
108
|
+
this._walkStatementsAndReportUnreachable(this._moduleNode.d.statements);
|
109
109
|
// Mark symbols accessed by __all__ as accessed.
|
110
110
|
const dunderAllInfo = AnalyzerNodeInfo.getDunderAllInfo(this._moduleNode);
|
111
111
|
if (dunderAllInfo) {
|
@@ -128,11 +128,11 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
128
128
|
}
|
129
129
|
}
|
130
130
|
visitSuite(node) {
|
131
|
-
this._walkStatementsAndReportUnreachable(node.statements);
|
131
|
+
this._walkStatementsAndReportUnreachable(node.d.statements);
|
132
132
|
return false;
|
133
133
|
}
|
134
134
|
visitStatementList(node) {
|
135
|
-
node.statements.forEach((statement) => {
|
135
|
+
node.d.statements.forEach((statement) => {
|
136
136
|
if ((0, parseNodes_1.isExpressionNode)(statement)) {
|
137
137
|
// Evaluate the expression in case it wasn't otherwise evaluated
|
138
138
|
// through lazy analysis. This will mark referenced symbols as
|
@@ -145,27 +145,27 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
145
145
|
}
|
146
146
|
visitClass(node) {
|
147
147
|
const classTypeResult = this._evaluator.getTypeOfClass(node);
|
148
|
-
if (node.
|
149
|
-
this.walk(node.
|
148
|
+
if (node.d.typeParams) {
|
149
|
+
this.walk(node.d.typeParams);
|
150
150
|
}
|
151
|
-
this.walk(node.suite);
|
152
|
-
this.walkMultiple(node.decorators);
|
153
|
-
this.walkMultiple(node.arguments);
|
151
|
+
this.walk(node.d.suite);
|
152
|
+
this.walkMultiple(node.d.decorators);
|
153
|
+
this.walkMultiple(node.d.arguments);
|
154
154
|
if (classTypeResult) {
|
155
155
|
// Protocol classes cannot derive from non-protocol classes.
|
156
156
|
if (types_1.ClassType.isProtocolClass(classTypeResult.classType)) {
|
157
|
-
node.arguments.forEach((arg) => {
|
158
|
-
if (!arg.name) {
|
159
|
-
const baseClassType = this._evaluator.getType(arg.
|
157
|
+
node.d.arguments.forEach((arg) => {
|
158
|
+
if (!arg.d.name) {
|
159
|
+
const baseClassType = this._evaluator.getType(arg.d.valueExpr);
|
160
160
|
if (baseClassType &&
|
161
161
|
(0, types_1.isInstantiableClass)(baseClassType) &&
|
162
162
|
!types_1.ClassType.isBuiltIn(baseClassType, 'Protocol') &&
|
163
163
|
!types_1.ClassType.isBuiltIn(baseClassType, 'Generic')) {
|
164
164
|
if (!types_1.ClassType.isProtocolClass(baseClassType)) {
|
165
165
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.protocolBaseClass().format({
|
166
|
-
classType: classTypeResult.classType.
|
167
|
-
baseType: baseClassType.
|
168
|
-
}), arg.
|
166
|
+
classType: classTypeResult.classType.shared.name,
|
167
|
+
baseType: baseClassType.shared.name,
|
168
|
+
}), arg.d.valueExpr);
|
169
169
|
}
|
170
170
|
}
|
171
171
|
}
|
@@ -182,16 +182,16 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
182
182
|
this._validateBaseClassOverrides(classTypeResult.classType);
|
183
183
|
this._validateTypedDictOverrides(classTypeResult.classType);
|
184
184
|
this._validateOverloadDecoratorConsistency(classTypeResult.classType);
|
185
|
-
this._validateMultipleInheritanceBaseClasses(classTypeResult.classType, node.name);
|
186
|
-
this._validateMultipleInheritanceCompatibility(classTypeResult.classType, node.name);
|
187
|
-
this._validateConstructorConsistency(classTypeResult.classType, node.name);
|
185
|
+
this._validateMultipleInheritanceBaseClasses(classTypeResult.classType, node.d.name);
|
186
|
+
this._validateMultipleInheritanceCompatibility(classTypeResult.classType, node.d.name);
|
187
|
+
this._validateConstructorConsistency(classTypeResult.classType, node.d.name);
|
188
188
|
this._validateFinalMemberOverrides(classTypeResult.classType);
|
189
189
|
this._validateInstanceVariableInitialization(node, classTypeResult.classType);
|
190
190
|
this._validateFinalClassNotAbstract(classTypeResult.classType, node);
|
191
|
-
this._validateDataClassPostInit(classTypeResult.classType
|
191
|
+
this._validateDataClassPostInit(classTypeResult.classType);
|
192
192
|
this._validateEnumMembers(classTypeResult.classType, node);
|
193
193
|
if (types_1.ClassType.isTypedDictClass(classTypeResult.classType)) {
|
194
|
-
this._validateTypedDictClassSuite(node.suite);
|
194
|
+
this._validateTypedDictClassSuite(node.d.suite);
|
195
195
|
}
|
196
196
|
if (types_1.ClassType.isEnumClass(classTypeResult.classType)) {
|
197
197
|
this._validateEnumClassOverride(node, classTypeResult.classType);
|
@@ -202,13 +202,13 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
202
202
|
return false;
|
203
203
|
}
|
204
204
|
visitFunction(node) {
|
205
|
-
var _a, _b;
|
206
|
-
if (node.
|
207
|
-
this.walk(node.
|
205
|
+
var _a, _b, _c;
|
206
|
+
if (node.d.typeParams) {
|
207
|
+
this.walk(node.d.typeParams);
|
208
208
|
}
|
209
209
|
if (!this._fileInfo.diagnosticRuleSet.analyzeUnannotatedFunctions && !this._fileInfo.isStubFile) {
|
210
210
|
if (ParseTreeUtils.isUnannotatedFunction(node)) {
|
211
|
-
this._evaluator.addInformation(localize_1.LocMessage.unannotatedFunctionSkipped().format({ name: node.name.value }), node.name);
|
211
|
+
this._evaluator.addInformation(localize_1.LocMessage.unannotatedFunctionSkipped().format({ name: node.d.name.d.value }), node.d.name);
|
212
212
|
}
|
213
213
|
}
|
214
214
|
const functionTypeResult = this._evaluator.getTypeOfFunction(node);
|
@@ -220,41 +220,42 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
220
220
|
const keywordNames = new Set();
|
221
221
|
const paramDetails = (0, parameterUtils_1.getParameterListDetails)(functionTypeResult.functionType);
|
222
222
|
// Report any unknown or missing parameter types.
|
223
|
-
node.
|
224
|
-
|
225
|
-
|
226
|
-
|
223
|
+
node.d.params.forEach((param, index) => {
|
224
|
+
var _a;
|
225
|
+
if (param.d.name) {
|
226
|
+
if (param.d.category === 0 /* ParameterCategory.Simple */ && index >= paramDetails.positionOnlyParamCount) {
|
227
|
+
keywordNames.add(param.d.name.d.value);
|
227
228
|
}
|
228
229
|
// Determine whether this is a P.args parameter.
|
229
|
-
if (param.category === 1 /* ParameterCategory.ArgsList */) {
|
230
|
-
const annotationExpr = param.
|
230
|
+
if (param.d.category === 1 /* ParameterCategory.ArgsList */) {
|
231
|
+
const annotationExpr = (_a = param.d.annotation) !== null && _a !== void 0 ? _a : param.d.annotationComment;
|
231
232
|
if (annotationExpr &&
|
232
233
|
annotationExpr.nodeType === 35 /* ParseNodeType.MemberAccess */ &&
|
233
|
-
annotationExpr.
|
234
|
-
const baseType = this._evaluator.getType(annotationExpr.
|
235
|
-
if (baseType && (0, types_1.isTypeVar)(baseType) && baseType.
|
234
|
+
annotationExpr.d.member.d.value === 'args') {
|
235
|
+
const baseType = this._evaluator.getType(annotationExpr.d.leftExpr);
|
236
|
+
if (baseType && (0, types_1.isTypeVar)(baseType) && baseType.shared.isParamSpec) {
|
236
237
|
sawParamSpecArgs = true;
|
237
238
|
}
|
238
239
|
}
|
239
240
|
}
|
240
|
-
else if (param.category === 2 /* ParameterCategory.KwargsDict */) {
|
241
|
+
else if (param.d.category === 2 /* ParameterCategory.KwargsDict */) {
|
241
242
|
sawParamSpecArgs = false;
|
242
243
|
}
|
243
244
|
}
|
244
|
-
if (param.name && param.category === 0 /* ParameterCategory.Simple */ && sawParamSpecArgs) {
|
245
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.namedParamAfterParamSpecArgs().format({ name: param.name.value }), param.name);
|
245
|
+
if (param.d.name && param.d.category === 0 /* ParameterCategory.Simple */ && sawParamSpecArgs) {
|
246
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.namedParamAfterParamSpecArgs().format({ name: param.d.name.d.value }), param.d.name);
|
246
247
|
}
|
247
248
|
// Allow unknown and missing param types if the param is named '_'.
|
248
|
-
if (param.name && param.name.value !== '_') {
|
249
|
-
const functionTypeParam = functionTypeResult.functionType.
|
249
|
+
if (param.d.name && param.d.name.d.value !== '_') {
|
250
|
+
const functionTypeParam = functionTypeResult.functionType.shared.parameters.find((p) => { var _a; return p.name === ((_a = param.d.name) === null || _a === void 0 ? void 0 : _a.d.value); });
|
250
251
|
if (functionTypeParam) {
|
251
252
|
const paramType = functionTypeParam.type;
|
252
253
|
if (this._fileInfo.diagnosticRuleSet.reportUnknownParameterType !== 'none') {
|
253
254
|
if ((0, types_1.isUnknown)(paramType) ||
|
254
255
|
((0, types_1.isTypeVar)(paramType) &&
|
255
|
-
paramType.
|
256
|
-
!paramType.
|
257
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnknownParameterType, localize_1.LocMessage.paramTypeUnknown().format({ paramName: param.name.value }), param.name);
|
256
|
+
paramType.shared.isSynthesized &&
|
257
|
+
!paramType.shared.isSynthesizedSelf)) {
|
258
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnknownParameterType, localize_1.LocMessage.paramTypeUnknown().format({ paramName: param.d.name.d.value }), param.d.name);
|
258
259
|
}
|
259
260
|
else if ((0, typeUtils_1.isPartlyUnknown)(paramType)) {
|
260
261
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
@@ -262,33 +263,33 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
262
263
|
paramType: this._evaluator.printType(paramType, { expandTypeAlias: true }),
|
263
264
|
}));
|
264
265
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnknownParameterType, localize_1.LocMessage.paramTypePartiallyUnknown().format({
|
265
|
-
paramName: param.name.value,
|
266
|
-
}) + diagAddendum.getString(), param.name);
|
266
|
+
paramName: param.d.name.d.value,
|
267
|
+
}) + diagAddendum.getString(), param.d.name);
|
267
268
|
}
|
268
269
|
}
|
269
270
|
let hasAnnotation = false;
|
270
|
-
if (functionTypeParam
|
271
|
+
if (types_1.FunctionParam.isTypeDeclared(functionTypeParam)) {
|
271
272
|
hasAnnotation = true;
|
272
273
|
}
|
273
274
|
else {
|
274
275
|
// See if this is a "self" and "cls" parameter. They are exempt from this rule.
|
275
|
-
if ((0, types_1.isTypeVar)(paramType) && paramType.
|
276
|
+
if ((0, types_1.isTypeVar)(paramType) && paramType.shared.isSynthesizedSelf) {
|
276
277
|
hasAnnotation = true;
|
277
278
|
}
|
278
279
|
}
|
279
280
|
if (!hasAnnotation && this._fileInfo.diagnosticRuleSet.reportMissingParameterType !== 'none') {
|
280
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportMissingParameterType, localize_1.LocMessage.paramAnnotationMissing().format({ name: param.name.value }), param.name);
|
281
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportMissingParameterType, localize_1.LocMessage.paramAnnotationMissing().format({ name: param.d.name.d.value }), param.d.name);
|
281
282
|
}
|
282
283
|
}
|
283
284
|
}
|
284
285
|
});
|
285
286
|
// Verify that an unpacked TypedDict doesn't overlap any keyword parameters.
|
286
287
|
if (paramDetails.hasUnpackedTypedDict) {
|
287
|
-
const kwargsIndex = functionTypeResult.functionType.
|
288
|
+
const kwargsIndex = functionTypeResult.functionType.shared.parameters.length - 1;
|
288
289
|
const kwargsType = types_1.FunctionType.getEffectiveParameterType(functionTypeResult.functionType, kwargsIndex);
|
289
|
-
if ((0, types_1.isClass)(kwargsType) && kwargsType.
|
290
|
+
if ((0, types_1.isClass)(kwargsType) && kwargsType.shared.typedDictEntries) {
|
290
291
|
const overlappingEntries = new Set();
|
291
|
-
kwargsType.
|
292
|
+
kwargsType.shared.typedDictEntries.knownItems.forEach((_, name) => {
|
292
293
|
if (keywordNames.has(name)) {
|
293
294
|
overlappingEntries.add(name);
|
294
295
|
}
|
@@ -296,85 +297,89 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
296
297
|
if (overlappingEntries.size > 0) {
|
297
298
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.overlappingKeywordArgs().format({
|
298
299
|
names: [...overlappingEntries.values()].join(', '),
|
299
|
-
}), (_a = node.
|
300
|
+
}), (_a = node.d.params[kwargsIndex].d.annotation) !== null && _a !== void 0 ? _a : node.d.params[kwargsIndex]);
|
300
301
|
}
|
301
302
|
}
|
302
303
|
}
|
303
304
|
// Check for invalid use of ParamSpec P.args and P.kwargs.
|
304
|
-
const paramSpecParams = functionTypeResult.functionType.
|
305
|
-
if (param
|
306
|
-
if (param.category !== 0 /* ParameterCategory.Simple */ && param.name && param.type.paramSpecAccess) {
|
305
|
+
const paramSpecParams = functionTypeResult.functionType.shared.parameters.filter((param) => {
|
306
|
+
if (types_1.FunctionParam.isTypeDeclared(param) && (0, types_1.isTypeVar)(param.type) && (0, types_1.isParamSpec)(param.type)) {
|
307
|
+
if (param.category !== 0 /* ParameterCategory.Simple */ && param.name && param.type.priv.paramSpecAccess) {
|
307
308
|
return true;
|
308
309
|
}
|
309
310
|
}
|
310
311
|
return false;
|
311
312
|
});
|
312
|
-
if (paramSpecParams.length === 1 && paramSpecParams[0].
|
313
|
-
|
313
|
+
if (paramSpecParams.length === 1 && paramSpecParams[0].name) {
|
314
|
+
const paramNode = node.d.params.find((param) => { var _a; return ((_a = param.d.name) === null || _a === void 0 ? void 0 : _a.d.value) === paramSpecParams[0].name; });
|
315
|
+
const annotationNode = (_b = paramNode === null || paramNode === void 0 ? void 0 : paramNode.d.annotation) !== null && _b !== void 0 ? _b : paramNode === null || paramNode === void 0 ? void 0 : paramNode.d.annotationComment;
|
316
|
+
if (annotationNode) {
|
317
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.paramSpecArgsKwargsUsage(), annotationNode);
|
318
|
+
}
|
314
319
|
}
|
315
320
|
// If this is a stub, ensure that the return type is specified.
|
316
321
|
if (this._fileInfo.isStubFile) {
|
317
|
-
const returnAnnotation = node.
|
322
|
+
const returnAnnotation = node.d.returnAnnotation || ((_c = node.d.funcAnnotationComment) === null || _c === void 0 ? void 0 : _c.d.returnAnnotation);
|
318
323
|
if (!returnAnnotation) {
|
319
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnknownParameterType, localize_1.LocMessage.returnTypeUnknown(), node.name);
|
324
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnknownParameterType, localize_1.LocMessage.returnTypeUnknown(), node.d.name);
|
320
325
|
}
|
321
326
|
}
|
322
327
|
if (containingClassNode) {
|
323
328
|
this._validateMethod(node, functionTypeResult.functionType, containingClassNode);
|
324
329
|
}
|
325
330
|
}
|
326
|
-
node.
|
327
|
-
if (param.defaultValue) {
|
328
|
-
this.walk(param.defaultValue);
|
331
|
+
node.d.params.forEach((param, index) => {
|
332
|
+
if (param.d.defaultValue) {
|
333
|
+
this.walk(param.d.defaultValue);
|
329
334
|
}
|
330
|
-
if (param.
|
331
|
-
this.walk(param.
|
335
|
+
if (param.d.annotation) {
|
336
|
+
this.walk(param.d.annotation);
|
332
337
|
}
|
333
|
-
if (param.
|
334
|
-
this.walk(param.
|
338
|
+
if (param.d.annotationComment) {
|
339
|
+
this.walk(param.d.annotationComment);
|
335
340
|
}
|
336
341
|
// Look for method parameters that are typed with TypeVars that have the wrong variance.
|
337
342
|
if (functionTypeResult) {
|
338
|
-
const annotationNode = param.
|
339
|
-
if (annotationNode && index < functionTypeResult.functionType.
|
340
|
-
const paramType = functionTypeResult.functionType.
|
343
|
+
const annotationNode = param.d.annotation || param.d.annotationComment;
|
344
|
+
if (annotationNode && index < functionTypeResult.functionType.shared.parameters.length) {
|
345
|
+
const paramType = functionTypeResult.functionType.shared.parameters[index].type;
|
341
346
|
const exemptMethods = ['__init__', '__new__'];
|
342
347
|
if (containingClassNode &&
|
343
348
|
(0, types_1.isTypeVar)(paramType) &&
|
344
|
-
paramType.
|
345
|
-
!paramType.
|
346
|
-
!exemptMethods.some((name) => name === functionTypeResult.functionType.
|
349
|
+
paramType.shared.declaredVariance === 3 /* Variance.Covariant */ &&
|
350
|
+
!paramType.shared.isSynthesized &&
|
351
|
+
!exemptMethods.some((name) => name === functionTypeResult.functionType.shared.name)) {
|
347
352
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.paramTypeCovariant(), annotationNode);
|
348
353
|
}
|
349
354
|
}
|
350
355
|
}
|
351
356
|
});
|
352
|
-
if (node.
|
353
|
-
this.walk(node.
|
357
|
+
if (node.d.returnAnnotation) {
|
358
|
+
this.walk(node.d.returnAnnotation);
|
354
359
|
}
|
355
|
-
if (node.
|
356
|
-
this.walk(node.
|
360
|
+
if (node.d.funcAnnotationComment) {
|
361
|
+
this.walk(node.d.funcAnnotationComment);
|
357
362
|
if (this._fileInfo.diagnosticRuleSet.reportTypeCommentUsage !== 'none' &&
|
358
363
|
this._fileInfo.executionEnvironment.pythonVersion.isGreaterOrEqualTo(pythonVersion_1.pythonVersion3_5)) {
|
359
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportTypeCommentUsage, localize_1.LocMessage.typeCommentDeprecated(), node.
|
364
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportTypeCommentUsage, localize_1.LocMessage.typeCommentDeprecated(), node.d.funcAnnotationComment);
|
360
365
|
}
|
361
366
|
}
|
362
|
-
this.walkMultiple(node.decorators);
|
363
|
-
node.
|
364
|
-
if (param.name) {
|
365
|
-
this.walk(param.name);
|
367
|
+
this.walkMultiple(node.d.decorators);
|
368
|
+
node.d.params.forEach((param) => {
|
369
|
+
if (param.d.name) {
|
370
|
+
this.walk(param.d.name);
|
366
371
|
}
|
367
372
|
});
|
368
373
|
const codeComplexity = AnalyzerNodeInfo.getCodeFlowComplexity(node);
|
369
374
|
const isTooComplexToAnalyze = codeComplexity > typeEvaluator_1.maxCodeComplexity;
|
370
375
|
if (isPrintCodeComplexityEnabled) {
|
371
|
-
console.log(`Code complexity of function ${node.name.value} is ${codeComplexity.toString()}`);
|
376
|
+
console.log(`Code complexity of function ${node.d.name.d.value} is ${codeComplexity.toString()}`);
|
372
377
|
}
|
373
378
|
if (isTooComplexToAnalyze) {
|
374
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.codeTooComplexToAnalyze(), node.name);
|
379
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.codeTooComplexToAnalyze(), node.d.name);
|
375
380
|
}
|
376
381
|
else {
|
377
|
-
this.walk(node.suite);
|
382
|
+
this.walk(node.d.suite);
|
378
383
|
}
|
379
384
|
if (functionTypeResult) {
|
380
385
|
// Validate that the function returns the declared type.
|
@@ -390,16 +395,16 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
390
395
|
this._reportDeprecatedClassProperty(node, functionTypeResult);
|
391
396
|
// If this is not a method, @final is disallowed.
|
392
397
|
if (!containingClassNode && types_1.FunctionType.isFinal(functionTypeResult.functionType)) {
|
393
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.finalNonMethod().format({ name: node.name.value }), node.name);
|
398
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.finalNonMethod().format({ name: node.d.name.d.value }), node.d.name);
|
394
399
|
}
|
395
400
|
}
|
396
401
|
// If we're at the module level within a stub file, report a diagnostic
|
397
402
|
// if there is a '__getattr__' function defined when in strict mode.
|
398
403
|
// This signifies an incomplete stub file that obscures type errors.
|
399
|
-
if (this._fileInfo.isStubFile && node.name.value === '__getattr__') {
|
404
|
+
if (this._fileInfo.isStubFile && node.d.name.d.value === '__getattr__') {
|
400
405
|
const scope = (0, scopeUtils_1.getScopeForNode)(node);
|
401
406
|
if ((scope === null || scope === void 0 ? void 0 : scope.type) === 4 /* ScopeType.Module */) {
|
402
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompleteStub, localize_1.LocMessage.stubUsesGetAttr(), node.name);
|
407
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompleteStub, localize_1.LocMessage.stubUsesGetAttr(), node.d.name);
|
403
408
|
}
|
404
409
|
}
|
405
410
|
this._scopedNodes.push(node);
|
@@ -426,29 +431,29 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
426
431
|
visitLambda(node) {
|
427
432
|
this._evaluator.getType(node);
|
428
433
|
// Walk the children.
|
429
|
-
this.walkMultiple([...node.
|
430
|
-
node.
|
431
|
-
if (param.name) {
|
432
|
-
const paramType = this._evaluator.getType(param.name);
|
434
|
+
this.walkMultiple([...node.d.params, node.d.expr]);
|
435
|
+
node.d.params.forEach((param) => {
|
436
|
+
if (param.d.name) {
|
437
|
+
const paramType = this._evaluator.getType(param.d.name);
|
433
438
|
if (paramType) {
|
434
439
|
if ((0, types_1.isUnknown)(paramType)) {
|
435
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnknownLambdaType, localize_1.LocMessage.paramTypeUnknown().format({ paramName: param.name.value }), param.name);
|
440
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnknownLambdaType, localize_1.LocMessage.paramTypeUnknown().format({ paramName: param.d.name.d.value }), param.d.name);
|
436
441
|
}
|
437
442
|
else if ((0, typeUtils_1.isPartlyUnknown)(paramType)) {
|
438
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnknownLambdaType, localize_1.LocMessage.paramTypePartiallyUnknown().format({ paramName: param.name.value }), param.name);
|
443
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnknownLambdaType, localize_1.LocMessage.paramTypePartiallyUnknown().format({ paramName: param.d.name.d.value }), param.d.name);
|
439
444
|
}
|
440
445
|
}
|
441
446
|
}
|
442
447
|
});
|
443
|
-
const returnType = this._evaluator.getType(node.
|
448
|
+
const returnType = this._evaluator.getType(node.d.expr);
|
444
449
|
if (returnType) {
|
445
450
|
if ((0, types_1.isUnknown)(returnType)) {
|
446
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnknownLambdaType, localize_1.LocMessage.lambdaReturnTypeUnknown(), node.
|
451
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnknownLambdaType, localize_1.LocMessage.lambdaReturnTypeUnknown(), node.d.expr);
|
447
452
|
}
|
448
453
|
else if ((0, typeUtils_1.isPartlyUnknown)(returnType)) {
|
449
454
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnknownLambdaType, localize_1.LocMessage.lambdaReturnTypePartiallyUnknown().format({
|
450
455
|
returnType: this._evaluator.printType(returnType, { expandTypeAlias: true }),
|
451
|
-
}), node.
|
456
|
+
}), node.d.expr);
|
452
457
|
}
|
453
458
|
}
|
454
459
|
this._scopedNodes.push(node);
|
@@ -462,7 +467,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
462
467
|
if (this._fileInfo.diagnosticRuleSet.reportUnusedCallResult !== 'none' ||
|
463
468
|
this._fileInfo.diagnosticRuleSet.reportUnusedCoroutine !== 'none') {
|
464
469
|
if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 47 /* ParseNodeType.StatementList */) {
|
465
|
-
const isRevealTypeCall = node.
|
470
|
+
const isRevealTypeCall = node.d.leftExpr.nodeType === 38 /* ParseNodeType.Name */ && node.d.leftExpr.d.value === 'reveal_type';
|
466
471
|
const returnType = this._evaluator.getType(node);
|
467
472
|
if (!isRevealTypeCall && returnType && this._isTypeValidForUnusedValueTest(returnType)) {
|
468
473
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnusedCallResult, localize_1.LocMessage.unusedCallResult().format({
|
@@ -479,8 +484,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
479
484
|
visitAwait(node) {
|
480
485
|
var _a;
|
481
486
|
if (this._fileInfo.diagnosticRuleSet.reportUnusedCallResult !== 'none') {
|
482
|
-
if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 47 /* ParseNodeType.StatementList */ &&
|
483
|
-
node.expression.nodeType === 9 /* ParseNodeType.Call */) {
|
487
|
+
if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 47 /* ParseNodeType.StatementList */ && node.d.expr.nodeType === 9 /* ParseNodeType.Call */) {
|
484
488
|
const returnType = this._evaluator.getType(node);
|
485
489
|
if (returnType && this._isTypeValidForUnusedValueTest(returnType)) {
|
486
490
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnusedCallResult, localize_1.LocMessage.unusedCallResult().format({
|
@@ -493,8 +497,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
493
497
|
}
|
494
498
|
visitFor(node) {
|
495
499
|
this._evaluator.evaluateTypesForStatement(node);
|
496
|
-
if (node.typeComment) {
|
497
|
-
this._evaluator.addDiagnosticForTextRange(this._fileInfo, diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.annotationNotSupported(), node.typeComment);
|
500
|
+
if (node.d.typeComment) {
|
501
|
+
this._evaluator.addDiagnosticForTextRange(this._fileInfo, diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.annotationNotSupported(), node.d.typeComment);
|
498
502
|
}
|
499
503
|
return true;
|
500
504
|
}
|
@@ -515,39 +519,39 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
515
519
|
return true;
|
516
520
|
}
|
517
521
|
visitComprehensionIf(node) {
|
518
|
-
this._validateConditionalIsBool(node.
|
519
|
-
this._reportUnnecessaryConditionExpression(node.
|
522
|
+
this._validateConditionalIsBool(node.d.testExpr);
|
523
|
+
this._reportUnnecessaryConditionExpression(node.d.testExpr);
|
520
524
|
return true;
|
521
525
|
}
|
522
526
|
visitIf(node) {
|
523
|
-
this._validateConditionalIsBool(node.
|
524
|
-
this._reportUnnecessaryConditionExpression(node.
|
527
|
+
this._validateConditionalIsBool(node.d.testExpr);
|
528
|
+
this._reportUnnecessaryConditionExpression(node.d.testExpr);
|
525
529
|
return true;
|
526
530
|
}
|
527
531
|
visitWhile(node) {
|
528
|
-
this._validateConditionalIsBool(node.
|
529
|
-
this._reportUnnecessaryConditionExpression(node.
|
532
|
+
this._validateConditionalIsBool(node.d.testExpr);
|
533
|
+
this._reportUnnecessaryConditionExpression(node.d.testExpr);
|
530
534
|
return true;
|
531
535
|
}
|
532
536
|
visitWith(node) {
|
533
|
-
node.withItems.forEach((item) => {
|
537
|
+
node.d.withItems.forEach((item) => {
|
534
538
|
this._evaluator.evaluateTypesForStatement(item);
|
535
539
|
});
|
536
|
-
if (node.typeComment) {
|
537
|
-
this._evaluator.addDiagnosticForTextRange(this._fileInfo, diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.annotationNotSupported(), node.typeComment);
|
540
|
+
if (node.d.typeComment) {
|
541
|
+
this._evaluator.addDiagnosticForTextRange(this._fileInfo, diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.annotationNotSupported(), node.d.typeComment);
|
538
542
|
}
|
539
543
|
return true;
|
540
544
|
}
|
541
545
|
visitReturn(node) {
|
542
|
-
var _a, _b, _c, _d, _e;
|
546
|
+
var _a, _b, _c, _d, _e, _f;
|
543
547
|
let returnTypeResult;
|
544
548
|
let returnType;
|
545
549
|
const enclosingFunctionNode = ParseTreeUtils.getEnclosingFunction(node);
|
546
|
-
|
550
|
+
let declaredReturnType = enclosingFunctionNode
|
547
551
|
? this._evaluator.getFunctionDeclaredReturnType(enclosingFunctionNode)
|
548
552
|
: undefined;
|
549
|
-
if (node.
|
550
|
-
returnTypeResult = (_a = this._evaluator.getTypeResult(node.
|
553
|
+
if (node.d.expr) {
|
554
|
+
returnTypeResult = (_a = this._evaluator.getTypeResult(node.d.expr)) !== null && _a !== void 0 ? _a : { type: types_1.UnknownType.create() };
|
551
555
|
}
|
552
556
|
else {
|
553
557
|
// There is no return expression, so "None" is assumed.
|
@@ -555,16 +559,16 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
555
559
|
}
|
556
560
|
returnType = returnTypeResult.type;
|
557
561
|
// If this type is a special form, use the special form instead.
|
558
|
-
if (returnType.specialForm) {
|
559
|
-
returnType = returnType.specialForm;
|
562
|
+
if ((_b = returnType.props) === null || _b === void 0 ? void 0 : _b.specialForm) {
|
563
|
+
returnType = returnType.props.specialForm;
|
560
564
|
}
|
561
565
|
// If the enclosing function is async and a generator, the return
|
562
566
|
// statement is not allowed to have an argument. A syntax error occurs
|
563
567
|
// at runtime in this case.
|
564
|
-
if ((enclosingFunctionNode === null || enclosingFunctionNode === void 0 ? void 0 : enclosingFunctionNode.isAsync) && node.
|
568
|
+
if ((enclosingFunctionNode === null || enclosingFunctionNode === void 0 ? void 0 : enclosingFunctionNode.d.isAsync) && node.d.expr) {
|
565
569
|
const functionDecl = AnalyzerNodeInfo.getDeclaration(enclosingFunctionNode);
|
566
570
|
if ((functionDecl === null || functionDecl === void 0 ? void 0 : functionDecl.type) === 5 /* DeclarationType.Function */ && functionDecl.isGenerator) {
|
567
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.returnInAsyncGenerator(), node.
|
571
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.returnInAsyncGenerator(), node.d.expr);
|
568
572
|
}
|
569
573
|
}
|
570
574
|
if (this._evaluator.isNodeReachable(node, /* sourceNode */ undefined) && enclosingFunctionNode) {
|
@@ -573,10 +577,12 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
573
577
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.noReturnContainsReturn(), node);
|
574
578
|
}
|
575
579
|
else {
|
580
|
+
const liveScopes = ParseTreeUtils.getTypeVarScopesForNode(node);
|
581
|
+
declaredReturnType = (0, typeUtils_1.updateTypeWithInternalTypeVars)(declaredReturnType, liveScopes);
|
576
582
|
let diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
577
583
|
let returnTypeMatches = false;
|
578
584
|
if (this._evaluator.assignType(declaredReturnType, returnType, diagAddendum,
|
579
|
-
/* destTypeVarContext */
|
585
|
+
/* destTypeVarContext */ new typeVarContext_1.TypeVarContext(),
|
580
586
|
/* srcTypeVarContext */ undefined, 128 /* AssignTypeFlags.AllowBoolTypeGuard */)) {
|
581
587
|
returnTypeMatches = true;
|
582
588
|
}
|
@@ -584,11 +590,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
584
590
|
// See if the declared return type includes one or more constrained TypeVars. If so,
|
585
591
|
// try to narrow these TypeVars to a single type.
|
586
592
|
const uniqueTypeVars = (0, typeUtils_1.getTypeVarArgumentsRecursive)(declaredReturnType);
|
587
|
-
if (uniqueTypeVars &&
|
588
|
-
uniqueTypeVars.some((typeVar) => typeVar.details.constraints.length > 0)) {
|
593
|
+
if (uniqueTypeVars && uniqueTypeVars.some((typeVar) => typeVar.shared.constraints.length > 0)) {
|
589
594
|
const typeVarContext = new typeVarContext_1.TypeVarContext();
|
590
595
|
for (const typeVar of uniqueTypeVars) {
|
591
|
-
if (typeVar.
|
596
|
+
if (typeVar.shared.constraints.length > 0) {
|
592
597
|
const narrowedType = this._evaluator.narrowConstrainedTypeVar(node, typeVar);
|
593
598
|
if (narrowedType) {
|
594
599
|
typeVarContext.setTypeVarType(typeVar, narrowedType);
|
@@ -615,32 +620,32 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
615
620
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportReturnType, localize_1.LocMessage.returnTypeMismatch().format({
|
616
621
|
exprType: this._evaluator.printType(returnType),
|
617
622
|
returnType: this._evaluator.printType(declaredReturnType),
|
618
|
-
}) + diagAddendum.getString(), (
|
623
|
+
}) + diagAddendum.getString(), (_c = node.d.expr) !== null && _c !== void 0 ? _c : node, (_d = returnTypeResult.expectedTypeDiagAddendum) === null || _d === void 0 ? void 0 : _d.getEffectiveTextRange());
|
619
624
|
}
|
620
625
|
}
|
621
626
|
}
|
622
627
|
if ((0, types_1.isUnknown)(returnType)) {
|
623
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnknownVariableType, localize_1.LocMessage.returnTypeUnknown(), (
|
628
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnknownVariableType, localize_1.LocMessage.returnTypeUnknown(), (_e = node.d.expr) !== null && _e !== void 0 ? _e : node);
|
624
629
|
}
|
625
630
|
else if ((0, typeUtils_1.isPartlyUnknown)(returnType)) {
|
626
631
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnknownVariableType, localize_1.LocMessage.returnTypePartiallyUnknown().format({
|
627
632
|
returnType: this._evaluator.printType(returnType, { expandTypeAlias: true }),
|
628
|
-
}), (
|
633
|
+
}), (_f = node.d.expr) !== null && _f !== void 0 ? _f : node);
|
629
634
|
}
|
630
635
|
}
|
631
636
|
return true;
|
632
637
|
}
|
633
638
|
visitYield(node) {
|
634
639
|
var _a;
|
635
|
-
const yieldTypeResult = node.
|
636
|
-
? this._evaluator.getTypeResult(node.
|
640
|
+
const yieldTypeResult = node.d.expr
|
641
|
+
? this._evaluator.getTypeResult(node.d.expr)
|
637
642
|
: { type: this._evaluator.getNoneType() };
|
638
643
|
this._validateYieldType(node, (_a = yieldTypeResult === null || yieldTypeResult === void 0 ? void 0 : yieldTypeResult.type) !== null && _a !== void 0 ? _a : types_1.UnknownType.create(), yieldTypeResult === null || yieldTypeResult === void 0 ? void 0 : yieldTypeResult.expectedTypeDiagAddendum);
|
639
644
|
return true;
|
640
645
|
}
|
641
646
|
visitYieldFrom(node) {
|
642
647
|
var _a, _b, _c, _d;
|
643
|
-
const yieldFromType = this._evaluator.getType(node.
|
648
|
+
const yieldFromType = this._evaluator.getType(node.d.expr) || types_1.UnknownType.create();
|
644
649
|
let yieldType;
|
645
650
|
let sendType;
|
646
651
|
if ((0, types_1.isClassInstance)(yieldFromType) && types_1.ClassType.isBuiltIn(yieldFromType, 'Coroutine')) {
|
@@ -668,9 +673,9 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
668
673
|
}
|
669
674
|
visitRaise(node) {
|
670
675
|
this._evaluator.verifyRaiseExceptionType(node);
|
671
|
-
if (node.valueExpression) {
|
676
|
+
if (node.d.valueExpression) {
|
672
677
|
const baseExceptionType = this._evaluator.getBuiltInType(node, 'BaseException');
|
673
|
-
const exceptionType = this._evaluator.getType(node.valueExpression);
|
678
|
+
const exceptionType = this._evaluator.getType(node.d.valueExpression);
|
674
679
|
// Validate that the argument of "raise" is an exception object or None.
|
675
680
|
if (exceptionType && baseExceptionType && (0, types_1.isInstantiableClass)(baseExceptionType)) {
|
676
681
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
@@ -692,36 +697,36 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
692
697
|
}
|
693
698
|
});
|
694
699
|
if (!diagAddendum.isEmpty()) {
|
695
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.expectedExceptionObj() + diagAddendum.getString(), node.valueExpression);
|
700
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.expectedExceptionObj() + diagAddendum.getString(), node.d.valueExpression);
|
696
701
|
}
|
697
702
|
}
|
698
703
|
}
|
699
704
|
return true;
|
700
705
|
}
|
701
706
|
visitExcept(node) {
|
702
|
-
if (node.
|
707
|
+
if (node.d.typeExpr) {
|
703
708
|
this._evaluator.evaluateTypesForStatement(node);
|
704
|
-
const exceptionType = this._evaluator.getType(node.
|
709
|
+
const exceptionType = this._evaluator.getType(node.d.typeExpr);
|
705
710
|
if (exceptionType) {
|
706
|
-
this._validateExceptionType(exceptionType, node.
|
711
|
+
this._validateExceptionType(exceptionType, node.d.typeExpr, node.d.isExceptGroup);
|
707
712
|
}
|
708
713
|
}
|
709
714
|
return true;
|
710
715
|
}
|
711
716
|
visitAssert(node) {
|
712
|
-
if (node.
|
713
|
-
this._evaluator.getType(node.
|
717
|
+
if (node.d.exceptionExpr) {
|
718
|
+
this._evaluator.getType(node.d.exceptionExpr);
|
714
719
|
}
|
715
|
-
this._validateConditionalIsBool(node.
|
720
|
+
this._validateConditionalIsBool(node.d.testExpr);
|
716
721
|
// Specifically look for a common programming error where the two arguments
|
717
722
|
// to an assert are enclosed in parens and interpreted as a two-element tuple.
|
718
723
|
// assert (x > 3, "bad value x")
|
719
|
-
const type = this._evaluator.getType(node.
|
724
|
+
const type = this._evaluator.getType(node.d.testExpr);
|
720
725
|
if (type && (0, types_1.isClassInstance)(type)) {
|
721
|
-
if ((0, typeUtils_1.isTupleClass)(type) && type.tupleTypeArguments) {
|
722
|
-
if (type.tupleTypeArguments.length > 0) {
|
726
|
+
if ((0, typeUtils_1.isTupleClass)(type) && type.priv.tupleTypeArguments) {
|
727
|
+
if (type.priv.tupleTypeArguments.length > 0) {
|
723
728
|
if (!(0, typeUtils_1.isUnboundedTupleClass)(type)) {
|
724
|
-
this._evaluator.addDiagnosticForTextRange(this._fileInfo, diagnosticRules_1.DiagnosticRule.reportAssertAlwaysTrue, localize_1.LocMessage.assertAlwaysTrue(), node.
|
729
|
+
this._evaluator.addDiagnosticForTextRange(this._fileInfo, diagnosticRules_1.DiagnosticRule.reportAssertAlwaysTrue, localize_1.LocMessage.assertAlwaysTrue(), node.d.testExpr);
|
725
730
|
}
|
726
731
|
}
|
727
732
|
}
|
@@ -730,23 +735,23 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
730
735
|
}
|
731
736
|
visitAssignment(node) {
|
732
737
|
this._evaluator.evaluateTypesForStatement(node);
|
733
|
-
if (node.
|
734
|
-
this._evaluator.getType(node.
|
738
|
+
if (node.d.annotationComment) {
|
739
|
+
this._evaluator.getType(node.d.annotationComment);
|
735
740
|
if (this._fileInfo.diagnosticRuleSet.reportTypeCommentUsage !== 'none' &&
|
736
741
|
this._fileInfo.executionEnvironment.pythonVersion.isGreaterOrEqualTo(pythonVersion_1.pythonVersion3_6)) {
|
737
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportTypeCommentUsage, localize_1.LocMessage.typeCommentDeprecated(), node.
|
742
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportTypeCommentUsage, localize_1.LocMessage.typeCommentDeprecated(), node.d.annotationComment);
|
738
743
|
}
|
739
744
|
}
|
740
745
|
// If this isn't a class or global scope, explicit type aliases are not allowed.
|
741
|
-
if (node.
|
742
|
-
const annotationType = this._evaluator.getTypeOfAnnotation(node.
|
746
|
+
if (node.d.leftExpr.nodeType === 54 /* ParseNodeType.TypeAnnotation */) {
|
747
|
+
const annotationType = this._evaluator.getTypeOfAnnotation(node.d.leftExpr.d.annotation);
|
743
748
|
if ((0, types_1.isClassInstance)(annotationType) && types_1.ClassType.isBuiltIn(annotationType, 'TypeAlias')) {
|
744
749
|
const scope = (0, scopeUtils_1.getScopeForNode)(node);
|
745
750
|
if (scope) {
|
746
751
|
if (scope.type !== 3 /* ScopeType.Class */ &&
|
747
752
|
scope.type !== 4 /* ScopeType.Module */ &&
|
748
753
|
scope.type !== 5 /* ScopeType.Builtin */) {
|
749
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeAliasNotInModuleOrClass(), node.
|
754
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeAliasNotInModuleOrClass(), node.d.leftExpr.d.annotation);
|
750
755
|
}
|
751
756
|
}
|
752
757
|
}
|
@@ -765,30 +770,32 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
765
770
|
this._evaluator.getType(node);
|
766
771
|
// If the index is a literal integer, see if this is a tuple with
|
767
772
|
// a known length and the integer value exceeds the length.
|
768
|
-
const baseType = this._evaluator.getType(node.
|
773
|
+
const baseType = this._evaluator.getType(node.d.leftExpr);
|
769
774
|
if (baseType) {
|
770
775
|
(0, typeUtils_1.doForEachSubtype)(baseType, (subtype) => {
|
771
776
|
const tupleType = (0, typeUtils_1.getSpecializedTupleType)(subtype);
|
772
|
-
if (!(0, types_1.isClassInstance)(subtype) ||
|
777
|
+
if (!(0, types_1.isClassInstance)(subtype) ||
|
778
|
+
!(tupleType === null || tupleType === void 0 ? void 0 : tupleType.priv.tupleTypeArguments) ||
|
779
|
+
(0, typeUtils_1.isUnboundedTupleClass)(tupleType)) {
|
773
780
|
return;
|
774
781
|
}
|
775
|
-
const tupleLength = tupleType.tupleTypeArguments.length;
|
776
|
-
if (node.items.length !== 1 ||
|
777
|
-
node.trailingComma ||
|
778
|
-
node.items[0].
|
779
|
-
node.items[0].name) {
|
782
|
+
const tupleLength = tupleType.priv.tupleTypeArguments.length;
|
783
|
+
if (node.d.items.length !== 1 ||
|
784
|
+
node.d.trailingComma ||
|
785
|
+
node.d.items[0].d.argCategory !== 0 /* ArgumentCategory.Simple */ ||
|
786
|
+
node.d.items[0].d.name) {
|
780
787
|
return;
|
781
788
|
}
|
782
|
-
const subscriptType = this._evaluator.getType(node.items[0].
|
789
|
+
const subscriptType = this._evaluator.getType(node.d.items[0].d.valueExpr);
|
783
790
|
if (!subscriptType ||
|
784
791
|
!(0, types_1.isClassInstance)(subscriptType) ||
|
785
792
|
!types_1.ClassType.isBuiltIn(subscriptType, 'int') ||
|
786
793
|
!(0, typeUtils_1.isLiteralType)(subscriptType) ||
|
787
|
-
typeof subscriptType.literalValue !== 'number') {
|
794
|
+
typeof subscriptType.priv.literalValue !== 'number') {
|
788
795
|
return;
|
789
796
|
}
|
790
|
-
if ((subscriptType.literalValue < 0 || subscriptType.literalValue < tupleLength) &&
|
791
|
-
(subscriptType.literalValue >= 0 || subscriptType.literalValue + tupleLength >= 0)) {
|
797
|
+
if ((subscriptType.priv.literalValue < 0 || subscriptType.priv.literalValue < tupleLength) &&
|
798
|
+
(subscriptType.priv.literalValue >= 0 || subscriptType.priv.literalValue + tupleLength >= 0)) {
|
792
799
|
return;
|
793
800
|
}
|
794
801
|
// This can be an expensive check, so we save it for the end once we
|
@@ -797,7 +804,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
797
804
|
return;
|
798
805
|
}
|
799
806
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.tupleIndexOutOfRange().format({
|
800
|
-
index: subscriptType.literalValue,
|
807
|
+
index: subscriptType.priv.literalValue,
|
801
808
|
type: this._evaluator.printType(subtype),
|
802
809
|
}), node);
|
803
810
|
});
|
@@ -805,23 +812,23 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
805
812
|
return true;
|
806
813
|
}
|
807
814
|
visitBinaryOperation(node) {
|
808
|
-
if (node.operator === 36 /* OperatorType.And */ || node.operator === 37 /* OperatorType.Or */) {
|
809
|
-
this._validateConditionalIsBool(node.
|
810
|
-
this._validateConditionalIsBool(node.
|
815
|
+
if (node.d.operator === 36 /* OperatorType.And */ || node.d.operator === 37 /* OperatorType.Or */) {
|
816
|
+
this._validateConditionalIsBool(node.d.leftExpr);
|
817
|
+
this._validateConditionalIsBool(node.d.rightExpr);
|
811
818
|
}
|
812
|
-
if (node.operator === 12 /* OperatorType.Equals */ || node.operator === 28 /* OperatorType.NotEquals */) {
|
819
|
+
if (node.d.operator === 12 /* OperatorType.Equals */ || node.d.operator === 28 /* OperatorType.NotEquals */) {
|
813
820
|
// Don't apply this rule if it's within an assert.
|
814
821
|
if (!ParseTreeUtils.isWithinAssertExpression(node)) {
|
815
822
|
this._validateComparisonTypes(node);
|
816
823
|
}
|
817
824
|
}
|
818
|
-
else if (node.operator === 39 /* OperatorType.Is */ || node.operator === 40 /* OperatorType.IsNot */) {
|
825
|
+
else if (node.d.operator === 39 /* OperatorType.Is */ || node.d.operator === 40 /* OperatorType.IsNot */) {
|
819
826
|
// Don't apply this rule if it's within an assert.
|
820
827
|
if (!ParseTreeUtils.isWithinAssertExpression(node)) {
|
821
828
|
this._validateComparisonTypesForIsOperator(node);
|
822
829
|
}
|
823
830
|
}
|
824
|
-
else if (node.operator === 41 /* OperatorType.In */ || node.operator === 42 /* OperatorType.NotIn */) {
|
831
|
+
else if (node.d.operator === 41 /* OperatorType.In */ || node.d.operator === 42 /* OperatorType.NotIn */) {
|
825
832
|
// Don't apply this rule if it's within an assert.
|
826
833
|
if (!ParseTreeUtils.isWithinAssertExpression(node)) {
|
827
834
|
this._validateContainmentTypes(node);
|
@@ -843,16 +850,16 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
843
850
|
return true;
|
844
851
|
}
|
845
852
|
visitUnaryOperation(node) {
|
846
|
-
if (node.operator === 38 /* OperatorType.Not */) {
|
847
|
-
this._validateConditionalIsBool(node.
|
853
|
+
if (node.d.operator === 38 /* OperatorType.Not */) {
|
854
|
+
this._validateConditionalIsBool(node.d.expr);
|
848
855
|
}
|
849
856
|
this._evaluator.getType(node);
|
850
857
|
return true;
|
851
858
|
}
|
852
859
|
visitTernary(node) {
|
853
860
|
this._evaluator.getType(node);
|
854
|
-
this._validateConditionalIsBool(node.
|
855
|
-
this._reportUnnecessaryConditionExpression(node.
|
861
|
+
this._validateConditionalIsBool(node.d.testExpr);
|
862
|
+
this._reportUnnecessaryConditionExpression(node.d.testExpr);
|
856
863
|
return true;
|
857
864
|
}
|
858
865
|
visitStringList(node) {
|
@@ -869,8 +876,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
869
876
|
curNode = curNode.parent;
|
870
877
|
}
|
871
878
|
}
|
872
|
-
for (const stringNode of node.strings) {
|
873
|
-
const stringTokens = stringNode.nodeType === 49 /* ParseNodeType.String */ ? [stringNode.token] : stringNode.middleTokens;
|
879
|
+
for (const stringNode of node.d.strings) {
|
880
|
+
const stringTokens = stringNode.nodeType === 49 /* ParseNodeType.String */ ? [stringNode.d.token] : stringNode.d.middleTokens;
|
874
881
|
stringTokens.forEach((token) => {
|
875
882
|
const unescapedResult = (0, stringTokenUtils_1.getUnescapedString)(token);
|
876
883
|
let start = token.start;
|
@@ -894,31 +901,32 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
894
901
|
// used the same quote scheme within an f-string.
|
895
902
|
if (fStringContainers.length > 0) {
|
896
903
|
const quoteTypeMask = 1 /* StringTokenFlags.SingleQuote */ | 2 /* StringTokenFlags.DoubleQuote */ | 4 /* StringTokenFlags.Triplicate */;
|
897
|
-
if (fStringContainers.some((fStringContainer) => (fStringContainer.token.flags & quoteTypeMask) ===
|
904
|
+
if (fStringContainers.some((fStringContainer) => (fStringContainer.d.token.flags & quoteTypeMask) ===
|
905
|
+
(stringNode.d.token.flags & quoteTypeMask))) {
|
898
906
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.formatStringNestedQuote(), stringNode);
|
899
907
|
}
|
900
908
|
}
|
901
909
|
}
|
902
|
-
if (node.
|
910
|
+
if (node.d.annotation) {
|
903
911
|
this._evaluator.getType(node);
|
904
912
|
}
|
905
|
-
if (node.strings.length > 1 && !node.
|
913
|
+
if (node.d.strings.length > 1 && !node.d.hasParens) {
|
906
914
|
this._evaluator.addDiagnosticForTextRange(this._fileInfo, diagnosticRules_1.DiagnosticRule.reportImplicitStringConcatenation, localize_1.LocMessage.implicitStringConcat(), node);
|
907
915
|
}
|
908
916
|
return true;
|
909
917
|
}
|
910
918
|
visitFormatString(node) {
|
911
|
-
node.
|
919
|
+
node.d.fieldExprs.forEach((expr) => {
|
912
920
|
this._evaluator.getType(expr);
|
913
921
|
});
|
914
|
-
node.
|
922
|
+
node.d.formatExprs.forEach((expr) => {
|
915
923
|
this._evaluator.getType(expr);
|
916
924
|
});
|
917
925
|
return true;
|
918
926
|
}
|
919
927
|
visitGlobal(node) {
|
920
928
|
this._suppressUnboundCheck(() => {
|
921
|
-
node.
|
929
|
+
node.d.targets.forEach((name) => {
|
922
930
|
this._evaluator.getType(name);
|
923
931
|
this.walk(name);
|
924
932
|
});
|
@@ -927,7 +935,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
927
935
|
}
|
928
936
|
visitNonlocal(node) {
|
929
937
|
this._suppressUnboundCheck(() => {
|
930
|
-
node.
|
938
|
+
node.d.targets.forEach((name) => {
|
931
939
|
this._evaluator.getType(name);
|
932
940
|
this.walk(name);
|
933
941
|
});
|
@@ -947,7 +955,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
947
955
|
return true;
|
948
956
|
}
|
949
957
|
visitDel(node) {
|
950
|
-
node.
|
958
|
+
node.d.targets.forEach((expr) => {
|
951
959
|
this._evaluator.verifyDeleteExpression(expr);
|
952
960
|
this.walk(expr);
|
953
961
|
});
|
@@ -957,14 +965,14 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
957
965
|
var _a;
|
958
966
|
const typeResult = this._evaluator.getTypeResult(node);
|
959
967
|
const type = (_a = typeResult === null || typeResult === void 0 ? void 0 : typeResult.type) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
|
960
|
-
const leftExprType = this._evaluator.getType(node.
|
961
|
-
this._reportDeprecatedUseForType(node.
|
968
|
+
const leftExprType = this._evaluator.getType(node.d.leftExpr);
|
969
|
+
this._reportDeprecatedUseForType(node.d.member, type, leftExprType && (0, types_1.isModule)(leftExprType) && leftExprType.priv.moduleName === 'typing');
|
962
970
|
if (typeResult === null || typeResult === void 0 ? void 0 : typeResult.memberAccessDeprecationInfo) {
|
963
|
-
this._reportDeprecatedUseForMemberAccess(node.
|
971
|
+
this._reportDeprecatedUseForMemberAccess(node.d.member, typeResult.memberAccessDeprecationInfo);
|
964
972
|
}
|
965
|
-
this._conditionallyReportPrivateUsage(node.
|
973
|
+
this._conditionallyReportPrivateUsage(node.d.member);
|
966
974
|
// Walk the leftExpression but not the memberName.
|
967
|
-
this.walk(node.
|
975
|
+
this.walk(node.d.leftExpr);
|
968
976
|
return false;
|
969
977
|
}
|
970
978
|
visitImportAs(node) {
|
@@ -974,27 +982,27 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
974
982
|
}
|
975
983
|
visitImportFrom(node) {
|
976
984
|
// Verify that any "__future__" import occurs at the top of the file.
|
977
|
-
if (node.module.leadingDots === 0 &&
|
978
|
-
node.module.nameParts.length === 1 &&
|
979
|
-
node.module.nameParts[0].value === '__future__') {
|
985
|
+
if (node.d.module.d.leadingDots === 0 &&
|
986
|
+
node.d.module.d.nameParts.length === 1 &&
|
987
|
+
node.d.module.d.nameParts[0].d.value === '__future__') {
|
980
988
|
if (!ParseTreeUtils.isValidLocationForFutureImport(node)) {
|
981
989
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.futureImportLocationNotAllowed(), node);
|
982
990
|
}
|
983
991
|
}
|
984
992
|
this._conditionallyReportShadowedImport(node);
|
985
|
-
if (!node.isWildcardImport) {
|
986
|
-
node.imports.forEach((importAs) => {
|
993
|
+
if (!node.d.isWildcardImport) {
|
994
|
+
node.d.imports.forEach((importAs) => {
|
987
995
|
this._evaluator.evaluateTypesForStatement(importAs);
|
988
996
|
});
|
989
997
|
}
|
990
998
|
else {
|
991
999
|
this._evaluator.evaluateTypesForStatement(node);
|
992
|
-
const importInfo = AnalyzerNodeInfo.getImportInfo(node.module);
|
1000
|
+
const importInfo = AnalyzerNodeInfo.getImportInfo(node.d.module);
|
993
1001
|
if (importInfo &&
|
994
1002
|
importInfo.isImportFound &&
|
995
1003
|
importInfo.importType !== 2 /* ImportType.Local */ &&
|
996
1004
|
!this._fileInfo.isStubFile) {
|
997
|
-
this._evaluator.addDiagnosticForTextRange(this._fileInfo, diagnosticRules_1.DiagnosticRule.reportWildcardImportFromLibrary, localize_1.LocMessage.wildcardLibraryImport(), node.wildcardToken || node);
|
1005
|
+
this._evaluator.addDiagnosticForTextRange(this._fileInfo, diagnosticRules_1.DiagnosticRule.reportWildcardImportFromLibrary, localize_1.LocMessage.wildcardLibraryImport(), node.d.wildcardToken || node);
|
998
1006
|
}
|
999
1007
|
}
|
1000
1008
|
return true;
|
@@ -1004,7 +1012,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1004
1012
|
if (this._fileInfo.isStubFile) {
|
1005
1013
|
return false;
|
1006
1014
|
}
|
1007
|
-
const decls = this._evaluator.getDeclarationsForNameNode(node.name);
|
1015
|
+
const decls = this._evaluator.getDeclarationsForNameNode(node.d.name);
|
1008
1016
|
if (!decls) {
|
1009
1017
|
return false;
|
1010
1018
|
}
|
@@ -1022,19 +1030,19 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1022
1030
|
if (!importResult) {
|
1023
1031
|
continue;
|
1024
1032
|
}
|
1025
|
-
this._addMissingModuleSourceDiagnosticIfNeeded(importResult, node.name);
|
1033
|
+
this._addMissingModuleSourceDiagnosticIfNeeded(importResult, node.d.name);
|
1026
1034
|
break;
|
1027
1035
|
}
|
1028
1036
|
let isImportFromTyping = false;
|
1029
1037
|
if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 25 /* ParseNodeType.ImportFrom */) {
|
1030
|
-
if (node.parent.module.leadingDots === 0 && node.parent.module.nameParts.length === 1) {
|
1031
|
-
if (node.parent.module.nameParts[0].value === 'typing') {
|
1038
|
+
if (node.parent.d.module.d.leadingDots === 0 && node.parent.d.module.d.nameParts.length === 1) {
|
1039
|
+
if (node.parent.d.module.d.nameParts[0].d.value === 'typing') {
|
1032
1040
|
isImportFromTyping = true;
|
1033
1041
|
}
|
1034
1042
|
}
|
1035
1043
|
}
|
1036
|
-
const type = this._evaluator.getType((_b = node.alias) !== null && _b !== void 0 ? _b : node.name);
|
1037
|
-
this._reportDeprecatedUseForType(node.name, type, isImportFromTyping);
|
1044
|
+
const type = this._evaluator.getType((_b = node.d.alias) !== null && _b !== void 0 ? _b : node.d.name);
|
1045
|
+
this._reportDeprecatedUseForType(node.d.name, type, isImportFromTyping);
|
1038
1046
|
return false;
|
1039
1047
|
}
|
1040
1048
|
visitModuleName(node) {
|
@@ -1063,14 +1071,14 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1063
1071
|
}
|
1064
1072
|
if (typeVarScopeNode.nodeType === 10 /* ParseNodeType.Class */) {
|
1065
1073
|
const classType = (_c = this._evaluator.getTypeOfClass(typeVarScopeNode)) === null || _c === void 0 ? void 0 : _c.classType;
|
1066
|
-
if (classType === null || classType === void 0 ? void 0 : classType.
|
1074
|
+
if (classType === null || classType === void 0 ? void 0 : classType.shared.typeParameters.some((param) => param.shared.name === node.d.name.d.value)) {
|
1067
1075
|
foundDuplicate = true;
|
1068
1076
|
break;
|
1069
1077
|
}
|
1070
1078
|
}
|
1071
1079
|
else if (typeVarScopeNode.nodeType === 31 /* ParseNodeType.Function */) {
|
1072
1080
|
const functionType = (_d = this._evaluator.getTypeOfFunction(typeVarScopeNode)) === null || _d === void 0 ? void 0 : _d.functionType;
|
1073
|
-
if (functionType === null || functionType === void 0 ? void 0 : functionType.
|
1081
|
+
if (functionType === null || functionType === void 0 ? void 0 : functionType.shared.typeParameters.some((param) => param.shared.name === node.d.name.d.value)) {
|
1074
1082
|
foundDuplicate = true;
|
1075
1083
|
break;
|
1076
1084
|
}
|
@@ -1078,7 +1086,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1078
1086
|
curNode = typeVarScopeNode.parent;
|
1079
1087
|
}
|
1080
1088
|
if (foundDuplicate) {
|
1081
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarUsedByOuterScope().format({ name: node.name.value }), node.name);
|
1089
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarUsedByOuterScope().format({ name: node.d.name.d.value }), node.d.name);
|
1082
1090
|
}
|
1083
1091
|
return false;
|
1084
1092
|
}
|
@@ -1086,25 +1094,25 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1086
1094
|
const scope = (0, scopeUtils_1.getScopeForNode)(node);
|
1087
1095
|
if (scope) {
|
1088
1096
|
if (scope.type !== 3 /* ScopeType.Class */ && scope.type !== 4 /* ScopeType.Module */ && scope.type !== 5 /* ScopeType.Builtin */) {
|
1089
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeAliasStatementBadScope(), node.name);
|
1097
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeAliasStatementBadScope(), node.d.name);
|
1090
1098
|
}
|
1091
1099
|
}
|
1092
1100
|
return true;
|
1093
1101
|
}
|
1094
1102
|
visitTypeAnnotation(node) {
|
1095
|
-
this._evaluator.getType(node.
|
1103
|
+
this._evaluator.getType(node.d.annotation);
|
1096
1104
|
return true;
|
1097
1105
|
}
|
1098
1106
|
visitMatch(node) {
|
1099
|
-
this._evaluator.getType(node.
|
1107
|
+
this._evaluator.getType(node.d.expr);
|
1100
1108
|
this._validateExhaustiveMatch(node);
|
1101
1109
|
return true;
|
1102
1110
|
}
|
1103
1111
|
visitCase(node) {
|
1104
|
-
if (node.
|
1105
|
-
this._validateConditionalIsBool(node.
|
1112
|
+
if (node.d.guardExpr) {
|
1113
|
+
this._validateConditionalIsBool(node.d.guardExpr);
|
1106
1114
|
}
|
1107
|
-
this._evaluator.evaluateTypesForStatement(node.pattern);
|
1115
|
+
this._evaluator.evaluateTypesForStatement(node.d.pattern);
|
1108
1116
|
return true;
|
1109
1117
|
}
|
1110
1118
|
visitPatternClass(node) {
|
@@ -1118,17 +1126,17 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1118
1126
|
visitError(node) {
|
1119
1127
|
// Get the type of the child so it's available to
|
1120
1128
|
// the completion provider.
|
1121
|
-
if (node.child) {
|
1122
|
-
this._evaluator.getType(node.child);
|
1129
|
+
if (node.d.child) {
|
1130
|
+
this._evaluator.getType(node.d.child);
|
1123
1131
|
}
|
1124
1132
|
// Don't explore further.
|
1125
1133
|
return false;
|
1126
1134
|
}
|
1127
1135
|
_getImportResult(node, uri) {
|
1128
1136
|
const execEnv = this._importResolver.getConfigOptions().findExecEnvironment(uri);
|
1129
|
-
const moduleNameNode = node.parent.module;
|
1137
|
+
const moduleNameNode = node.parent.d.module;
|
1130
1138
|
// Handle both absolute and relative imports.
|
1131
|
-
const moduleName = moduleNameNode.leadingDots === 0
|
1139
|
+
const moduleName = moduleNameNode.d.leadingDots === 0
|
1132
1140
|
? this._importResolver.getModuleNameForImport(uri, execEnv).moduleName
|
1133
1141
|
: (0, importStatementUtils_1.getRelativeModuleName)(this._importResolver.fileSystem, this._fileInfo.fileUri, uri, this._importResolver.getConfigOptions());
|
1134
1142
|
if (!moduleName) {
|
@@ -1190,15 +1198,15 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1190
1198
|
}
|
1191
1199
|
_reportUnnecessaryConditionExpression(expression) {
|
1192
1200
|
if (expression.nodeType === 7 /* ParseNodeType.BinaryOperation */) {
|
1193
|
-
if (expression.operator === 36 /* OperatorType.And */ || expression.operator === 37 /* OperatorType.Or */) {
|
1194
|
-
this._reportUnnecessaryConditionExpression(expression.
|
1195
|
-
this._reportUnnecessaryConditionExpression(expression.
|
1201
|
+
if (expression.d.operator === 36 /* OperatorType.And */ || expression.d.operator === 37 /* OperatorType.Or */) {
|
1202
|
+
this._reportUnnecessaryConditionExpression(expression.d.leftExpr);
|
1203
|
+
this._reportUnnecessaryConditionExpression(expression.d.rightExpr);
|
1196
1204
|
}
|
1197
1205
|
return;
|
1198
1206
|
}
|
1199
1207
|
else if (expression.nodeType === 55 /* ParseNodeType.UnaryOperation */) {
|
1200
|
-
if (expression.operator === 38 /* OperatorType.Not */) {
|
1201
|
-
this._reportUnnecessaryConditionExpression(expression.
|
1208
|
+
if (expression.d.operator === 38 /* OperatorType.Not */) {
|
1209
|
+
this._reportUnnecessaryConditionExpression(expression.d.expr);
|
1202
1210
|
}
|
1203
1211
|
return;
|
1204
1212
|
}
|
@@ -1242,16 +1250,16 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1242
1250
|
node.nodeType === 45 /* ParseNodeType.Set */ ||
|
1243
1251
|
node.nodeType === 18 /* ParseNodeType.Dictionary */) {
|
1244
1252
|
// Exclude comprehensions.
|
1245
|
-
if (!node.
|
1253
|
+
if (!node.d.items.some((entry) => entry.nodeType === 11 /* ParseNodeType.Comprehension */)) {
|
1246
1254
|
reportAsUnused = true;
|
1247
1255
|
}
|
1248
1256
|
}
|
1249
1257
|
if (reportAsUnused &&
|
1250
1258
|
this._fileInfo.ipythonMode === sourceFile_1.IPythonMode.CellDocs &&
|
1251
1259
|
((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 47 /* ParseNodeType.StatementList */ &&
|
1252
|
-
node.parent.statements[node.parent.statements.length - 1] === node &&
|
1260
|
+
node.parent.d.statements[node.parent.d.statements.length - 1] === node &&
|
1253
1261
|
((_b = node.parent.parent) === null || _b === void 0 ? void 0 : _b.nodeType) === 36 /* ParseNodeType.Module */ &&
|
1254
|
-
node.parent.parent.statements[node.parent.parent.statements.length - 1] === node.parent) {
|
1262
|
+
node.parent.parent.d.statements[node.parent.parent.d.statements.length - 1] === node.parent) {
|
1255
1263
|
// Exclude an expression at the end of a notebook cell, as that is treated as
|
1256
1264
|
// the cell's value.
|
1257
1265
|
reportAsUnused = false;
|
@@ -1274,7 +1282,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1274
1282
|
type: this._evaluator.printType(narrowedTypeResult.type),
|
1275
1283
|
}));
|
1276
1284
|
diagAddendum.addMessage(localize_1.LocAddendum.matchIsNotExhaustiveHint());
|
1277
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportMatchNotExhaustive, localize_1.LocMessage.matchIsNotExhaustive() + diagAddendum.getString(), node.
|
1285
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportMatchNotExhaustive, localize_1.LocMessage.matchIsNotExhaustive() + diagAddendum.getString(), node.d.expr);
|
1278
1286
|
}
|
1279
1287
|
}
|
1280
1288
|
_suppressUnboundCheck(callback) {
|
@@ -1295,24 +1303,24 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1295
1303
|
}
|
1296
1304
|
}
|
1297
1305
|
_validateStandardCollectionInstantiation(node) {
|
1298
|
-
const leftType = this._evaluator.getType(node.
|
1306
|
+
const leftType = this._evaluator.getType(node.d.leftExpr);
|
1299
1307
|
if (leftType &&
|
1300
1308
|
(0, types_1.isInstantiableClass)(leftType) &&
|
1301
1309
|
types_1.ClassType.isBuiltIn(leftType) &&
|
1302
|
-
!leftType.includeSubclasses &&
|
1303
|
-
leftType.aliasName) {
|
1310
|
+
!leftType.priv.includeSubclasses &&
|
1311
|
+
leftType.priv.aliasName) {
|
1304
1312
|
const nonInstantiable = ['List', 'Set', 'Dict', 'Tuple'];
|
1305
|
-
if (nonInstantiable.some((name) => name === leftType.aliasName)) {
|
1313
|
+
if (nonInstantiable.some((name) => name === leftType.priv.aliasName)) {
|
1306
1314
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.collectionAliasInstantiation().format({
|
1307
|
-
type: leftType.aliasName,
|
1308
|
-
alias: leftType.
|
1309
|
-
}), node.
|
1315
|
+
type: leftType.priv.aliasName,
|
1316
|
+
alias: leftType.shared.name,
|
1317
|
+
}), node.d.leftExpr);
|
1310
1318
|
}
|
1311
1319
|
}
|
1312
1320
|
}
|
1313
1321
|
_validateContainmentTypes(node) {
|
1314
|
-
const leftType = this._evaluator.getType(node.
|
1315
|
-
const containerType = this._evaluator.getType(node.
|
1322
|
+
const leftType = this._evaluator.getType(node.d.leftExpr);
|
1323
|
+
const containerType = this._evaluator.getType(node.d.rightExpr);
|
1316
1324
|
if (!leftType || !containerType) {
|
1317
1325
|
return;
|
1318
1326
|
}
|
@@ -1327,7 +1335,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1327
1335
|
const narrowedType = (0, typeGuards_1.narrowTypeForContainerElementType)(this._evaluator, leftType, this._evaluator.makeTopLevelTypeVarsConcrete(elementType));
|
1328
1336
|
if ((0, types_1.isNever)(narrowedType)) {
|
1329
1337
|
const getMessage = () => {
|
1330
|
-
return node.operator === 41 /* OperatorType.In */
|
1338
|
+
return node.d.operator === 41 /* OperatorType.In */
|
1331
1339
|
? localize_1.LocMessage.containmentAlwaysFalse()
|
1332
1340
|
: localize_1.LocMessage.containmentAlwaysTrue();
|
1333
1341
|
};
|
@@ -1340,11 +1348,11 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1340
1348
|
// Determines whether the types of the two operands for an "is" or "is not"
|
1341
1349
|
// operation have overlapping types.
|
1342
1350
|
_validateComparisonTypesForIsOperator(node) {
|
1343
|
-
const rightType = this._evaluator.getType(node.
|
1351
|
+
const rightType = this._evaluator.getType(node.d.rightExpr);
|
1344
1352
|
if (!rightType || !(0, typeUtils_1.isNoneInstance)(rightType)) {
|
1345
1353
|
return;
|
1346
1354
|
}
|
1347
|
-
const leftType = this._evaluator.getType(node.
|
1355
|
+
const leftType = this._evaluator.getType(node.d.leftExpr);
|
1348
1356
|
if (!leftType) {
|
1349
1357
|
return;
|
1350
1358
|
}
|
@@ -1356,7 +1364,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1356
1364
|
}
|
1357
1365
|
});
|
1358
1366
|
const getMessage = () => {
|
1359
|
-
return node.operator === 39 /* OperatorType.Is */
|
1367
|
+
return node.d.operator === 39 /* OperatorType.Is */
|
1360
1368
|
? localize_1.LocMessage.comparisonAlwaysFalse()
|
1361
1369
|
: localize_1.LocMessage.comparisonAlwaysTrue();
|
1362
1370
|
};
|
@@ -1370,15 +1378,15 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1370
1378
|
// Determines whether the types of the two operands for an == or != operation
|
1371
1379
|
// have overlapping types.
|
1372
1380
|
_validateComparisonTypes(node) {
|
1373
|
-
let rightExpression = node.
|
1381
|
+
let rightExpression = node.d.rightExpr;
|
1374
1382
|
// Check for chained comparisons.
|
1375
1383
|
if (rightExpression.nodeType === 7 /* ParseNodeType.BinaryOperation */ &&
|
1376
|
-
!rightExpression.
|
1377
|
-
ParseTreeUtils.operatorSupportsChaining(rightExpression.operator)) {
|
1384
|
+
!rightExpression.d.hasParens &&
|
1385
|
+
ParseTreeUtils.operatorSupportsChaining(rightExpression.d.operator)) {
|
1378
1386
|
// Use the left side of the right expression for comparison purposes.
|
1379
|
-
rightExpression = rightExpression.
|
1387
|
+
rightExpression = rightExpression.d.leftExpr;
|
1380
1388
|
}
|
1381
|
-
const leftType = this._evaluator.getType(node.
|
1389
|
+
const leftType = this._evaluator.getType(node.d.leftExpr);
|
1382
1390
|
const rightType = this._evaluator.getType(rightExpression);
|
1383
1391
|
if (!leftType || !rightType) {
|
1384
1392
|
return;
|
@@ -1387,7 +1395,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1387
1395
|
return;
|
1388
1396
|
}
|
1389
1397
|
const getMessage = () => {
|
1390
|
-
return node.operator === 12 /* OperatorType.Equals */
|
1398
|
+
return node.d.operator === 12 /* OperatorType.Equals */
|
1391
1399
|
? localize_1.LocMessage.comparisonAlwaysFalse()
|
1392
1400
|
: localize_1.LocMessage.comparisonAlwaysTrue();
|
1393
1401
|
};
|
@@ -1471,7 +1479,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1471
1479
|
}
|
1472
1480
|
}
|
1473
1481
|
// Does the class have an operator overload for eq?
|
1474
|
-
const metaclass = leftType.
|
1482
|
+
const metaclass = leftType.shared.effectiveMetaclass;
|
1475
1483
|
if (metaclass && (0, types_1.isClass)(metaclass)) {
|
1476
1484
|
if ((0, typeUtils_1.lookUpClassMember)(metaclass, '__eq__', 4 /* MemberAccessFlags.SkipObjectBaseClass */)) {
|
1477
1485
|
return true;
|
@@ -1518,19 +1526,19 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1518
1526
|
if (!types_1.FunctionType.isGenerator(functionType)) {
|
1519
1527
|
return;
|
1520
1528
|
}
|
1521
|
-
const declaredReturnType = functionType.
|
1529
|
+
const declaredReturnType = functionType.shared.declaredReturnType;
|
1522
1530
|
if (!declaredReturnType) {
|
1523
1531
|
return;
|
1524
1532
|
}
|
1525
1533
|
if ((0, types_1.isNever)(declaredReturnType)) {
|
1526
1534
|
return;
|
1527
1535
|
}
|
1528
|
-
const functionDecl = functionType.
|
1536
|
+
const functionDecl = functionType.shared.declaration;
|
1529
1537
|
if (!functionDecl || !functionDecl.yieldStatements || functionDecl.yieldStatements.length === 0) {
|
1530
1538
|
return;
|
1531
1539
|
}
|
1532
1540
|
let generatorType;
|
1533
|
-
if (!node.isAsync &&
|
1541
|
+
if (!node.d.isAsync &&
|
1534
1542
|
(0, types_1.isClassInstance)(declaredReturnType) &&
|
1535
1543
|
types_1.ClassType.isBuiltIn(declaredReturnType, 'AwaitableGenerator')) {
|
1536
1544
|
// Handle the old-style (pre-await) generator case
|
@@ -1538,7 +1546,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1538
1546
|
generatorType = this._evaluator.getTypingType(node, 'AwaitableGenerator');
|
1539
1547
|
}
|
1540
1548
|
else {
|
1541
|
-
generatorType = this._evaluator.getTypingType(node, node.isAsync ? 'AsyncGenerator' : 'Generator');
|
1549
|
+
generatorType = this._evaluator.getTypingType(node, node.d.isAsync ? 'AsyncGenerator' : 'Generator');
|
1542
1550
|
}
|
1543
1551
|
if (!generatorType || !(0, types_1.isInstantiableClass)(generatorType)) {
|
1544
1552
|
return;
|
@@ -1547,11 +1555,11 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1547
1555
|
/* isTypeArgumentExplicit */ true));
|
1548
1556
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
1549
1557
|
if (!this._evaluator.assignType(declaredReturnType, specializedGenerator, diagAddendum)) {
|
1550
|
-
const errorMessage = node.isAsync
|
1558
|
+
const errorMessage = node.d.isAsync
|
1551
1559
|
? localize_1.LocMessage.generatorAsyncReturnType()
|
1552
1560
|
: localize_1.LocMessage.generatorSyncReturnType();
|
1553
1561
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, errorMessage.format({ yieldType: this._evaluator.printType(types_1.AnyType.create()) }) +
|
1554
|
-
diagAddendum.getString(), (_a = node.
|
1562
|
+
diagAddendum.getString(), (_a = node.d.returnAnnotation) !== null && _a !== void 0 ? _a : node.d.name);
|
1555
1563
|
}
|
1556
1564
|
}
|
1557
1565
|
// Determines whether the specified type is one that should trigger
|
@@ -1572,7 +1580,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1572
1580
|
let curParamNode;
|
1573
1581
|
// Is this a constructor (an __init__ method) for a generic class?
|
1574
1582
|
let constructorClass;
|
1575
|
-
if (types_1.FunctionType.isInstanceMethod(type) && node.name.value === '__init__') {
|
1583
|
+
if (types_1.FunctionType.isInstanceMethod(type) && node.d.name.d.value === '__init__') {
|
1576
1584
|
const containingClassNode = ParseTreeUtils.getEnclosingClassOrFunction(node);
|
1577
1585
|
if (containingClassNode && containingClassNode.nodeType === 10 /* ParseNodeType.Class */) {
|
1578
1586
|
const classType = this._evaluator.getTypeOfClass(containingClassNode);
|
@@ -1582,17 +1590,17 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1582
1590
|
}
|
1583
1591
|
}
|
1584
1592
|
const nameWalker = new ParseTreeUtils.NameNodeWalker((nameNode, subscriptIndex, baseExpression) => {
|
1585
|
-
var _a, _b, _c, _d, _e, _f;
|
1593
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
1586
1594
|
const nameType = this._evaluator.getType(nameNode);
|
1587
1595
|
``;
|
1588
|
-
if (nameType && (0, types_1.isTypeVar)(nameType) && !nameType.
|
1596
|
+
if (nameType && (0, types_1.isTypeVar)(nameType) && !nameType.shared.isSynthesizedSelf) {
|
1589
1597
|
// Does this name refer to a TypeVar that is scoped to this function?
|
1590
|
-
if (nameType.scopeId === ParseTreeUtils.getScopeIdForNode(node)) {
|
1598
|
+
if (nameType.priv.scopeId === ParseTreeUtils.getScopeIdForNode(node)) {
|
1591
1599
|
// We exempt constrained TypeVars, TypeVars that are type arguments of
|
1592
1600
|
// other types, and ParamSpecs. There are legitimate uses for singleton
|
1593
1601
|
// instances in these particular cases.
|
1594
|
-
let isExempt = nameType.
|
1595
|
-
nameType.
|
1602
|
+
let isExempt = nameType.shared.constraints.length > 0 ||
|
1603
|
+
nameType.shared.isDefaultExplicit ||
|
1596
1604
|
(exemptBoundTypeVar && subscriptIndex !== undefined) ||
|
1597
1605
|
(0, types_1.isParamSpec)(nameType);
|
1598
1606
|
if (!isExempt && baseExpression && subscriptIndex !== undefined) {
|
@@ -1600,22 +1608,21 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1600
1608
|
// exempt it from the check because the type alias may repeat
|
1601
1609
|
// the TypeVar multiple times.
|
1602
1610
|
const baseType = this._evaluator.getType(baseExpression);
|
1603
|
-
|
1604
|
-
|
1605
|
-
subscriptIndex < baseType.typeAliasInfo.typeParameters.length) {
|
1611
|
+
const aliasInfo = (_a = baseType === null || baseType === void 0 ? void 0 : baseType.props) === null || _a === void 0 ? void 0 : _a.typeAliasInfo;
|
1612
|
+
if ((aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.typeParameters) && subscriptIndex < aliasInfo.typeParameters.length) {
|
1606
1613
|
isExempt = true;
|
1607
1614
|
}
|
1608
1615
|
}
|
1609
|
-
const existingEntry = localTypeVarUsage.get(nameType.
|
1610
|
-
const isParamTypeWithEllipsisUsage = ((
|
1616
|
+
const existingEntry = localTypeVarUsage.get(nameType.shared.name);
|
1617
|
+
const isParamTypeWithEllipsisUsage = ((_b = curParamNode === null || curParamNode === void 0 ? void 0 : curParamNode.d.defaultValue) === null || _b === void 0 ? void 0 : _b.nodeType) === 21 /* ParseNodeType.Ellipsis */;
|
1611
1618
|
if (!existingEntry) {
|
1612
|
-
localTypeVarUsage.set(nameType.
|
1619
|
+
localTypeVarUsage.set(nameType.shared.name, {
|
1613
1620
|
nodes: [nameNode],
|
1614
1621
|
typeVar: nameType,
|
1615
1622
|
paramTypeUsageCount: curParamNode !== undefined ? 1 : 0,
|
1616
1623
|
paramTypeWithEllipsisUsageCount: isParamTypeWithEllipsisUsage ? 1 : 0,
|
1617
1624
|
returnTypeUsageCount: curParamNode === undefined ? 1 : 0,
|
1618
|
-
paramWithEllipsis: isParamTypeWithEllipsisUsage ? (
|
1625
|
+
paramWithEllipsis: isParamTypeWithEllipsisUsage ? (_c = curParamNode === null || curParamNode === void 0 ? void 0 : curParamNode.d.name) === null || _c === void 0 ? void 0 : _c.d.value : undefined,
|
1619
1626
|
isExempt,
|
1620
1627
|
});
|
1621
1628
|
}
|
@@ -1626,7 +1633,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1626
1633
|
if (isParamTypeWithEllipsisUsage) {
|
1627
1634
|
existingEntry.paramTypeWithEllipsisUsageCount += 1;
|
1628
1635
|
if (!existingEntry.paramWithEllipsis) {
|
1629
|
-
existingEntry.paramWithEllipsis = (
|
1636
|
+
existingEntry.paramWithEllipsis = (_d = curParamNode === null || curParamNode === void 0 ? void 0 : curParamNode.d.name) === null || _d === void 0 ? void 0 : _d.d.value;
|
1630
1637
|
}
|
1631
1638
|
}
|
1632
1639
|
}
|
@@ -1637,18 +1644,18 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1637
1644
|
}
|
1638
1645
|
// Does this name refer to a TypeVar that is scoped to the class associated with
|
1639
1646
|
// this constructor method?
|
1640
|
-
if (constructorClass && nameType.scopeId === constructorClass.
|
1641
|
-
const existingEntry = classTypeVarUsage.get(nameType.
|
1642
|
-
const isParamTypeWithEllipsisUsage = ((
|
1643
|
-
const isExempt = !!nameType.
|
1647
|
+
if (constructorClass && nameType.priv.scopeId === constructorClass.shared.typeVarScopeId) {
|
1648
|
+
const existingEntry = classTypeVarUsage.get(nameType.shared.name);
|
1649
|
+
const isParamTypeWithEllipsisUsage = ((_e = curParamNode === null || curParamNode === void 0 ? void 0 : curParamNode.d.defaultValue) === null || _e === void 0 ? void 0 : _e.nodeType) === 21 /* ParseNodeType.Ellipsis */;
|
1650
|
+
const isExempt = !!nameType.shared.isDefaultExplicit;
|
1644
1651
|
if (!existingEntry) {
|
1645
|
-
classTypeVarUsage.set(nameType.
|
1652
|
+
classTypeVarUsage.set(nameType.shared.name, {
|
1646
1653
|
typeVar: nameType,
|
1647
1654
|
nodes: [nameNode],
|
1648
1655
|
paramTypeUsageCount: curParamNode !== undefined ? 1 : 0,
|
1649
1656
|
paramTypeWithEllipsisUsageCount: isParamTypeWithEllipsisUsage ? 1 : 0,
|
1650
1657
|
returnTypeUsageCount: 0,
|
1651
|
-
paramWithEllipsis: isParamTypeWithEllipsisUsage ? (
|
1658
|
+
paramWithEllipsis: isParamTypeWithEllipsisUsage ? (_f = curParamNode === null || curParamNode === void 0 ? void 0 : curParamNode.d.name) === null || _f === void 0 ? void 0 : _f.d.value : undefined,
|
1652
1659
|
isExempt,
|
1653
1660
|
});
|
1654
1661
|
}
|
@@ -1659,7 +1666,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1659
1666
|
if (isParamTypeWithEllipsisUsage) {
|
1660
1667
|
existingEntry.paramTypeWithEllipsisUsageCount += 1;
|
1661
1668
|
if (!existingEntry.paramWithEllipsis) {
|
1662
|
-
existingEntry.paramWithEllipsis = (
|
1669
|
+
existingEntry.paramWithEllipsis = (_g = curParamNode === null || curParamNode === void 0 ? void 0 : curParamNode.d.name) === null || _g === void 0 ? void 0 : _g.d.value;
|
1663
1670
|
}
|
1664
1671
|
}
|
1665
1672
|
}
|
@@ -1668,28 +1675,28 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1668
1675
|
}
|
1669
1676
|
});
|
1670
1677
|
// Find all of the local type variables in signature.
|
1671
|
-
node.
|
1672
|
-
const annotation = param.
|
1678
|
+
node.d.params.forEach((param) => {
|
1679
|
+
const annotation = param.d.annotation || param.d.annotationComment;
|
1673
1680
|
if (annotation) {
|
1674
1681
|
curParamNode = param;
|
1675
1682
|
nameWalker.walk(annotation);
|
1676
1683
|
}
|
1677
1684
|
});
|
1678
1685
|
curParamNode = undefined;
|
1679
|
-
if (node.
|
1686
|
+
if (node.d.returnAnnotation) {
|
1680
1687
|
// Don't exempt the use of a bound TypeVar when used as a type argument
|
1681
1688
|
// within a return type. This exemption applies only to input parameter
|
1682
1689
|
// annotations.
|
1683
1690
|
exemptBoundTypeVar = false;
|
1684
|
-
nameWalker.walk(node.
|
1691
|
+
nameWalker.walk(node.d.returnAnnotation);
|
1685
1692
|
}
|
1686
|
-
if (node.
|
1687
|
-
node.
|
1693
|
+
if (node.d.funcAnnotationComment) {
|
1694
|
+
node.d.funcAnnotationComment.d.paramAnnotations.forEach((expr) => {
|
1688
1695
|
nameWalker.walk(expr);
|
1689
1696
|
});
|
1690
|
-
if (node.
|
1697
|
+
if (node.d.funcAnnotationComment.d.returnAnnotation) {
|
1691
1698
|
exemptBoundTypeVar = false;
|
1692
|
-
nameWalker.walk(node.
|
1699
|
+
nameWalker.walk(node.d.funcAnnotationComment.d.returnAnnotation);
|
1693
1700
|
}
|
1694
1701
|
}
|
1695
1702
|
localTypeVarUsage.forEach((usage) => {
|
@@ -1697,11 +1704,11 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1697
1704
|
// Report error for local type variable that appears only once.
|
1698
1705
|
if (usage.nodes.length === 1 && !usage.isExempt) {
|
1699
1706
|
let altTypeText;
|
1700
|
-
if (usage.typeVar.
|
1707
|
+
if (usage.typeVar.shared.isVariadic) {
|
1701
1708
|
altTypeText = '"tuple[object, ...]"';
|
1702
1709
|
}
|
1703
|
-
else if (usage.typeVar.
|
1704
|
-
altTypeText = `"${this._evaluator.printType((0, typeUtils_1.convertToInstance)(usage.typeVar.
|
1710
|
+
else if (usage.typeVar.shared.boundType) {
|
1711
|
+
altTypeText = `"${this._evaluator.printType((0, typeUtils_1.convertToInstance)(usage.typeVar.shared.boundType))}"`;
|
1705
1712
|
}
|
1706
1713
|
else {
|
1707
1714
|
altTypeText = '"object"';
|
@@ -1711,21 +1718,21 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1711
1718
|
type: altTypeText,
|
1712
1719
|
}));
|
1713
1720
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeVarUse, localize_1.LocMessage.typeVarUsedOnlyOnce().format({
|
1714
|
-
name: usage.nodes[0].value,
|
1721
|
+
name: usage.nodes[0].d.value,
|
1715
1722
|
}) + diag.getString(), usage.nodes[0]);
|
1716
1723
|
}
|
1717
1724
|
// Report error for local type variable that appears in return type
|
1718
1725
|
// (but not as a top-level TypeVar within a union) and appears only
|
1719
1726
|
// within parameters that have default values. These may go unsolved.
|
1720
1727
|
let isUsedInReturnType = usage.returnTypeUsageCount > 0;
|
1721
|
-
if (usage.returnTypeUsageCount === 1 && type.
|
1728
|
+
if (usage.returnTypeUsageCount === 1 && type.shared.declaredReturnType) {
|
1722
1729
|
// If the TypeVar appears only once in the return type and it's a top-level
|
1723
1730
|
// TypeVar within a union, exempt it from this check. Although these
|
1724
1731
|
// TypeVars may go unsolved, they can be safely eliminated from the union
|
1725
1732
|
// without generating an Unknown type.
|
1726
|
-
const returnType = type.
|
1733
|
+
const returnType = type.shared.declaredReturnType;
|
1727
1734
|
if ((0, types_1.isUnion)(returnType) &&
|
1728
|
-
returnType.subtypes.some((subtype) => (0, types_1.isTypeVar)(subtype) && subtype.
|
1735
|
+
returnType.priv.subtypes.some((subtype) => (0, types_1.isTypeVar)(subtype) && subtype.shared.name === usage.nodes[0].d.value)) {
|
1729
1736
|
isUsedInReturnType = false;
|
1730
1737
|
}
|
1731
1738
|
}
|
@@ -1740,7 +1747,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1740
1747
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
1741
1748
|
diag.addMessage(localize_1.LocAddendum.typeVarUnsolvableRemedy());
|
1742
1749
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeVarUse, localize_1.LocMessage.typeVarPossiblyUnsolvable().format({
|
1743
|
-
name: usage.nodes[0].value,
|
1750
|
+
name: usage.nodes[0].d.value,
|
1744
1751
|
param: (_a = usage.paramWithEllipsis) !== null && _a !== void 0 ? _a : '',
|
1745
1752
|
}) + diag.getString(), usage.nodes[0]);
|
1746
1753
|
}
|
@@ -1755,7 +1762,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1755
1762
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
1756
1763
|
diag.addMessage(localize_1.LocAddendum.typeVarUnsolvableRemedy());
|
1757
1764
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeVarUse, localize_1.LocMessage.typeVarPossiblyUnsolvable().format({
|
1758
|
-
name: usage.nodes[0].value,
|
1765
|
+
name: usage.nodes[0].d.value,
|
1759
1766
|
param: (_a = usage.paramWithEllipsis) !== null && _a !== void 0 ? _a : '',
|
1760
1767
|
}) + diag.getString(), usage.nodes[0]);
|
1761
1768
|
}
|
@@ -1766,7 +1773,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1766
1773
|
var _a, _b, _c, _d, _e, _f;
|
1767
1774
|
let staticMethodCount = 0;
|
1768
1775
|
let classMethodCount = 0;
|
1769
|
-
functionType.overloads.forEach((overload) => {
|
1776
|
+
functionType.priv.overloads.forEach((overload) => {
|
1770
1777
|
if (types_1.FunctionType.isStaticMethod(overload)) {
|
1771
1778
|
staticMethodCount++;
|
1772
1779
|
}
|
@@ -1774,15 +1781,15 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1774
1781
|
classMethodCount++;
|
1775
1782
|
}
|
1776
1783
|
});
|
1777
|
-
if (staticMethodCount > 0 && staticMethodCount < functionType.overloads.length) {
|
1784
|
+
if (staticMethodCount > 0 && staticMethodCount < functionType.priv.overloads.length) {
|
1778
1785
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInconsistentOverload, localize_1.LocMessage.overloadStaticMethodInconsistent().format({
|
1779
|
-
name: node.name.value,
|
1780
|
-
}), (_c = (_b = (_a = functionType.overloads[0]) === null || _a === void 0 ? void 0 : _a.
|
1786
|
+
name: node.d.name.d.value,
|
1787
|
+
}), (_c = (_b = (_a = functionType.priv.overloads[0]) === null || _a === void 0 ? void 0 : _a.shared.declaration) === null || _b === void 0 ? void 0 : _b.node.d.name) !== null && _c !== void 0 ? _c : node.d.name);
|
1781
1788
|
}
|
1782
|
-
if (classMethodCount > 0 && classMethodCount < functionType.overloads.length) {
|
1789
|
+
if (classMethodCount > 0 && classMethodCount < functionType.priv.overloads.length) {
|
1783
1790
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInconsistentOverload, localize_1.LocMessage.overloadClassMethodInconsistent().format({
|
1784
|
-
name: node.name.value,
|
1785
|
-
}), (_f = (_e = (_d = functionType.overloads[0]) === null || _d === void 0 ? void 0 : _d.
|
1791
|
+
name: node.d.name.d.value,
|
1792
|
+
}), (_f = (_e = (_d = functionType.priv.overloads[0]) === null || _d === void 0 ? void 0 : _d.shared.declaration) === null || _e === void 0 ? void 0 : _e.node.d.name) !== null && _f !== void 0 ? _f : node.d.name);
|
1786
1793
|
}
|
1787
1794
|
}
|
1788
1795
|
// Validates that overloads do not overlap with inconsistent return results.
|
@@ -1791,10 +1798,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1791
1798
|
const prevOverload = prevOverloads[i];
|
1792
1799
|
if (this._isOverlappingOverload(functionType, prevOverload, /* partialOverlap */ false)) {
|
1793
1800
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportOverlappingOverload, localize_1.LocMessage.overlappingOverload().format({
|
1794
|
-
name: node.name.value,
|
1801
|
+
name: node.d.name.d.value,
|
1795
1802
|
obscured: prevOverloads.length + 1,
|
1796
1803
|
obscuredBy: i + 1,
|
1797
|
-
}), node.name);
|
1804
|
+
}), node.d.name);
|
1798
1805
|
break;
|
1799
1806
|
}
|
1800
1807
|
}
|
@@ -1810,10 +1817,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1810
1817
|
/* srcTypeVarContext */ undefined, 8 /* AssignTypeFlags.SkipSolveTypeVars */ | 1024 /* AssignTypeFlags.IgnoreTypeVarScope */)) {
|
1811
1818
|
const altNode = this._findNodeForOverload(node, prevOverload);
|
1812
1819
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportOverlappingOverload, localize_1.LocMessage.overloadReturnTypeMismatch().format({
|
1813
|
-
name: node.name.value,
|
1820
|
+
name: node.d.name.d.value,
|
1814
1821
|
newIndex: prevOverloads.length + 1,
|
1815
1822
|
prevIndex: i + 1,
|
1816
|
-
}), (altNode || node).name);
|
1823
|
+
}), (altNode || node).d.name);
|
1817
1824
|
break;
|
1818
1825
|
}
|
1819
1826
|
}
|
@@ -1823,7 +1830,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1823
1830
|
// earlier overload. Typeshed stubs contain type: ignore comments on these
|
1824
1831
|
// lines, so it is important for us to report them in the same manner.
|
1825
1832
|
_findNodeForOverload(functionNode, overloadType) {
|
1826
|
-
const decls = this._evaluator.getDeclarationsForNameNode(functionNode.name);
|
1833
|
+
const decls = this._evaluator.getDeclarationsForNameNode(functionNode.d.name);
|
1827
1834
|
if (!decls) {
|
1828
1835
|
return undefined;
|
1829
1836
|
}
|
@@ -1843,15 +1850,15 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1843
1850
|
// the case, but for consistency with other type checkers, we'll honor
|
1844
1851
|
// this rule. See https://github.com/python/typing/issues/253#issuecomment-389262904
|
1845
1852
|
// for details.
|
1846
|
-
if (types_1.FunctionType.isInstanceMethod(functionType) && functionType.
|
1853
|
+
if (types_1.FunctionType.isInstanceMethod(functionType) && functionType.shared.name === '__get__') {
|
1847
1854
|
return false;
|
1848
1855
|
}
|
1849
|
-
let flags = 64 /* AssignTypeFlags.
|
1856
|
+
let flags = 64 /* AssignTypeFlags.SkipReturnTypeCheck */ | 16 /* AssignTypeFlags.OverloadOverlap */;
|
1850
1857
|
if (partialOverlap) {
|
1851
|
-
flags |= 32 /* AssignTypeFlags.
|
1858
|
+
flags |= 32 /* AssignTypeFlags.PartialOverloadOverlap */;
|
1852
1859
|
}
|
1853
1860
|
return this._evaluator.assignType(functionType, prevOverload,
|
1854
|
-
/* diag */ undefined, new typeVarContext_1.TypeVarContext(
|
1861
|
+
/* diag */ undefined, new typeVarContext_1.TypeVarContext(),
|
1855
1862
|
/* srcTypeVarContext */ undefined, flags);
|
1856
1863
|
}
|
1857
1864
|
_isLegalOverloadImplementation(overload, implementation, diag) {
|
@@ -1859,12 +1866,12 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1859
1866
|
const implTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(implementation));
|
1860
1867
|
const overloadTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(overload));
|
1861
1868
|
// First check the parameters to see if they are assignable.
|
1862
|
-
let isLegal = this._evaluator.assignType(overload, implementation, diag, overloadTypeVarContext, implTypeVarContext, 64 /* AssignTypeFlags.
|
1869
|
+
let isLegal = this._evaluator.assignType(overload, implementation, diag, overloadTypeVarContext, implTypeVarContext, 64 /* AssignTypeFlags.SkipReturnTypeCheck */ |
|
1863
1870
|
2 /* AssignTypeFlags.ReverseTypeVarMatching */ |
|
1864
1871
|
512 /* AssignTypeFlags.SkipSelfClsTypeCheck */);
|
1865
1872
|
// Now check the return types.
|
1866
|
-
const overloadReturnType = (_a = overload.
|
1867
|
-
const implementationReturnType = (0, typeUtils_1.applySolvedTypeVars)(implementation.
|
1873
|
+
const overloadReturnType = (_a = overload.shared.declaredReturnType) !== null && _a !== void 0 ? _a : this._evaluator.getFunctionInferredReturnType(overload);
|
1874
|
+
const implementationReturnType = (0, typeUtils_1.applySolvedTypeVars)(implementation.shared.declaredReturnType || this._evaluator.getFunctionInferredReturnType(implementation), implTypeVarContext);
|
1868
1875
|
const returnDiag = new diagnostic_1.DiagnosticAddendum();
|
1869
1876
|
if (!(0, types_1.isNever)(overloadReturnType) &&
|
1870
1877
|
!this._evaluator.assignType(implementationReturnType, overloadReturnType, returnDiag.createAddendum(), implTypeVarContext, overloadTypeVarContext, 8 /* AssignTypeFlags.SkipSolveTypeVars */)) {
|
@@ -1919,7 +1926,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1919
1926
|
break;
|
1920
1927
|
}
|
1921
1928
|
case 47 /* ParseNodeType.StatementList */: {
|
1922
|
-
for (const substatement of statement.statements) {
|
1929
|
+
for (const substatement of statement.d.statements) {
|
1923
1930
|
let isValid = true;
|
1924
1931
|
switch (substatement.nodeType) {
|
1925
1932
|
case 2 /* ParseNodeType.Assert */:
|
@@ -1959,17 +1966,17 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1959
1966
|
case 5 /* ParseNodeType.AugmentedAssignment */: {
|
1960
1967
|
// Exempt __all__ manipulations.
|
1961
1968
|
isValid =
|
1962
|
-
substatement.operator === 1 /* OperatorType.AddEqual */ &&
|
1963
|
-
substatement.
|
1964
|
-
substatement.
|
1969
|
+
substatement.d.operator === 1 /* OperatorType.AddEqual */ &&
|
1970
|
+
substatement.d.leftExpr.nodeType === 38 /* ParseNodeType.Name */ &&
|
1971
|
+
substatement.d.leftExpr.d.value === '__all__';
|
1965
1972
|
break;
|
1966
1973
|
}
|
1967
1974
|
case 9 /* ParseNodeType.Call */: {
|
1968
1975
|
// Exempt __all__ manipulations.
|
1969
1976
|
isValid =
|
1970
|
-
substatement.
|
1971
|
-
substatement.
|
1972
|
-
substatement.
|
1977
|
+
substatement.d.leftExpr.nodeType === 35 /* ParseNodeType.MemberAccess */ &&
|
1978
|
+
substatement.d.leftExpr.d.leftExpr.nodeType === 38 /* ParseNodeType.Name */ &&
|
1979
|
+
substatement.d.leftExpr.d.leftExpr.d.value === '__all__';
|
1973
1980
|
break;
|
1974
1981
|
}
|
1975
1982
|
}
|
@@ -2009,8 +2016,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2009
2016
|
}
|
2010
2017
|
return;
|
2011
2018
|
}
|
2012
|
-
if (allowTuple && exceptionSubtype.tupleTypeArguments) {
|
2013
|
-
exceptionSubtype.tupleTypeArguments.forEach((typeArg) => {
|
2019
|
+
if (allowTuple && exceptionSubtype.priv.tupleTypeArguments) {
|
2020
|
+
exceptionSubtype.priv.tupleTypeArguments.forEach((typeArg) => {
|
2014
2021
|
this._validateExceptionTypeRecursive(typeArg.type, diag, baseExceptionType, baseExceptionGroupType,
|
2015
2022
|
/* allowTuple */ false, isExceptGroup);
|
2016
2023
|
});
|
@@ -2044,8 +2051,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2044
2051
|
return;
|
2045
2052
|
}
|
2046
2053
|
nodes.forEach((node) => {
|
2047
|
-
if (!moduleScope.symbolTable.has(node.value)) {
|
2048
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnsupportedDunderAll, localize_1.LocMessage.dunderAllSymbolNotPresent().format({ name: node.value }), node);
|
2054
|
+
if (!moduleScope.symbolTable.has(node.d.value)) {
|
2055
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnsupportedDunderAll, localize_1.LocMessage.dunderAllSymbolNotPresent().format({ name: node.d.value }), node);
|
2049
2056
|
}
|
2050
2057
|
});
|
2051
2058
|
}
|
@@ -2068,8 +2075,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2068
2075
|
const accessedSymbolSet = this._fileInfo.accessedSymbolSet;
|
2069
2076
|
for (const paramList of this._typeParameterLists) {
|
2070
2077
|
const typeParamScope = AnalyzerNodeInfo.getScope(paramList);
|
2071
|
-
for (const param of paramList.
|
2072
|
-
const symbol = typeParamScope === null || typeParamScope === void 0 ? void 0 : typeParamScope.symbolTable.get(param.name.value);
|
2078
|
+
for (const param of paramList.d.params) {
|
2079
|
+
const symbol = typeParamScope === null || typeParamScope === void 0 ? void 0 : typeParamScope.symbolTable.get(param.d.name.d.value);
|
2073
2080
|
if (!symbol) {
|
2074
2081
|
// This can happen if the code is unreachable.
|
2075
2082
|
return;
|
@@ -2103,18 +2110,18 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2103
2110
|
// overloaded signature. We'll exempt it from this check.
|
2104
2111
|
if ((0, types_1.isOverloadedFunction)(type)) {
|
2105
2112
|
const overloads = types_1.OverloadedFunctionType.getOverloads(type);
|
2106
|
-
if (overloads.length > 0 && overloads[0].
|
2113
|
+
if (overloads.length > 0 && overloads[0].shared.name === '') {
|
2107
2114
|
return;
|
2108
2115
|
}
|
2109
2116
|
}
|
2110
2117
|
else if ((0, types_1.isFunction)(type)) {
|
2111
|
-
if (type.
|
2118
|
+
if (type.shared.name === '') {
|
2112
2119
|
return;
|
2113
2120
|
}
|
2114
2121
|
}
|
2115
2122
|
if (overloadedFunctions.length === 1) {
|
2116
2123
|
// There should never be a single overload.
|
2117
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInconsistentOverload, localize_1.LocMessage.singleOverload().format({ name }), primaryDecl.node.name);
|
2124
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInconsistentOverload, localize_1.LocMessage.singleOverload().format({ name }), primaryDecl.node.d.name);
|
2118
2125
|
}
|
2119
2126
|
// If the file is not a stub and this is the first overload,
|
2120
2127
|
// verify that there is an implementation.
|
@@ -2147,8 +2154,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2147
2154
|
// If this is a method within a protocol class, don't require that
|
2148
2155
|
// there is an implementation.
|
2149
2156
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportNoOverloadImplementation, localize_1.LocMessage.overloadWithoutImplementation().format({
|
2150
|
-
name: primaryDecl.node.name.value,
|
2151
|
-
}), primaryDecl.node.name);
|
2157
|
+
name: primaryDecl.node.d.name.d.value,
|
2158
|
+
}), primaryDecl.node.d.name);
|
2152
2159
|
return;
|
2153
2160
|
}
|
2154
2161
|
if (!(0, types_1.isOverloadedFunction)(type)) {
|
@@ -2159,13 +2166,13 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2159
2166
|
var _a, _b, _c, _d;
|
2160
2167
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
2161
2168
|
if (!this._isLegalOverloadImplementation(overload, implementationFunction, diag)) {
|
2162
|
-
if (implementationFunction.
|
2169
|
+
if (implementationFunction.shared.declaration) {
|
2163
2170
|
const diagnostic = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInconsistentOverload, localize_1.LocMessage.overloadImplementationMismatch().format({
|
2164
2171
|
name,
|
2165
2172
|
index: index + 1,
|
2166
|
-
}) + diag.getString(), implementationFunction.
|
2167
|
-
if (diagnostic && overload.
|
2168
|
-
diagnostic.addRelatedInfo(localize_1.LocAddendum.overloadSignature(), (_b = (_a = overload.
|
2173
|
+
}) + diag.getString(), implementationFunction.shared.declaration.node.d.name);
|
2174
|
+
if (diagnostic && overload.shared.declaration) {
|
2175
|
+
diagnostic.addRelatedInfo(localize_1.LocAddendum.overloadSignature(), (_b = (_a = overload.shared.declaration) === null || _a === void 0 ? void 0 : _a.uri) !== null && _b !== void 0 ? _b : primaryDecl.uri, (_d = (_c = overload.shared.declaration) === null || _c === void 0 ? void 0 : _c.range) !== null && _d !== void 0 ? _d : primaryDecl.range);
|
2169
2176
|
}
|
2170
2177
|
}
|
2171
2178
|
}
|
@@ -2297,7 +2304,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2297
2304
|
types_1.ClassType.isPropertyClass(decoratedType) &&
|
2298
2305
|
(0, types_1.isClassInstance)(funcTypeInfo.decoratedType) &&
|
2299
2306
|
types_1.ClassType.isPropertyClass(funcTypeInfo.decoratedType)) {
|
2300
|
-
return funcTypeInfo.decoratedType.
|
2307
|
+
return funcTypeInfo.decoratedType.shared.typeSourceId !== decoratedType.shared.typeSourceId;
|
2301
2308
|
}
|
2302
2309
|
return !types_1.FunctionType.isOverloaded(funcTypeInfo.functionType);
|
2303
2310
|
});
|
@@ -2334,7 +2341,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2334
2341
|
if (diag) {
|
2335
2342
|
let primaryDeclNode;
|
2336
2343
|
if (primaryDecl.type === 5 /* DeclarationType.Function */ || primaryDecl.type === 6 /* DeclarationType.Class */) {
|
2337
|
-
primaryDeclNode = primaryDecl.node.name;
|
2344
|
+
primaryDeclNode = primaryDecl.node.d.name;
|
2338
2345
|
}
|
2339
2346
|
else if (primaryDecl.type === 1 /* DeclarationType.Variable */) {
|
2340
2347
|
if (primaryDecl.node.nodeType === 38 /* ParseNodeType.Name */) {
|
@@ -2343,8 +2350,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2343
2350
|
}
|
2344
2351
|
else if (primaryDecl.type === 2 /* DeclarationType.Parameter */ ||
|
2345
2352
|
primaryDecl.type === 3 /* DeclarationType.TypeParameter */) {
|
2346
|
-
if (primaryDecl.node.name) {
|
2347
|
-
primaryDeclNode = primaryDecl.node.name;
|
2353
|
+
if (primaryDecl.node.d.name) {
|
2354
|
+
primaryDeclNode = primaryDecl.node.d.name;
|
2348
2355
|
}
|
2349
2356
|
}
|
2350
2357
|
if (primaryDeclNode) {
|
@@ -2361,7 +2368,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2361
2368
|
duplicateIsOk = true;
|
2362
2369
|
}
|
2363
2370
|
if (!duplicateIsOk) {
|
2364
|
-
const diag = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportRedeclaration, localize_1.LocMessage.obscuredClassDeclaration().format({ name }), otherDecl.node.name);
|
2371
|
+
const diag = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportRedeclaration, localize_1.LocMessage.obscuredClassDeclaration().format({ name }), otherDecl.node.d.name);
|
2365
2372
|
addPrimaryDeclInfo(diag);
|
2366
2373
|
}
|
2367
2374
|
}
|
@@ -2396,12 +2403,12 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2396
2403
|
if (!duplicateIsOk) {
|
2397
2404
|
const diag = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportRedeclaration, otherDecl.isMethod
|
2398
2405
|
? localize_1.LocMessage.obscuredMethodDeclaration().format({ name })
|
2399
|
-
: localize_1.LocMessage.obscuredFunctionDeclaration().format({ name }), otherDecl.node.name);
|
2406
|
+
: localize_1.LocMessage.obscuredFunctionDeclaration().format({ name }), otherDecl.node.d.name);
|
2400
2407
|
addPrimaryDeclInfo(diag);
|
2401
2408
|
}
|
2402
2409
|
}
|
2403
2410
|
else if (otherDecl.type === 2 /* DeclarationType.Parameter */) {
|
2404
|
-
if (otherDecl.node.name) {
|
2411
|
+
if (otherDecl.node.d.name) {
|
2405
2412
|
let duplicateIsOk = false;
|
2406
2413
|
if (primaryDecl.type === 3 /* DeclarationType.TypeParameter */) {
|
2407
2414
|
// The error will be reported elsewhere if a type parameter is
|
@@ -2410,7 +2417,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2410
2417
|
}
|
2411
2418
|
if (!duplicateIsOk) {
|
2412
2419
|
const message = localize_1.LocMessage.obscuredParameterDeclaration();
|
2413
|
-
const diag = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportRedeclaration, message.format({ name }), otherDecl.node.name);
|
2420
|
+
const diag = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportRedeclaration, message.format({ name }), otherDecl.node.d.name);
|
2414
2421
|
addPrimaryDeclInfo(diag);
|
2415
2422
|
}
|
2416
2423
|
}
|
@@ -2438,7 +2445,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2438
2445
|
}
|
2439
2446
|
}
|
2440
2447
|
else if (otherDecl.type === 4 /* DeclarationType.TypeAlias */) {
|
2441
|
-
const diag = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportRedeclaration, localize_1.LocMessage.obscuredTypeAliasDeclaration().format({ name }), otherDecl.node.name);
|
2448
|
+
const diag = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportRedeclaration, localize_1.LocMessage.obscuredTypeAliasDeclaration().format({ name }), otherDecl.node.d.name);
|
2442
2449
|
addPrimaryDeclInfo(diag);
|
2443
2450
|
}
|
2444
2451
|
}
|
@@ -2477,19 +2484,19 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2477
2484
|
diagnosticLevel = this._fileInfo.diagnosticRuleSet.reportUnusedImport;
|
2478
2485
|
rule = diagnosticRules_1.DiagnosticRule.reportUnusedImport;
|
2479
2486
|
if (decl.node.nodeType === 24 /* ParseNodeType.ImportAs */) {
|
2480
|
-
if (decl.node.alias) {
|
2487
|
+
if (decl.node.d.alias) {
|
2481
2488
|
// For statements of the form "import x as x", don't mark "x" as unaccessed
|
2482
2489
|
// because it's assumed to be re-exported.
|
2483
2490
|
// See https://typing.readthedocs.io/en/latest/source/stubs.html#imports.
|
2484
|
-
if (decl.node.alias.value !== decl.moduleName) {
|
2485
|
-
nameNode = decl.node.alias;
|
2491
|
+
if (decl.node.d.alias.d.value !== decl.moduleName) {
|
2492
|
+
nameNode = decl.node.d.alias;
|
2486
2493
|
}
|
2487
2494
|
}
|
2488
2495
|
else {
|
2489
2496
|
// Handle multi-part names specially.
|
2490
|
-
const nameParts = decl.node.module.nameParts;
|
2497
|
+
const nameParts = decl.node.d.module.d.nameParts;
|
2491
2498
|
if (nameParts.length > 0) {
|
2492
|
-
const multipartName = nameParts.map((np) => np.value).join('.');
|
2499
|
+
const multipartName = nameParts.map((np) => np.d.value).join('.');
|
2493
2500
|
let textRange = { start: nameParts[0].start, length: nameParts[0].length };
|
2494
2501
|
textRange = textRange_1.TextRange.extend(textRange, nameParts[nameParts.length - 1]);
|
2495
2502
|
this._fileInfo.diagnosticSink.addUnusedCodeWithTextRange(localize_1.LocMessage.unaccessedSymbol().format({ name: multipartName }), textRange, { action: "pyright.unusedImport" /* Commands.unusedImport */ });
|
@@ -2502,16 +2509,16 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2502
2509
|
const importFrom = decl.node.parent;
|
2503
2510
|
// For statements of the form "from y import x as x", don't mark "x" as
|
2504
2511
|
// unaccessed because it's assumed to be re-exported.
|
2505
|
-
const isReexport = ((_a = decl.node.alias) === null || _a === void 0 ? void 0 : _a.value) === decl.node.name.value;
|
2512
|
+
const isReexport = ((_a = decl.node.d.alias) === null || _a === void 0 ? void 0 : _a.d.value) === decl.node.d.name.d.value;
|
2506
2513
|
// If this is a __future__ import, it's OK for the import symbol to be unaccessed.
|
2507
|
-
const isFuture = importFrom.module.nameParts.length === 1 &&
|
2508
|
-
importFrom.module.nameParts[0].value === '__future__';
|
2514
|
+
const isFuture = importFrom.d.module.d.nameParts.length === 1 &&
|
2515
|
+
importFrom.d.module.d.nameParts[0].d.value === '__future__';
|
2509
2516
|
if (!isReexport && !isFuture) {
|
2510
|
-
nameNode = decl.node.alias || decl.node.name;
|
2517
|
+
nameNode = decl.node.d.alias || decl.node.d.name;
|
2511
2518
|
}
|
2512
2519
|
}
|
2513
2520
|
if (nameNode) {
|
2514
|
-
message = localize_1.LocMessage.unaccessedImport().format({ name: nameNode.value });
|
2521
|
+
message = localize_1.LocMessage.unaccessedImport().format({ name: nameNode.d.value });
|
2515
2522
|
}
|
2516
2523
|
break;
|
2517
2524
|
case 4 /* DeclarationType.TypeAlias */:
|
@@ -2530,18 +2537,18 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2530
2537
|
nameNode = decl.node;
|
2531
2538
|
// Don't emit a diagnostic if the name starts with an underscore.
|
2532
2539
|
// This indicates that the variable is unused.
|
2533
|
-
if (nameNode.value.startsWith('_')) {
|
2540
|
+
if (nameNode.d.value.startsWith('_')) {
|
2534
2541
|
diagnosticLevel = 'none';
|
2535
2542
|
}
|
2536
2543
|
}
|
2537
2544
|
else if (decl.node.nodeType === 41 /* ParseNodeType.Parameter */) {
|
2538
|
-
nameNode = decl.node.name;
|
2545
|
+
nameNode = decl.node.d.name;
|
2539
2546
|
// Don't emit a diagnostic for unused parameters or type parameters.
|
2540
2547
|
diagnosticLevel = 'none';
|
2541
2548
|
}
|
2542
2549
|
if (nameNode) {
|
2543
2550
|
rule = diagnosticRules_1.DiagnosticRule.reportUnusedVariable;
|
2544
|
-
message = localize_1.LocMessage.unaccessedVariable().format({ name: nameNode.value });
|
2551
|
+
message = localize_1.LocMessage.unaccessedVariable().format({ name: nameNode.d.value });
|
2545
2552
|
}
|
2546
2553
|
break;
|
2547
2554
|
case 6 /* DeclarationType.Class */:
|
@@ -2554,9 +2561,9 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2554
2561
|
return;
|
2555
2562
|
}
|
2556
2563
|
diagnosticLevel = this._fileInfo.diagnosticRuleSet.reportUnusedClass;
|
2557
|
-
nameNode = decl.node.name;
|
2564
|
+
nameNode = decl.node.d.name;
|
2558
2565
|
rule = diagnosticRules_1.DiagnosticRule.reportUnusedClass;
|
2559
|
-
message = localize_1.LocMessage.unaccessedClass().format({ name: nameNode.value });
|
2566
|
+
message = localize_1.LocMessage.unaccessedClass().format({ name: nameNode.d.value });
|
2560
2567
|
break;
|
2561
2568
|
case 5 /* DeclarationType.Function */:
|
2562
2569
|
if (!isPrivate) {
|
@@ -2568,14 +2575,14 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2568
2575
|
return;
|
2569
2576
|
}
|
2570
2577
|
diagnosticLevel = this._fileInfo.diagnosticRuleSet.reportUnusedFunction;
|
2571
|
-
nameNode = decl.node.name;
|
2578
|
+
nameNode = decl.node.d.name;
|
2572
2579
|
rule = diagnosticRules_1.DiagnosticRule.reportUnusedFunction;
|
2573
|
-
message = localize_1.LocMessage.unaccessedFunction().format({ name: nameNode.value });
|
2580
|
+
message = localize_1.LocMessage.unaccessedFunction().format({ name: nameNode.d.value });
|
2574
2581
|
break;
|
2575
2582
|
case 3 /* DeclarationType.TypeParameter */:
|
2576
2583
|
// Never report a diagnostic for an unused TypeParameter.
|
2577
2584
|
diagnosticLevel = 'none';
|
2578
|
-
nameNode = decl.node.name;
|
2585
|
+
nameNode = decl.node.d.name;
|
2579
2586
|
break;
|
2580
2587
|
case 0 /* DeclarationType.Intrinsic */:
|
2581
2588
|
case 7 /* DeclarationType.SpecialBuiltInClass */:
|
@@ -2585,7 +2592,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2585
2592
|
}
|
2586
2593
|
const action = rule === diagnosticRules_1.DiagnosticRule.reportUnusedImport ? { action: "pyright.unusedImport" /* Commands.unusedImport */ } : undefined;
|
2587
2594
|
if (nameNode) {
|
2588
|
-
this._fileInfo.diagnosticSink.addUnusedCodeWithTextRange(localize_1.LocMessage.unaccessedSymbol().format({ name: nameNode.value }), nameNode, action);
|
2595
|
+
this._fileInfo.diagnosticSink.addUnusedCodeWithTextRange(localize_1.LocMessage.unaccessedSymbol().format({ name: nameNode.d.value }), nameNode, action);
|
2589
2596
|
if (rule !== undefined && message && diagnosticLevel !== 'none') {
|
2590
2597
|
this._evaluator.addDiagnostic(rule, message, nameNode);
|
2591
2598
|
}
|
@@ -2595,14 +2602,14 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2595
2602
|
// common source of programming errors. Also validates that arguments passed
|
2596
2603
|
// to isinstance or issubclass won't generate exceptions.
|
2597
2604
|
_validateIsInstanceCall(node) {
|
2598
|
-
if (node.
|
2599
|
-
(node.
|
2600
|
-
node.
|
2605
|
+
if (node.d.leftExpr.nodeType !== 38 /* ParseNodeType.Name */ ||
|
2606
|
+
(node.d.leftExpr.d.value !== 'isinstance' && node.d.leftExpr.d.value !== 'issubclass') ||
|
2607
|
+
node.d.args.length !== 2) {
|
2601
2608
|
return;
|
2602
2609
|
}
|
2603
|
-
const callName = node.
|
2610
|
+
const callName = node.d.leftExpr.d.value;
|
2604
2611
|
const isInstanceCheck = callName === 'isinstance';
|
2605
|
-
let arg0Type = this._evaluator.getType(node.
|
2612
|
+
let arg0Type = this._evaluator.getType(node.d.args[0].d.valueExpr);
|
2606
2613
|
if (!arg0Type) {
|
2607
2614
|
return;
|
2608
2615
|
}
|
@@ -2610,15 +2617,17 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2610
2617
|
return (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(subtype);
|
2611
2618
|
});
|
2612
2619
|
arg0Type = this._evaluator.expandPromotionTypes(node, arg0Type);
|
2613
|
-
const arg1Type = this._evaluator.getType(node.
|
2620
|
+
const arg1Type = this._evaluator.getType(node.d.args[1].d.valueExpr);
|
2614
2621
|
if (!arg1Type) {
|
2615
2622
|
return;
|
2616
2623
|
}
|
2617
2624
|
let isValidType = true;
|
2618
2625
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
2619
2626
|
(0, typeUtils_1.doForEachSubtype)(arg1Type, (arg1Subtype) => {
|
2620
|
-
if ((0, types_1.isClassInstance)(arg1Subtype) &&
|
2621
|
-
|
2627
|
+
if ((0, types_1.isClassInstance)(arg1Subtype) &&
|
2628
|
+
types_1.ClassType.isTupleClass(arg1Subtype) &&
|
2629
|
+
arg1Subtype.priv.tupleTypeArguments) {
|
2630
|
+
if (arg1Subtype.priv.tupleTypeArguments.some((typeArg) => !this._isTypeSupportedTypeForIsInstance(typeArg.type, isInstanceCheck, diag))) {
|
2622
2631
|
isValidType = false;
|
2623
2632
|
}
|
2624
2633
|
}
|
@@ -2635,7 +2644,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2635
2644
|
}) + diag.getString()
|
2636
2645
|
: localize_1.LocMessage.isSubclassInvalidType().format({
|
2637
2646
|
type: this._evaluator.printType(arg1Type),
|
2638
|
-
}) + diag.getString(), node.
|
2647
|
+
}) + diag.getString(), node.d.args[1]);
|
2639
2648
|
}
|
2640
2649
|
// If this call is an issubclass, check for the use of a "data protocol",
|
2641
2650
|
// which PEP 544 says cannot be used in issubclass.
|
@@ -2644,8 +2653,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2644
2653
|
(0, typeUtils_1.doForEachSubtype)(arg1Type, (arg1Subtype) => {
|
2645
2654
|
if ((0, types_1.isClassInstance)(arg1Subtype) &&
|
2646
2655
|
types_1.ClassType.isTupleClass(arg1Subtype) &&
|
2647
|
-
arg1Subtype.tupleTypeArguments) {
|
2648
|
-
arg1Subtype.tupleTypeArguments.forEach((typeArg) => {
|
2656
|
+
arg1Subtype.priv.tupleTypeArguments) {
|
2657
|
+
arg1Subtype.priv.tupleTypeArguments.forEach((typeArg) => {
|
2649
2658
|
this._validateNotDataProtocol(typeArg.type, diag);
|
2650
2659
|
});
|
2651
2660
|
}
|
@@ -2654,7 +2663,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2654
2663
|
}
|
2655
2664
|
});
|
2656
2665
|
if (!diag.isEmpty()) {
|
2657
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.dataProtocolInSubclassCheck(), node.
|
2666
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.dataProtocolInSubclassCheck(), node.d.args[1]);
|
2658
2667
|
}
|
2659
2668
|
}
|
2660
2669
|
// If this call is within an assert statement, we won't check whether
|
@@ -2682,33 +2691,33 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2682
2691
|
(0, typeUtils_1.doForEachSubtype)(arg1Type, (arg1Subtype) => {
|
2683
2692
|
if ((0, types_1.isClass)(arg1Subtype)) {
|
2684
2693
|
if (types_1.TypeBase.isInstantiable(arg1Subtype)) {
|
2685
|
-
if (arg1Subtype.literalValue === undefined) {
|
2694
|
+
if (arg1Subtype.priv.literalValue === undefined) {
|
2686
2695
|
classTypeList.push(arg1Subtype);
|
2687
2696
|
if (types_1.ClassType.isBuiltIn(arg1Subtype) &&
|
2688
|
-
nonstandardClassTypes.some((name) => name === arg1Subtype.
|
2697
|
+
nonstandardClassTypes.some((name) => name === arg1Subtype.shared.name)) {
|
2689
2698
|
isValidType = false;
|
2690
2699
|
}
|
2691
|
-
if (arg1Subtype.includeSubclasses) {
|
2700
|
+
if (arg1Subtype.priv.includeSubclasses) {
|
2692
2701
|
arg1IncludesSubclasses = true;
|
2693
2702
|
}
|
2694
2703
|
}
|
2695
2704
|
if (arg0Type) {
|
2696
|
-
this._validateUnsafeProtocolOverlap(node.
|
2705
|
+
this._validateUnsafeProtocolOverlap(node.d.args[0].d.valueExpr, (0, typeUtils_1.convertToInstance)(arg1Subtype), isInstanceCheck ? arg0Type : (0, typeUtils_1.convertToInstance)(arg0Type));
|
2697
2706
|
}
|
2698
2707
|
}
|
2699
2708
|
else {
|
2700
2709
|
// The isinstance and issubclass call supports a variation where the second
|
2701
2710
|
// parameter is a tuple of classes.
|
2702
2711
|
if ((0, typeUtils_1.isTupleClass)(arg1Subtype)) {
|
2703
|
-
if (arg1Subtype.tupleTypeArguments) {
|
2704
|
-
arg1Subtype.tupleTypeArguments.forEach((typeArg) => {
|
2712
|
+
if (arg1Subtype.priv.tupleTypeArguments) {
|
2713
|
+
arg1Subtype.priv.tupleTypeArguments.forEach((typeArg) => {
|
2705
2714
|
if ((0, types_1.isInstantiableClass)(typeArg.type)) {
|
2706
2715
|
classTypeList.push(typeArg.type);
|
2707
|
-
if (typeArg.type.includeSubclasses) {
|
2716
|
+
if (typeArg.type.priv.includeSubclasses) {
|
2708
2717
|
arg1IncludesSubclasses = true;
|
2709
2718
|
}
|
2710
2719
|
if (arg0Type) {
|
2711
|
-
this._validateUnsafeProtocolOverlap(node.
|
2720
|
+
this._validateUnsafeProtocolOverlap(node.d.args[0].d.valueExpr, (0, typeUtils_1.convertToInstance)(typeArg.type), isInstanceCheck ? arg0Type : (0, typeUtils_1.convertToInstance)(arg0Type));
|
2712
2721
|
}
|
2713
2722
|
}
|
2714
2723
|
else {
|
@@ -2718,12 +2727,12 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2718
2727
|
}
|
2719
2728
|
}
|
2720
2729
|
else {
|
2721
|
-
if (arg1Subtype.includeSubclasses) {
|
2730
|
+
if (arg1Subtype.priv.includeSubclasses) {
|
2722
2731
|
arg1IncludesSubclasses = true;
|
2723
2732
|
}
|
2724
2733
|
}
|
2725
2734
|
if (types_1.ClassType.isBuiltIn(arg1Subtype) &&
|
2726
|
-
nonstandardClassTypes.some((name) => name === arg1Subtype.
|
2735
|
+
nonstandardClassTypes.some((name) => name === arg1Subtype.shared.name)) {
|
2727
2736
|
isValidType = false;
|
2728
2737
|
}
|
2729
2738
|
}
|
@@ -2834,14 +2843,14 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2834
2843
|
if ((0, protocols_1.isProtocolUnsafeOverlap)(this._evaluator, protocol, testSubtype)) {
|
2835
2844
|
isUnsafeOverlap = true;
|
2836
2845
|
diag.addMessage(localize_1.LocAddendum.protocolUnsafeOverlap().format({
|
2837
|
-
name: testSubtype.
|
2846
|
+
name: testSubtype.shared.name,
|
2838
2847
|
}));
|
2839
2848
|
}
|
2840
2849
|
}
|
2841
2850
|
});
|
2842
2851
|
if (isUnsafeOverlap) {
|
2843
2852
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.protocolUnsafeOverlap().format({
|
2844
|
-
name: protocol.
|
2853
|
+
name: protocol.shared.name,
|
2845
2854
|
}) + diag.getString(), errorNode);
|
2846
2855
|
}
|
2847
2856
|
}
|
@@ -2851,9 +2860,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2851
2860
|
_isTypeSupportedTypeForIsInstance(type, isInstanceCheck, diag) {
|
2852
2861
|
let isSupported = true;
|
2853
2862
|
(0, typeUtils_1.doForEachSubtype)(type, (subtype) => {
|
2863
|
+
var _a, _b;
|
2854
2864
|
subtype = this._evaluator.makeTopLevelTypeVarsConcrete(subtype);
|
2855
2865
|
subtype = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(subtype);
|
2856
|
-
if (subtype.specialForm && types_1.ClassType.isBuiltIn(subtype.specialForm, 'TypeAliasType')) {
|
2866
|
+
if (((_a = subtype.props) === null || _a === void 0 ? void 0 : _a.specialForm) && types_1.ClassType.isBuiltIn(subtype.props.specialForm, 'TypeAliasType')) {
|
2857
2867
|
diag.addMessage(localize_1.LocAddendum.typeAliasInstanceCheck());
|
2858
2868
|
isSupported = false;
|
2859
2869
|
return;
|
@@ -2880,19 +2890,19 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2880
2890
|
diag.addMessage(localize_1.LocAddendum.typedDictClassNotAllowed());
|
2881
2891
|
isSupported = false;
|
2882
2892
|
}
|
2883
|
-
else if (subtype.isTypeArgumentExplicit && !subtype.includeSubclasses) {
|
2893
|
+
else if (subtype.priv.isTypeArgumentExplicit && !subtype.priv.includeSubclasses) {
|
2884
2894
|
// If it's a class, make sure that it has not been given explicit
|
2885
2895
|
// type arguments. This will result in a TypeError exception.
|
2886
2896
|
diag.addMessage(localize_1.LocAddendum.genericClassNotAllowed());
|
2887
2897
|
isSupported = false;
|
2888
2898
|
}
|
2889
2899
|
else if (types_1.ClassType.isIllegalIsinstanceClass(subtype)) {
|
2890
|
-
diag.addMessage(localize_1.LocAddendum.isinstanceClassNotSupported().format({ type: subtype.
|
2900
|
+
diag.addMessage(localize_1.LocAddendum.isinstanceClassNotSupported().format({ type: subtype.shared.name }));
|
2891
2901
|
isSupported = false;
|
2892
2902
|
}
|
2893
2903
|
else if (types_1.ClassType.isProtocolClass(subtype) &&
|
2894
2904
|
!types_1.ClassType.isRuntimeCheckable(subtype) &&
|
2895
|
-
!subtype.includeSubclasses) {
|
2905
|
+
!subtype.priv.includeSubclasses) {
|
2896
2906
|
// According to PEP 544, protocol classes cannot be used as the right-hand
|
2897
2907
|
// argument to isinstance or issubclass unless they are annotated as
|
2898
2908
|
// "runtime checkable".
|
@@ -2903,15 +2913,15 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2903
2913
|
diag.addMessage(localize_1.LocAddendum.newTypeClassNotAllowed());
|
2904
2914
|
isSupported = false;
|
2905
2915
|
}
|
2906
|
-
else if (subtype.specialForm &&
|
2907
|
-
(0, types_1.isInstantiableClass)(subtype.specialForm) &&
|
2908
|
-
types_1.ClassType.isBuiltIn(subtype.specialForm, 'Annotated')) {
|
2916
|
+
else if (((_b = subtype.props) === null || _b === void 0 ? void 0 : _b.specialForm) &&
|
2917
|
+
(0, types_1.isInstantiableClass)(subtype.props.specialForm) &&
|
2918
|
+
types_1.ClassType.isBuiltIn(subtype.props.specialForm, 'Annotated')) {
|
2909
2919
|
diag.addMessage(localize_1.LocAddendum.annotatedNotAllowed());
|
2910
2920
|
isSupported = false;
|
2911
2921
|
}
|
2912
2922
|
break;
|
2913
2923
|
case 4 /* TypeCategory.Function */:
|
2914
|
-
if (!types_1.TypeBase.isInstantiable(subtype) || subtype.isCallableWithTypeArgs) {
|
2924
|
+
if (!types_1.TypeBase.isInstantiable(subtype) || subtype.priv.isCallableWithTypeArgs) {
|
2915
2925
|
diag.addMessage(localize_1.LocAddendum.genericClassNotAllowed());
|
2916
2926
|
isSupported = false;
|
2917
2927
|
}
|
@@ -2927,7 +2937,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2927
2937
|
_validateNotDataProtocol(type, diag) {
|
2928
2938
|
if ((0, types_1.isInstantiableClass)(type) && types_1.ClassType.isProtocolClass(type) && !(0, protocols_1.isMethodOnlyProtocol)(type)) {
|
2929
2939
|
diag.addMessage(localize_1.LocAddendum.dataProtocolUnsupported().format({
|
2930
|
-
name: type.
|
2940
|
+
name: type.shared.name,
|
2931
2941
|
}));
|
2932
2942
|
}
|
2933
2943
|
}
|
@@ -2953,30 +2963,30 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2953
2963
|
!types_1.ClassType.isClassProperty(functionTypeResult.decoratedType)) {
|
2954
2964
|
return;
|
2955
2965
|
}
|
2956
|
-
this._reportDeprecatedDiagnostic(node.name, localize_1.LocMessage.classPropertyDeprecated());
|
2966
|
+
this._reportDeprecatedDiagnostic(node.d.name, localize_1.LocMessage.classPropertyDeprecated());
|
2957
2967
|
}
|
2958
2968
|
_reportDeprecatedUseForMemberAccess(node, info) {
|
2959
2969
|
let errorMessage;
|
2960
2970
|
if (info.accessType === 'property') {
|
2961
2971
|
if (info.accessMethod === 'get') {
|
2962
|
-
errorMessage = localize_1.LocMessage.deprecatedPropertyGetter().format({ name: node.value });
|
2972
|
+
errorMessage = localize_1.LocMessage.deprecatedPropertyGetter().format({ name: node.d.value });
|
2963
2973
|
}
|
2964
2974
|
else if (info.accessMethod === 'set') {
|
2965
|
-
errorMessage = localize_1.LocMessage.deprecatedPropertySetter().format({ name: node.value });
|
2975
|
+
errorMessage = localize_1.LocMessage.deprecatedPropertySetter().format({ name: node.d.value });
|
2966
2976
|
}
|
2967
2977
|
else {
|
2968
|
-
errorMessage = localize_1.LocMessage.deprecatedPropertyDeleter().format({ name: node.value });
|
2978
|
+
errorMessage = localize_1.LocMessage.deprecatedPropertyDeleter().format({ name: node.d.value });
|
2969
2979
|
}
|
2970
2980
|
}
|
2971
2981
|
else if (info.accessType === 'descriptor') {
|
2972
2982
|
if (info.accessMethod === 'get') {
|
2973
|
-
errorMessage = localize_1.LocMessage.deprecatedDescriptorGetter().format({ name: node.value });
|
2983
|
+
errorMessage = localize_1.LocMessage.deprecatedDescriptorGetter().format({ name: node.d.value });
|
2974
2984
|
}
|
2975
2985
|
else if (info.accessMethod === 'set') {
|
2976
|
-
errorMessage = localize_1.LocMessage.deprecatedDescriptorSetter().format({ name: node.value });
|
2986
|
+
errorMessage = localize_1.LocMessage.deprecatedDescriptorSetter().format({ name: node.d.value });
|
2977
2987
|
}
|
2978
2988
|
else {
|
2979
|
-
errorMessage = localize_1.LocMessage.deprecatedDescriptorDeleter().format({ name: node.value });
|
2989
|
+
errorMessage = localize_1.LocMessage.deprecatedDescriptorDeleter().format({ name: node.d.value });
|
2980
2990
|
}
|
2981
2991
|
}
|
2982
2992
|
if (errorMessage) {
|
@@ -2984,26 +2994,26 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2984
2994
|
}
|
2985
2995
|
}
|
2986
2996
|
_reportDeprecatedUseForType(node, type, isImportFromTyping = false) {
|
2987
|
-
var _a, _b;
|
2997
|
+
var _a, _b, _c;
|
2988
2998
|
if (!type) {
|
2989
2999
|
return;
|
2990
3000
|
}
|
2991
3001
|
let errorMessage;
|
2992
3002
|
let deprecatedMessage;
|
2993
3003
|
function getDeprecatedMessageForFunction(functionType) {
|
2994
|
-
if (functionType.
|
2995
|
-
functionType.
|
2996
|
-
const containingClass = ParseTreeUtils.getEnclosingClass(functionType.
|
3004
|
+
if (functionType.shared.declaration &&
|
3005
|
+
functionType.shared.declaration.node.nodeType === 31 /* ParseNodeType.Function */) {
|
3006
|
+
const containingClass = ParseTreeUtils.getEnclosingClass(functionType.shared.declaration.node,
|
2997
3007
|
/* stopAtFunction */ true);
|
2998
3008
|
if (containingClass) {
|
2999
3009
|
return localize_1.LocMessage.deprecatedMethod().format({
|
3000
|
-
name: functionType.
|
3001
|
-
className: containingClass.name.value,
|
3010
|
+
name: functionType.shared.name || '<anonymous>',
|
3011
|
+
className: containingClass.d.name.d.value,
|
3002
3012
|
});
|
3003
3013
|
}
|
3004
3014
|
}
|
3005
3015
|
return localize_1.LocMessage.deprecatedFunction().format({
|
3006
|
-
name: functionType.
|
3016
|
+
name: functionType.shared.name,
|
3007
3017
|
});
|
3008
3018
|
}
|
3009
3019
|
function getDeprecatedMessageForOverloadedCall(evaluator, type) {
|
@@ -3026,21 +3036,21 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3026
3036
|
callTypeResult.overloadsUsedForCall &&
|
3027
3037
|
callTypeResult.overloadsUsedForCall.length > 0) {
|
3028
3038
|
callTypeResult.overloadsUsedForCall.forEach((overload) => {
|
3029
|
-
if (overload.
|
3030
|
-
if (node.value === overload.
|
3031
|
-
deprecatedMessage = overload.
|
3039
|
+
if (overload.shared.deprecatedMessage !== undefined) {
|
3040
|
+
if (node.d.value === overload.shared.name) {
|
3041
|
+
deprecatedMessage = overload.shared.deprecatedMessage;
|
3032
3042
|
errorMessage = getDeprecatedMessageForFunction(overload);
|
3033
3043
|
}
|
3034
|
-
else if ((0, types_1.isInstantiableClass)(type) && overload.
|
3035
|
-
deprecatedMessage = overload.
|
3044
|
+
else if ((0, types_1.isInstantiableClass)(type) && overload.shared.name === '__init__') {
|
3045
|
+
deprecatedMessage = overload.shared.deprecatedMessage;
|
3036
3046
|
errorMessage = localize_1.LocMessage.deprecatedConstructor().format({
|
3037
|
-
name: type.
|
3047
|
+
name: type.shared.name,
|
3038
3048
|
});
|
3039
3049
|
}
|
3040
|
-
else if ((0, types_1.isClassInstance)(type) && overload.
|
3041
|
-
deprecatedMessage = overload.
|
3050
|
+
else if ((0, types_1.isClassInstance)(type) && overload.shared.name === '__call__') {
|
3051
|
+
deprecatedMessage = overload.shared.deprecatedMessage;
|
3042
3052
|
errorMessage = localize_1.LocMessage.deprecatedFunction().format({
|
3043
|
-
name: node.value,
|
3053
|
+
name: node.d.value,
|
3044
3054
|
});
|
3045
3055
|
}
|
3046
3056
|
}
|
@@ -3049,22 +3059,22 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3049
3059
|
}
|
3050
3060
|
(0, typeUtils_1.doForEachSubtype)(type, (subtype) => {
|
3051
3061
|
if ((0, types_1.isClass)(subtype)) {
|
3052
|
-
if (!subtype.includeSubclasses &&
|
3053
|
-
subtype.
|
3054
|
-
node.value === subtype.
|
3055
|
-
deprecatedMessage = subtype.
|
3056
|
-
errorMessage = localize_1.LocMessage.deprecatedClass().format({ name: subtype.
|
3062
|
+
if (!subtype.priv.includeSubclasses &&
|
3063
|
+
subtype.shared.deprecatedMessage !== undefined &&
|
3064
|
+
node.d.value === subtype.shared.name) {
|
3065
|
+
deprecatedMessage = subtype.shared.deprecatedMessage;
|
3066
|
+
errorMessage = localize_1.LocMessage.deprecatedClass().format({ name: subtype.shared.name });
|
3057
3067
|
return;
|
3058
3068
|
}
|
3059
3069
|
getDeprecatedMessageForOverloadedCall(this._evaluator, subtype);
|
3060
3070
|
return;
|
3061
3071
|
}
|
3062
3072
|
if ((0, types_1.isFunction)(subtype)) {
|
3063
|
-
if (subtype.
|
3064
|
-
if (!subtype.
|
3065
|
-
subtype.
|
3066
|
-
node.value === subtype.
|
3067
|
-
deprecatedMessage = subtype.
|
3073
|
+
if (subtype.shared.deprecatedMessage !== undefined) {
|
3074
|
+
if (!subtype.shared.name ||
|
3075
|
+
subtype.shared.name === '__call__' ||
|
3076
|
+
node.d.value === subtype.shared.name) {
|
3077
|
+
deprecatedMessage = subtype.shared.deprecatedMessage;
|
3068
3078
|
errorMessage = getDeprecatedMessageForFunction(subtype);
|
3069
3079
|
}
|
3070
3080
|
}
|
@@ -3078,9 +3088,9 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3078
3088
|
// If there the implementation itself is deprecated, assume it
|
3079
3089
|
// is deprecated even if it's outside of a call expression.
|
3080
3090
|
const overloadImpl = types_1.OverloadedFunctionType.getImplementation(subtype);
|
3081
|
-
if ((overloadImpl === null || overloadImpl === void 0 ? void 0 : overloadImpl.
|
3082
|
-
if (!overloadImpl.
|
3083
|
-
deprecatedMessage = overloadImpl.
|
3091
|
+
if ((overloadImpl === null || overloadImpl === void 0 ? void 0 : overloadImpl.shared.deprecatedMessage) !== undefined) {
|
3092
|
+
if (!overloadImpl.shared.name || node.d.value === overloadImpl.shared.name) {
|
3093
|
+
deprecatedMessage = overloadImpl.shared.deprecatedMessage;
|
3084
3094
|
errorMessage = getDeprecatedMessageForFunction(overloadImpl);
|
3085
3095
|
}
|
3086
3096
|
}
|
@@ -3090,10 +3100,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3090
3100
|
this._reportDeprecatedDiagnostic(node, errorMessage, deprecatedMessage);
|
3091
3101
|
}
|
3092
3102
|
if (this._fileInfo.diagnosticRuleSet.deprecateTypingAliases) {
|
3093
|
-
const deprecatedForm = (_a = deprecatedSymbols_1.deprecatedAliases.get(node.value)) !== null && _a !== void 0 ? _a : deprecatedSymbols_1.deprecatedSpecialForms.get(node.value);
|
3103
|
+
const deprecatedForm = (_a = deprecatedSymbols_1.deprecatedAliases.get(node.d.value)) !== null && _a !== void 0 ? _a : deprecatedSymbols_1.deprecatedSpecialForms.get(node.d.value);
|
3094
3104
|
if (deprecatedForm) {
|
3095
|
-
if (((0, types_1.isInstantiableClass)(type) && type.
|
3096
|
-
((_b = type.
|
3105
|
+
if (((0, types_1.isInstantiableClass)(type) && type.shared.fullName === deprecatedForm.fullName) ||
|
3106
|
+
((_c = (_b = type.props) === null || _b === void 0 ? void 0 : _b.typeAliasInfo) === null || _c === void 0 ? void 0 : _c.fullName) === deprecatedForm.fullName) {
|
3097
3107
|
if (this._fileInfo.executionEnvironment.pythonVersion.isGreaterOrEqualTo(deprecatedForm.version)) {
|
3098
3108
|
if (!deprecatedForm.typingImportOnly || isImportFromTyping) {
|
3099
3109
|
if (this._fileInfo.diagnosticRuleSet.reportDeprecated === 'none') {
|
@@ -3135,11 +3145,11 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3135
3145
|
if (type) {
|
3136
3146
|
if ((0, types_1.isUnbound)(type)) {
|
3137
3147
|
if (this._evaluator.isNodeReachable(node)) {
|
3138
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnboundVariable, localize_1.LocMessage.symbolIsUnbound().format({ name: node.value }), node);
|
3148
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnboundVariable, localize_1.LocMessage.symbolIsUnbound().format({ name: node.d.value }), node);
|
3139
3149
|
}
|
3140
3150
|
}
|
3141
3151
|
else if ((0, types_1.isPossiblyUnbound)(type)) {
|
3142
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportPossiblyUnboundVariable, localize_1.LocMessage.symbolIsPossiblyUnbound().format({ name: node.value }), node);
|
3152
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportPossiblyUnboundVariable, localize_1.LocMessage.symbolIsPossiblyUnbound().format({ name: node.d.value }), node);
|
3143
3153
|
}
|
3144
3154
|
}
|
3145
3155
|
}
|
@@ -3183,19 +3193,19 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3183
3193
|
// Skip this check for relative imports.
|
3184
3194
|
const nodeModule = node.nodeType === 26 /* ParseNodeType.ImportFromAs */
|
3185
3195
|
? ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 25 /* ParseNodeType.ImportFrom */
|
3186
|
-
? (_b = node.parent) === null || _b === void 0 ? void 0 : _b.module
|
3196
|
+
? (_b = node.parent) === null || _b === void 0 ? void 0 : _b.d.module
|
3187
3197
|
: undefined
|
3188
|
-
: node.module;
|
3189
|
-
if (nodeModule === null || nodeModule === void 0 ? void 0 : nodeModule.leadingDots) {
|
3198
|
+
: node.d.module;
|
3199
|
+
if (nodeModule === null || nodeModule === void 0 ? void 0 : nodeModule.d.leadingDots) {
|
3190
3200
|
return;
|
3191
3201
|
}
|
3192
3202
|
// Otherwise use the name to determine if a match for a stdlib module.
|
3193
3203
|
const namePartNodes = node.nodeType === 24 /* ParseNodeType.ImportAs */
|
3194
|
-
? node.module.nameParts
|
3204
|
+
? node.d.module.d.nameParts
|
3195
3205
|
: node.nodeType === 26 /* ParseNodeType.ImportFromAs */
|
3196
|
-
? [node.name]
|
3197
|
-
: node.module.nameParts;
|
3198
|
-
const nameParts = namePartNodes.map((n) => n.value);
|
3206
|
+
? [node.d.name]
|
3207
|
+
: node.d.module.d.nameParts;
|
3208
|
+
const nameParts = namePartNodes.map((n) => n.d.value);
|
3199
3209
|
const module = {
|
3200
3210
|
nameParts,
|
3201
3211
|
leadingDots: 0,
|
@@ -3238,10 +3248,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3238
3248
|
return;
|
3239
3249
|
}
|
3240
3250
|
// Ignore privates in named arguments.
|
3241
|
-
if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 1 /* ParseNodeType.Argument */ && node.parent.name === node) {
|
3251
|
+
if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 1 /* ParseNodeType.Argument */ && node.parent.d.name === node) {
|
3242
3252
|
return;
|
3243
3253
|
}
|
3244
|
-
const nameValue = node.value;
|
3254
|
+
const nameValue = node.d.value;
|
3245
3255
|
const isPrivateName = SymbolNameUtils.isPrivateName(nameValue);
|
3246
3256
|
const isProtectedName = SymbolNameUtils.isProtectedName(nameValue);
|
3247
3257
|
// If it's not a protected or private name, don't bother with
|
@@ -3329,9 +3339,9 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3329
3339
|
// Validates that an enum class does not attempt to override another
|
3330
3340
|
// enum class that has already defined values.
|
3331
3341
|
_validateEnumClassOverride(node, classType) {
|
3332
|
-
classType.
|
3342
|
+
classType.shared.baseClasses.forEach((baseClass, index) => {
|
3333
3343
|
if ((0, types_1.isClass)(baseClass) && (0, enums_1.isEnumClassWithMembers)(this._evaluator, baseClass)) {
|
3334
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.enumClassOverride().format({ name: baseClass.
|
3344
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.enumClassOverride().format({ name: baseClass.shared.name }), node.d.arguments[index]);
|
3335
3345
|
}
|
3336
3346
|
});
|
3337
3347
|
}
|
@@ -3342,10 +3352,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3342
3352
|
const emitBadStatementError = (node) => {
|
3343
3353
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typedDictBadVar(), node);
|
3344
3354
|
};
|
3345
|
-
suiteNode.statements.forEach((statement) => {
|
3355
|
+
suiteNode.d.statements.forEach((statement) => {
|
3346
3356
|
if (!AnalyzerNodeInfo.isCodeUnreachable(statement)) {
|
3347
3357
|
if (statement.nodeType === 47 /* ParseNodeType.StatementList */) {
|
3348
|
-
for (const substatement of statement.statements) {
|
3358
|
+
for (const substatement of statement.d.statements) {
|
3349
3359
|
if (substatement.nodeType !== 54 /* ParseNodeType.TypeAnnotation */ &&
|
3350
3360
|
substatement.nodeType !== 21 /* ParseNodeType.Ellipsis */ &&
|
3351
3361
|
substatement.nodeType !== 48 /* ParseNodeType.StringList */ &&
|
@@ -3362,11 +3372,13 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3362
3372
|
}
|
3363
3373
|
_validateTypeGuardFunction(node, functionType, isMethod) {
|
3364
3374
|
var _a;
|
3365
|
-
const returnType = functionType.
|
3375
|
+
const returnType = functionType.shared.declaredReturnType;
|
3366
3376
|
if (!returnType) {
|
3367
3377
|
return;
|
3368
3378
|
}
|
3369
|
-
if (!(0, types_1.isClassInstance)(returnType) ||
|
3379
|
+
if (!(0, types_1.isClassInstance)(returnType) ||
|
3380
|
+
!returnType.priv.typeArguments ||
|
3381
|
+
returnType.priv.typeArguments.length < 1) {
|
3370
3382
|
return;
|
3371
3383
|
}
|
3372
3384
|
const isTypeGuard = types_1.ClassType.isBuiltIn(returnType, 'TypeGuard');
|
@@ -3375,7 +3387,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3375
3387
|
return;
|
3376
3388
|
}
|
3377
3389
|
// Make sure there's at least one input parameter provided.
|
3378
|
-
let paramCount = functionType.
|
3390
|
+
let paramCount = functionType.shared.parameters.length;
|
3379
3391
|
if (isMethod) {
|
3380
3392
|
if (types_1.FunctionType.isInstanceMethod(functionType) ||
|
3381
3393
|
types_1.FunctionType.isConstructorMethod(functionType) ||
|
@@ -3384,19 +3396,19 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3384
3396
|
}
|
3385
3397
|
}
|
3386
3398
|
if (paramCount < 1) {
|
3387
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeGuardParamCount(), node.name);
|
3399
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeGuardParamCount(), node.d.name);
|
3388
3400
|
}
|
3389
3401
|
if (isTypeIs) {
|
3390
|
-
const typeGuardType = returnType.typeArguments[0];
|
3402
|
+
const typeGuardType = returnType.priv.typeArguments[0];
|
3391
3403
|
// Determine the type of the first parameter.
|
3392
3404
|
const paramIndex = isMethod && !types_1.FunctionType.isStaticMethod(functionType) ? 1 : 0;
|
3393
|
-
if (paramIndex >= functionType.
|
3405
|
+
if (paramIndex >= functionType.shared.parameters.length) {
|
3394
3406
|
return;
|
3395
3407
|
}
|
3396
3408
|
const paramType = types_1.FunctionType.getEffectiveParameterType(functionType, paramIndex);
|
3397
3409
|
// Verify that the typeGuardType is a narrower type than the paramType.
|
3398
3410
|
if (!this._evaluator.assignType(paramType, typeGuardType)) {
|
3399
|
-
const returnAnnotation = node.
|
3411
|
+
const returnAnnotation = node.d.returnAnnotation || ((_a = node.d.funcAnnotationComment) === null || _a === void 0 ? void 0 : _a.d.returnAnnotation);
|
3400
3412
|
if (returnAnnotation) {
|
3401
3413
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeIsReturnType().format({
|
3402
3414
|
type: this._evaluator.printType(paramType),
|
@@ -3408,11 +3420,11 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3408
3420
|
}
|
3409
3421
|
_validateDunderSignatures(node, functionType, isMethod) {
|
3410
3422
|
var _a;
|
3411
|
-
const functionName = functionType.
|
3423
|
+
const functionName = functionType.shared.name;
|
3412
3424
|
// Is this an '__init__' method? Verify that it returns None.
|
3413
3425
|
if (isMethod && functionName === '__init__') {
|
3414
|
-
const returnAnnotation = node.
|
3415
|
-
const declaredReturnType = functionType.
|
3426
|
+
const returnAnnotation = node.d.returnAnnotation || ((_a = node.d.funcAnnotationComment) === null || _a === void 0 ? void 0 : _a.d.returnAnnotation);
|
3427
|
+
const declaredReturnType = functionType.shared.declaredReturnType;
|
3416
3428
|
if (returnAnnotation && declaredReturnType) {
|
3417
3429
|
if (!(0, typeUtils_1.isNoneInstance)(declaredReturnType) && !(0, types_1.isNever)(declaredReturnType)) {
|
3418
3430
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.initMustReturnNone(), returnAnnotation);
|
@@ -3423,7 +3435,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3423
3435
|
if (!(0, types_1.isNever)(inferredReturnType) &&
|
3424
3436
|
!(0, typeUtils_1.isNoneInstance)(inferredReturnType) &&
|
3425
3437
|
!(0, types_1.isAnyOrUnknown)(inferredReturnType)) {
|
3426
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.initMustReturnNone(), node.name);
|
3438
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.initMustReturnNone(), node.d.name);
|
3427
3439
|
}
|
3428
3440
|
}
|
3429
3441
|
}
|
@@ -3435,11 +3447,11 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3435
3447
|
if (this._fileInfo.isStubFile) {
|
3436
3448
|
return;
|
3437
3449
|
}
|
3438
|
-
const returnAnnotation = node.
|
3450
|
+
const returnAnnotation = node.d.returnAnnotation || ((_a = node.d.funcAnnotationComment) === null || _a === void 0 ? void 0 : _a.d.returnAnnotation);
|
3439
3451
|
if (returnAnnotation) {
|
3440
3452
|
const functionNeverReturns = !this._evaluator.isAfterNodeReachable(node);
|
3441
|
-
const implicitlyReturnsNone = this._evaluator.isAfterNodeReachable(node.suite);
|
3442
|
-
let declaredReturnType = functionType.
|
3453
|
+
const implicitlyReturnsNone = this._evaluator.isAfterNodeReachable(node.d.suite);
|
3454
|
+
let declaredReturnType = functionType.shared.declaredReturnType;
|
3443
3455
|
if (declaredReturnType) {
|
3444
3456
|
this._reportUnknownReturnResult(node, declaredReturnType);
|
3445
3457
|
this._validateReturnTypeIsNotContravariant(declaredReturnType, returnAnnotation);
|
@@ -3456,7 +3468,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3456
3468
|
// If the function consists entirely of "...", assume that it's
|
3457
3469
|
// an abstract method or a protocol method and don't require that
|
3458
3470
|
// the return type matches. This check can also be skipped for an overload.
|
3459
|
-
if (!ParseTreeUtils.isSuiteEmpty(node.suite) &&
|
3471
|
+
if (!ParseTreeUtils.isSuiteEmpty(node.d.suite) &&
|
3460
3472
|
!types_1.FunctionType.isOverloaded(functionType) &&
|
3461
3473
|
!types_1.FunctionType.isAsync(functionType)) {
|
3462
3474
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportReturnType, localize_1.LocMessage.noReturnReturnsNone(), returnAnnotation);
|
@@ -3471,7 +3483,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3471
3483
|
// If the function consists entirely of "...", assume that it's
|
3472
3484
|
// an abstract method or a protocol method and don't require that
|
3473
3485
|
// the return type matches. This check can also be skipped for an overload.
|
3474
|
-
if (!ParseTreeUtils.isSuiteEmpty(node.suite) && !types_1.FunctionType.isOverloaded(functionType)) {
|
3486
|
+
if (!ParseTreeUtils.isSuiteEmpty(node.d.suite) && !types_1.FunctionType.isOverloaded(functionType)) {
|
3475
3487
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportReturnType, localize_1.LocMessage.returnMissing().format({
|
3476
3488
|
returnType: this._evaluator.printType(declaredReturnType),
|
3477
3489
|
}) + diagAddendum.getString(), returnAnnotation);
|
@@ -3483,15 +3495,15 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3483
3495
|
else {
|
3484
3496
|
const inferredReturnType = this._evaluator.getFunctionInferredReturnType(functionType);
|
3485
3497
|
this._reportUnknownReturnResult(node, inferredReturnType);
|
3486
|
-
this._validateReturnTypeIsNotContravariant(inferredReturnType, node.name);
|
3498
|
+
this._validateReturnTypeIsNotContravariant(inferredReturnType, node.d.name);
|
3487
3499
|
}
|
3488
3500
|
}
|
3489
3501
|
_validateReturnTypeIsNotContravariant(returnType, errorNode) {
|
3490
3502
|
let isContraTypeVar = false;
|
3491
3503
|
(0, typeUtils_1.doForEachSubtype)(returnType, (subtype) => {
|
3492
3504
|
if ((0, types_1.isTypeVar)(subtype) &&
|
3493
|
-
subtype.
|
3494
|
-
subtype.scopeType === 0 /* TypeVarScopeType.Class */) {
|
3505
|
+
subtype.shared.declaredVariance === 4 /* Variance.Contravariant */ &&
|
3506
|
+
subtype.priv.scopeType === 0 /* TypeVarScopeType.Class */) {
|
3495
3507
|
isContraTypeVar = true;
|
3496
3508
|
}
|
3497
3509
|
});
|
@@ -3501,12 +3513,12 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3501
3513
|
}
|
3502
3514
|
_reportUnknownReturnResult(node, returnType) {
|
3503
3515
|
if ((0, types_1.isUnknown)(returnType)) {
|
3504
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnknownParameterType, localize_1.LocMessage.returnTypeUnknown(), node.name);
|
3516
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnknownParameterType, localize_1.LocMessage.returnTypeUnknown(), node.d.name);
|
3505
3517
|
}
|
3506
3518
|
else if ((0, typeUtils_1.isPartlyUnknown)(returnType)) {
|
3507
3519
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnknownParameterType, localize_1.LocMessage.returnTypePartiallyUnknown().format({
|
3508
3520
|
returnType: this._evaluator.printType(returnType, { expandTypeAlias: true }),
|
3509
|
-
}), node.name);
|
3521
|
+
}), node.d.name);
|
3510
3522
|
}
|
3511
3523
|
}
|
3512
3524
|
// Validates that any overridden member variables are not marked
|
@@ -3520,7 +3532,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3520
3532
|
const decl = localSymbol.getDeclarations()[0];
|
3521
3533
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.finalRedeclarationBySubclass().format({
|
3522
3534
|
name,
|
3523
|
-
className: parentSymbol.classType.
|
3535
|
+
className: parentSymbol.classType.shared.name,
|
3524
3536
|
}), decl.node);
|
3525
3537
|
}
|
3526
3538
|
else if (types_1.ClassType.isReadOnlyInstanceVariables(parentSymbol.classType) &&
|
@@ -3531,7 +3543,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3531
3543
|
if (decl.type === 1 /* DeclarationType.Variable */) {
|
3532
3544
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompatibleVariableOverride, localize_1.LocMessage.namedTupleEntryRedeclared().format({
|
3533
3545
|
name,
|
3534
|
-
className: parentSymbol.classType.
|
3546
|
+
className: parentSymbol.classType.shared.name,
|
3535
3547
|
}), decl.node);
|
3536
3548
|
}
|
3537
3549
|
}
|
@@ -3548,7 +3560,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3548
3560
|
const declaredValueType = (0, enums_1.getEnumDeclaredValueType)(this._evaluator, classType, /* declaredTypesOnly */ true);
|
3549
3561
|
// Is there a custom "__new__" and/or "__init__" method? If so, we'll
|
3550
3562
|
// verify that the signature of these calls is compatible with the values.
|
3551
|
-
let newMemberTypeResult = (0, constructors_1.getBoundNewMethod)(this._evaluator, node.name, classType,
|
3563
|
+
let newMemberTypeResult = (0, constructors_1.getBoundNewMethod)(this._evaluator, node.d.name, classType,
|
3552
3564
|
/* diag */ undefined, 4 /* MemberAccessFlags.SkipObjectBaseClass */);
|
3553
3565
|
// If this __new__ comes from a built-in class like Enum, we'll ignore it.
|
3554
3566
|
if (newMemberTypeResult === null || newMemberTypeResult === void 0 ? void 0 : newMemberTypeResult.classType) {
|
@@ -3556,7 +3568,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3556
3568
|
newMemberTypeResult = undefined;
|
3557
3569
|
}
|
3558
3570
|
}
|
3559
|
-
let initMemberTypeResult = (0, constructors_1.getBoundInitMethod)(this._evaluator, node.name, types_1.ClassType.cloneAsInstance(classType),
|
3571
|
+
let initMemberTypeResult = (0, constructors_1.getBoundInitMethod)(this._evaluator, node.d.name, types_1.ClassType.cloneAsInstance(classType),
|
3560
3572
|
/* diag */ undefined, 4 /* MemberAccessFlags.SkipObjectBaseClass */);
|
3561
3573
|
// If this __init__ comes from a built-in class like Enum, we'll ignore it.
|
3562
3574
|
if (initMemberTypeResult === null || initMemberTypeResult === void 0 ? void 0 : initMemberTypeResult.classType) {
|
@@ -3577,7 +3589,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3577
3589
|
if (!symbolType ||
|
3578
3590
|
!(0, types_1.isClassInstance)(symbolType) ||
|
3579
3591
|
!types_1.ClassType.isSameGenericClass(symbolType, classType) ||
|
3580
|
-
!(symbolType.literalValue instanceof types_1.EnumLiteral)) {
|
3592
|
+
!(symbolType.priv.literalValue instanceof types_1.EnumLiteral)) {
|
3581
3593
|
return;
|
3582
3594
|
}
|
3583
3595
|
// Enum members should not have type annotations.
|
@@ -3598,9 +3610,9 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3598
3610
|
return;
|
3599
3611
|
}
|
3600
3612
|
const declNode = decls[0].node;
|
3601
|
-
const assignedValueType = symbolType.literalValue.itemType;
|
3613
|
+
const assignedValueType = symbolType.priv.literalValue.itemType;
|
3602
3614
|
const assignmentNode = ParseTreeUtils.getParentNodeOfType(declNode, 3 /* ParseNodeType.Assignment */);
|
3603
|
-
const errorNode = (_a = assignmentNode === null || assignmentNode === void 0 ? void 0 : assignmentNode.
|
3615
|
+
const errorNode = (_a = assignmentNode === null || assignmentNode === void 0 ? void 0 : assignmentNode.d.rightExpr) !== null && _a !== void 0 ? _a : declNode;
|
3604
3616
|
// Validate the __new__ and __init__ methods if present.
|
3605
3617
|
if (newMemberTypeResult || initMemberTypeResult) {
|
3606
3618
|
if (!(0, types_1.isAnyOrUnknown)(assignedValueType)) {
|
@@ -3618,15 +3630,13 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3618
3630
|
this._evaluator.validateCallArguments(errorNode, argList, newMemberTypeResult,
|
3619
3631
|
/* typeVarContext */ undefined,
|
3620
3632
|
/* skipUnknownArgCheck */ undefined,
|
3621
|
-
/* inferenceContext */ undefined
|
3622
|
-
/* signatureTracker */ undefined);
|
3633
|
+
/* inferenceContext */ undefined);
|
3623
3634
|
}
|
3624
3635
|
if (initMemberTypeResult) {
|
3625
3636
|
this._evaluator.validateCallArguments(errorNode, argList, initMemberTypeResult,
|
3626
3637
|
/* typeVarContext */ undefined,
|
3627
3638
|
/* skipUnknownArgCheck */ undefined,
|
3628
|
-
/* inferenceContext */ undefined
|
3629
|
-
/* signatureTracker */ undefined);
|
3639
|
+
/* inferenceContext */ undefined);
|
3630
3640
|
}
|
3631
3641
|
}
|
3632
3642
|
}
|
@@ -3644,7 +3654,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3644
3654
|
}
|
3645
3655
|
// If a class is a dataclass with a `__post_init__` method, verify that its
|
3646
3656
|
// signature is correct.
|
3647
|
-
_validateDataClassPostInit(classType
|
3657
|
+
_validateDataClassPostInit(classType) {
|
3648
3658
|
if (!types_1.ClassType.isDataClass(classType)) {
|
3649
3659
|
return;
|
3650
3660
|
}
|
@@ -3671,7 +3681,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3671
3681
|
const postInitType = this._evaluator.getTypeOfMember(postInitMember);
|
3672
3682
|
if (!(0, types_1.isFunction)(postInitType) ||
|
3673
3683
|
!types_1.FunctionType.isInstanceMethod(postInitType) ||
|
3674
|
-
!postInitType.
|
3684
|
+
!postInitType.shared.declaration) {
|
3675
3685
|
return;
|
3676
3686
|
}
|
3677
3687
|
const paramListDetails = (0, parameterUtils_1.getParameterListDetails)(postInitType);
|
@@ -3683,26 +3693,29 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3683
3693
|
return;
|
3684
3694
|
}
|
3685
3695
|
// Verify that the parameter count matches.
|
3686
|
-
const nonDefaultParams = paramListDetails.params.filter((paramInfo) => !paramInfo.param.
|
3696
|
+
const nonDefaultParams = paramListDetails.params.filter((paramInfo) => !paramInfo.param.defaultType);
|
3687
3697
|
// We expect to see one param for "self" plus one for each of the InitVars.
|
3688
3698
|
const expectedParamCount = initOnlySymbolMap.size + 1;
|
3699
|
+
const postInitNode = postInitType.shared.declaration.node;
|
3689
3700
|
if (expectedParamCount < nonDefaultParams.length || expectedParamCount > paramListDetails.params.length) {
|
3690
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.dataClassPostInitParamCount().format({ expected: initOnlySymbolMap.size }),
|
3701
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.dataClassPostInitParamCount().format({ expected: initOnlySymbolMap.size }), postInitNode.d.name);
|
3691
3702
|
}
|
3692
3703
|
// Verify that the parameter types match.
|
3693
3704
|
let paramIndex = 1;
|
3694
3705
|
initOnlySymbolMap.forEach((symbol, fieldName) => {
|
3695
|
-
var _a;
|
3706
|
+
var _a, _b;
|
3696
3707
|
if (paramIndex >= paramListDetails.params.length) {
|
3697
3708
|
return;
|
3698
3709
|
}
|
3699
3710
|
const param = paramListDetails.params[paramIndex].param;
|
3700
|
-
|
3701
|
-
|
3711
|
+
const paramNode = postInitNode.d.params.find((node) => { var _a; return ((_a = node.d.name) === null || _a === void 0 ? void 0 : _a.d.value) === param.name; });
|
3712
|
+
const annotationNode = (_a = paramNode === null || paramNode === void 0 ? void 0 : paramNode.d.annotation) !== null && _a !== void 0 ? _a : paramNode === null || paramNode === void 0 ? void 0 : paramNode.d.annotationComment;
|
3713
|
+
if (types_1.FunctionParam.isTypeDeclared(param) && annotationNode) {
|
3714
|
+
const fieldType = (_b = this._evaluator.getDeclaredTypeOfSymbol(symbol)) === null || _b === void 0 ? void 0 : _b.type;
|
3702
3715
|
const paramType = types_1.FunctionType.getEffectiveParameterType(postInitType, paramListDetails.params[paramIndex].index);
|
3703
3716
|
const assignTypeDiag = new diagnostic_1.DiagnosticAddendum();
|
3704
3717
|
if (fieldType && !this._evaluator.assignType(paramType, fieldType, assignTypeDiag)) {
|
3705
|
-
const diagnostic = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.dataClassPostInitType().format({ fieldName }) + assignTypeDiag.getString(),
|
3718
|
+
const diagnostic = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.dataClassPostInitType().format({ fieldName }) + assignTypeDiag.getString(), annotationNode);
|
3706
3719
|
if (diagnostic) {
|
3707
3720
|
const fieldDecls = symbol.getTypedDeclarations();
|
3708
3721
|
if (fieldDecls.length > 0) {
|
@@ -3737,7 +3750,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3737
3750
|
}
|
3738
3751
|
else if (index < errorsToDisplay) {
|
3739
3752
|
if ((0, types_1.isInstantiableClass)(abstractMethod.classType)) {
|
3740
|
-
const className = abstractMethod.classType.
|
3753
|
+
const className = abstractMethod.classType.shared.name;
|
3741
3754
|
diagAddendum.addMessage(localize_1.LocAddendum.memberIsAbstract().format({
|
3742
3755
|
type: className,
|
3743
3756
|
name: abstractMethod.symbolName,
|
@@ -3746,8 +3759,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3746
3759
|
}
|
3747
3760
|
});
|
3748
3761
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.finalClassIsAbstract().format({
|
3749
|
-
type: classType.
|
3750
|
-
}) + diagAddendum.getString(), errorNode.name);
|
3762
|
+
type: classType.shared.name,
|
3763
|
+
}) + diagAddendum.getString(), errorNode.d.name);
|
3751
3764
|
}
|
3752
3765
|
// Reports the case where an instance variable is not declared or initialized
|
3753
3766
|
// within the class body or constructor method.
|
@@ -3816,7 +3829,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3816
3829
|
return true;
|
3817
3830
|
}
|
3818
3831
|
}
|
3819
|
-
if (containingClass.name.value === '__init__') {
|
3832
|
+
if (containingClass.d.name.d.value === '__init__') {
|
3820
3833
|
return true;
|
3821
3834
|
}
|
3822
3835
|
return false;
|
@@ -3859,12 +3872,12 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3859
3872
|
}
|
3860
3873
|
diagAddendum.addMessage(localize_1.LocAddendum.uninitializedAbstractVariable().format({
|
3861
3874
|
name,
|
3862
|
-
classType: member.classType.
|
3875
|
+
classType: member.classType.shared.name,
|
3863
3876
|
}));
|
3864
3877
|
});
|
3865
3878
|
if (!diagAddendum.isEmpty()) {
|
3866
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUninitializedInstanceVariable, localize_1.LocMessage.uninitializedAbstractVariables().format({ classType: classType.
|
3867
|
-
diagAddendum.getString(), node.name);
|
3879
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUninitializedInstanceVariable, localize_1.LocMessage.uninitializedAbstractVariables().format({ classType: classType.shared.name }) +
|
3880
|
+
diagAddendum.getString(), node.d.name);
|
3868
3881
|
}
|
3869
3882
|
}
|
3870
3883
|
// Validates that the type variables used in a generic protocol class have
|
@@ -3872,7 +3885,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3872
3885
|
// for an explanation for why this is important to enforce.
|
3873
3886
|
_validateProtocolTypeParamVariance(errorNode, classType) {
|
3874
3887
|
// If this protocol has no TypeVars with specified variance, there's nothing to do here.
|
3875
|
-
if (classType.
|
3888
|
+
if (classType.shared.typeParameters.length === 0) {
|
3876
3889
|
return;
|
3877
3890
|
}
|
3878
3891
|
const objectType = this._evaluator.getBuiltInType(errorNode, 'object');
|
@@ -3881,27 +3894,27 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3881
3894
|
}
|
3882
3895
|
const objectObject = types_1.ClassType.cloneAsInstance(objectType);
|
3883
3896
|
const dummyTypeObject = types_1.ClassType.createInstantiable('__varianceDummy', '', '', uri_1.Uri.empty(), 0, 0, undefined, undefined);
|
3884
|
-
classType.
|
3897
|
+
classType.shared.typeParameters.forEach((param, paramIndex) => {
|
3885
3898
|
// Skip variadics and ParamSpecs.
|
3886
|
-
if (param.
|
3899
|
+
if (param.shared.isVariadic || param.shared.isParamSpec) {
|
3887
3900
|
return;
|
3888
3901
|
}
|
3889
3902
|
// Skip type variables with auto-variance.
|
3890
|
-
if (param.
|
3903
|
+
if (param.shared.declaredVariance === 0 /* Variance.Auto */) {
|
3891
3904
|
return;
|
3892
3905
|
}
|
3893
3906
|
// Replace all type arguments with a dummy type except for the
|
3894
3907
|
// TypeVar of interest, which is replaced with an object instance.
|
3895
|
-
const srcTypeArgs = classType.
|
3896
|
-
if (p.
|
3908
|
+
const srcTypeArgs = classType.shared.typeParameters.map((p, i) => {
|
3909
|
+
if (p.shared.isVariadic) {
|
3897
3910
|
return p;
|
3898
3911
|
}
|
3899
3912
|
return i === paramIndex ? objectObject : dummyTypeObject;
|
3900
3913
|
});
|
3901
3914
|
// Replace all type arguments with a dummy type except for the
|
3902
3915
|
// TypeVar of interest, which is replaced with itself.
|
3903
|
-
const destTypeArgs = classType.
|
3904
|
-
return i === paramIndex || p.
|
3916
|
+
const destTypeArgs = classType.shared.typeParameters.map((p, i) => {
|
3917
|
+
return i === paramIndex || p.shared.isVariadic ? p : dummyTypeObject;
|
3905
3918
|
});
|
3906
3919
|
const srcType = types_1.ClassType.cloneForSpecialization(classType, srcTypeArgs, /* isTypeArgumentExplicit */ true);
|
3907
3920
|
const destType = types_1.ClassType.cloneForSpecialization(classType, destTypeArgs,
|
@@ -3920,34 +3933,34 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3920
3933
|
expectedVariance = 2 /* Variance.Invariant */;
|
3921
3934
|
}
|
3922
3935
|
}
|
3923
|
-
if (expectedVariance !== classType.
|
3936
|
+
if (expectedVariance !== classType.shared.typeParameters[paramIndex].shared.declaredVariance) {
|
3924
3937
|
let message;
|
3925
3938
|
if (expectedVariance === 3 /* Variance.Covariant */) {
|
3926
3939
|
message = localize_1.LocMessage.protocolVarianceCovariant().format({
|
3927
|
-
variable: param.
|
3928
|
-
class: classType.
|
3940
|
+
variable: param.shared.name,
|
3941
|
+
class: classType.shared.name,
|
3929
3942
|
});
|
3930
3943
|
}
|
3931
3944
|
else if (expectedVariance === 4 /* Variance.Contravariant */) {
|
3932
3945
|
message = localize_1.LocMessage.protocolVarianceContravariant().format({
|
3933
|
-
variable: param.
|
3934
|
-
class: classType.
|
3946
|
+
variable: param.shared.name,
|
3947
|
+
class: classType.shared.name,
|
3935
3948
|
});
|
3936
3949
|
}
|
3937
3950
|
else {
|
3938
3951
|
message = localize_1.LocMessage.protocolVarianceInvariant().format({
|
3939
|
-
variable: param.
|
3940
|
-
class: classType.
|
3952
|
+
variable: param.shared.name,
|
3953
|
+
class: classType.shared.name,
|
3941
3954
|
});
|
3942
3955
|
}
|
3943
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeVarUse, message, errorNode.name);
|
3956
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeVarUse, message, errorNode.d.name);
|
3944
3957
|
}
|
3945
3958
|
});
|
3946
3959
|
}
|
3947
3960
|
// Validates that a class variable doesn't conflict with a __slots__
|
3948
3961
|
// name. This will generate a runtime exception.
|
3949
3962
|
_validateSlotsClassVarConflict(classType) {
|
3950
|
-
if (!classType.
|
3963
|
+
if (!classType.shared.localSlotsNames) {
|
3951
3964
|
// Nothing to check, since this class doesn't use __slots__.
|
3952
3965
|
return;
|
3953
3966
|
}
|
@@ -4029,22 +4042,22 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4029
4042
|
// We'll set the "SkipArgsKwargs" flag for pragmatic reasons since __new__
|
4030
4043
|
// often has an *args and/or **kwargs. We'll also set the ParamSpecValue
|
4031
4044
|
// because we don't care about the return type for this check.
|
4032
|
-
initMemberType = types_1.FunctionType.cloneWithNewFlags(initMemberType, initMemberType.
|
4033
|
-
newMemberType = types_1.FunctionType.cloneWithNewFlags(newMemberType, initMemberType.
|
4045
|
+
initMemberType = types_1.FunctionType.cloneWithNewFlags(initMemberType, initMemberType.shared.flags | 32768 /* FunctionTypeFlags.GradualCallableForm */ | 65536 /* FunctionTypeFlags.ParamSpecValue */);
|
4046
|
+
newMemberType = types_1.FunctionType.cloneWithNewFlags(newMemberType, initMemberType.shared.flags | 32768 /* FunctionTypeFlags.GradualCallableForm */ | 65536 /* FunctionTypeFlags.ParamSpecValue */);
|
4034
4047
|
if (!this._evaluator.assignType(newMemberType, initMemberType,
|
4035
4048
|
/* diag */ undefined,
|
4036
4049
|
/* destTypeVarContext */ undefined,
|
4037
|
-
/* srcTypeVarContext */ undefined, 64 /* AssignTypeFlags.
|
4050
|
+
/* srcTypeVarContext */ undefined, 64 /* AssignTypeFlags.SkipReturnTypeCheck */) ||
|
4038
4051
|
!this._evaluator.assignType(initMemberType, newMemberType,
|
4039
4052
|
/* diag */ undefined,
|
4040
4053
|
/* destTypeVarContext */ undefined,
|
4041
|
-
/* srcTypeVarContext */ undefined, 64 /* AssignTypeFlags.
|
4054
|
+
/* srcTypeVarContext */ undefined, 64 /* AssignTypeFlags.SkipReturnTypeCheck */)) {
|
4042
4055
|
const displayOnInit = types_1.ClassType.isSameGenericClass(initMethodResult.classType, classType);
|
4043
|
-
const initDecl = initMemberType.
|
4044
|
-
const newDecl = newMemberType.
|
4056
|
+
const initDecl = initMemberType.shared.declaration;
|
4057
|
+
const newDecl = newMemberType.shared.declaration;
|
4045
4058
|
if (initDecl && newDecl) {
|
4046
4059
|
const mainDecl = displayOnInit ? initDecl : newDecl;
|
4047
|
-
const mainDeclNode = mainDecl.node.nodeType === 31 /* ParseNodeType.Function */ ? mainDecl.node.name : mainDecl.node;
|
4060
|
+
const mainDeclNode = mainDecl.node.nodeType === 31 /* ParseNodeType.Function */ ? mainDecl.node.d.name : mainDecl.node;
|
4048
4061
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
4049
4062
|
const initSignature = this._evaluator.printType(initMemberType);
|
4050
4063
|
const newSignature = this._evaluator.printType(newMemberType);
|
@@ -4072,7 +4085,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4072
4085
|
// Skip this check if the class has only one base class or one or more
|
4073
4086
|
// of the base classes are Any.
|
4074
4087
|
const filteredBaseClasses = [];
|
4075
|
-
for (const baseClass of classType.
|
4088
|
+
for (const baseClass of classType.shared.baseClasses) {
|
4076
4089
|
if (!(0, types_1.isClass)(baseClass)) {
|
4077
4090
|
return;
|
4078
4091
|
}
|
@@ -4086,12 +4099,12 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4086
4099
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
4087
4100
|
for (const baseClass of filteredBaseClasses) {
|
4088
4101
|
const typeVarContext = (0, typeUtils_1.buildTypeVarContextFromSpecializedClass)(baseClass);
|
4089
|
-
for (const baseClassMroClass of baseClass.
|
4102
|
+
for (const baseClassMroClass of baseClass.shared.mro) {
|
4090
4103
|
// There's no need to check for conflicts if this class isn't generic.
|
4091
|
-
if ((0, types_1.isClass)(baseClassMroClass) && baseClassMroClass.
|
4104
|
+
if ((0, types_1.isClass)(baseClassMroClass) && baseClassMroClass.shared.typeParameters.length > 0) {
|
4092
4105
|
const specializedBaseClassMroClass = (0, typeUtils_1.applySolvedTypeVars)(baseClassMroClass, typeVarContext);
|
4093
4106
|
// Find the corresponding class in the derived class's MRO list.
|
4094
|
-
const matchingMroClass = classType.
|
4107
|
+
const matchingMroClass = classType.shared.mro.find((mroClass) => (0, types_1.isClass)(mroClass) && types_1.ClassType.isSameGenericClass(mroClass, specializedBaseClassMroClass));
|
4095
4108
|
if (matchingMroClass && (0, types_1.isInstantiableClass)(matchingMroClass)) {
|
4096
4109
|
const matchingMroObject = types_1.ClassType.cloneAsInstance(matchingMroClass);
|
4097
4110
|
const baseClassMroObject = types_1.ClassType.cloneAsInstance(specializedBaseClassMroClass);
|
@@ -4120,7 +4133,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4120
4133
|
}
|
4121
4134
|
}
|
4122
4135
|
if (!diagAddendum.isEmpty()) {
|
4123
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.baseClassIncompatible().format({ type: classType.
|
4136
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.baseClassIncompatible().format({ type: classType.shared.name }) + diagAddendum.getString(), errorNode);
|
4124
4137
|
}
|
4125
4138
|
}
|
4126
4139
|
// Validates that any methods and variables in multiple base classes are
|
@@ -4135,7 +4148,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4135
4148
|
const baseClasses = [];
|
4136
4149
|
// Filter any unknown base classes. Also remove Generic and Protocol
|
4137
4150
|
// base classes.
|
4138
|
-
classType.
|
4151
|
+
classType.shared.baseClasses.forEach((baseClass) => {
|
4139
4152
|
if ((0, types_1.isClass)(baseClass) &&
|
4140
4153
|
!types_1.ClassType.isBuiltIn(baseClass, 'Generic') &&
|
4141
4154
|
!types_1.ClassType.isBuiltIn(baseClass, 'Protocol')) {
|
@@ -4148,7 +4161,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4148
4161
|
}
|
4149
4162
|
// Build maps of symbols for each of the base classes.
|
4150
4163
|
const baseClassSymbolMaps = baseClasses.map((baseClass) => {
|
4151
|
-
const specializedBaseClass = classType.
|
4164
|
+
const specializedBaseClass = classType.shared.mro.find((c) => (0, types_1.isClass)(c) && types_1.ClassType.isSameGenericClass(c, baseClass));
|
4152
4165
|
if (!specializedBaseClass || !(0, types_1.isClass)(specializedBaseClass)) {
|
4153
4166
|
return new Map();
|
4154
4167
|
}
|
@@ -4195,10 +4208,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4195
4208
|
return;
|
4196
4209
|
}
|
4197
4210
|
let overriddenType = this._evaluator.getEffectiveTypeOfSymbol(overriddenClassAndSymbol.symbol);
|
4198
|
-
overriddenType = (0, typeUtils_1.partiallySpecializeType)(overriddenType, overriddenClassAndSymbol.classType);
|
4211
|
+
overriddenType = (0, typeUtils_1.partiallySpecializeType)(overriddenType, overriddenClassAndSymbol.classType, this._evaluator.getTypeClassType());
|
4199
4212
|
const overrideSymbol = overrideClassAndSymbol.symbol;
|
4200
4213
|
let overrideType = this._evaluator.getEffectiveTypeOfSymbol(overrideSymbol);
|
4201
|
-
overrideType = (0, typeUtils_1.partiallySpecializeType)(overrideType, overrideClassAndSymbol.classType);
|
4214
|
+
overrideType = (0, typeUtils_1.partiallySpecializeType)(overrideType, overrideClassAndSymbol.classType, this._evaluator.getTypeClassType());
|
4202
4215
|
const childOverrideSymbol = types_1.ClassType.getSymbolTable(childClassType).get(memberName);
|
4203
4216
|
const childOverrideType = childOverrideSymbol
|
4204
4217
|
? this._evaluator.getEffectiveTypeOfSymbol(childOverrideSymbol)
|
@@ -4224,10 +4237,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4224
4237
|
if (!this._evaluator.validateOverrideMethod(overriddenType, overrideFunction,
|
4225
4238
|
/* baseClass */ undefined, diagAddendum,
|
4226
4239
|
/* enforceParamNameMatch */ true)) {
|
4227
|
-
const decl = overrideFunction.
|
4240
|
+
const decl = overrideFunction.shared.declaration;
|
4228
4241
|
if (decl && decl.type === 5 /* DeclarationType.Function */) {
|
4229
4242
|
diag = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompatibleMethodOverride, localize_1.LocMessage.baseClassMethodTypeIncompatible().format({
|
4230
|
-
classType: childClassType.
|
4243
|
+
classType: childClassType.shared.name,
|
4231
4244
|
name: memberName,
|
4232
4245
|
}) + diagAddendum.getString(), errorNode);
|
4233
4246
|
}
|
@@ -4240,7 +4253,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4240
4253
|
const decls = overrideSymbol.getDeclarations();
|
4241
4254
|
if (decls.length > 0) {
|
4242
4255
|
diag = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompatibleVariableOverride, localize_1.LocMessage.baseClassVariableTypeIncompatible().format({
|
4243
|
-
classType: childClassType.
|
4256
|
+
classType: childClassType.shared.name,
|
4244
4257
|
name: memberName,
|
4245
4258
|
}), errorNode);
|
4246
4259
|
}
|
@@ -4258,31 +4271,31 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4258
4271
|
// If the entry is a member of a frozen dataclass, it is immutable,
|
4259
4272
|
// so it does not need to be invariant.
|
4260
4273
|
if (types_1.ClassType.isDataClassFrozen(overriddenClassAndSymbol.classType) &&
|
4261
|
-
overriddenClassAndSymbol.classType.
|
4262
|
-
const dataclassEntry = overriddenClassAndSymbol.classType.
|
4274
|
+
overriddenClassAndSymbol.classType.shared.dataClassEntries) {
|
4275
|
+
const dataclassEntry = overriddenClassAndSymbol.classType.shared.dataClassEntries.find((entry) => entry.name === memberName);
|
4263
4276
|
if (dataclassEntry) {
|
4264
4277
|
isInvariant = false;
|
4265
4278
|
}
|
4266
4279
|
}
|
4267
4280
|
let overriddenTDEntry;
|
4268
|
-
if (overriddenClassAndSymbol.classType.
|
4281
|
+
if (overriddenClassAndSymbol.classType.shared.typedDictEntries) {
|
4269
4282
|
overriddenTDEntry =
|
4270
|
-
(_b = (_a = overriddenClassAndSymbol.classType.
|
4283
|
+
(_b = (_a = overriddenClassAndSymbol.classType.shared.typedDictEntries.knownItems.get(memberName)) !== null && _a !== void 0 ? _a : overriddenClassAndSymbol.classType.shared.typedDictEntries.extraItems) !== null && _b !== void 0 ? _b : (0, typedDicts_1.getEffectiveExtraItemsEntryType)(this._evaluator, overriddenClassAndSymbol.classType);
|
4271
4284
|
if (overriddenTDEntry === null || overriddenTDEntry === void 0 ? void 0 : overriddenTDEntry.isReadOnly) {
|
4272
4285
|
isInvariant = false;
|
4273
4286
|
}
|
4274
4287
|
}
|
4275
4288
|
let overrideTDEntry;
|
4276
|
-
if (overrideClassAndSymbol.classType.
|
4289
|
+
if (overrideClassAndSymbol.classType.shared.typedDictEntries) {
|
4277
4290
|
overrideTDEntry =
|
4278
|
-
(_d = (_c = overrideClassAndSymbol.classType.
|
4291
|
+
(_d = (_c = overrideClassAndSymbol.classType.shared.typedDictEntries.knownItems.get(memberName)) !== null && _c !== void 0 ? _c : overrideClassAndSymbol.classType.shared.typedDictEntries.extraItems) !== null && _d !== void 0 ? _d : (0, typedDicts_1.getEffectiveExtraItemsEntryType)(this._evaluator, overrideClassAndSymbol.classType);
|
4279
4292
|
}
|
4280
4293
|
if (!this._evaluator.assignType(overriddenType, childOverrideType !== null && childOverrideType !== void 0 ? childOverrideType : overrideType,
|
4281
4294
|
/* diag */ undefined,
|
4282
4295
|
/* destTypeVarContext */ undefined,
|
4283
4296
|
/* srcTypeVarContext */ undefined, isInvariant ? 1 /* AssignTypeFlags.EnforceInvariance */ : 0 /* AssignTypeFlags.Default */)) {
|
4284
4297
|
diag = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompatibleVariableOverride, localize_1.LocMessage.baseClassVariableTypeIncompatible().format({
|
4285
|
-
classType: childClassType.
|
4298
|
+
classType: childClassType.shared.name,
|
4286
4299
|
name: memberName,
|
4287
4300
|
}), errorNode);
|
4288
4301
|
}
|
@@ -4328,9 +4341,9 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4328
4341
|
}
|
4329
4342
|
_validateMultipleInheritancePropertyOverride(overriddenClassType, overrideClassType, overriddenSymbolType, overrideSymbolType, overrideSymbol, memberName, errorNode) {
|
4330
4343
|
const propMethodInfo = [
|
4331
|
-
['fget', (c) => { var _a; return (_a = c.fgetInfo) === null || _a === void 0 ? void 0 : _a.methodType; }],
|
4332
|
-
['fset', (c) => { var _a; return (_a = c.fsetInfo) === null || _a === void 0 ? void 0 : _a.methodType; }],
|
4333
|
-
['fdel', (c) => { var _a; return (_a = c.fdelInfo) === null || _a === void 0 ? void 0 : _a.methodType; }],
|
4344
|
+
['fget', (c) => { var _a; return (_a = c.priv.fgetInfo) === null || _a === void 0 ? void 0 : _a.methodType; }],
|
4345
|
+
['fset', (c) => { var _a; return (_a = c.priv.fsetInfo) === null || _a === void 0 ? void 0 : _a.methodType; }],
|
4346
|
+
['fdel', (c) => { var _a; return (_a = c.priv.fdelInfo) === null || _a === void 0 ? void 0 : _a.methodType; }],
|
4334
4347
|
];
|
4335
4348
|
propMethodInfo.forEach((info) => {
|
4336
4349
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
@@ -4339,7 +4352,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4339
4352
|
const subclassPropMethod = methodAccessor(overrideSymbolType);
|
4340
4353
|
// Is the method present on the base class but missing in the subclass?
|
4341
4354
|
if (baseClassPropMethod) {
|
4342
|
-
const baseClassMethodType = (0, typeUtils_1.partiallySpecializeType)(baseClassPropMethod, overriddenClassType);
|
4355
|
+
const baseClassMethodType = (0, typeUtils_1.partiallySpecializeType)(baseClassPropMethod, overriddenClassType, this._evaluator.getTypeClassType());
|
4343
4356
|
if ((0, types_1.isFunction)(baseClassMethodType)) {
|
4344
4357
|
if (!subclassPropMethod) {
|
4345
4358
|
// The method is missing.
|
@@ -4351,28 +4364,28 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4351
4364
|
const lastDecl = decls[decls.length - 1];
|
4352
4365
|
const diag = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompatibleMethodOverride, localize_1.LocMessage.propertyOverridden().format({
|
4353
4366
|
name: memberName,
|
4354
|
-
className: overriddenClassType.
|
4367
|
+
className: overriddenClassType.shared.name,
|
4355
4368
|
}) + diagAddendum.getString(), errorNode);
|
4356
|
-
const origDecl = baseClassMethodType.
|
4369
|
+
const origDecl = baseClassMethodType.shared.declaration;
|
4357
4370
|
if (diag && origDecl) {
|
4358
4371
|
this._addMultipleInheritanceRelatedInfo(diag, overriddenClassType, overriddenSymbolType, origDecl, overrideClassType, overrideSymbolType, lastDecl);
|
4359
4372
|
}
|
4360
4373
|
}
|
4361
4374
|
}
|
4362
4375
|
else {
|
4363
|
-
const subclassMethodType = (0, typeUtils_1.partiallySpecializeType)(subclassPropMethod, overrideClassType);
|
4376
|
+
const subclassMethodType = (0, typeUtils_1.partiallySpecializeType)(subclassPropMethod, overrideClassType, this._evaluator.getTypeClassType());
|
4364
4377
|
if ((0, types_1.isFunction)(subclassMethodType)) {
|
4365
4378
|
if (!this._evaluator.validateOverrideMethod(baseClassMethodType, subclassMethodType, overrideClassType, diagAddendum.createAddendum())) {
|
4366
4379
|
diagAddendum.addMessage(localize_1.LocAddendum.propertyMethodIncompatible().format({
|
4367
4380
|
name: methodName,
|
4368
4381
|
}));
|
4369
|
-
const decl = subclassMethodType.
|
4382
|
+
const decl = subclassMethodType.shared.declaration;
|
4370
4383
|
if (decl && decl.type === 5 /* DeclarationType.Function */) {
|
4371
4384
|
const diag = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompatibleMethodOverride, localize_1.LocMessage.propertyOverridden().format({
|
4372
4385
|
name: memberName,
|
4373
|
-
className: overriddenClassType.
|
4386
|
+
className: overriddenClassType.shared.name,
|
4374
4387
|
}) + diagAddendum.getString(), errorNode);
|
4375
|
-
const origDecl = baseClassMethodType.
|
4388
|
+
const origDecl = baseClassMethodType.shared.declaration;
|
4376
4389
|
if (diag && origDecl) {
|
4377
4390
|
this._addMultipleInheritanceRelatedInfo(diag, overriddenClassType, overriddenSymbolType, origDecl, overrideClassType, overrideSymbolType, decl);
|
4378
4391
|
}
|
@@ -4407,10 +4420,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4407
4420
|
if (!types_1.FunctionType.isFinal(implementation)) {
|
4408
4421
|
overloads.forEach((overload) => {
|
4409
4422
|
var _a, _b;
|
4410
|
-
if (types_1.FunctionType.isFinal(overload) && ((_a = overload.
|
4423
|
+
if (types_1.FunctionType.isFinal(overload) && ((_a = overload.shared.declaration) === null || _a === void 0 ? void 0 : _a.node)) {
|
4411
4424
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInconsistentOverload, localize_1.LocMessage.overloadFinalInconsistencyImpl().format({
|
4412
|
-
name: overload.
|
4413
|
-
}), (_b = (0, declarationUtils_1.getNameNodeForDeclaration)(overload.
|
4425
|
+
name: overload.shared.name,
|
4426
|
+
}), (_b = (0, declarationUtils_1.getNameNodeForDeclaration)(overload.shared.declaration)) !== null && _b !== void 0 ? _b : overload.shared.declaration.node);
|
4414
4427
|
}
|
4415
4428
|
});
|
4416
4429
|
}
|
@@ -4419,11 +4432,11 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4419
4432
|
if (!types_1.FunctionType.isFinal(overloads[0])) {
|
4420
4433
|
overloads.slice(1).forEach((overload, index) => {
|
4421
4434
|
var _a, _b;
|
4422
|
-
if (types_1.FunctionType.isFinal(overload) && ((_a = overload.
|
4435
|
+
if (types_1.FunctionType.isFinal(overload) && ((_a = overload.shared.declaration) === null || _a === void 0 ? void 0 : _a.node)) {
|
4423
4436
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInconsistentOverload, localize_1.LocMessage.overloadFinalInconsistencyNoImpl().format({
|
4424
|
-
name: overload.
|
4437
|
+
name: overload.shared.name,
|
4425
4438
|
index: index + 2,
|
4426
|
-
}), (_b = (0, declarationUtils_1.getNameNodeForDeclaration)(overload.
|
4439
|
+
}), (_b = (0, declarationUtils_1.getNameNodeForDeclaration)(overload.shared.declaration)) !== null && _b !== void 0 ? _b : overload.shared.declaration.node);
|
4427
4440
|
}
|
4428
4441
|
});
|
4429
4442
|
}
|
@@ -4437,7 +4450,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4437
4450
|
return;
|
4438
4451
|
}
|
4439
4452
|
const typedDictEntries = (0, typedDicts_1.getTypedDictMembersForClass)(this._evaluator, classType, /* allowNarrowed */ false);
|
4440
|
-
for (const baseClass of classType.
|
4453
|
+
for (const baseClass of classType.shared.baseClasses) {
|
4441
4454
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
4442
4455
|
if (!(0, types_1.isClass)(baseClass) ||
|
4443
4456
|
!types_1.ClassType.isTypedDictClass(baseClass) ||
|
@@ -4489,18 +4502,18 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4489
4502
|
}));
|
4490
4503
|
}
|
4491
4504
|
}
|
4492
|
-
if (!diag.isEmpty() && classType.
|
4493
|
-
const declNode = (0, declarationUtils_1.getNameNodeForDeclaration)(classType.
|
4505
|
+
if (!diag.isEmpty() && classType.shared.declaration) {
|
4506
|
+
const declNode = (0, declarationUtils_1.getNameNodeForDeclaration)(classType.shared.declaration);
|
4494
4507
|
if (declNode) {
|
4495
4508
|
if (baseTypedDictEntries.extraItems) {
|
4496
4509
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompatibleVariableOverride, localize_1.LocMessage.typedDictClosedExtras().format({
|
4497
|
-
name: baseClass.
|
4510
|
+
name: baseClass.shared.name,
|
4498
4511
|
type: this._evaluator.printType(baseExtraItemsType),
|
4499
4512
|
}) + diag.getString(), declNode);
|
4500
4513
|
}
|
4501
4514
|
else {
|
4502
4515
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompatibleVariableOverride, localize_1.LocMessage.typedDictClosedNoExtras().format({
|
4503
|
-
name: baseClass.
|
4516
|
+
name: baseClass.shared.name,
|
4504
4517
|
}) + diag.getString(), declNode);
|
4505
4518
|
}
|
4506
4519
|
}
|
@@ -4532,13 +4545,13 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4532
4545
|
return;
|
4533
4546
|
}
|
4534
4547
|
let firstOverride;
|
4535
|
-
for (const baseClass of classType.
|
4548
|
+
for (const baseClass of classType.shared.baseClasses) {
|
4536
4549
|
if (!(0, types_1.isClass)(baseClass)) {
|
4537
4550
|
continue;
|
4538
4551
|
}
|
4539
4552
|
// Look up the base class in the MRO list. It's the same generic class
|
4540
4553
|
// but has already been specialized using the type variables of the classType.
|
4541
|
-
const mroBaseClass = classType.
|
4554
|
+
const mroBaseClass = classType.shared.mro.find((mroClass) => (0, types_1.isClass)(mroClass) && types_1.ClassType.isSameGenericClass(mroClass, baseClass));
|
4542
4555
|
if (!mroBaseClass) {
|
4543
4556
|
continue;
|
4544
4557
|
}
|
@@ -4573,31 +4586,31 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4573
4586
|
overrideFunction = types_1.OverloadedFunctionType.getImplementation(overrideType);
|
4574
4587
|
}
|
4575
4588
|
else if ((0, types_1.isClassInstance)(overrideType) && types_1.ClassType.isPropertyClass(overrideType)) {
|
4576
|
-
if (overrideType.fgetInfo) {
|
4577
|
-
overrideFunction = overrideType.fgetInfo.methodType;
|
4589
|
+
if (overrideType.priv.fgetInfo) {
|
4590
|
+
overrideFunction = overrideType.priv.fgetInfo.methodType;
|
4578
4591
|
}
|
4579
4592
|
}
|
4580
|
-
if (!(overrideFunction === null || overrideFunction === void 0 ? void 0 : overrideFunction.
|
4593
|
+
if (!(overrideFunction === null || overrideFunction === void 0 ? void 0 : overrideFunction.shared.declaration) || types_1.FunctionType.isOverridden(overrideFunction)) {
|
4581
4594
|
return;
|
4582
4595
|
}
|
4583
4596
|
// Constructors are exempt.
|
4584
|
-
if (this._isMethodExemptFromLsp(overrideFunction.
|
4597
|
+
if (this._isMethodExemptFromLsp(overrideFunction.shared.name)) {
|
4585
4598
|
return;
|
4586
4599
|
}
|
4587
4600
|
// If the declaration for the override function is not the same as the
|
4588
4601
|
// declaration for the symbol, the function was probably replaced by a decorator.
|
4589
|
-
if (!symbol.getDeclarations().some((decl) => decl === overrideFunction.
|
4602
|
+
if (!symbol.getDeclarations().some((decl) => decl === overrideFunction.shared.declaration)) {
|
4590
4603
|
return;
|
4591
4604
|
}
|
4592
4605
|
// If the base class is unknown, don't report a missing decorator.
|
4593
4606
|
if ((0, types_1.isAnyOrUnknown)(baseMember.classType)) {
|
4594
4607
|
return;
|
4595
4608
|
}
|
4596
|
-
const funcNode = overrideFunction.
|
4609
|
+
const funcNode = overrideFunction.shared.declaration.node;
|
4597
4610
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportImplicitOverride, localize_1.LocMessage.overrideDecoratorMissing().format({
|
4598
|
-
name: funcNode.name.value,
|
4611
|
+
name: funcNode.d.name.d.value,
|
4599
4612
|
className: this._evaluator.printType((0, typeUtils_1.convertToInstance)(baseMember.classType)),
|
4600
|
-
}), funcNode.name);
|
4613
|
+
}), funcNode.d.name);
|
4601
4614
|
}
|
4602
4615
|
// Determines whether the name is exempt from Liskov Substitution Principle rules.
|
4603
4616
|
_isMethodExemptFromLsp(name) {
|
@@ -4616,20 +4629,20 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4616
4629
|
overrideFunction = types_1.OverloadedFunctionType.getImplementation(overrideType);
|
4617
4630
|
}
|
4618
4631
|
else if ((0, types_1.isClassInstance)(overrideType) && types_1.ClassType.isPropertyClass(overrideType)) {
|
4619
|
-
if (overrideType.fgetInfo) {
|
4620
|
-
overrideFunction = overrideType.fgetInfo.methodType;
|
4632
|
+
if (overrideType.priv.fgetInfo) {
|
4633
|
+
overrideFunction = overrideType.priv.fgetInfo.methodType;
|
4621
4634
|
}
|
4622
4635
|
}
|
4623
|
-
if (!(overrideFunction === null || overrideFunction === void 0 ? void 0 : overrideFunction.
|
4636
|
+
if (!(overrideFunction === null || overrideFunction === void 0 ? void 0 : overrideFunction.shared.declaration) || !types_1.FunctionType.isOverridden(overrideFunction)) {
|
4624
4637
|
return;
|
4625
4638
|
}
|
4626
4639
|
// If the declaration for the override function is not the same as the
|
4627
4640
|
// declaration for the symbol, the function was probably replaced by a decorator.
|
4628
|
-
if (!symbol.getDeclarations().some((decl) => decl === overrideFunction.
|
4641
|
+
if (!symbol.getDeclarations().some((decl) => decl === overrideFunction.shared.declaration)) {
|
4629
4642
|
return;
|
4630
4643
|
}
|
4631
|
-
const funcNode = overrideFunction.
|
4632
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.overriddenMethodNotFound().format({ name: funcNode.name.value }), funcNode.name);
|
4644
|
+
const funcNode = overrideFunction.shared.declaration.node;
|
4645
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.overriddenMethodNotFound().format({ name: funcNode.d.name.d.value }), funcNode.d.name);
|
4633
4646
|
}
|
4634
4647
|
_validateBaseClassOverride(baseClassAndSymbol, overrideSymbol, overrideType, childClassType, memberName) {
|
4635
4648
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
@@ -4652,8 +4665,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4652
4665
|
}
|
4653
4666
|
const baseClass = baseClassAndSymbol.classType;
|
4654
4667
|
const childClassSelf = types_1.ClassType.cloneAsInstance((0, typeUtils_1.selfSpecializeClass)(childClassType));
|
4655
|
-
const baseType = (0, typeUtils_1.partiallySpecializeType)(this._evaluator.getEffectiveTypeOfSymbol(baseClassAndSymbol.symbol), baseClass, childClassSelf);
|
4656
|
-
overrideType = (0, typeUtils_1.partiallySpecializeType)(overrideType, childClassType, childClassSelf);
|
4668
|
+
const baseType = (0, typeUtils_1.partiallySpecializeType)(this._evaluator.getEffectiveTypeOfSymbol(baseClassAndSymbol.symbol), baseClass, this._evaluator.getTypeClassType(), childClassSelf);
|
4669
|
+
overrideType = (0, typeUtils_1.partiallySpecializeType)(overrideType, childClassType, this._evaluator.getTypeClassType(), childClassSelf);
|
4657
4670
|
if ((0, types_1.isFunction)(baseType) || (0, types_1.isOverloadedFunction)(baseType)) {
|
4658
4671
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
4659
4672
|
// Determine whether this is an attempt to override a method marked @final.
|
@@ -4664,7 +4677,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4664
4677
|
reportFinalMethodOverride = true;
|
4665
4678
|
}
|
4666
4679
|
else if ((0, types_1.isOverloadedFunction)(baseType) &&
|
4667
|
-
baseType.overloads.some((overload) => types_1.FunctionType.isFinal(overload))) {
|
4680
|
+
baseType.priv.overloads.some((overload) => types_1.FunctionType.isFinal(overload))) {
|
4668
4681
|
reportFinalMethodOverride = true;
|
4669
4682
|
}
|
4670
4683
|
}
|
@@ -4673,8 +4686,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4673
4686
|
if (decl && decl.type === 5 /* DeclarationType.Function */) {
|
4674
4687
|
const diag = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompatibleMethodOverride, localize_1.LocMessage.finalMethodOverride().format({
|
4675
4688
|
name: memberName,
|
4676
|
-
className: baseClass.
|
4677
|
-
}), decl.node.name);
|
4689
|
+
className: baseClass.shared.name,
|
4690
|
+
}), decl.node.d.name);
|
4678
4691
|
const origDecl = (0, symbolUtils_1.getLastTypedDeclarationForSymbol)(baseClassAndSymbol.symbol);
|
4679
4692
|
if (diag && origDecl) {
|
4680
4693
|
diag.addRelatedInfo(localize_1.LocAddendum.finalMethod(), origDecl.uri, origDecl.range);
|
@@ -4694,13 +4707,13 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4694
4707
|
!SymbolNameUtils.isPrivateName(memberName) &&
|
4695
4708
|
!types_1.ClassType.isTypedDictClass(childClassType)) {
|
4696
4709
|
if (!this._evaluator.validateOverrideMethod(baseType, overrideType, childClassType, diagAddendum, enforceParamNameMatch)) {
|
4697
|
-
const decl = (0, types_1.isFunction)(overrideType) && overrideType.
|
4698
|
-
? overrideType.
|
4710
|
+
const decl = (0, types_1.isFunction)(overrideType) && overrideType.shared.declaration
|
4711
|
+
? overrideType.shared.declaration
|
4699
4712
|
: (0, symbolUtils_1.getLastTypedDeclarationForSymbol)(overrideSymbol);
|
4700
4713
|
if (decl) {
|
4701
4714
|
const diag = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompatibleMethodOverride, localize_1.LocMessage.incompatibleMethodOverride().format({
|
4702
4715
|
name: memberName,
|
4703
|
-
className: baseClass.
|
4716
|
+
className: baseClass.shared.name,
|
4704
4717
|
}) + diagAddendum.getString(), (_a = (0, declarationUtils_1.getNameNodeForDeclaration)(decl)) !== null && _a !== void 0 ? _a : decl.node);
|
4705
4718
|
const origDecl = (0, symbolUtils_1.getLastTypedDeclarationForSymbol)(baseClassAndSymbol.symbol);
|
4706
4719
|
if (diag && origDecl) {
|
@@ -4720,7 +4733,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4720
4733
|
const lastDecl = decls[decls.length - 1];
|
4721
4734
|
const diag = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompatibleMethodOverride, localize_1.LocMessage.methodOverridden().format({
|
4722
4735
|
name: memberName,
|
4723
|
-
className: baseClass.
|
4736
|
+
className: baseClass.shared.name,
|
4724
4737
|
type: this._evaluator.printType(overrideType),
|
4725
4738
|
}), (_b = (0, declarationUtils_1.getNameNodeForDeclaration)(lastDecl)) !== null && _b !== void 0 ? _b : lastDecl.node);
|
4726
4739
|
const origDecl = (0, symbolUtils_1.getLastTypedDeclarationForSymbol)(baseClassAndSymbol.symbol);
|
@@ -4739,7 +4752,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4739
4752
|
const lastDecl = decls[decls.length - 1];
|
4740
4753
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompatibleMethodOverride, localize_1.LocMessage.propertyOverridden().format({
|
4741
4754
|
name: memberName,
|
4742
|
-
className: baseClass.
|
4755
|
+
className: baseClass.shared.name,
|
4743
4756
|
}), (_c = (0, declarationUtils_1.getNameNodeForDeclaration)(lastDecl)) !== null && _c !== void 0 ? _c : lastDecl.node);
|
4744
4757
|
}
|
4745
4758
|
}
|
@@ -4760,8 +4773,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4760
4773
|
let isInvariant = (primaryDecl === null || primaryDecl === void 0 ? void 0 : primaryDecl.type) === 1 /* DeclarationType.Variable */ && !primaryDecl.isFinal;
|
4761
4774
|
// If the entry is a member of a frozen dataclass, it is immutable,
|
4762
4775
|
// so it does not need to be invariant.
|
4763
|
-
if (types_1.ClassType.isDataClassFrozen(baseClass) && baseClass.
|
4764
|
-
const dataclassEntry = baseClass.
|
4776
|
+
if (types_1.ClassType.isDataClassFrozen(baseClass) && baseClass.shared.dataClassEntries) {
|
4777
|
+
const dataclassEntry = baseClass.shared.dataClassEntries.find((entry) => entry.name === memberName);
|
4765
4778
|
if (dataclassEntry) {
|
4766
4779
|
isInvariant = false;
|
4767
4780
|
}
|
@@ -4769,14 +4782,14 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4769
4782
|
let overriddenTDEntry;
|
4770
4783
|
let overrideTDEntry;
|
4771
4784
|
if (!overrideSymbol.isIgnoredForProtocolMatch()) {
|
4772
|
-
if (baseClass.
|
4785
|
+
if (baseClass.shared.typedDictEntries) {
|
4773
4786
|
overriddenTDEntry =
|
4774
|
-
(_e = (_d = baseClass.
|
4787
|
+
(_e = (_d = baseClass.shared.typedDictEntries.knownItems.get(memberName)) !== null && _d !== void 0 ? _d : baseClass.shared.typedDictEntries.extraItems) !== null && _e !== void 0 ? _e : (0, typedDicts_1.getEffectiveExtraItemsEntryType)(this._evaluator, baseClass);
|
4775
4788
|
if (overriddenTDEntry === null || overriddenTDEntry === void 0 ? void 0 : overriddenTDEntry.isReadOnly) {
|
4776
4789
|
isInvariant = false;
|
4777
4790
|
}
|
4778
4791
|
}
|
4779
|
-
if (childClassType.
|
4792
|
+
if (childClassType.shared.typedDictEntries) {
|
4780
4793
|
// Exempt __extra_items__ here. We'll check this separately
|
4781
4794
|
// in _validateTypedDictOverrides. If we don't skip it here,
|
4782
4795
|
// redundant errors will be produced.
|
@@ -4786,7 +4799,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4786
4799
|
}
|
4787
4800
|
else {
|
4788
4801
|
overrideTDEntry =
|
4789
|
-
(_g = (_f = childClassType.
|
4802
|
+
(_g = (_f = childClassType.shared.typedDictEntries.knownItems.get(memberName)) !== null && _f !== void 0 ? _f : childClassType.shared.typedDictEntries.extraItems) !== null && _g !== void 0 ? _g : (0, typedDicts_1.getEffectiveExtraItemsEntryType)(this._evaluator, childClassType);
|
4790
4803
|
}
|
4791
4804
|
}
|
4792
4805
|
}
|
@@ -4804,7 +4817,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4804
4817
|
}
|
4805
4818
|
const diag = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompatibleVariableOverride, localize_1.LocMessage.symbolOverridden().format({
|
4806
4819
|
name: memberName,
|
4807
|
-
className: baseClass.
|
4820
|
+
className: baseClass.shared.name,
|
4808
4821
|
}) + diagAddendum.getString(), (_h = (0, declarationUtils_1.getNameNodeForDeclaration)(lastDecl)) !== null && _h !== void 0 ? _h : lastDecl.node);
|
4809
4822
|
const origDecl = (0, symbolUtils_1.getLastTypedDeclarationForSymbol)(baseClassAndSymbol.symbol);
|
4810
4823
|
if (diag && origDecl) {
|
@@ -4842,7 +4855,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4842
4855
|
if (!isBaseVarFinal && overrideFinalVarDecl) {
|
4843
4856
|
const diag = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompatibleVariableOverride, localize_1.LocMessage.variableFinalOverride().format({
|
4844
4857
|
name: memberName,
|
4845
|
-
className: baseClass.
|
4858
|
+
className: baseClass.shared.name,
|
4846
4859
|
}), (_l = (0, declarationUtils_1.getNameNodeForDeclaration)(lastDecl)) !== null && _l !== void 0 ? _l : lastDecl.node);
|
4847
4860
|
if (diag) {
|
4848
4861
|
diag.addRelatedInfo(localize_1.LocAddendum.overriddenSymbol(), overrideFinalVarDecl.uri, overrideFinalVarDecl.range);
|
@@ -4874,7 +4887,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4874
4887
|
: localize_1.LocMessage.instanceVarOverridesClassVar();
|
4875
4888
|
const diag = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompatibleVariableOverride, unformattedMessage.format({
|
4876
4889
|
name: memberName,
|
4877
|
-
className: baseClass.
|
4890
|
+
className: baseClass.shared.name,
|
4878
4891
|
}), (_m = (0, declarationUtils_1.getNameNodeForDeclaration)(lastDecl)) !== null && _m !== void 0 ? _m : lastDecl.node);
|
4879
4892
|
const origDecl = (0, symbolUtils_1.getLastTypedDeclarationForSymbol)(baseClassAndSymbol.symbol);
|
4880
4893
|
if (diag && origDecl) {
|
@@ -4887,9 +4900,9 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4887
4900
|
}
|
4888
4901
|
_validatePropertyOverride(baseClassType, childClassType, baseType, childType, overrideSymbol, memberName) {
|
4889
4902
|
const propMethodInfo = [
|
4890
|
-
['fget', (c) => { var _a; return (_a = c.fgetInfo) === null || _a === void 0 ? void 0 : _a.methodType; }],
|
4891
|
-
['fset', (c) => { var _a; return (_a = c.fsetInfo) === null || _a === void 0 ? void 0 : _a.methodType; }],
|
4892
|
-
['fdel', (c) => { var _a; return (_a = c.fdelInfo) === null || _a === void 0 ? void 0 : _a.methodType; }],
|
4903
|
+
['fget', (c) => { var _a; return (_a = c.priv.fgetInfo) === null || _a === void 0 ? void 0 : _a.methodType; }],
|
4904
|
+
['fset', (c) => { var _a; return (_a = c.priv.fsetInfo) === null || _a === void 0 ? void 0 : _a.methodType; }],
|
4905
|
+
['fdel', (c) => { var _a; return (_a = c.priv.fdelInfo) === null || _a === void 0 ? void 0 : _a.methodType; }],
|
4893
4906
|
];
|
4894
4907
|
propMethodInfo.forEach((info) => {
|
4895
4908
|
var _a;
|
@@ -4899,7 +4912,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4899
4912
|
const subclassPropMethod = methodAccessor(childType);
|
4900
4913
|
// Is the method present on the base class but missing in the subclass?
|
4901
4914
|
if (baseClassPropMethod) {
|
4902
|
-
const baseClassMethodType = (0, typeUtils_1.partiallySpecializeType)(baseClassPropMethod, baseClassType);
|
4915
|
+
const baseClassMethodType = (0, typeUtils_1.partiallySpecializeType)(baseClassPropMethod, baseClassType, this._evaluator.getTypeClassType());
|
4903
4916
|
if ((0, types_1.isFunction)(baseClassMethodType)) {
|
4904
4917
|
if (!subclassPropMethod) {
|
4905
4918
|
// The method is missing.
|
@@ -4911,28 +4924,28 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4911
4924
|
const lastDecl = decls[decls.length - 1];
|
4912
4925
|
const diag = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompatibleMethodOverride, localize_1.LocMessage.propertyOverridden().format({
|
4913
4926
|
name: memberName,
|
4914
|
-
className: baseClassType.
|
4927
|
+
className: baseClassType.shared.name,
|
4915
4928
|
}) + diagAddendum.getString(), (_a = (0, declarationUtils_1.getNameNodeForDeclaration)(lastDecl)) !== null && _a !== void 0 ? _a : lastDecl.node);
|
4916
|
-
const origDecl = baseClassMethodType.
|
4929
|
+
const origDecl = baseClassMethodType.shared.declaration;
|
4917
4930
|
if (diag && origDecl) {
|
4918
4931
|
diag.addRelatedInfo(localize_1.LocAddendum.overriddenMethod(), origDecl.uri, origDecl.range);
|
4919
4932
|
}
|
4920
4933
|
}
|
4921
4934
|
}
|
4922
4935
|
else {
|
4923
|
-
const subclassMethodType = (0, typeUtils_1.partiallySpecializeType)(subclassPropMethod, childClassType);
|
4936
|
+
const subclassMethodType = (0, typeUtils_1.partiallySpecializeType)(subclassPropMethod, childClassType, this._evaluator.getTypeClassType());
|
4924
4937
|
if ((0, types_1.isFunction)(subclassMethodType)) {
|
4925
4938
|
if (!this._evaluator.validateOverrideMethod(baseClassMethodType, subclassMethodType, childClassType, diagAddendum.createAddendum())) {
|
4926
4939
|
diagAddendum.addMessage(localize_1.LocAddendum.propertyMethodIncompatible().format({
|
4927
4940
|
name: methodName,
|
4928
4941
|
}));
|
4929
|
-
const decl = subclassMethodType.
|
4942
|
+
const decl = subclassMethodType.shared.declaration;
|
4930
4943
|
if (decl && decl.type === 5 /* DeclarationType.Function */) {
|
4931
4944
|
const diag = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompatibleMethodOverride, localize_1.LocMessage.propertyOverridden().format({
|
4932
4945
|
name: memberName,
|
4933
|
-
className: baseClassType.
|
4934
|
-
}) + diagAddendum.getString(), decl.node.name);
|
4935
|
-
const origDecl = baseClassMethodType.
|
4946
|
+
className: baseClassType.shared.name,
|
4947
|
+
}) + diagAddendum.getString(), decl.node.d.name);
|
4948
|
+
const origDecl = baseClassMethodType.shared.declaration;
|
4936
4949
|
if (diag && origDecl) {
|
4937
4950
|
diag.addRelatedInfo(localize_1.LocAddendum.overriddenMethod(), origDecl.uri, origDecl.range);
|
4938
4951
|
}
|
@@ -4950,9 +4963,9 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4950
4963
|
var _a, _b;
|
4951
4964
|
const classTypeInfo = this._evaluator.getTypeOfClass(classNode);
|
4952
4965
|
const classType = classTypeInfo === null || classTypeInfo === void 0 ? void 0 : classTypeInfo.classType;
|
4953
|
-
if (node.name && classType) {
|
4966
|
+
if (node.d.name && classType) {
|
4954
4967
|
const superCheckMethods = ['__init__', '__init_subclass__', '__enter__', '__exit__'];
|
4955
|
-
if (superCheckMethods.some((name) => name === node.name.value)) {
|
4968
|
+
if (superCheckMethods.some((name) => name === node.d.name.d.value)) {
|
4956
4969
|
if (!types_1.FunctionType.isAbstractMethod(functionType) &&
|
4957
4970
|
!types_1.FunctionType.isOverloaded(functionType) &&
|
4958
4971
|
!this._fileInfo.isStubFile) {
|
@@ -4960,48 +4973,48 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4960
4973
|
}
|
4961
4974
|
}
|
4962
4975
|
}
|
4963
|
-
if (((_a = node.name) === null || _a === void 0 ? void 0 : _a.value) === '__new__') {
|
4976
|
+
if (((_a = node.d.name) === null || _a === void 0 ? void 0 : _a.d.value) === '__new__') {
|
4964
4977
|
// __new__ overrides should have a "cls" parameter.
|
4965
|
-
if (node.
|
4966
|
-
!node.
|
4967
|
-
!['cls', '_cls', '__cls', '__mcls', 'mcls', 'mcs', 'metacls'].some((name) => node.
|
4968
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportSelfClsParameterName, localize_1.LocMessage.newClsParam(), node.
|
4978
|
+
if (node.d.params.length === 0 ||
|
4979
|
+
!node.d.params[0].d.name ||
|
4980
|
+
!['cls', '_cls', '__cls', '__mcls', 'mcls', 'mcs', 'metacls'].some((name) => node.d.params[0].d.name.d.value === name)) {
|
4981
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportSelfClsParameterName, localize_1.LocMessage.newClsParam(), node.d.params.length > 0 ? node.d.params[0] : node.d.name);
|
4969
4982
|
}
|
4970
4983
|
if (classType) {
|
4971
|
-
this._validateClsSelfParameterType(functionType, classType, /* isCls */ true);
|
4984
|
+
this._validateClsSelfParameterType(node, functionType, classType, /* isCls */ true);
|
4972
4985
|
}
|
4973
4986
|
}
|
4974
|
-
else if (((_b = node.name) === null || _b === void 0 ? void 0 : _b.value) === '_generate_next_value_') {
|
4987
|
+
else if (((_b = node.d.name) === null || _b === void 0 ? void 0 : _b.d.value) === '_generate_next_value_') {
|
4975
4988
|
// Skip this check for _generate_next_value_.
|
4976
4989
|
}
|
4977
4990
|
else if (types_1.FunctionType.isStaticMethod(functionType)) {
|
4978
4991
|
// Static methods should not have "self" or "cls" parameters.
|
4979
|
-
if (node.
|
4980
|
-
const paramName = node.
|
4992
|
+
if (node.d.params.length > 0 && node.d.params[0].d.name) {
|
4993
|
+
const paramName = node.d.params[0].d.name.d.value;
|
4981
4994
|
if (paramName === 'self' || paramName === 'cls') {
|
4982
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportSelfClsParameterName, localize_1.LocMessage.staticClsSelfParam(), node.
|
4995
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportSelfClsParameterName, localize_1.LocMessage.staticClsSelfParam(), node.d.params[0].d.name);
|
4983
4996
|
}
|
4984
4997
|
}
|
4985
4998
|
}
|
4986
4999
|
else if (types_1.FunctionType.isClassMethod(functionType)) {
|
4987
5000
|
let paramName = '';
|
4988
|
-
if (node.
|
4989
|
-
paramName = node.
|
5001
|
+
if (node.d.params.length > 0 && node.d.params[0].d.name) {
|
5002
|
+
paramName = node.d.params[0].d.name.d.value;
|
4990
5003
|
}
|
4991
5004
|
// Class methods should have a "cls" parameter. We'll exempt parameter
|
4992
5005
|
// names that start with an underscore since those are used in a few
|
4993
5006
|
// cases in the stdlib pyi files.
|
4994
5007
|
if (paramName !== 'cls') {
|
4995
5008
|
if (!this._fileInfo.isStubFile || (!paramName.startsWith('_') && paramName !== 'metacls')) {
|
4996
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportSelfClsParameterName, localize_1.LocMessage.classMethodClsParam(), node.
|
5009
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportSelfClsParameterName, localize_1.LocMessage.classMethodClsParam(), node.d.params.length > 0 ? node.d.params[0] : node.d.name);
|
4997
5010
|
}
|
4998
5011
|
}
|
4999
5012
|
if (classType) {
|
5000
|
-
this._validateClsSelfParameterType(functionType, classType, /* isCls */ true);
|
5013
|
+
this._validateClsSelfParameterType(node, functionType, classType, /* isCls */ true);
|
5001
5014
|
}
|
5002
5015
|
}
|
5003
5016
|
else {
|
5004
|
-
const decoratorIsPresent = node.decorators.length > 0;
|
5017
|
+
const decoratorIsPresent = node.d.decorators.length > 0;
|
5005
5018
|
const isOverloaded = types_1.FunctionType.isOverloaded(functionType);
|
5006
5019
|
// The presence of a decorator can change the behavior, so we need
|
5007
5020
|
// to back off from this check if a decorator is present. An overload
|
@@ -5009,11 +5022,11 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5009
5022
|
if (isOverloaded || !decoratorIsPresent) {
|
5010
5023
|
let paramName = '';
|
5011
5024
|
let firstParamIsSimple = true;
|
5012
|
-
if (node.
|
5013
|
-
if (node.
|
5014
|
-
paramName = node.
|
5025
|
+
if (node.d.params.length > 0) {
|
5026
|
+
if (node.d.params[0].d.name) {
|
5027
|
+
paramName = node.d.params[0].d.name.d.value;
|
5015
5028
|
}
|
5016
|
-
if (node.
|
5029
|
+
if (node.d.params[0].d.category !== 0 /* ParameterCategory.Simple */) {
|
5017
5030
|
firstParamIsSimple = false;
|
5018
5031
|
}
|
5019
5032
|
}
|
@@ -5037,12 +5050,12 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5037
5050
|
// a parameter that cannot be positional.
|
5038
5051
|
const isPrivateName = SymbolNameUtils.isPrivateOrProtectedName(paramName);
|
5039
5052
|
if (!isLegalMetaclassName && !isPrivateName) {
|
5040
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportSelfClsParameterName, localize_1.LocMessage.instanceMethodSelfParam(), node.
|
5053
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportSelfClsParameterName, localize_1.LocMessage.instanceMethodSelfParam(), node.d.params.length > 0 ? node.d.params[0] : node.d.name);
|
5041
5054
|
}
|
5042
5055
|
}
|
5043
5056
|
}
|
5044
5057
|
if (classType) {
|
5045
|
-
this._validateClsSelfParameterType(functionType, classType, /* isCls */ false);
|
5058
|
+
this._validateClsSelfParameterType(node, functionType, classType, /* isCls */ false);
|
5046
5059
|
}
|
5047
5060
|
}
|
5048
5061
|
}
|
@@ -5063,7 +5076,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5063
5076
|
if (types_1.ClassType.isFinal(classType)) {
|
5064
5077
|
effectiveFlags |= 4 /* MemberAccessFlags.SkipObjectBaseClass */;
|
5065
5078
|
}
|
5066
|
-
const methodMember = (0, typeUtils_1.lookUpClassMember)(classType, methodType.
|
5079
|
+
const methodMember = (0, typeUtils_1.lookUpClassMember)(classType, methodType.shared.name, effectiveFlags);
|
5067
5080
|
if (!methodMember) {
|
5068
5081
|
return;
|
5069
5082
|
}
|
@@ -5071,14 +5084,14 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5071
5084
|
// Now scan the implementation of the method to determine whether
|
5072
5085
|
// super().<method> has been called for all of the required base classes.
|
5073
5086
|
const callNodeWalker = new ParseTreeUtils.CallNodeWalker((node) => {
|
5074
|
-
if (node.
|
5087
|
+
if (node.d.leftExpr.nodeType === 35 /* ParseNodeType.MemberAccess */) {
|
5075
5088
|
// Is it accessing the method by the same name?
|
5076
|
-
if (node.
|
5077
|
-
const memberBaseExpr = node.
|
5089
|
+
if (node.d.leftExpr.d.member.d.value === methodType.shared.name) {
|
5090
|
+
const memberBaseExpr = node.d.leftExpr.d.leftExpr;
|
5078
5091
|
// Is it a "super" call?
|
5079
5092
|
if (memberBaseExpr.nodeType === 9 /* ParseNodeType.Call */ &&
|
5080
|
-
memberBaseExpr.
|
5081
|
-
memberBaseExpr.
|
5093
|
+
memberBaseExpr.d.leftExpr.nodeType === 38 /* ParseNodeType.Name */ &&
|
5094
|
+
memberBaseExpr.d.leftExpr.d.value === 'super') {
|
5082
5095
|
foundCallOfMember = true;
|
5083
5096
|
}
|
5084
5097
|
else {
|
@@ -5091,33 +5104,35 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5091
5104
|
}
|
5092
5105
|
}
|
5093
5106
|
});
|
5094
|
-
callNodeWalker.walk(node.suite);
|
5107
|
+
callNodeWalker.walk(node.d.suite);
|
5095
5108
|
// If we didn't find a call to at least one base class, report the problem.
|
5096
5109
|
if (!foundCallOfMember) {
|
5097
5110
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportMissingSuperCall, localize_1.LocMessage.missingSuperCall().format({
|
5098
|
-
methodName: methodType.
|
5099
|
-
}), node.name);
|
5111
|
+
methodName: methodType.shared.name,
|
5112
|
+
}), node.d.name);
|
5100
5113
|
}
|
5101
5114
|
}
|
5102
5115
|
// Validates that the annotated type of a "self" or "cls" parameter is
|
5103
5116
|
// compatible with the type of the class that contains it.
|
5104
|
-
_validateClsSelfParameterType(functionType, classType, isCls) {
|
5105
|
-
|
5117
|
+
_validateClsSelfParameterType(node, functionType, classType, isCls) {
|
5118
|
+
var _a;
|
5119
|
+
if (node.d.params.length < 1 || functionType.shared.parameters.length < 1) {
|
5106
5120
|
return;
|
5107
5121
|
}
|
5108
5122
|
// If there is no type annotation, there's nothing to check because
|
5109
|
-
// the type will be inferred.
|
5110
|
-
const paramInfo = functionType.
|
5111
|
-
|
5123
|
+
// the type will be inferred.d.typeAnnotation
|
5124
|
+
const paramInfo = functionType.shared.parameters[0];
|
5125
|
+
const paramAnnotation = (_a = node.d.params[0].d.annotation) !== null && _a !== void 0 ? _a : node.d.params[0].d.annotationComment;
|
5126
|
+
if (!paramAnnotation || !paramInfo.name) {
|
5112
5127
|
return;
|
5113
5128
|
}
|
5114
5129
|
// If this is an __init__ method, we need to specifically check for the
|
5115
5130
|
// use of class-scoped TypeVars, which are not allowed in this context
|
5116
5131
|
// according to the typing spec.
|
5117
|
-
if (functionType.
|
5132
|
+
if (functionType.shared.name === '__init__' && functionType.shared.methodClass) {
|
5118
5133
|
const typeVars = (0, typeUtils_1.getTypeVarArgumentsRecursive)(paramInfo.type);
|
5119
|
-
if (typeVars.some((typeVar) => { var _a; return typeVar.scopeId === ((_a = functionType.
|
5120
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeVarUse, localize_1.LocMessage.initMethodSelfParamTypeVar(),
|
5134
|
+
if (typeVars.some((typeVar) => { var _a; return typeVar.priv.scopeId === ((_a = functionType.shared.methodClass) === null || _a === void 0 ? void 0 : _a.shared.typeVarScopeId); })) {
|
5135
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeVarUse, localize_1.LocMessage.initMethodSelfParamTypeVar(), paramAnnotation);
|
5121
5136
|
}
|
5122
5137
|
}
|
5123
5138
|
// If this is a protocol class, the self and cls parameters can be bound
|
@@ -5138,7 +5153,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5138
5153
|
// If the method starts with a `*args: P.args`, skip the check.
|
5139
5154
|
if (paramInfo.category === 1 /* ParameterCategory.ArgsList */ &&
|
5140
5155
|
(0, types_1.isParamSpec)(paramInfo.type) &&
|
5141
|
-
paramInfo.type.paramSpecAccess === 'args') {
|
5156
|
+
paramInfo.type.priv.paramSpecAccess === 'args') {
|
5142
5157
|
return;
|
5143
5158
|
}
|
5144
5159
|
// Don't enforce this for an overloaded method because the "self" param
|
@@ -5162,7 +5177,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5162
5177
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.clsSelfParamTypeMismatch().format({
|
5163
5178
|
name: paramInfo.name,
|
5164
5179
|
classType: this._evaluator.printType(expectedType),
|
5165
|
-
}),
|
5180
|
+
}), paramAnnotation);
|
5166
5181
|
}
|
5167
5182
|
}
|
5168
5183
|
}
|
@@ -5171,19 +5186,21 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5171
5186
|
_validateYieldType(node, yieldType, expectedDiagAddendum, sendType) {
|
5172
5187
|
var _a, _b, _c, _d;
|
5173
5188
|
const enclosingFunctionNode = ParseTreeUtils.getEnclosingFunction(node);
|
5174
|
-
if (!enclosingFunctionNode || !enclosingFunctionNode.
|
5189
|
+
if (!enclosingFunctionNode || !enclosingFunctionNode.d.returnAnnotation) {
|
5175
5190
|
return;
|
5176
5191
|
}
|
5177
5192
|
const functionTypeResult = this._evaluator.getTypeOfFunction(enclosingFunctionNode);
|
5178
5193
|
if (!functionTypeResult) {
|
5179
5194
|
return;
|
5180
5195
|
}
|
5181
|
-
|
5196
|
+
let declaredReturnType = types_1.FunctionType.getEffectiveReturnType(functionTypeResult.functionType);
|
5182
5197
|
if (!declaredReturnType) {
|
5183
5198
|
return;
|
5184
5199
|
}
|
5200
|
+
const liveScopes = ParseTreeUtils.getTypeVarScopesForNode(node);
|
5201
|
+
declaredReturnType = (0, typeUtils_1.updateTypeWithInternalTypeVars)(declaredReturnType, liveScopes);
|
5185
5202
|
let generatorType;
|
5186
|
-
if (!enclosingFunctionNode.isAsync &&
|
5203
|
+
if (!enclosingFunctionNode.d.isAsync &&
|
5187
5204
|
(0, types_1.isClassInstance)(declaredReturnType) &&
|
5188
5205
|
types_1.ClassType.isBuiltIn(declaredReturnType, 'AwaitableGenerator')) {
|
5189
5206
|
// Handle the old-style (pre-await) generator case
|
@@ -5191,7 +5208,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5191
5208
|
generatorType = this._evaluator.getTypingType(node, 'AwaitableGenerator');
|
5192
5209
|
}
|
5193
5210
|
else {
|
5194
|
-
generatorType = this._evaluator.getTypingType(node, enclosingFunctionNode.isAsync ? 'AsyncGenerator' : 'Generator');
|
5211
|
+
generatorType = this._evaluator.getTypingType(node, enclosingFunctionNode.d.isAsync ? 'AsyncGenerator' : 'Generator');
|
5195
5212
|
}
|
5196
5213
|
if (!generatorType || !(0, types_1.isInstantiableClass)(generatorType)) {
|
5197
5214
|
return;
|
@@ -5207,11 +5224,11 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5207
5224
|
const specializedGenerator = types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneForSpecialization(generatorType, generatorTypeArgs, /* isTypeArgumentExplicit */ true));
|
5208
5225
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
5209
5226
|
if (!this._evaluator.assignType(declaredReturnType, specializedGenerator, diagAddendum)) {
|
5210
|
-
const errorMessage = enclosingFunctionNode.isAsync
|
5227
|
+
const errorMessage = enclosingFunctionNode.d.isAsync
|
5211
5228
|
? localize_1.LocMessage.generatorAsyncReturnType()
|
5212
5229
|
: localize_1.LocMessage.generatorSyncReturnType();
|
5213
5230
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportReturnType, errorMessage.format({ yieldType: this._evaluator.printType(yieldType) }) +
|
5214
|
-
((_a = expectedDiagAddendum === null || expectedDiagAddendum === void 0 ? void 0 : expectedDiagAddendum.getString()) !== null && _a !== void 0 ? _a : diagAddendum.getString()), (_b = node.
|
5231
|
+
((_a = expectedDiagAddendum === null || expectedDiagAddendum === void 0 ? void 0 : expectedDiagAddendum.getString()) !== null && _a !== void 0 ? _a : diagAddendum.getString()), (_b = node.d.expr) !== null && _b !== void 0 ? _b : node, (_d = (_c = expectedDiagAddendum === null || expectedDiagAddendum === void 0 ? void 0 : expectedDiagAddendum.getEffectiveTextRange()) !== null && _c !== void 0 ? _c : node.d.expr) !== null && _d !== void 0 ? _d : node);
|
5215
5232
|
}
|
5216
5233
|
}
|
5217
5234
|
// Determines whether any of the except statements are unreachable because
|
@@ -5219,12 +5236,12 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5219
5236
|
_reportUnusedExceptStatements(node) {
|
5220
5237
|
let sawUnknownExceptionType = false;
|
5221
5238
|
const exceptionTypesSoFar = [];
|
5222
|
-
node.exceptClauses.forEach((except) => {
|
5239
|
+
node.d.exceptClauses.forEach((except) => {
|
5223
5240
|
var _a, _b;
|
5224
|
-
if (sawUnknownExceptionType || except.isExceptGroup || !except.
|
5241
|
+
if (sawUnknownExceptionType || except.d.isExceptGroup || !except.d.typeExpr) {
|
5225
5242
|
return;
|
5226
5243
|
}
|
5227
|
-
const exceptionType = this._evaluator.getType(except.
|
5244
|
+
const exceptionType = this._evaluator.getType(except.d.typeExpr);
|
5228
5245
|
if (!exceptionType || (0, types_1.isAnyOrUnknown)(exceptionType)) {
|
5229
5246
|
sawUnknownExceptionType = true;
|
5230
5247
|
return;
|
@@ -5233,7 +5250,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5233
5250
|
if ((0, types_1.isInstantiableClass)(exceptionType)) {
|
5234
5251
|
// If the exception type is a variable whose type could represent
|
5235
5252
|
// subclasses, the actual exception type is statically unknown.
|
5236
|
-
if (exceptionType.includeSubclasses) {
|
5253
|
+
if (exceptionType.priv.includeSubclasses) {
|
5237
5254
|
sawUnknownExceptionType = true;
|
5238
5255
|
}
|
5239
5256
|
typesOfThisExcept.push(exceptionType);
|
@@ -5241,7 +5258,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5241
5258
|
else if ((0, types_1.isClassInstance)(exceptionType)) {
|
5242
5259
|
const iterableType = (_b = (_a = this._evaluator.getTypeOfIterator({ type: exceptionType },
|
5243
5260
|
/* isAsync */ false,
|
5244
|
-
/* errorNode */ except.
|
5261
|
+
/* errorNode */ except.d.typeExpr,
|
5245
5262
|
/* emitNotIterableError */ false)) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : types_1.UnknownType.create();
|
5246
5263
|
(0, typeUtils_1.doForEachSubtype)(iterableType, (subtype) => {
|
5247
5264
|
if ((0, types_1.isAnyOrUnknown)(subtype)) {
|
@@ -5250,7 +5267,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5250
5267
|
if ((0, types_1.isInstantiableClass)(subtype)) {
|
5251
5268
|
// If the exception type is a variable whose type could represent
|
5252
5269
|
// subclasses, the actual exception type is statically unknown.
|
5253
|
-
if (subtype.includeSubclasses) {
|
5270
|
+
if (subtype.priv.includeSubclasses) {
|
5254
5271
|
sawUnknownExceptionType = true;
|
5255
5272
|
}
|
5256
5273
|
typesOfThisExcept.push(subtype);
|
@@ -5277,8 +5294,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5277
5294
|
});
|
5278
5295
|
// Were all of the exception types overridden?
|
5279
5296
|
if (typesOfThisExcept.length > 0 && typesOfThisExcept.length === overriddenExceptionCount) {
|
5280
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnusedExcept, localize_1.LocMessage.unreachableExcept() + diagAddendum.getString(), except.
|
5281
|
-
this._evaluator.addUnreachableCode(except, except.exceptSuite);
|
5297
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnusedExcept, localize_1.LocMessage.unreachableExcept() + diagAddendum.getString(), except.d.typeExpr);
|
5298
|
+
this._evaluator.addUnreachableCode(except, except.d.exceptSuite);
|
5282
5299
|
}
|
5283
5300
|
}
|
5284
5301
|
(0, collectionUtils_1.appendArray)(exceptionTypesSoFar, typesOfThisExcept);
|
@@ -5290,22 +5307,22 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5290
5307
|
importStatements.orderedImports.forEach((importStatement) => {
|
5291
5308
|
if (importStatement.node.nodeType === 25 /* ParseNodeType.ImportFrom */) {
|
5292
5309
|
const symbolMap = new Map();
|
5293
|
-
importStatement.node.imports.forEach((importFromAs) => {
|
5310
|
+
importStatement.node.d.imports.forEach((importFromAs) => {
|
5294
5311
|
// Ignore duplicates if they're aliased.
|
5295
|
-
if (!importFromAs.alias) {
|
5296
|
-
const prevImport = symbolMap.get(importFromAs.name.value);
|
5312
|
+
if (!importFromAs.d.alias) {
|
5313
|
+
const prevImport = symbolMap.get(importFromAs.d.name.d.value);
|
5297
5314
|
if (prevImport) {
|
5298
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportDuplicateImport, localize_1.LocMessage.duplicateImport().format({ importName: importFromAs.name.value }), importFromAs.name);
|
5315
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportDuplicateImport, localize_1.LocMessage.duplicateImport().format({ importName: importFromAs.d.name.d.value }), importFromAs.d.name);
|
5299
5316
|
}
|
5300
5317
|
else {
|
5301
|
-
symbolMap.set(importFromAs.name.value, importFromAs);
|
5318
|
+
symbolMap.set(importFromAs.d.name.d.value, importFromAs);
|
5302
5319
|
}
|
5303
5320
|
}
|
5304
5321
|
});
|
5305
5322
|
}
|
5306
5323
|
else if (importStatement.subnode) {
|
5307
5324
|
// Ignore duplicates if they're aliased.
|
5308
|
-
if (!importStatement.subnode.alias) {
|
5325
|
+
if (!importStatement.subnode.d.alias) {
|
5309
5326
|
const prevImport = importModuleMap.get(importStatement.moduleName);
|
5310
5327
|
if (prevImport) {
|
5311
5328
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportDuplicateImport, localize_1.LocMessage.duplicateImport().format({ importName: importStatement.moduleName }), importStatement.subnode);
|