@zzzen/pyright-internal 1.2.0-dev.20240707 → 1.2.0-dev.20240714
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 +649 -634
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.d.ts +5 -3
- package/dist/analyzer/codeFlowEngine.js +87 -101
- 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 +68 -64
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constructorTransform.js +22 -22
- package/dist/analyzer/constructorTransform.js.map +1 -1
- package/dist/analyzer/constructors.js +51 -48
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.js +109 -175
- 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 +77 -77
- 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 +66 -66
- 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 +28 -46
- package/dist/analyzer/parameterUtils.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.js +268 -269
- 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 +176 -143
- 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 +78 -147
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/protocols.js +21 -21
- 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 +2 -2
- 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 +1884 -1937
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +6 -5
- package/dist/analyzer/typeEvaluatorTypes.js +4 -1
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +211 -211
- 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 +14 -3
- package/dist/analyzer/typeUtils.js +432 -402
- 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 +96 -198
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +144 -102
- package/dist/analyzer/types.js +662 -494
- package/dist/analyzer/types.js.map +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js +33 -33
- 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 +25 -24
- 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.js +8 -8
- package/dist/languageService/referencesProvider.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/parser/parseNodes.d.ts +468 -401
- package/dist/parser/parseNodes.js +626 -355
- package/dist/parser/parseNodes.js.map +1 -1
- package/dist/parser/parser.d.ts +1 -0
- package/dist/parser/parser.js +316 -294
- 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/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/typeEvaluator3.test.js +8 -3
- package/dist/tests/typeEvaluator3.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
|
const 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) {
|
@@ -584,11 +588,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
584
588
|
// See if the declared return type includes one or more constrained TypeVars. If so,
|
585
589
|
// try to narrow these TypeVars to a single type.
|
586
590
|
const uniqueTypeVars = (0, typeUtils_1.getTypeVarArgumentsRecursive)(declaredReturnType);
|
587
|
-
if (uniqueTypeVars &&
|
588
|
-
uniqueTypeVars.some((typeVar) => typeVar.details.constraints.length > 0)) {
|
591
|
+
if (uniqueTypeVars && uniqueTypeVars.some((typeVar) => typeVar.shared.constraints.length > 0)) {
|
589
592
|
const typeVarContext = new typeVarContext_1.TypeVarContext();
|
590
593
|
for (const typeVar of uniqueTypeVars) {
|
591
|
-
if (typeVar.
|
594
|
+
if (typeVar.shared.constraints.length > 0) {
|
592
595
|
const narrowedType = this._evaluator.narrowConstrainedTypeVar(node, typeVar);
|
593
596
|
if (narrowedType) {
|
594
597
|
typeVarContext.setTypeVarType(typeVar, narrowedType);
|
@@ -615,32 +618,32 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
615
618
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportReturnType, localize_1.LocMessage.returnTypeMismatch().format({
|
616
619
|
exprType: this._evaluator.printType(returnType),
|
617
620
|
returnType: this._evaluator.printType(declaredReturnType),
|
618
|
-
}) + diagAddendum.getString(), (
|
621
|
+
}) + diagAddendum.getString(), (_c = node.d.expr) !== null && _c !== void 0 ? _c : node, (_d = returnTypeResult.expectedTypeDiagAddendum) === null || _d === void 0 ? void 0 : _d.getEffectiveTextRange());
|
619
622
|
}
|
620
623
|
}
|
621
624
|
}
|
622
625
|
if ((0, types_1.isUnknown)(returnType)) {
|
623
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnknownVariableType, localize_1.LocMessage.returnTypeUnknown(), (
|
626
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnknownVariableType, localize_1.LocMessage.returnTypeUnknown(), (_e = node.d.expr) !== null && _e !== void 0 ? _e : node);
|
624
627
|
}
|
625
628
|
else if ((0, typeUtils_1.isPartlyUnknown)(returnType)) {
|
626
629
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnknownVariableType, localize_1.LocMessage.returnTypePartiallyUnknown().format({
|
627
630
|
returnType: this._evaluator.printType(returnType, { expandTypeAlias: true }),
|
628
|
-
}), (
|
631
|
+
}), (_f = node.d.expr) !== null && _f !== void 0 ? _f : node);
|
629
632
|
}
|
630
633
|
}
|
631
634
|
return true;
|
632
635
|
}
|
633
636
|
visitYield(node) {
|
634
637
|
var _a;
|
635
|
-
const yieldTypeResult = node.
|
636
|
-
? this._evaluator.getTypeResult(node.
|
638
|
+
const yieldTypeResult = node.d.expr
|
639
|
+
? this._evaluator.getTypeResult(node.d.expr)
|
637
640
|
: { type: this._evaluator.getNoneType() };
|
638
641
|
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
642
|
return true;
|
640
643
|
}
|
641
644
|
visitYieldFrom(node) {
|
642
645
|
var _a, _b, _c, _d;
|
643
|
-
const yieldFromType = this._evaluator.getType(node.
|
646
|
+
const yieldFromType = this._evaluator.getType(node.d.expr) || types_1.UnknownType.create();
|
644
647
|
let yieldType;
|
645
648
|
let sendType;
|
646
649
|
if ((0, types_1.isClassInstance)(yieldFromType) && types_1.ClassType.isBuiltIn(yieldFromType, 'Coroutine')) {
|
@@ -668,9 +671,9 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
668
671
|
}
|
669
672
|
visitRaise(node) {
|
670
673
|
this._evaluator.verifyRaiseExceptionType(node);
|
671
|
-
if (node.valueExpression) {
|
674
|
+
if (node.d.valueExpression) {
|
672
675
|
const baseExceptionType = this._evaluator.getBuiltInType(node, 'BaseException');
|
673
|
-
const exceptionType = this._evaluator.getType(node.valueExpression);
|
676
|
+
const exceptionType = this._evaluator.getType(node.d.valueExpression);
|
674
677
|
// Validate that the argument of "raise" is an exception object or None.
|
675
678
|
if (exceptionType && baseExceptionType && (0, types_1.isInstantiableClass)(baseExceptionType)) {
|
676
679
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
@@ -692,36 +695,36 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
692
695
|
}
|
693
696
|
});
|
694
697
|
if (!diagAddendum.isEmpty()) {
|
695
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.expectedExceptionObj() + diagAddendum.getString(), node.valueExpression);
|
698
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.expectedExceptionObj() + diagAddendum.getString(), node.d.valueExpression);
|
696
699
|
}
|
697
700
|
}
|
698
701
|
}
|
699
702
|
return true;
|
700
703
|
}
|
701
704
|
visitExcept(node) {
|
702
|
-
if (node.
|
705
|
+
if (node.d.typeExpr) {
|
703
706
|
this._evaluator.evaluateTypesForStatement(node);
|
704
|
-
const exceptionType = this._evaluator.getType(node.
|
707
|
+
const exceptionType = this._evaluator.getType(node.d.typeExpr);
|
705
708
|
if (exceptionType) {
|
706
|
-
this._validateExceptionType(exceptionType, node.
|
709
|
+
this._validateExceptionType(exceptionType, node.d.typeExpr, node.d.isExceptGroup);
|
707
710
|
}
|
708
711
|
}
|
709
712
|
return true;
|
710
713
|
}
|
711
714
|
visitAssert(node) {
|
712
|
-
if (node.
|
713
|
-
this._evaluator.getType(node.
|
715
|
+
if (node.d.exceptionExpr) {
|
716
|
+
this._evaluator.getType(node.d.exceptionExpr);
|
714
717
|
}
|
715
|
-
this._validateConditionalIsBool(node.
|
718
|
+
this._validateConditionalIsBool(node.d.testExpr);
|
716
719
|
// Specifically look for a common programming error where the two arguments
|
717
720
|
// to an assert are enclosed in parens and interpreted as a two-element tuple.
|
718
721
|
// assert (x > 3, "bad value x")
|
719
|
-
const type = this._evaluator.getType(node.
|
722
|
+
const type = this._evaluator.getType(node.d.testExpr);
|
720
723
|
if (type && (0, types_1.isClassInstance)(type)) {
|
721
|
-
if ((0, typeUtils_1.isTupleClass)(type) && type.tupleTypeArguments) {
|
722
|
-
if (type.tupleTypeArguments.length > 0) {
|
724
|
+
if ((0, typeUtils_1.isTupleClass)(type) && type.priv.tupleTypeArguments) {
|
725
|
+
if (type.priv.tupleTypeArguments.length > 0) {
|
723
726
|
if (!(0, typeUtils_1.isUnboundedTupleClass)(type)) {
|
724
|
-
this._evaluator.addDiagnosticForTextRange(this._fileInfo, diagnosticRules_1.DiagnosticRule.reportAssertAlwaysTrue, localize_1.LocMessage.assertAlwaysTrue(), node.
|
727
|
+
this._evaluator.addDiagnosticForTextRange(this._fileInfo, diagnosticRules_1.DiagnosticRule.reportAssertAlwaysTrue, localize_1.LocMessage.assertAlwaysTrue(), node.d.testExpr);
|
725
728
|
}
|
726
729
|
}
|
727
730
|
}
|
@@ -730,23 +733,23 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
730
733
|
}
|
731
734
|
visitAssignment(node) {
|
732
735
|
this._evaluator.evaluateTypesForStatement(node);
|
733
|
-
if (node.
|
734
|
-
this._evaluator.getType(node.
|
736
|
+
if (node.d.annotationComment) {
|
737
|
+
this._evaluator.getType(node.d.annotationComment);
|
735
738
|
if (this._fileInfo.diagnosticRuleSet.reportTypeCommentUsage !== 'none' &&
|
736
739
|
this._fileInfo.executionEnvironment.pythonVersion.isGreaterOrEqualTo(pythonVersion_1.pythonVersion3_6)) {
|
737
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportTypeCommentUsage, localize_1.LocMessage.typeCommentDeprecated(), node.
|
740
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportTypeCommentUsage, localize_1.LocMessage.typeCommentDeprecated(), node.d.annotationComment);
|
738
741
|
}
|
739
742
|
}
|
740
743
|
// 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.
|
744
|
+
if (node.d.leftExpr.nodeType === 54 /* ParseNodeType.TypeAnnotation */) {
|
745
|
+
const annotationType = this._evaluator.getTypeOfAnnotation(node.d.leftExpr.d.annotation);
|
743
746
|
if ((0, types_1.isClassInstance)(annotationType) && types_1.ClassType.isBuiltIn(annotationType, 'TypeAlias')) {
|
744
747
|
const scope = (0, scopeUtils_1.getScopeForNode)(node);
|
745
748
|
if (scope) {
|
746
749
|
if (scope.type !== 3 /* ScopeType.Class */ &&
|
747
750
|
scope.type !== 4 /* ScopeType.Module */ &&
|
748
751
|
scope.type !== 5 /* ScopeType.Builtin */) {
|
749
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeAliasNotInModuleOrClass(), node.
|
752
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeAliasNotInModuleOrClass(), node.d.leftExpr.d.annotation);
|
750
753
|
}
|
751
754
|
}
|
752
755
|
}
|
@@ -765,30 +768,32 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
765
768
|
this._evaluator.getType(node);
|
766
769
|
// If the index is a literal integer, see if this is a tuple with
|
767
770
|
// a known length and the integer value exceeds the length.
|
768
|
-
const baseType = this._evaluator.getType(node.
|
771
|
+
const baseType = this._evaluator.getType(node.d.leftExpr);
|
769
772
|
if (baseType) {
|
770
773
|
(0, typeUtils_1.doForEachSubtype)(baseType, (subtype) => {
|
771
774
|
const tupleType = (0, typeUtils_1.getSpecializedTupleType)(subtype);
|
772
|
-
if (!(0, types_1.isClassInstance)(subtype) ||
|
775
|
+
if (!(0, types_1.isClassInstance)(subtype) ||
|
776
|
+
!(tupleType === null || tupleType === void 0 ? void 0 : tupleType.priv.tupleTypeArguments) ||
|
777
|
+
(0, typeUtils_1.isUnboundedTupleClass)(tupleType)) {
|
773
778
|
return;
|
774
779
|
}
|
775
|
-
const tupleLength = tupleType.tupleTypeArguments.length;
|
776
|
-
if (node.items.length !== 1 ||
|
777
|
-
node.trailingComma ||
|
778
|
-
node.items[0].
|
779
|
-
node.items[0].name) {
|
780
|
+
const tupleLength = tupleType.priv.tupleTypeArguments.length;
|
781
|
+
if (node.d.items.length !== 1 ||
|
782
|
+
node.d.trailingComma ||
|
783
|
+
node.d.items[0].d.argCategory !== 0 /* ArgumentCategory.Simple */ ||
|
784
|
+
node.d.items[0].d.name) {
|
780
785
|
return;
|
781
786
|
}
|
782
|
-
const subscriptType = this._evaluator.getType(node.items[0].
|
787
|
+
const subscriptType = this._evaluator.getType(node.d.items[0].d.valueExpr);
|
783
788
|
if (!subscriptType ||
|
784
789
|
!(0, types_1.isClassInstance)(subscriptType) ||
|
785
790
|
!types_1.ClassType.isBuiltIn(subscriptType, 'int') ||
|
786
791
|
!(0, typeUtils_1.isLiteralType)(subscriptType) ||
|
787
|
-
typeof subscriptType.literalValue !== 'number') {
|
792
|
+
typeof subscriptType.priv.literalValue !== 'number') {
|
788
793
|
return;
|
789
794
|
}
|
790
|
-
if ((subscriptType.literalValue < 0 || subscriptType.literalValue < tupleLength) &&
|
791
|
-
(subscriptType.literalValue >= 0 || subscriptType.literalValue + tupleLength >= 0)) {
|
795
|
+
if ((subscriptType.priv.literalValue < 0 || subscriptType.priv.literalValue < tupleLength) &&
|
796
|
+
(subscriptType.priv.literalValue >= 0 || subscriptType.priv.literalValue + tupleLength >= 0)) {
|
792
797
|
return;
|
793
798
|
}
|
794
799
|
// This can be an expensive check, so we save it for the end once we
|
@@ -797,7 +802,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
797
802
|
return;
|
798
803
|
}
|
799
804
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.tupleIndexOutOfRange().format({
|
800
|
-
index: subscriptType.literalValue,
|
805
|
+
index: subscriptType.priv.literalValue,
|
801
806
|
type: this._evaluator.printType(subtype),
|
802
807
|
}), node);
|
803
808
|
});
|
@@ -805,23 +810,23 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
805
810
|
return true;
|
806
811
|
}
|
807
812
|
visitBinaryOperation(node) {
|
808
|
-
if (node.operator === 36 /* OperatorType.And */ || node.operator === 37 /* OperatorType.Or */) {
|
809
|
-
this._validateConditionalIsBool(node.
|
810
|
-
this._validateConditionalIsBool(node.
|
813
|
+
if (node.d.operator === 36 /* OperatorType.And */ || node.d.operator === 37 /* OperatorType.Or */) {
|
814
|
+
this._validateConditionalIsBool(node.d.leftExpr);
|
815
|
+
this._validateConditionalIsBool(node.d.rightExpr);
|
811
816
|
}
|
812
|
-
if (node.operator === 12 /* OperatorType.Equals */ || node.operator === 28 /* OperatorType.NotEquals */) {
|
817
|
+
if (node.d.operator === 12 /* OperatorType.Equals */ || node.d.operator === 28 /* OperatorType.NotEquals */) {
|
813
818
|
// Don't apply this rule if it's within an assert.
|
814
819
|
if (!ParseTreeUtils.isWithinAssertExpression(node)) {
|
815
820
|
this._validateComparisonTypes(node);
|
816
821
|
}
|
817
822
|
}
|
818
|
-
else if (node.operator === 39 /* OperatorType.Is */ || node.operator === 40 /* OperatorType.IsNot */) {
|
823
|
+
else if (node.d.operator === 39 /* OperatorType.Is */ || node.d.operator === 40 /* OperatorType.IsNot */) {
|
819
824
|
// Don't apply this rule if it's within an assert.
|
820
825
|
if (!ParseTreeUtils.isWithinAssertExpression(node)) {
|
821
826
|
this._validateComparisonTypesForIsOperator(node);
|
822
827
|
}
|
823
828
|
}
|
824
|
-
else if (node.operator === 41 /* OperatorType.In */ || node.operator === 42 /* OperatorType.NotIn */) {
|
829
|
+
else if (node.d.operator === 41 /* OperatorType.In */ || node.d.operator === 42 /* OperatorType.NotIn */) {
|
825
830
|
// Don't apply this rule if it's within an assert.
|
826
831
|
if (!ParseTreeUtils.isWithinAssertExpression(node)) {
|
827
832
|
this._validateContainmentTypes(node);
|
@@ -843,16 +848,16 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
843
848
|
return true;
|
844
849
|
}
|
845
850
|
visitUnaryOperation(node) {
|
846
|
-
if (node.operator === 38 /* OperatorType.Not */) {
|
847
|
-
this._validateConditionalIsBool(node.
|
851
|
+
if (node.d.operator === 38 /* OperatorType.Not */) {
|
852
|
+
this._validateConditionalIsBool(node.d.expr);
|
848
853
|
}
|
849
854
|
this._evaluator.getType(node);
|
850
855
|
return true;
|
851
856
|
}
|
852
857
|
visitTernary(node) {
|
853
858
|
this._evaluator.getType(node);
|
854
|
-
this._validateConditionalIsBool(node.
|
855
|
-
this._reportUnnecessaryConditionExpression(node.
|
859
|
+
this._validateConditionalIsBool(node.d.testExpr);
|
860
|
+
this._reportUnnecessaryConditionExpression(node.d.testExpr);
|
856
861
|
return true;
|
857
862
|
}
|
858
863
|
visitStringList(node) {
|
@@ -869,8 +874,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
869
874
|
curNode = curNode.parent;
|
870
875
|
}
|
871
876
|
}
|
872
|
-
for (const stringNode of node.strings) {
|
873
|
-
const stringTokens = stringNode.nodeType === 49 /* ParseNodeType.String */ ? [stringNode.token] : stringNode.middleTokens;
|
877
|
+
for (const stringNode of node.d.strings) {
|
878
|
+
const stringTokens = stringNode.nodeType === 49 /* ParseNodeType.String */ ? [stringNode.d.token] : stringNode.d.middleTokens;
|
874
879
|
stringTokens.forEach((token) => {
|
875
880
|
const unescapedResult = (0, stringTokenUtils_1.getUnescapedString)(token);
|
876
881
|
let start = token.start;
|
@@ -894,31 +899,32 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
894
899
|
// used the same quote scheme within an f-string.
|
895
900
|
if (fStringContainers.length > 0) {
|
896
901
|
const quoteTypeMask = 1 /* StringTokenFlags.SingleQuote */ | 2 /* StringTokenFlags.DoubleQuote */ | 4 /* StringTokenFlags.Triplicate */;
|
897
|
-
if (fStringContainers.some((fStringContainer) => (fStringContainer.token.flags & quoteTypeMask) ===
|
902
|
+
if (fStringContainers.some((fStringContainer) => (fStringContainer.d.token.flags & quoteTypeMask) ===
|
903
|
+
(stringNode.d.token.flags & quoteTypeMask))) {
|
898
904
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.formatStringNestedQuote(), stringNode);
|
899
905
|
}
|
900
906
|
}
|
901
907
|
}
|
902
|
-
if (node.
|
908
|
+
if (node.d.annotation) {
|
903
909
|
this._evaluator.getType(node);
|
904
910
|
}
|
905
|
-
if (node.strings.length > 1 && !node.
|
911
|
+
if (node.d.strings.length > 1 && !node.d.hasParens) {
|
906
912
|
this._evaluator.addDiagnosticForTextRange(this._fileInfo, diagnosticRules_1.DiagnosticRule.reportImplicitStringConcatenation, localize_1.LocMessage.implicitStringConcat(), node);
|
907
913
|
}
|
908
914
|
return true;
|
909
915
|
}
|
910
916
|
visitFormatString(node) {
|
911
|
-
node.
|
917
|
+
node.d.fieldExprs.forEach((expr) => {
|
912
918
|
this._evaluator.getType(expr);
|
913
919
|
});
|
914
|
-
node.
|
920
|
+
node.d.formatExprs.forEach((expr) => {
|
915
921
|
this._evaluator.getType(expr);
|
916
922
|
});
|
917
923
|
return true;
|
918
924
|
}
|
919
925
|
visitGlobal(node) {
|
920
926
|
this._suppressUnboundCheck(() => {
|
921
|
-
node.
|
927
|
+
node.d.targets.forEach((name) => {
|
922
928
|
this._evaluator.getType(name);
|
923
929
|
this.walk(name);
|
924
930
|
});
|
@@ -927,7 +933,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
927
933
|
}
|
928
934
|
visitNonlocal(node) {
|
929
935
|
this._suppressUnboundCheck(() => {
|
930
|
-
node.
|
936
|
+
node.d.targets.forEach((name) => {
|
931
937
|
this._evaluator.getType(name);
|
932
938
|
this.walk(name);
|
933
939
|
});
|
@@ -947,7 +953,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
947
953
|
return true;
|
948
954
|
}
|
949
955
|
visitDel(node) {
|
950
|
-
node.
|
956
|
+
node.d.targets.forEach((expr) => {
|
951
957
|
this._evaluator.verifyDeleteExpression(expr);
|
952
958
|
this.walk(expr);
|
953
959
|
});
|
@@ -957,14 +963,14 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
957
963
|
var _a;
|
958
964
|
const typeResult = this._evaluator.getTypeResult(node);
|
959
965
|
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.
|
966
|
+
const leftExprType = this._evaluator.getType(node.d.leftExpr);
|
967
|
+
this._reportDeprecatedUseForType(node.d.member, type, leftExprType && (0, types_1.isModule)(leftExprType) && leftExprType.priv.moduleName === 'typing');
|
962
968
|
if (typeResult === null || typeResult === void 0 ? void 0 : typeResult.memberAccessDeprecationInfo) {
|
963
|
-
this._reportDeprecatedUseForMemberAccess(node.
|
969
|
+
this._reportDeprecatedUseForMemberAccess(node.d.member, typeResult.memberAccessDeprecationInfo);
|
964
970
|
}
|
965
|
-
this._conditionallyReportPrivateUsage(node.
|
971
|
+
this._conditionallyReportPrivateUsage(node.d.member);
|
966
972
|
// Walk the leftExpression but not the memberName.
|
967
|
-
this.walk(node.
|
973
|
+
this.walk(node.d.leftExpr);
|
968
974
|
return false;
|
969
975
|
}
|
970
976
|
visitImportAs(node) {
|
@@ -974,27 +980,27 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
974
980
|
}
|
975
981
|
visitImportFrom(node) {
|
976
982
|
// 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__') {
|
983
|
+
if (node.d.module.d.leadingDots === 0 &&
|
984
|
+
node.d.module.d.nameParts.length === 1 &&
|
985
|
+
node.d.module.d.nameParts[0].d.value === '__future__') {
|
980
986
|
if (!ParseTreeUtils.isValidLocationForFutureImport(node)) {
|
981
987
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.futureImportLocationNotAllowed(), node);
|
982
988
|
}
|
983
989
|
}
|
984
990
|
this._conditionallyReportShadowedImport(node);
|
985
|
-
if (!node.isWildcardImport) {
|
986
|
-
node.imports.forEach((importAs) => {
|
991
|
+
if (!node.d.isWildcardImport) {
|
992
|
+
node.d.imports.forEach((importAs) => {
|
987
993
|
this._evaluator.evaluateTypesForStatement(importAs);
|
988
994
|
});
|
989
995
|
}
|
990
996
|
else {
|
991
997
|
this._evaluator.evaluateTypesForStatement(node);
|
992
|
-
const importInfo = AnalyzerNodeInfo.getImportInfo(node.module);
|
998
|
+
const importInfo = AnalyzerNodeInfo.getImportInfo(node.d.module);
|
993
999
|
if (importInfo &&
|
994
1000
|
importInfo.isImportFound &&
|
995
1001
|
importInfo.importType !== 2 /* ImportType.Local */ &&
|
996
1002
|
!this._fileInfo.isStubFile) {
|
997
|
-
this._evaluator.addDiagnosticForTextRange(this._fileInfo, diagnosticRules_1.DiagnosticRule.reportWildcardImportFromLibrary, localize_1.LocMessage.wildcardLibraryImport(), node.wildcardToken || node);
|
1003
|
+
this._evaluator.addDiagnosticForTextRange(this._fileInfo, diagnosticRules_1.DiagnosticRule.reportWildcardImportFromLibrary, localize_1.LocMessage.wildcardLibraryImport(), node.d.wildcardToken || node);
|
998
1004
|
}
|
999
1005
|
}
|
1000
1006
|
return true;
|
@@ -1004,7 +1010,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1004
1010
|
if (this._fileInfo.isStubFile) {
|
1005
1011
|
return false;
|
1006
1012
|
}
|
1007
|
-
const decls = this._evaluator.getDeclarationsForNameNode(node.name);
|
1013
|
+
const decls = this._evaluator.getDeclarationsForNameNode(node.d.name);
|
1008
1014
|
if (!decls) {
|
1009
1015
|
return false;
|
1010
1016
|
}
|
@@ -1022,19 +1028,19 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1022
1028
|
if (!importResult) {
|
1023
1029
|
continue;
|
1024
1030
|
}
|
1025
|
-
this._addMissingModuleSourceDiagnosticIfNeeded(importResult, node.name);
|
1031
|
+
this._addMissingModuleSourceDiagnosticIfNeeded(importResult, node.d.name);
|
1026
1032
|
break;
|
1027
1033
|
}
|
1028
1034
|
let isImportFromTyping = false;
|
1029
1035
|
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') {
|
1036
|
+
if (node.parent.d.module.d.leadingDots === 0 && node.parent.d.module.d.nameParts.length === 1) {
|
1037
|
+
if (node.parent.d.module.d.nameParts[0].d.value === 'typing') {
|
1032
1038
|
isImportFromTyping = true;
|
1033
1039
|
}
|
1034
1040
|
}
|
1035
1041
|
}
|
1036
|
-
const type = this._evaluator.getType((_b = node.alias) !== null && _b !== void 0 ? _b : node.name);
|
1037
|
-
this._reportDeprecatedUseForType(node.name, type, isImportFromTyping);
|
1042
|
+
const type = this._evaluator.getType((_b = node.d.alias) !== null && _b !== void 0 ? _b : node.d.name);
|
1043
|
+
this._reportDeprecatedUseForType(node.d.name, type, isImportFromTyping);
|
1038
1044
|
return false;
|
1039
1045
|
}
|
1040
1046
|
visitModuleName(node) {
|
@@ -1063,14 +1069,14 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1063
1069
|
}
|
1064
1070
|
if (typeVarScopeNode.nodeType === 10 /* ParseNodeType.Class */) {
|
1065
1071
|
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.
|
1072
|
+
if (classType === null || classType === void 0 ? void 0 : classType.shared.typeParameters.some((param) => param.shared.name === node.d.name.d.value)) {
|
1067
1073
|
foundDuplicate = true;
|
1068
1074
|
break;
|
1069
1075
|
}
|
1070
1076
|
}
|
1071
1077
|
else if (typeVarScopeNode.nodeType === 31 /* ParseNodeType.Function */) {
|
1072
1078
|
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.
|
1079
|
+
if (functionType === null || functionType === void 0 ? void 0 : functionType.shared.typeParameters.some((param) => param.shared.name === node.d.name.d.value)) {
|
1074
1080
|
foundDuplicate = true;
|
1075
1081
|
break;
|
1076
1082
|
}
|
@@ -1078,7 +1084,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1078
1084
|
curNode = typeVarScopeNode.parent;
|
1079
1085
|
}
|
1080
1086
|
if (foundDuplicate) {
|
1081
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarUsedByOuterScope().format({ name: node.name.value }), node.name);
|
1087
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarUsedByOuterScope().format({ name: node.d.name.d.value }), node.d.name);
|
1082
1088
|
}
|
1083
1089
|
return false;
|
1084
1090
|
}
|
@@ -1086,25 +1092,25 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1086
1092
|
const scope = (0, scopeUtils_1.getScopeForNode)(node);
|
1087
1093
|
if (scope) {
|
1088
1094
|
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);
|
1095
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeAliasStatementBadScope(), node.d.name);
|
1090
1096
|
}
|
1091
1097
|
}
|
1092
1098
|
return true;
|
1093
1099
|
}
|
1094
1100
|
visitTypeAnnotation(node) {
|
1095
|
-
this._evaluator.getType(node.
|
1101
|
+
this._evaluator.getType(node.d.annotation);
|
1096
1102
|
return true;
|
1097
1103
|
}
|
1098
1104
|
visitMatch(node) {
|
1099
|
-
this._evaluator.getType(node.
|
1105
|
+
this._evaluator.getType(node.d.expr);
|
1100
1106
|
this._validateExhaustiveMatch(node);
|
1101
1107
|
return true;
|
1102
1108
|
}
|
1103
1109
|
visitCase(node) {
|
1104
|
-
if (node.
|
1105
|
-
this._validateConditionalIsBool(node.
|
1110
|
+
if (node.d.guardExpr) {
|
1111
|
+
this._validateConditionalIsBool(node.d.guardExpr);
|
1106
1112
|
}
|
1107
|
-
this._evaluator.evaluateTypesForStatement(node.pattern);
|
1113
|
+
this._evaluator.evaluateTypesForStatement(node.d.pattern);
|
1108
1114
|
return true;
|
1109
1115
|
}
|
1110
1116
|
visitPatternClass(node) {
|
@@ -1118,17 +1124,17 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1118
1124
|
visitError(node) {
|
1119
1125
|
// Get the type of the child so it's available to
|
1120
1126
|
// the completion provider.
|
1121
|
-
if (node.child) {
|
1122
|
-
this._evaluator.getType(node.child);
|
1127
|
+
if (node.d.child) {
|
1128
|
+
this._evaluator.getType(node.d.child);
|
1123
1129
|
}
|
1124
1130
|
// Don't explore further.
|
1125
1131
|
return false;
|
1126
1132
|
}
|
1127
1133
|
_getImportResult(node, uri) {
|
1128
1134
|
const execEnv = this._importResolver.getConfigOptions().findExecEnvironment(uri);
|
1129
|
-
const moduleNameNode = node.parent.module;
|
1135
|
+
const moduleNameNode = node.parent.d.module;
|
1130
1136
|
// Handle both absolute and relative imports.
|
1131
|
-
const moduleName = moduleNameNode.leadingDots === 0
|
1137
|
+
const moduleName = moduleNameNode.d.leadingDots === 0
|
1132
1138
|
? this._importResolver.getModuleNameForImport(uri, execEnv).moduleName
|
1133
1139
|
: (0, importStatementUtils_1.getRelativeModuleName)(this._importResolver.fileSystem, this._fileInfo.fileUri, uri, this._importResolver.getConfigOptions());
|
1134
1140
|
if (!moduleName) {
|
@@ -1190,15 +1196,15 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1190
1196
|
}
|
1191
1197
|
_reportUnnecessaryConditionExpression(expression) {
|
1192
1198
|
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.
|
1199
|
+
if (expression.d.operator === 36 /* OperatorType.And */ || expression.d.operator === 37 /* OperatorType.Or */) {
|
1200
|
+
this._reportUnnecessaryConditionExpression(expression.d.leftExpr);
|
1201
|
+
this._reportUnnecessaryConditionExpression(expression.d.rightExpr);
|
1196
1202
|
}
|
1197
1203
|
return;
|
1198
1204
|
}
|
1199
1205
|
else if (expression.nodeType === 55 /* ParseNodeType.UnaryOperation */) {
|
1200
|
-
if (expression.operator === 38 /* OperatorType.Not */) {
|
1201
|
-
this._reportUnnecessaryConditionExpression(expression.
|
1206
|
+
if (expression.d.operator === 38 /* OperatorType.Not */) {
|
1207
|
+
this._reportUnnecessaryConditionExpression(expression.d.expr);
|
1202
1208
|
}
|
1203
1209
|
return;
|
1204
1210
|
}
|
@@ -1242,16 +1248,16 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1242
1248
|
node.nodeType === 45 /* ParseNodeType.Set */ ||
|
1243
1249
|
node.nodeType === 18 /* ParseNodeType.Dictionary */) {
|
1244
1250
|
// Exclude comprehensions.
|
1245
|
-
if (!node.
|
1251
|
+
if (!node.d.items.some((entry) => entry.nodeType === 11 /* ParseNodeType.Comprehension */)) {
|
1246
1252
|
reportAsUnused = true;
|
1247
1253
|
}
|
1248
1254
|
}
|
1249
1255
|
if (reportAsUnused &&
|
1250
1256
|
this._fileInfo.ipythonMode === sourceFile_1.IPythonMode.CellDocs &&
|
1251
1257
|
((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 47 /* ParseNodeType.StatementList */ &&
|
1252
|
-
node.parent.statements[node.parent.statements.length - 1] === node &&
|
1258
|
+
node.parent.d.statements[node.parent.d.statements.length - 1] === node &&
|
1253
1259
|
((_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) {
|
1260
|
+
node.parent.parent.d.statements[node.parent.parent.d.statements.length - 1] === node.parent) {
|
1255
1261
|
// Exclude an expression at the end of a notebook cell, as that is treated as
|
1256
1262
|
// the cell's value.
|
1257
1263
|
reportAsUnused = false;
|
@@ -1274,7 +1280,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1274
1280
|
type: this._evaluator.printType(narrowedTypeResult.type),
|
1275
1281
|
}));
|
1276
1282
|
diagAddendum.addMessage(localize_1.LocAddendum.matchIsNotExhaustiveHint());
|
1277
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportMatchNotExhaustive, localize_1.LocMessage.matchIsNotExhaustive() + diagAddendum.getString(), node.
|
1283
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportMatchNotExhaustive, localize_1.LocMessage.matchIsNotExhaustive() + diagAddendum.getString(), node.d.expr);
|
1278
1284
|
}
|
1279
1285
|
}
|
1280
1286
|
_suppressUnboundCheck(callback) {
|
@@ -1295,24 +1301,24 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1295
1301
|
}
|
1296
1302
|
}
|
1297
1303
|
_validateStandardCollectionInstantiation(node) {
|
1298
|
-
const leftType = this._evaluator.getType(node.
|
1304
|
+
const leftType = this._evaluator.getType(node.d.leftExpr);
|
1299
1305
|
if (leftType &&
|
1300
1306
|
(0, types_1.isInstantiableClass)(leftType) &&
|
1301
1307
|
types_1.ClassType.isBuiltIn(leftType) &&
|
1302
|
-
!leftType.includeSubclasses &&
|
1303
|
-
leftType.aliasName) {
|
1308
|
+
!leftType.priv.includeSubclasses &&
|
1309
|
+
leftType.priv.aliasName) {
|
1304
1310
|
const nonInstantiable = ['List', 'Set', 'Dict', 'Tuple'];
|
1305
|
-
if (nonInstantiable.some((name) => name === leftType.aliasName)) {
|
1311
|
+
if (nonInstantiable.some((name) => name === leftType.priv.aliasName)) {
|
1306
1312
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.collectionAliasInstantiation().format({
|
1307
|
-
type: leftType.aliasName,
|
1308
|
-
alias: leftType.
|
1309
|
-
}), node.
|
1313
|
+
type: leftType.priv.aliasName,
|
1314
|
+
alias: leftType.shared.name,
|
1315
|
+
}), node.d.leftExpr);
|
1310
1316
|
}
|
1311
1317
|
}
|
1312
1318
|
}
|
1313
1319
|
_validateContainmentTypes(node) {
|
1314
|
-
const leftType = this._evaluator.getType(node.
|
1315
|
-
const containerType = this._evaluator.getType(node.
|
1320
|
+
const leftType = this._evaluator.getType(node.d.leftExpr);
|
1321
|
+
const containerType = this._evaluator.getType(node.d.rightExpr);
|
1316
1322
|
if (!leftType || !containerType) {
|
1317
1323
|
return;
|
1318
1324
|
}
|
@@ -1327,7 +1333,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1327
1333
|
const narrowedType = (0, typeGuards_1.narrowTypeForContainerElementType)(this._evaluator, leftType, this._evaluator.makeTopLevelTypeVarsConcrete(elementType));
|
1328
1334
|
if ((0, types_1.isNever)(narrowedType)) {
|
1329
1335
|
const getMessage = () => {
|
1330
|
-
return node.operator === 41 /* OperatorType.In */
|
1336
|
+
return node.d.operator === 41 /* OperatorType.In */
|
1331
1337
|
? localize_1.LocMessage.containmentAlwaysFalse()
|
1332
1338
|
: localize_1.LocMessage.containmentAlwaysTrue();
|
1333
1339
|
};
|
@@ -1340,11 +1346,11 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1340
1346
|
// Determines whether the types of the two operands for an "is" or "is not"
|
1341
1347
|
// operation have overlapping types.
|
1342
1348
|
_validateComparisonTypesForIsOperator(node) {
|
1343
|
-
const rightType = this._evaluator.getType(node.
|
1349
|
+
const rightType = this._evaluator.getType(node.d.rightExpr);
|
1344
1350
|
if (!rightType || !(0, typeUtils_1.isNoneInstance)(rightType)) {
|
1345
1351
|
return;
|
1346
1352
|
}
|
1347
|
-
const leftType = this._evaluator.getType(node.
|
1353
|
+
const leftType = this._evaluator.getType(node.d.leftExpr);
|
1348
1354
|
if (!leftType) {
|
1349
1355
|
return;
|
1350
1356
|
}
|
@@ -1356,7 +1362,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1356
1362
|
}
|
1357
1363
|
});
|
1358
1364
|
const getMessage = () => {
|
1359
|
-
return node.operator === 39 /* OperatorType.Is */
|
1365
|
+
return node.d.operator === 39 /* OperatorType.Is */
|
1360
1366
|
? localize_1.LocMessage.comparisonAlwaysFalse()
|
1361
1367
|
: localize_1.LocMessage.comparisonAlwaysTrue();
|
1362
1368
|
};
|
@@ -1370,15 +1376,15 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1370
1376
|
// Determines whether the types of the two operands for an == or != operation
|
1371
1377
|
// have overlapping types.
|
1372
1378
|
_validateComparisonTypes(node) {
|
1373
|
-
let rightExpression = node.
|
1379
|
+
let rightExpression = node.d.rightExpr;
|
1374
1380
|
// Check for chained comparisons.
|
1375
1381
|
if (rightExpression.nodeType === 7 /* ParseNodeType.BinaryOperation */ &&
|
1376
|
-
!rightExpression.
|
1377
|
-
ParseTreeUtils.operatorSupportsChaining(rightExpression.operator)) {
|
1382
|
+
!rightExpression.d.hasParens &&
|
1383
|
+
ParseTreeUtils.operatorSupportsChaining(rightExpression.d.operator)) {
|
1378
1384
|
// Use the left side of the right expression for comparison purposes.
|
1379
|
-
rightExpression = rightExpression.
|
1385
|
+
rightExpression = rightExpression.d.leftExpr;
|
1380
1386
|
}
|
1381
|
-
const leftType = this._evaluator.getType(node.
|
1387
|
+
const leftType = this._evaluator.getType(node.d.leftExpr);
|
1382
1388
|
const rightType = this._evaluator.getType(rightExpression);
|
1383
1389
|
if (!leftType || !rightType) {
|
1384
1390
|
return;
|
@@ -1387,7 +1393,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1387
1393
|
return;
|
1388
1394
|
}
|
1389
1395
|
const getMessage = () => {
|
1390
|
-
return node.operator === 12 /* OperatorType.Equals */
|
1396
|
+
return node.d.operator === 12 /* OperatorType.Equals */
|
1391
1397
|
? localize_1.LocMessage.comparisonAlwaysFalse()
|
1392
1398
|
: localize_1.LocMessage.comparisonAlwaysTrue();
|
1393
1399
|
};
|
@@ -1471,7 +1477,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1471
1477
|
}
|
1472
1478
|
}
|
1473
1479
|
// Does the class have an operator overload for eq?
|
1474
|
-
const metaclass = leftType.
|
1480
|
+
const metaclass = leftType.shared.effectiveMetaclass;
|
1475
1481
|
if (metaclass && (0, types_1.isClass)(metaclass)) {
|
1476
1482
|
if ((0, typeUtils_1.lookUpClassMember)(metaclass, '__eq__', 4 /* MemberAccessFlags.SkipObjectBaseClass */)) {
|
1477
1483
|
return true;
|
@@ -1518,19 +1524,19 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1518
1524
|
if (!types_1.FunctionType.isGenerator(functionType)) {
|
1519
1525
|
return;
|
1520
1526
|
}
|
1521
|
-
const declaredReturnType = functionType.
|
1527
|
+
const declaredReturnType = functionType.shared.declaredReturnType;
|
1522
1528
|
if (!declaredReturnType) {
|
1523
1529
|
return;
|
1524
1530
|
}
|
1525
1531
|
if ((0, types_1.isNever)(declaredReturnType)) {
|
1526
1532
|
return;
|
1527
1533
|
}
|
1528
|
-
const functionDecl = functionType.
|
1534
|
+
const functionDecl = functionType.shared.declaration;
|
1529
1535
|
if (!functionDecl || !functionDecl.yieldStatements || functionDecl.yieldStatements.length === 0) {
|
1530
1536
|
return;
|
1531
1537
|
}
|
1532
1538
|
let generatorType;
|
1533
|
-
if (!node.isAsync &&
|
1539
|
+
if (!node.d.isAsync &&
|
1534
1540
|
(0, types_1.isClassInstance)(declaredReturnType) &&
|
1535
1541
|
types_1.ClassType.isBuiltIn(declaredReturnType, 'AwaitableGenerator')) {
|
1536
1542
|
// Handle the old-style (pre-await) generator case
|
@@ -1538,7 +1544,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1538
1544
|
generatorType = this._evaluator.getTypingType(node, 'AwaitableGenerator');
|
1539
1545
|
}
|
1540
1546
|
else {
|
1541
|
-
generatorType = this._evaluator.getTypingType(node, node.isAsync ? 'AsyncGenerator' : 'Generator');
|
1547
|
+
generatorType = this._evaluator.getTypingType(node, node.d.isAsync ? 'AsyncGenerator' : 'Generator');
|
1542
1548
|
}
|
1543
1549
|
if (!generatorType || !(0, types_1.isInstantiableClass)(generatorType)) {
|
1544
1550
|
return;
|
@@ -1547,11 +1553,11 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1547
1553
|
/* isTypeArgumentExplicit */ true));
|
1548
1554
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
1549
1555
|
if (!this._evaluator.assignType(declaredReturnType, specializedGenerator, diagAddendum)) {
|
1550
|
-
const errorMessage = node.isAsync
|
1556
|
+
const errorMessage = node.d.isAsync
|
1551
1557
|
? localize_1.LocMessage.generatorAsyncReturnType()
|
1552
1558
|
: localize_1.LocMessage.generatorSyncReturnType();
|
1553
1559
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, errorMessage.format({ yieldType: this._evaluator.printType(types_1.AnyType.create()) }) +
|
1554
|
-
diagAddendum.getString(), (_a = node.
|
1560
|
+
diagAddendum.getString(), (_a = node.d.returnAnnotation) !== null && _a !== void 0 ? _a : node.d.name);
|
1555
1561
|
}
|
1556
1562
|
}
|
1557
1563
|
// Determines whether the specified type is one that should trigger
|
@@ -1572,7 +1578,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1572
1578
|
let curParamNode;
|
1573
1579
|
// Is this a constructor (an __init__ method) for a generic class?
|
1574
1580
|
let constructorClass;
|
1575
|
-
if (types_1.FunctionType.isInstanceMethod(type) && node.name.value === '__init__') {
|
1581
|
+
if (types_1.FunctionType.isInstanceMethod(type) && node.d.name.d.value === '__init__') {
|
1576
1582
|
const containingClassNode = ParseTreeUtils.getEnclosingClassOrFunction(node);
|
1577
1583
|
if (containingClassNode && containingClassNode.nodeType === 10 /* ParseNodeType.Class */) {
|
1578
1584
|
const classType = this._evaluator.getTypeOfClass(containingClassNode);
|
@@ -1582,17 +1588,17 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1582
1588
|
}
|
1583
1589
|
}
|
1584
1590
|
const nameWalker = new ParseTreeUtils.NameNodeWalker((nameNode, subscriptIndex, baseExpression) => {
|
1585
|
-
var _a, _b, _c, _d, _e, _f;
|
1591
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
1586
1592
|
const nameType = this._evaluator.getType(nameNode);
|
1587
1593
|
``;
|
1588
|
-
if (nameType && (0, types_1.isTypeVar)(nameType) && !nameType.
|
1594
|
+
if (nameType && (0, types_1.isTypeVar)(nameType) && !nameType.shared.isSynthesizedSelf) {
|
1589
1595
|
// Does this name refer to a TypeVar that is scoped to this function?
|
1590
|
-
if (nameType.scopeId === ParseTreeUtils.getScopeIdForNode(node)) {
|
1596
|
+
if (nameType.priv.scopeId === ParseTreeUtils.getScopeIdForNode(node)) {
|
1591
1597
|
// We exempt constrained TypeVars, TypeVars that are type arguments of
|
1592
1598
|
// other types, and ParamSpecs. There are legitimate uses for singleton
|
1593
1599
|
// instances in these particular cases.
|
1594
|
-
let isExempt = nameType.
|
1595
|
-
nameType.
|
1600
|
+
let isExempt = nameType.shared.constraints.length > 0 ||
|
1601
|
+
nameType.shared.isDefaultExplicit ||
|
1596
1602
|
(exemptBoundTypeVar && subscriptIndex !== undefined) ||
|
1597
1603
|
(0, types_1.isParamSpec)(nameType);
|
1598
1604
|
if (!isExempt && baseExpression && subscriptIndex !== undefined) {
|
@@ -1600,22 +1606,21 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1600
1606
|
// exempt it from the check because the type alias may repeat
|
1601
1607
|
// the TypeVar multiple times.
|
1602
1608
|
const baseType = this._evaluator.getType(baseExpression);
|
1603
|
-
|
1604
|
-
|
1605
|
-
subscriptIndex < baseType.typeAliasInfo.typeParameters.length) {
|
1609
|
+
const aliasInfo = (_a = baseType === null || baseType === void 0 ? void 0 : baseType.props) === null || _a === void 0 ? void 0 : _a.typeAliasInfo;
|
1610
|
+
if ((aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.typeParameters) && subscriptIndex < aliasInfo.typeParameters.length) {
|
1606
1611
|
isExempt = true;
|
1607
1612
|
}
|
1608
1613
|
}
|
1609
|
-
const existingEntry = localTypeVarUsage.get(nameType.
|
1610
|
-
const isParamTypeWithEllipsisUsage = ((
|
1614
|
+
const existingEntry = localTypeVarUsage.get(nameType.shared.name);
|
1615
|
+
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
1616
|
if (!existingEntry) {
|
1612
|
-
localTypeVarUsage.set(nameType.
|
1617
|
+
localTypeVarUsage.set(nameType.shared.name, {
|
1613
1618
|
nodes: [nameNode],
|
1614
1619
|
typeVar: nameType,
|
1615
1620
|
paramTypeUsageCount: curParamNode !== undefined ? 1 : 0,
|
1616
1621
|
paramTypeWithEllipsisUsageCount: isParamTypeWithEllipsisUsage ? 1 : 0,
|
1617
1622
|
returnTypeUsageCount: curParamNode === undefined ? 1 : 0,
|
1618
|
-
paramWithEllipsis: isParamTypeWithEllipsisUsage ? (
|
1623
|
+
paramWithEllipsis: isParamTypeWithEllipsisUsage ? (_c = curParamNode === null || curParamNode === void 0 ? void 0 : curParamNode.d.name) === null || _c === void 0 ? void 0 : _c.d.value : undefined,
|
1619
1624
|
isExempt,
|
1620
1625
|
});
|
1621
1626
|
}
|
@@ -1626,7 +1631,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1626
1631
|
if (isParamTypeWithEllipsisUsage) {
|
1627
1632
|
existingEntry.paramTypeWithEllipsisUsageCount += 1;
|
1628
1633
|
if (!existingEntry.paramWithEllipsis) {
|
1629
|
-
existingEntry.paramWithEllipsis = (
|
1634
|
+
existingEntry.paramWithEllipsis = (_d = curParamNode === null || curParamNode === void 0 ? void 0 : curParamNode.d.name) === null || _d === void 0 ? void 0 : _d.d.value;
|
1630
1635
|
}
|
1631
1636
|
}
|
1632
1637
|
}
|
@@ -1637,18 +1642,18 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1637
1642
|
}
|
1638
1643
|
// Does this name refer to a TypeVar that is scoped to the class associated with
|
1639
1644
|
// this constructor method?
|
1640
|
-
if (constructorClass && nameType.scopeId === constructorClass.
|
1641
|
-
const existingEntry = classTypeVarUsage.get(nameType.
|
1642
|
-
const isParamTypeWithEllipsisUsage = ((
|
1643
|
-
const isExempt = !!nameType.
|
1645
|
+
if (constructorClass && nameType.priv.scopeId === constructorClass.shared.typeVarScopeId) {
|
1646
|
+
const existingEntry = classTypeVarUsage.get(nameType.shared.name);
|
1647
|
+
const isParamTypeWithEllipsisUsage = ((_e = curParamNode === null || curParamNode === void 0 ? void 0 : curParamNode.d.defaultValue) === null || _e === void 0 ? void 0 : _e.nodeType) === 21 /* ParseNodeType.Ellipsis */;
|
1648
|
+
const isExempt = !!nameType.shared.isDefaultExplicit;
|
1644
1649
|
if (!existingEntry) {
|
1645
|
-
classTypeVarUsage.set(nameType.
|
1650
|
+
classTypeVarUsage.set(nameType.shared.name, {
|
1646
1651
|
typeVar: nameType,
|
1647
1652
|
nodes: [nameNode],
|
1648
1653
|
paramTypeUsageCount: curParamNode !== undefined ? 1 : 0,
|
1649
1654
|
paramTypeWithEllipsisUsageCount: isParamTypeWithEllipsisUsage ? 1 : 0,
|
1650
1655
|
returnTypeUsageCount: 0,
|
1651
|
-
paramWithEllipsis: isParamTypeWithEllipsisUsage ? (
|
1656
|
+
paramWithEllipsis: isParamTypeWithEllipsisUsage ? (_f = curParamNode === null || curParamNode === void 0 ? void 0 : curParamNode.d.name) === null || _f === void 0 ? void 0 : _f.d.value : undefined,
|
1652
1657
|
isExempt,
|
1653
1658
|
});
|
1654
1659
|
}
|
@@ -1659,7 +1664,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1659
1664
|
if (isParamTypeWithEllipsisUsage) {
|
1660
1665
|
existingEntry.paramTypeWithEllipsisUsageCount += 1;
|
1661
1666
|
if (!existingEntry.paramWithEllipsis) {
|
1662
|
-
existingEntry.paramWithEllipsis = (
|
1667
|
+
existingEntry.paramWithEllipsis = (_g = curParamNode === null || curParamNode === void 0 ? void 0 : curParamNode.d.name) === null || _g === void 0 ? void 0 : _g.d.value;
|
1663
1668
|
}
|
1664
1669
|
}
|
1665
1670
|
}
|
@@ -1668,28 +1673,28 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1668
1673
|
}
|
1669
1674
|
});
|
1670
1675
|
// Find all of the local type variables in signature.
|
1671
|
-
node.
|
1672
|
-
const annotation = param.
|
1676
|
+
node.d.params.forEach((param) => {
|
1677
|
+
const annotation = param.d.annotation || param.d.annotationComment;
|
1673
1678
|
if (annotation) {
|
1674
1679
|
curParamNode = param;
|
1675
1680
|
nameWalker.walk(annotation);
|
1676
1681
|
}
|
1677
1682
|
});
|
1678
1683
|
curParamNode = undefined;
|
1679
|
-
if (node.
|
1684
|
+
if (node.d.returnAnnotation) {
|
1680
1685
|
// Don't exempt the use of a bound TypeVar when used as a type argument
|
1681
1686
|
// within a return type. This exemption applies only to input parameter
|
1682
1687
|
// annotations.
|
1683
1688
|
exemptBoundTypeVar = false;
|
1684
|
-
nameWalker.walk(node.
|
1689
|
+
nameWalker.walk(node.d.returnAnnotation);
|
1685
1690
|
}
|
1686
|
-
if (node.
|
1687
|
-
node.
|
1691
|
+
if (node.d.funcAnnotationComment) {
|
1692
|
+
node.d.funcAnnotationComment.d.paramAnnotations.forEach((expr) => {
|
1688
1693
|
nameWalker.walk(expr);
|
1689
1694
|
});
|
1690
|
-
if (node.
|
1695
|
+
if (node.d.funcAnnotationComment.d.returnAnnotation) {
|
1691
1696
|
exemptBoundTypeVar = false;
|
1692
|
-
nameWalker.walk(node.
|
1697
|
+
nameWalker.walk(node.d.funcAnnotationComment.d.returnAnnotation);
|
1693
1698
|
}
|
1694
1699
|
}
|
1695
1700
|
localTypeVarUsage.forEach((usage) => {
|
@@ -1697,11 +1702,11 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1697
1702
|
// Report error for local type variable that appears only once.
|
1698
1703
|
if (usage.nodes.length === 1 && !usage.isExempt) {
|
1699
1704
|
let altTypeText;
|
1700
|
-
if (usage.typeVar.
|
1705
|
+
if (usage.typeVar.shared.isVariadic) {
|
1701
1706
|
altTypeText = '"tuple[object, ...]"';
|
1702
1707
|
}
|
1703
|
-
else if (usage.typeVar.
|
1704
|
-
altTypeText = `"${this._evaluator.printType((0, typeUtils_1.convertToInstance)(usage.typeVar.
|
1708
|
+
else if (usage.typeVar.shared.boundType) {
|
1709
|
+
altTypeText = `"${this._evaluator.printType((0, typeUtils_1.convertToInstance)(usage.typeVar.shared.boundType))}"`;
|
1705
1710
|
}
|
1706
1711
|
else {
|
1707
1712
|
altTypeText = '"object"';
|
@@ -1711,21 +1716,21 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1711
1716
|
type: altTypeText,
|
1712
1717
|
}));
|
1713
1718
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeVarUse, localize_1.LocMessage.typeVarUsedOnlyOnce().format({
|
1714
|
-
name: usage.nodes[0].value,
|
1719
|
+
name: usage.nodes[0].d.value,
|
1715
1720
|
}) + diag.getString(), usage.nodes[0]);
|
1716
1721
|
}
|
1717
1722
|
// Report error for local type variable that appears in return type
|
1718
1723
|
// (but not as a top-level TypeVar within a union) and appears only
|
1719
1724
|
// within parameters that have default values. These may go unsolved.
|
1720
1725
|
let isUsedInReturnType = usage.returnTypeUsageCount > 0;
|
1721
|
-
if (usage.returnTypeUsageCount === 1 && type.
|
1726
|
+
if (usage.returnTypeUsageCount === 1 && type.shared.declaredReturnType) {
|
1722
1727
|
// If the TypeVar appears only once in the return type and it's a top-level
|
1723
1728
|
// TypeVar within a union, exempt it from this check. Although these
|
1724
1729
|
// TypeVars may go unsolved, they can be safely eliminated from the union
|
1725
1730
|
// without generating an Unknown type.
|
1726
|
-
const returnType = type.
|
1731
|
+
const returnType = type.shared.declaredReturnType;
|
1727
1732
|
if ((0, types_1.isUnion)(returnType) &&
|
1728
|
-
returnType.subtypes.some((subtype) => (0, types_1.isTypeVar)(subtype) && subtype.
|
1733
|
+
returnType.priv.subtypes.some((subtype) => (0, types_1.isTypeVar)(subtype) && subtype.shared.name === usage.nodes[0].d.value)) {
|
1729
1734
|
isUsedInReturnType = false;
|
1730
1735
|
}
|
1731
1736
|
}
|
@@ -1740,7 +1745,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1740
1745
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
1741
1746
|
diag.addMessage(localize_1.LocAddendum.typeVarUnsolvableRemedy());
|
1742
1747
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeVarUse, localize_1.LocMessage.typeVarPossiblyUnsolvable().format({
|
1743
|
-
name: usage.nodes[0].value,
|
1748
|
+
name: usage.nodes[0].d.value,
|
1744
1749
|
param: (_a = usage.paramWithEllipsis) !== null && _a !== void 0 ? _a : '',
|
1745
1750
|
}) + diag.getString(), usage.nodes[0]);
|
1746
1751
|
}
|
@@ -1755,7 +1760,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1755
1760
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
1756
1761
|
diag.addMessage(localize_1.LocAddendum.typeVarUnsolvableRemedy());
|
1757
1762
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeVarUse, localize_1.LocMessage.typeVarPossiblyUnsolvable().format({
|
1758
|
-
name: usage.nodes[0].value,
|
1763
|
+
name: usage.nodes[0].d.value,
|
1759
1764
|
param: (_a = usage.paramWithEllipsis) !== null && _a !== void 0 ? _a : '',
|
1760
1765
|
}) + diag.getString(), usage.nodes[0]);
|
1761
1766
|
}
|
@@ -1766,7 +1771,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1766
1771
|
var _a, _b, _c, _d, _e, _f;
|
1767
1772
|
let staticMethodCount = 0;
|
1768
1773
|
let classMethodCount = 0;
|
1769
|
-
functionType.overloads.forEach((overload) => {
|
1774
|
+
functionType.priv.overloads.forEach((overload) => {
|
1770
1775
|
if (types_1.FunctionType.isStaticMethod(overload)) {
|
1771
1776
|
staticMethodCount++;
|
1772
1777
|
}
|
@@ -1774,15 +1779,15 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1774
1779
|
classMethodCount++;
|
1775
1780
|
}
|
1776
1781
|
});
|
1777
|
-
if (staticMethodCount > 0 && staticMethodCount < functionType.overloads.length) {
|
1782
|
+
if (staticMethodCount > 0 && staticMethodCount < functionType.priv.overloads.length) {
|
1778
1783
|
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.
|
1784
|
+
name: node.d.name.d.value,
|
1785
|
+
}), (_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
1786
|
}
|
1782
|
-
if (classMethodCount > 0 && classMethodCount < functionType.overloads.length) {
|
1787
|
+
if (classMethodCount > 0 && classMethodCount < functionType.priv.overloads.length) {
|
1783
1788
|
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.
|
1789
|
+
name: node.d.name.d.value,
|
1790
|
+
}), (_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
1791
|
}
|
1787
1792
|
}
|
1788
1793
|
// Validates that overloads do not overlap with inconsistent return results.
|
@@ -1791,10 +1796,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1791
1796
|
const prevOverload = prevOverloads[i];
|
1792
1797
|
if (this._isOverlappingOverload(functionType, prevOverload, /* partialOverlap */ false)) {
|
1793
1798
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportOverlappingOverload, localize_1.LocMessage.overlappingOverload().format({
|
1794
|
-
name: node.name.value,
|
1799
|
+
name: node.d.name.d.value,
|
1795
1800
|
obscured: prevOverloads.length + 1,
|
1796
1801
|
obscuredBy: i + 1,
|
1797
|
-
}), node.name);
|
1802
|
+
}), node.d.name);
|
1798
1803
|
break;
|
1799
1804
|
}
|
1800
1805
|
}
|
@@ -1810,10 +1815,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1810
1815
|
/* srcTypeVarContext */ undefined, 8 /* AssignTypeFlags.SkipSolveTypeVars */ | 1024 /* AssignTypeFlags.IgnoreTypeVarScope */)) {
|
1811
1816
|
const altNode = this._findNodeForOverload(node, prevOverload);
|
1812
1817
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportOverlappingOverload, localize_1.LocMessage.overloadReturnTypeMismatch().format({
|
1813
|
-
name: node.name.value,
|
1818
|
+
name: node.d.name.d.value,
|
1814
1819
|
newIndex: prevOverloads.length + 1,
|
1815
1820
|
prevIndex: i + 1,
|
1816
|
-
}), (altNode || node).name);
|
1821
|
+
}), (altNode || node).d.name);
|
1817
1822
|
break;
|
1818
1823
|
}
|
1819
1824
|
}
|
@@ -1823,7 +1828,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1823
1828
|
// earlier overload. Typeshed stubs contain type: ignore comments on these
|
1824
1829
|
// lines, so it is important for us to report them in the same manner.
|
1825
1830
|
_findNodeForOverload(functionNode, overloadType) {
|
1826
|
-
const decls = this._evaluator.getDeclarationsForNameNode(functionNode.name);
|
1831
|
+
const decls = this._evaluator.getDeclarationsForNameNode(functionNode.d.name);
|
1827
1832
|
if (!decls) {
|
1828
1833
|
return undefined;
|
1829
1834
|
}
|
@@ -1843,7 +1848,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1843
1848
|
// the case, but for consistency with other type checkers, we'll honor
|
1844
1849
|
// this rule. See https://github.com/python/typing/issues/253#issuecomment-389262904
|
1845
1850
|
// for details.
|
1846
|
-
if (types_1.FunctionType.isInstanceMethod(functionType) && functionType.
|
1851
|
+
if (types_1.FunctionType.isInstanceMethod(functionType) && functionType.shared.name === '__get__') {
|
1847
1852
|
return false;
|
1848
1853
|
}
|
1849
1854
|
let flags = 64 /* AssignTypeFlags.SkipFunctionReturnTypeCheck */ | 16 /* AssignTypeFlags.OverloadOverlapCheck */;
|
@@ -1863,8 +1868,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1863
1868
|
2 /* AssignTypeFlags.ReverseTypeVarMatching */ |
|
1864
1869
|
512 /* AssignTypeFlags.SkipSelfClsTypeCheck */);
|
1865
1870
|
// Now check the return types.
|
1866
|
-
const overloadReturnType = (_a = overload.
|
1867
|
-
const implementationReturnType = (0, typeUtils_1.applySolvedTypeVars)(implementation.
|
1871
|
+
const overloadReturnType = (_a = overload.shared.declaredReturnType) !== null && _a !== void 0 ? _a : this._evaluator.getFunctionInferredReturnType(overload);
|
1872
|
+
const implementationReturnType = (0, typeUtils_1.applySolvedTypeVars)(implementation.shared.declaredReturnType || this._evaluator.getFunctionInferredReturnType(implementation), implTypeVarContext);
|
1868
1873
|
const returnDiag = new diagnostic_1.DiagnosticAddendum();
|
1869
1874
|
if (!(0, types_1.isNever)(overloadReturnType) &&
|
1870
1875
|
!this._evaluator.assignType(implementationReturnType, overloadReturnType, returnDiag.createAddendum(), implTypeVarContext, overloadTypeVarContext, 8 /* AssignTypeFlags.SkipSolveTypeVars */)) {
|
@@ -1919,7 +1924,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1919
1924
|
break;
|
1920
1925
|
}
|
1921
1926
|
case 47 /* ParseNodeType.StatementList */: {
|
1922
|
-
for (const substatement of statement.statements) {
|
1927
|
+
for (const substatement of statement.d.statements) {
|
1923
1928
|
let isValid = true;
|
1924
1929
|
switch (substatement.nodeType) {
|
1925
1930
|
case 2 /* ParseNodeType.Assert */:
|
@@ -1959,17 +1964,17 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1959
1964
|
case 5 /* ParseNodeType.AugmentedAssignment */: {
|
1960
1965
|
// Exempt __all__ manipulations.
|
1961
1966
|
isValid =
|
1962
|
-
substatement.operator === 1 /* OperatorType.AddEqual */ &&
|
1963
|
-
substatement.
|
1964
|
-
substatement.
|
1967
|
+
substatement.d.operator === 1 /* OperatorType.AddEqual */ &&
|
1968
|
+
substatement.d.leftExpr.nodeType === 38 /* ParseNodeType.Name */ &&
|
1969
|
+
substatement.d.leftExpr.d.value === '__all__';
|
1965
1970
|
break;
|
1966
1971
|
}
|
1967
1972
|
case 9 /* ParseNodeType.Call */: {
|
1968
1973
|
// Exempt __all__ manipulations.
|
1969
1974
|
isValid =
|
1970
|
-
substatement.
|
1971
|
-
substatement.
|
1972
|
-
substatement.
|
1975
|
+
substatement.d.leftExpr.nodeType === 35 /* ParseNodeType.MemberAccess */ &&
|
1976
|
+
substatement.d.leftExpr.d.leftExpr.nodeType === 38 /* ParseNodeType.Name */ &&
|
1977
|
+
substatement.d.leftExpr.d.leftExpr.d.value === '__all__';
|
1973
1978
|
break;
|
1974
1979
|
}
|
1975
1980
|
}
|
@@ -2009,8 +2014,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2009
2014
|
}
|
2010
2015
|
return;
|
2011
2016
|
}
|
2012
|
-
if (allowTuple && exceptionSubtype.tupleTypeArguments) {
|
2013
|
-
exceptionSubtype.tupleTypeArguments.forEach((typeArg) => {
|
2017
|
+
if (allowTuple && exceptionSubtype.priv.tupleTypeArguments) {
|
2018
|
+
exceptionSubtype.priv.tupleTypeArguments.forEach((typeArg) => {
|
2014
2019
|
this._validateExceptionTypeRecursive(typeArg.type, diag, baseExceptionType, baseExceptionGroupType,
|
2015
2020
|
/* allowTuple */ false, isExceptGroup);
|
2016
2021
|
});
|
@@ -2044,8 +2049,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2044
2049
|
return;
|
2045
2050
|
}
|
2046
2051
|
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);
|
2052
|
+
if (!moduleScope.symbolTable.has(node.d.value)) {
|
2053
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnsupportedDunderAll, localize_1.LocMessage.dunderAllSymbolNotPresent().format({ name: node.d.value }), node);
|
2049
2054
|
}
|
2050
2055
|
});
|
2051
2056
|
}
|
@@ -2068,8 +2073,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2068
2073
|
const accessedSymbolSet = this._fileInfo.accessedSymbolSet;
|
2069
2074
|
for (const paramList of this._typeParameterLists) {
|
2070
2075
|
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);
|
2076
|
+
for (const param of paramList.d.params) {
|
2077
|
+
const symbol = typeParamScope === null || typeParamScope === void 0 ? void 0 : typeParamScope.symbolTable.get(param.d.name.d.value);
|
2073
2078
|
if (!symbol) {
|
2074
2079
|
// This can happen if the code is unreachable.
|
2075
2080
|
return;
|
@@ -2103,18 +2108,18 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2103
2108
|
// overloaded signature. We'll exempt it from this check.
|
2104
2109
|
if ((0, types_1.isOverloadedFunction)(type)) {
|
2105
2110
|
const overloads = types_1.OverloadedFunctionType.getOverloads(type);
|
2106
|
-
if (overloads.length > 0 && overloads[0].
|
2111
|
+
if (overloads.length > 0 && overloads[0].shared.name === '') {
|
2107
2112
|
return;
|
2108
2113
|
}
|
2109
2114
|
}
|
2110
2115
|
else if ((0, types_1.isFunction)(type)) {
|
2111
|
-
if (type.
|
2116
|
+
if (type.shared.name === '') {
|
2112
2117
|
return;
|
2113
2118
|
}
|
2114
2119
|
}
|
2115
2120
|
if (overloadedFunctions.length === 1) {
|
2116
2121
|
// There should never be a single overload.
|
2117
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInconsistentOverload, localize_1.LocMessage.singleOverload().format({ name }), primaryDecl.node.name);
|
2122
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInconsistentOverload, localize_1.LocMessage.singleOverload().format({ name }), primaryDecl.node.d.name);
|
2118
2123
|
}
|
2119
2124
|
// If the file is not a stub and this is the first overload,
|
2120
2125
|
// verify that there is an implementation.
|
@@ -2147,8 +2152,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2147
2152
|
// If this is a method within a protocol class, don't require that
|
2148
2153
|
// there is an implementation.
|
2149
2154
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportNoOverloadImplementation, localize_1.LocMessage.overloadWithoutImplementation().format({
|
2150
|
-
name: primaryDecl.node.name.value,
|
2151
|
-
}), primaryDecl.node.name);
|
2155
|
+
name: primaryDecl.node.d.name.d.value,
|
2156
|
+
}), primaryDecl.node.d.name);
|
2152
2157
|
return;
|
2153
2158
|
}
|
2154
2159
|
if (!(0, types_1.isOverloadedFunction)(type)) {
|
@@ -2159,13 +2164,13 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2159
2164
|
var _a, _b, _c, _d;
|
2160
2165
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
2161
2166
|
if (!this._isLegalOverloadImplementation(overload, implementationFunction, diag)) {
|
2162
|
-
if (implementationFunction.
|
2167
|
+
if (implementationFunction.shared.declaration) {
|
2163
2168
|
const diagnostic = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInconsistentOverload, localize_1.LocMessage.overloadImplementationMismatch().format({
|
2164
2169
|
name,
|
2165
2170
|
index: index + 1,
|
2166
|
-
}) + diag.getString(), implementationFunction.
|
2167
|
-
if (diagnostic && overload.
|
2168
|
-
diagnostic.addRelatedInfo(localize_1.LocAddendum.overloadSignature(), (_b = (_a = overload.
|
2171
|
+
}) + diag.getString(), implementationFunction.shared.declaration.node.d.name);
|
2172
|
+
if (diagnostic && overload.shared.declaration) {
|
2173
|
+
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
2174
|
}
|
2170
2175
|
}
|
2171
2176
|
}
|
@@ -2297,7 +2302,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2297
2302
|
types_1.ClassType.isPropertyClass(decoratedType) &&
|
2298
2303
|
(0, types_1.isClassInstance)(funcTypeInfo.decoratedType) &&
|
2299
2304
|
types_1.ClassType.isPropertyClass(funcTypeInfo.decoratedType)) {
|
2300
|
-
return funcTypeInfo.decoratedType.
|
2305
|
+
return funcTypeInfo.decoratedType.shared.typeSourceId !== decoratedType.shared.typeSourceId;
|
2301
2306
|
}
|
2302
2307
|
return !types_1.FunctionType.isOverloaded(funcTypeInfo.functionType);
|
2303
2308
|
});
|
@@ -2334,7 +2339,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2334
2339
|
if (diag) {
|
2335
2340
|
let primaryDeclNode;
|
2336
2341
|
if (primaryDecl.type === 5 /* DeclarationType.Function */ || primaryDecl.type === 6 /* DeclarationType.Class */) {
|
2337
|
-
primaryDeclNode = primaryDecl.node.name;
|
2342
|
+
primaryDeclNode = primaryDecl.node.d.name;
|
2338
2343
|
}
|
2339
2344
|
else if (primaryDecl.type === 1 /* DeclarationType.Variable */) {
|
2340
2345
|
if (primaryDecl.node.nodeType === 38 /* ParseNodeType.Name */) {
|
@@ -2343,8 +2348,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2343
2348
|
}
|
2344
2349
|
else if (primaryDecl.type === 2 /* DeclarationType.Parameter */ ||
|
2345
2350
|
primaryDecl.type === 3 /* DeclarationType.TypeParameter */) {
|
2346
|
-
if (primaryDecl.node.name) {
|
2347
|
-
primaryDeclNode = primaryDecl.node.name;
|
2351
|
+
if (primaryDecl.node.d.name) {
|
2352
|
+
primaryDeclNode = primaryDecl.node.d.name;
|
2348
2353
|
}
|
2349
2354
|
}
|
2350
2355
|
if (primaryDeclNode) {
|
@@ -2361,7 +2366,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2361
2366
|
duplicateIsOk = true;
|
2362
2367
|
}
|
2363
2368
|
if (!duplicateIsOk) {
|
2364
|
-
const diag = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportRedeclaration, localize_1.LocMessage.obscuredClassDeclaration().format({ name }), otherDecl.node.name);
|
2369
|
+
const diag = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportRedeclaration, localize_1.LocMessage.obscuredClassDeclaration().format({ name }), otherDecl.node.d.name);
|
2365
2370
|
addPrimaryDeclInfo(diag);
|
2366
2371
|
}
|
2367
2372
|
}
|
@@ -2396,12 +2401,12 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2396
2401
|
if (!duplicateIsOk) {
|
2397
2402
|
const diag = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportRedeclaration, otherDecl.isMethod
|
2398
2403
|
? localize_1.LocMessage.obscuredMethodDeclaration().format({ name })
|
2399
|
-
: localize_1.LocMessage.obscuredFunctionDeclaration().format({ name }), otherDecl.node.name);
|
2404
|
+
: localize_1.LocMessage.obscuredFunctionDeclaration().format({ name }), otherDecl.node.d.name);
|
2400
2405
|
addPrimaryDeclInfo(diag);
|
2401
2406
|
}
|
2402
2407
|
}
|
2403
2408
|
else if (otherDecl.type === 2 /* DeclarationType.Parameter */) {
|
2404
|
-
if (otherDecl.node.name) {
|
2409
|
+
if (otherDecl.node.d.name) {
|
2405
2410
|
let duplicateIsOk = false;
|
2406
2411
|
if (primaryDecl.type === 3 /* DeclarationType.TypeParameter */) {
|
2407
2412
|
// The error will be reported elsewhere if a type parameter is
|
@@ -2410,7 +2415,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2410
2415
|
}
|
2411
2416
|
if (!duplicateIsOk) {
|
2412
2417
|
const message = localize_1.LocMessage.obscuredParameterDeclaration();
|
2413
|
-
const diag = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportRedeclaration, message.format({ name }), otherDecl.node.name);
|
2418
|
+
const diag = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportRedeclaration, message.format({ name }), otherDecl.node.d.name);
|
2414
2419
|
addPrimaryDeclInfo(diag);
|
2415
2420
|
}
|
2416
2421
|
}
|
@@ -2438,7 +2443,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2438
2443
|
}
|
2439
2444
|
}
|
2440
2445
|
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);
|
2446
|
+
const diag = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportRedeclaration, localize_1.LocMessage.obscuredTypeAliasDeclaration().format({ name }), otherDecl.node.d.name);
|
2442
2447
|
addPrimaryDeclInfo(diag);
|
2443
2448
|
}
|
2444
2449
|
}
|
@@ -2477,19 +2482,19 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2477
2482
|
diagnosticLevel = this._fileInfo.diagnosticRuleSet.reportUnusedImport;
|
2478
2483
|
rule = diagnosticRules_1.DiagnosticRule.reportUnusedImport;
|
2479
2484
|
if (decl.node.nodeType === 24 /* ParseNodeType.ImportAs */) {
|
2480
|
-
if (decl.node.alias) {
|
2485
|
+
if (decl.node.d.alias) {
|
2481
2486
|
// For statements of the form "import x as x", don't mark "x" as unaccessed
|
2482
2487
|
// because it's assumed to be re-exported.
|
2483
2488
|
// See https://typing.readthedocs.io/en/latest/source/stubs.html#imports.
|
2484
|
-
if (decl.node.alias.value !== decl.moduleName) {
|
2485
|
-
nameNode = decl.node.alias;
|
2489
|
+
if (decl.node.d.alias.d.value !== decl.moduleName) {
|
2490
|
+
nameNode = decl.node.d.alias;
|
2486
2491
|
}
|
2487
2492
|
}
|
2488
2493
|
else {
|
2489
2494
|
// Handle multi-part names specially.
|
2490
|
-
const nameParts = decl.node.module.nameParts;
|
2495
|
+
const nameParts = decl.node.d.module.d.nameParts;
|
2491
2496
|
if (nameParts.length > 0) {
|
2492
|
-
const multipartName = nameParts.map((np) => np.value).join('.');
|
2497
|
+
const multipartName = nameParts.map((np) => np.d.value).join('.');
|
2493
2498
|
let textRange = { start: nameParts[0].start, length: nameParts[0].length };
|
2494
2499
|
textRange = textRange_1.TextRange.extend(textRange, nameParts[nameParts.length - 1]);
|
2495
2500
|
this._fileInfo.diagnosticSink.addUnusedCodeWithTextRange(localize_1.LocMessage.unaccessedSymbol().format({ name: multipartName }), textRange, { action: "pyright.unusedImport" /* Commands.unusedImport */ });
|
@@ -2502,16 +2507,16 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2502
2507
|
const importFrom = decl.node.parent;
|
2503
2508
|
// For statements of the form "from y import x as x", don't mark "x" as
|
2504
2509
|
// 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;
|
2510
|
+
const isReexport = ((_a = decl.node.d.alias) === null || _a === void 0 ? void 0 : _a.d.value) === decl.node.d.name.d.value;
|
2506
2511
|
// 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__';
|
2512
|
+
const isFuture = importFrom.d.module.d.nameParts.length === 1 &&
|
2513
|
+
importFrom.d.module.d.nameParts[0].d.value === '__future__';
|
2509
2514
|
if (!isReexport && !isFuture) {
|
2510
|
-
nameNode = decl.node.alias || decl.node.name;
|
2515
|
+
nameNode = decl.node.d.alias || decl.node.d.name;
|
2511
2516
|
}
|
2512
2517
|
}
|
2513
2518
|
if (nameNode) {
|
2514
|
-
message = localize_1.LocMessage.unaccessedImport().format({ name: nameNode.value });
|
2519
|
+
message = localize_1.LocMessage.unaccessedImport().format({ name: nameNode.d.value });
|
2515
2520
|
}
|
2516
2521
|
break;
|
2517
2522
|
case 4 /* DeclarationType.TypeAlias */:
|
@@ -2530,18 +2535,18 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2530
2535
|
nameNode = decl.node;
|
2531
2536
|
// Don't emit a diagnostic if the name starts with an underscore.
|
2532
2537
|
// This indicates that the variable is unused.
|
2533
|
-
if (nameNode.value.startsWith('_')) {
|
2538
|
+
if (nameNode.d.value.startsWith('_')) {
|
2534
2539
|
diagnosticLevel = 'none';
|
2535
2540
|
}
|
2536
2541
|
}
|
2537
2542
|
else if (decl.node.nodeType === 41 /* ParseNodeType.Parameter */) {
|
2538
|
-
nameNode = decl.node.name;
|
2543
|
+
nameNode = decl.node.d.name;
|
2539
2544
|
// Don't emit a diagnostic for unused parameters or type parameters.
|
2540
2545
|
diagnosticLevel = 'none';
|
2541
2546
|
}
|
2542
2547
|
if (nameNode) {
|
2543
2548
|
rule = diagnosticRules_1.DiagnosticRule.reportUnusedVariable;
|
2544
|
-
message = localize_1.LocMessage.unaccessedVariable().format({ name: nameNode.value });
|
2549
|
+
message = localize_1.LocMessage.unaccessedVariable().format({ name: nameNode.d.value });
|
2545
2550
|
}
|
2546
2551
|
break;
|
2547
2552
|
case 6 /* DeclarationType.Class */:
|
@@ -2554,9 +2559,9 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2554
2559
|
return;
|
2555
2560
|
}
|
2556
2561
|
diagnosticLevel = this._fileInfo.diagnosticRuleSet.reportUnusedClass;
|
2557
|
-
nameNode = decl.node.name;
|
2562
|
+
nameNode = decl.node.d.name;
|
2558
2563
|
rule = diagnosticRules_1.DiagnosticRule.reportUnusedClass;
|
2559
|
-
message = localize_1.LocMessage.unaccessedClass().format({ name: nameNode.value });
|
2564
|
+
message = localize_1.LocMessage.unaccessedClass().format({ name: nameNode.d.value });
|
2560
2565
|
break;
|
2561
2566
|
case 5 /* DeclarationType.Function */:
|
2562
2567
|
if (!isPrivate) {
|
@@ -2568,14 +2573,14 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2568
2573
|
return;
|
2569
2574
|
}
|
2570
2575
|
diagnosticLevel = this._fileInfo.diagnosticRuleSet.reportUnusedFunction;
|
2571
|
-
nameNode = decl.node.name;
|
2576
|
+
nameNode = decl.node.d.name;
|
2572
2577
|
rule = diagnosticRules_1.DiagnosticRule.reportUnusedFunction;
|
2573
|
-
message = localize_1.LocMessage.unaccessedFunction().format({ name: nameNode.value });
|
2578
|
+
message = localize_1.LocMessage.unaccessedFunction().format({ name: nameNode.d.value });
|
2574
2579
|
break;
|
2575
2580
|
case 3 /* DeclarationType.TypeParameter */:
|
2576
2581
|
// Never report a diagnostic for an unused TypeParameter.
|
2577
2582
|
diagnosticLevel = 'none';
|
2578
|
-
nameNode = decl.node.name;
|
2583
|
+
nameNode = decl.node.d.name;
|
2579
2584
|
break;
|
2580
2585
|
case 0 /* DeclarationType.Intrinsic */:
|
2581
2586
|
case 7 /* DeclarationType.SpecialBuiltInClass */:
|
@@ -2585,7 +2590,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2585
2590
|
}
|
2586
2591
|
const action = rule === diagnosticRules_1.DiagnosticRule.reportUnusedImport ? { action: "pyright.unusedImport" /* Commands.unusedImport */ } : undefined;
|
2587
2592
|
if (nameNode) {
|
2588
|
-
this._fileInfo.diagnosticSink.addUnusedCodeWithTextRange(localize_1.LocMessage.unaccessedSymbol().format({ name: nameNode.value }), nameNode, action);
|
2593
|
+
this._fileInfo.diagnosticSink.addUnusedCodeWithTextRange(localize_1.LocMessage.unaccessedSymbol().format({ name: nameNode.d.value }), nameNode, action);
|
2589
2594
|
if (rule !== undefined && message && diagnosticLevel !== 'none') {
|
2590
2595
|
this._evaluator.addDiagnostic(rule, message, nameNode);
|
2591
2596
|
}
|
@@ -2595,14 +2600,14 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2595
2600
|
// common source of programming errors. Also validates that arguments passed
|
2596
2601
|
// to isinstance or issubclass won't generate exceptions.
|
2597
2602
|
_validateIsInstanceCall(node) {
|
2598
|
-
if (node.
|
2599
|
-
(node.
|
2600
|
-
node.
|
2603
|
+
if (node.d.leftExpr.nodeType !== 38 /* ParseNodeType.Name */ ||
|
2604
|
+
(node.d.leftExpr.d.value !== 'isinstance' && node.d.leftExpr.d.value !== 'issubclass') ||
|
2605
|
+
node.d.args.length !== 2) {
|
2601
2606
|
return;
|
2602
2607
|
}
|
2603
|
-
const callName = node.
|
2608
|
+
const callName = node.d.leftExpr.d.value;
|
2604
2609
|
const isInstanceCheck = callName === 'isinstance';
|
2605
|
-
let arg0Type = this._evaluator.getType(node.
|
2610
|
+
let arg0Type = this._evaluator.getType(node.d.args[0].d.valueExpr);
|
2606
2611
|
if (!arg0Type) {
|
2607
2612
|
return;
|
2608
2613
|
}
|
@@ -2610,15 +2615,17 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2610
2615
|
return (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(subtype);
|
2611
2616
|
});
|
2612
2617
|
arg0Type = this._evaluator.expandPromotionTypes(node, arg0Type);
|
2613
|
-
const arg1Type = this._evaluator.getType(node.
|
2618
|
+
const arg1Type = this._evaluator.getType(node.d.args[1].d.valueExpr);
|
2614
2619
|
if (!arg1Type) {
|
2615
2620
|
return;
|
2616
2621
|
}
|
2617
2622
|
let isValidType = true;
|
2618
2623
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
2619
2624
|
(0, typeUtils_1.doForEachSubtype)(arg1Type, (arg1Subtype) => {
|
2620
|
-
if ((0, types_1.isClassInstance)(arg1Subtype) &&
|
2621
|
-
|
2625
|
+
if ((0, types_1.isClassInstance)(arg1Subtype) &&
|
2626
|
+
types_1.ClassType.isTupleClass(arg1Subtype) &&
|
2627
|
+
arg1Subtype.priv.tupleTypeArguments) {
|
2628
|
+
if (arg1Subtype.priv.tupleTypeArguments.some((typeArg) => !this._isTypeSupportedTypeForIsInstance(typeArg.type, isInstanceCheck, diag))) {
|
2622
2629
|
isValidType = false;
|
2623
2630
|
}
|
2624
2631
|
}
|
@@ -2635,7 +2642,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2635
2642
|
}) + diag.getString()
|
2636
2643
|
: localize_1.LocMessage.isSubclassInvalidType().format({
|
2637
2644
|
type: this._evaluator.printType(arg1Type),
|
2638
|
-
}) + diag.getString(), node.
|
2645
|
+
}) + diag.getString(), node.d.args[1]);
|
2639
2646
|
}
|
2640
2647
|
// If this call is an issubclass, check for the use of a "data protocol",
|
2641
2648
|
// which PEP 544 says cannot be used in issubclass.
|
@@ -2644,8 +2651,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2644
2651
|
(0, typeUtils_1.doForEachSubtype)(arg1Type, (arg1Subtype) => {
|
2645
2652
|
if ((0, types_1.isClassInstance)(arg1Subtype) &&
|
2646
2653
|
types_1.ClassType.isTupleClass(arg1Subtype) &&
|
2647
|
-
arg1Subtype.tupleTypeArguments) {
|
2648
|
-
arg1Subtype.tupleTypeArguments.forEach((typeArg) => {
|
2654
|
+
arg1Subtype.priv.tupleTypeArguments) {
|
2655
|
+
arg1Subtype.priv.tupleTypeArguments.forEach((typeArg) => {
|
2649
2656
|
this._validateNotDataProtocol(typeArg.type, diag);
|
2650
2657
|
});
|
2651
2658
|
}
|
@@ -2654,7 +2661,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2654
2661
|
}
|
2655
2662
|
});
|
2656
2663
|
if (!diag.isEmpty()) {
|
2657
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.dataProtocolInSubclassCheck(), node.
|
2664
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.dataProtocolInSubclassCheck(), node.d.args[1]);
|
2658
2665
|
}
|
2659
2666
|
}
|
2660
2667
|
// If this call is within an assert statement, we won't check whether
|
@@ -2682,33 +2689,33 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2682
2689
|
(0, typeUtils_1.doForEachSubtype)(arg1Type, (arg1Subtype) => {
|
2683
2690
|
if ((0, types_1.isClass)(arg1Subtype)) {
|
2684
2691
|
if (types_1.TypeBase.isInstantiable(arg1Subtype)) {
|
2685
|
-
if (arg1Subtype.literalValue === undefined) {
|
2692
|
+
if (arg1Subtype.priv.literalValue === undefined) {
|
2686
2693
|
classTypeList.push(arg1Subtype);
|
2687
2694
|
if (types_1.ClassType.isBuiltIn(arg1Subtype) &&
|
2688
|
-
nonstandardClassTypes.some((name) => name === arg1Subtype.
|
2695
|
+
nonstandardClassTypes.some((name) => name === arg1Subtype.shared.name)) {
|
2689
2696
|
isValidType = false;
|
2690
2697
|
}
|
2691
|
-
if (arg1Subtype.includeSubclasses) {
|
2698
|
+
if (arg1Subtype.priv.includeSubclasses) {
|
2692
2699
|
arg1IncludesSubclasses = true;
|
2693
2700
|
}
|
2694
2701
|
}
|
2695
2702
|
if (arg0Type) {
|
2696
|
-
this._validateUnsafeProtocolOverlap(node.
|
2703
|
+
this._validateUnsafeProtocolOverlap(node.d.args[0].d.valueExpr, (0, typeUtils_1.convertToInstance)(arg1Subtype), isInstanceCheck ? arg0Type : (0, typeUtils_1.convertToInstance)(arg0Type));
|
2697
2704
|
}
|
2698
2705
|
}
|
2699
2706
|
else {
|
2700
2707
|
// The isinstance and issubclass call supports a variation where the second
|
2701
2708
|
// parameter is a tuple of classes.
|
2702
2709
|
if ((0, typeUtils_1.isTupleClass)(arg1Subtype)) {
|
2703
|
-
if (arg1Subtype.tupleTypeArguments) {
|
2704
|
-
arg1Subtype.tupleTypeArguments.forEach((typeArg) => {
|
2710
|
+
if (arg1Subtype.priv.tupleTypeArguments) {
|
2711
|
+
arg1Subtype.priv.tupleTypeArguments.forEach((typeArg) => {
|
2705
2712
|
if ((0, types_1.isInstantiableClass)(typeArg.type)) {
|
2706
2713
|
classTypeList.push(typeArg.type);
|
2707
|
-
if (typeArg.type.includeSubclasses) {
|
2714
|
+
if (typeArg.type.priv.includeSubclasses) {
|
2708
2715
|
arg1IncludesSubclasses = true;
|
2709
2716
|
}
|
2710
2717
|
if (arg0Type) {
|
2711
|
-
this._validateUnsafeProtocolOverlap(node.
|
2718
|
+
this._validateUnsafeProtocolOverlap(node.d.args[0].d.valueExpr, (0, typeUtils_1.convertToInstance)(typeArg.type), isInstanceCheck ? arg0Type : (0, typeUtils_1.convertToInstance)(arg0Type));
|
2712
2719
|
}
|
2713
2720
|
}
|
2714
2721
|
else {
|
@@ -2718,12 +2725,12 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2718
2725
|
}
|
2719
2726
|
}
|
2720
2727
|
else {
|
2721
|
-
if (arg1Subtype.includeSubclasses) {
|
2728
|
+
if (arg1Subtype.priv.includeSubclasses) {
|
2722
2729
|
arg1IncludesSubclasses = true;
|
2723
2730
|
}
|
2724
2731
|
}
|
2725
2732
|
if (types_1.ClassType.isBuiltIn(arg1Subtype) &&
|
2726
|
-
nonstandardClassTypes.some((name) => name === arg1Subtype.
|
2733
|
+
nonstandardClassTypes.some((name) => name === arg1Subtype.shared.name)) {
|
2727
2734
|
isValidType = false;
|
2728
2735
|
}
|
2729
2736
|
}
|
@@ -2834,14 +2841,14 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2834
2841
|
if ((0, protocols_1.isProtocolUnsafeOverlap)(this._evaluator, protocol, testSubtype)) {
|
2835
2842
|
isUnsafeOverlap = true;
|
2836
2843
|
diag.addMessage(localize_1.LocAddendum.protocolUnsafeOverlap().format({
|
2837
|
-
name: testSubtype.
|
2844
|
+
name: testSubtype.shared.name,
|
2838
2845
|
}));
|
2839
2846
|
}
|
2840
2847
|
}
|
2841
2848
|
});
|
2842
2849
|
if (isUnsafeOverlap) {
|
2843
2850
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.protocolUnsafeOverlap().format({
|
2844
|
-
name: protocol.
|
2851
|
+
name: protocol.shared.name,
|
2845
2852
|
}) + diag.getString(), errorNode);
|
2846
2853
|
}
|
2847
2854
|
}
|
@@ -2851,9 +2858,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2851
2858
|
_isTypeSupportedTypeForIsInstance(type, isInstanceCheck, diag) {
|
2852
2859
|
let isSupported = true;
|
2853
2860
|
(0, typeUtils_1.doForEachSubtype)(type, (subtype) => {
|
2861
|
+
var _a, _b;
|
2854
2862
|
subtype = this._evaluator.makeTopLevelTypeVarsConcrete(subtype);
|
2855
2863
|
subtype = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(subtype);
|
2856
|
-
if (subtype.specialForm && types_1.ClassType.isBuiltIn(subtype.specialForm, 'TypeAliasType')) {
|
2864
|
+
if (((_a = subtype.props) === null || _a === void 0 ? void 0 : _a.specialForm) && types_1.ClassType.isBuiltIn(subtype.props.specialForm, 'TypeAliasType')) {
|
2857
2865
|
diag.addMessage(localize_1.LocAddendum.typeAliasInstanceCheck());
|
2858
2866
|
isSupported = false;
|
2859
2867
|
return;
|
@@ -2880,19 +2888,19 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2880
2888
|
diag.addMessage(localize_1.LocAddendum.typedDictClassNotAllowed());
|
2881
2889
|
isSupported = false;
|
2882
2890
|
}
|
2883
|
-
else if (subtype.isTypeArgumentExplicit && !subtype.includeSubclasses) {
|
2891
|
+
else if (subtype.priv.isTypeArgumentExplicit && !subtype.priv.includeSubclasses) {
|
2884
2892
|
// If it's a class, make sure that it has not been given explicit
|
2885
2893
|
// type arguments. This will result in a TypeError exception.
|
2886
2894
|
diag.addMessage(localize_1.LocAddendum.genericClassNotAllowed());
|
2887
2895
|
isSupported = false;
|
2888
2896
|
}
|
2889
2897
|
else if (types_1.ClassType.isIllegalIsinstanceClass(subtype)) {
|
2890
|
-
diag.addMessage(localize_1.LocAddendum.isinstanceClassNotSupported().format({ type: subtype.
|
2898
|
+
diag.addMessage(localize_1.LocAddendum.isinstanceClassNotSupported().format({ type: subtype.shared.name }));
|
2891
2899
|
isSupported = false;
|
2892
2900
|
}
|
2893
2901
|
else if (types_1.ClassType.isProtocolClass(subtype) &&
|
2894
2902
|
!types_1.ClassType.isRuntimeCheckable(subtype) &&
|
2895
|
-
!subtype.includeSubclasses) {
|
2903
|
+
!subtype.priv.includeSubclasses) {
|
2896
2904
|
// According to PEP 544, protocol classes cannot be used as the right-hand
|
2897
2905
|
// argument to isinstance or issubclass unless they are annotated as
|
2898
2906
|
// "runtime checkable".
|
@@ -2903,15 +2911,15 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2903
2911
|
diag.addMessage(localize_1.LocAddendum.newTypeClassNotAllowed());
|
2904
2912
|
isSupported = false;
|
2905
2913
|
}
|
2906
|
-
else if (subtype.specialForm &&
|
2907
|
-
(0, types_1.isInstantiableClass)(subtype.specialForm) &&
|
2908
|
-
types_1.ClassType.isBuiltIn(subtype.specialForm, 'Annotated')) {
|
2914
|
+
else if (((_b = subtype.props) === null || _b === void 0 ? void 0 : _b.specialForm) &&
|
2915
|
+
(0, types_1.isInstantiableClass)(subtype.props.specialForm) &&
|
2916
|
+
types_1.ClassType.isBuiltIn(subtype.props.specialForm, 'Annotated')) {
|
2909
2917
|
diag.addMessage(localize_1.LocAddendum.annotatedNotAllowed());
|
2910
2918
|
isSupported = false;
|
2911
2919
|
}
|
2912
2920
|
break;
|
2913
2921
|
case 4 /* TypeCategory.Function */:
|
2914
|
-
if (!types_1.TypeBase.isInstantiable(subtype) || subtype.isCallableWithTypeArgs) {
|
2922
|
+
if (!types_1.TypeBase.isInstantiable(subtype) || subtype.priv.isCallableWithTypeArgs) {
|
2915
2923
|
diag.addMessage(localize_1.LocAddendum.genericClassNotAllowed());
|
2916
2924
|
isSupported = false;
|
2917
2925
|
}
|
@@ -2927,7 +2935,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2927
2935
|
_validateNotDataProtocol(type, diag) {
|
2928
2936
|
if ((0, types_1.isInstantiableClass)(type) && types_1.ClassType.isProtocolClass(type) && !(0, protocols_1.isMethodOnlyProtocol)(type)) {
|
2929
2937
|
diag.addMessage(localize_1.LocAddendum.dataProtocolUnsupported().format({
|
2930
|
-
name: type.
|
2938
|
+
name: type.shared.name,
|
2931
2939
|
}));
|
2932
2940
|
}
|
2933
2941
|
}
|
@@ -2953,30 +2961,30 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2953
2961
|
!types_1.ClassType.isClassProperty(functionTypeResult.decoratedType)) {
|
2954
2962
|
return;
|
2955
2963
|
}
|
2956
|
-
this._reportDeprecatedDiagnostic(node.name, localize_1.LocMessage.classPropertyDeprecated());
|
2964
|
+
this._reportDeprecatedDiagnostic(node.d.name, localize_1.LocMessage.classPropertyDeprecated());
|
2957
2965
|
}
|
2958
2966
|
_reportDeprecatedUseForMemberAccess(node, info) {
|
2959
2967
|
let errorMessage;
|
2960
2968
|
if (info.accessType === 'property') {
|
2961
2969
|
if (info.accessMethod === 'get') {
|
2962
|
-
errorMessage = localize_1.LocMessage.deprecatedPropertyGetter().format({ name: node.value });
|
2970
|
+
errorMessage = localize_1.LocMessage.deprecatedPropertyGetter().format({ name: node.d.value });
|
2963
2971
|
}
|
2964
2972
|
else if (info.accessMethod === 'set') {
|
2965
|
-
errorMessage = localize_1.LocMessage.deprecatedPropertySetter().format({ name: node.value });
|
2973
|
+
errorMessage = localize_1.LocMessage.deprecatedPropertySetter().format({ name: node.d.value });
|
2966
2974
|
}
|
2967
2975
|
else {
|
2968
|
-
errorMessage = localize_1.LocMessage.deprecatedPropertyDeleter().format({ name: node.value });
|
2976
|
+
errorMessage = localize_1.LocMessage.deprecatedPropertyDeleter().format({ name: node.d.value });
|
2969
2977
|
}
|
2970
2978
|
}
|
2971
2979
|
else if (info.accessType === 'descriptor') {
|
2972
2980
|
if (info.accessMethod === 'get') {
|
2973
|
-
errorMessage = localize_1.LocMessage.deprecatedDescriptorGetter().format({ name: node.value });
|
2981
|
+
errorMessage = localize_1.LocMessage.deprecatedDescriptorGetter().format({ name: node.d.value });
|
2974
2982
|
}
|
2975
2983
|
else if (info.accessMethod === 'set') {
|
2976
|
-
errorMessage = localize_1.LocMessage.deprecatedDescriptorSetter().format({ name: node.value });
|
2984
|
+
errorMessage = localize_1.LocMessage.deprecatedDescriptorSetter().format({ name: node.d.value });
|
2977
2985
|
}
|
2978
2986
|
else {
|
2979
|
-
errorMessage = localize_1.LocMessage.deprecatedDescriptorDeleter().format({ name: node.value });
|
2987
|
+
errorMessage = localize_1.LocMessage.deprecatedDescriptorDeleter().format({ name: node.d.value });
|
2980
2988
|
}
|
2981
2989
|
}
|
2982
2990
|
if (errorMessage) {
|
@@ -2984,26 +2992,26 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2984
2992
|
}
|
2985
2993
|
}
|
2986
2994
|
_reportDeprecatedUseForType(node, type, isImportFromTyping = false) {
|
2987
|
-
var _a, _b;
|
2995
|
+
var _a, _b, _c;
|
2988
2996
|
if (!type) {
|
2989
2997
|
return;
|
2990
2998
|
}
|
2991
2999
|
let errorMessage;
|
2992
3000
|
let deprecatedMessage;
|
2993
3001
|
function getDeprecatedMessageForFunction(functionType) {
|
2994
|
-
if (functionType.
|
2995
|
-
functionType.
|
2996
|
-
const containingClass = ParseTreeUtils.getEnclosingClass(functionType.
|
3002
|
+
if (functionType.shared.declaration &&
|
3003
|
+
functionType.shared.declaration.node.nodeType === 31 /* ParseNodeType.Function */) {
|
3004
|
+
const containingClass = ParseTreeUtils.getEnclosingClass(functionType.shared.declaration.node,
|
2997
3005
|
/* stopAtFunction */ true);
|
2998
3006
|
if (containingClass) {
|
2999
3007
|
return localize_1.LocMessage.deprecatedMethod().format({
|
3000
|
-
name: functionType.
|
3001
|
-
className: containingClass.name.value,
|
3008
|
+
name: functionType.shared.name || '<anonymous>',
|
3009
|
+
className: containingClass.d.name.d.value,
|
3002
3010
|
});
|
3003
3011
|
}
|
3004
3012
|
}
|
3005
3013
|
return localize_1.LocMessage.deprecatedFunction().format({
|
3006
|
-
name: functionType.
|
3014
|
+
name: functionType.shared.name,
|
3007
3015
|
});
|
3008
3016
|
}
|
3009
3017
|
function getDeprecatedMessageForOverloadedCall(evaluator, type) {
|
@@ -3026,21 +3034,21 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3026
3034
|
callTypeResult.overloadsUsedForCall &&
|
3027
3035
|
callTypeResult.overloadsUsedForCall.length > 0) {
|
3028
3036
|
callTypeResult.overloadsUsedForCall.forEach((overload) => {
|
3029
|
-
if (overload.
|
3030
|
-
if (node.value === overload.
|
3031
|
-
deprecatedMessage = overload.
|
3037
|
+
if (overload.shared.deprecatedMessage !== undefined) {
|
3038
|
+
if (node.d.value === overload.shared.name) {
|
3039
|
+
deprecatedMessage = overload.shared.deprecatedMessage;
|
3032
3040
|
errorMessage = getDeprecatedMessageForFunction(overload);
|
3033
3041
|
}
|
3034
|
-
else if ((0, types_1.isInstantiableClass)(type) && overload.
|
3035
|
-
deprecatedMessage = overload.
|
3042
|
+
else if ((0, types_1.isInstantiableClass)(type) && overload.shared.name === '__init__') {
|
3043
|
+
deprecatedMessage = overload.shared.deprecatedMessage;
|
3036
3044
|
errorMessage = localize_1.LocMessage.deprecatedConstructor().format({
|
3037
|
-
name: type.
|
3045
|
+
name: type.shared.name,
|
3038
3046
|
});
|
3039
3047
|
}
|
3040
|
-
else if ((0, types_1.isClassInstance)(type) && overload.
|
3041
|
-
deprecatedMessage = overload.
|
3048
|
+
else if ((0, types_1.isClassInstance)(type) && overload.shared.name === '__call__') {
|
3049
|
+
deprecatedMessage = overload.shared.deprecatedMessage;
|
3042
3050
|
errorMessage = localize_1.LocMessage.deprecatedFunction().format({
|
3043
|
-
name: node.value,
|
3051
|
+
name: node.d.value,
|
3044
3052
|
});
|
3045
3053
|
}
|
3046
3054
|
}
|
@@ -3049,22 +3057,22 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3049
3057
|
}
|
3050
3058
|
(0, typeUtils_1.doForEachSubtype)(type, (subtype) => {
|
3051
3059
|
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.
|
3060
|
+
if (!subtype.priv.includeSubclasses &&
|
3061
|
+
subtype.shared.deprecatedMessage !== undefined &&
|
3062
|
+
node.d.value === subtype.shared.name) {
|
3063
|
+
deprecatedMessage = subtype.shared.deprecatedMessage;
|
3064
|
+
errorMessage = localize_1.LocMessage.deprecatedClass().format({ name: subtype.shared.name });
|
3057
3065
|
return;
|
3058
3066
|
}
|
3059
3067
|
getDeprecatedMessageForOverloadedCall(this._evaluator, subtype);
|
3060
3068
|
return;
|
3061
3069
|
}
|
3062
3070
|
if ((0, types_1.isFunction)(subtype)) {
|
3063
|
-
if (subtype.
|
3064
|
-
if (!subtype.
|
3065
|
-
subtype.
|
3066
|
-
node.value === subtype.
|
3067
|
-
deprecatedMessage = subtype.
|
3071
|
+
if (subtype.shared.deprecatedMessage !== undefined) {
|
3072
|
+
if (!subtype.shared.name ||
|
3073
|
+
subtype.shared.name === '__call__' ||
|
3074
|
+
node.d.value === subtype.shared.name) {
|
3075
|
+
deprecatedMessage = subtype.shared.deprecatedMessage;
|
3068
3076
|
errorMessage = getDeprecatedMessageForFunction(subtype);
|
3069
3077
|
}
|
3070
3078
|
}
|
@@ -3078,9 +3086,9 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3078
3086
|
// If there the implementation itself is deprecated, assume it
|
3079
3087
|
// is deprecated even if it's outside of a call expression.
|
3080
3088
|
const overloadImpl = types_1.OverloadedFunctionType.getImplementation(subtype);
|
3081
|
-
if ((overloadImpl === null || overloadImpl === void 0 ? void 0 : overloadImpl.
|
3082
|
-
if (!overloadImpl.
|
3083
|
-
deprecatedMessage = overloadImpl.
|
3089
|
+
if ((overloadImpl === null || overloadImpl === void 0 ? void 0 : overloadImpl.shared.deprecatedMessage) !== undefined) {
|
3090
|
+
if (!overloadImpl.shared.name || node.d.value === overloadImpl.shared.name) {
|
3091
|
+
deprecatedMessage = overloadImpl.shared.deprecatedMessage;
|
3084
3092
|
errorMessage = getDeprecatedMessageForFunction(overloadImpl);
|
3085
3093
|
}
|
3086
3094
|
}
|
@@ -3090,10 +3098,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3090
3098
|
this._reportDeprecatedDiagnostic(node, errorMessage, deprecatedMessage);
|
3091
3099
|
}
|
3092
3100
|
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);
|
3101
|
+
const deprecatedForm = (_a = deprecatedSymbols_1.deprecatedAliases.get(node.d.value)) !== null && _a !== void 0 ? _a : deprecatedSymbols_1.deprecatedSpecialForms.get(node.d.value);
|
3094
3102
|
if (deprecatedForm) {
|
3095
|
-
if (((0, types_1.isInstantiableClass)(type) && type.
|
3096
|
-
((_b = type.
|
3103
|
+
if (((0, types_1.isInstantiableClass)(type) && type.shared.fullName === deprecatedForm.fullName) ||
|
3104
|
+
((_c = (_b = type.props) === null || _b === void 0 ? void 0 : _b.typeAliasInfo) === null || _c === void 0 ? void 0 : _c.fullName) === deprecatedForm.fullName) {
|
3097
3105
|
if (this._fileInfo.executionEnvironment.pythonVersion.isGreaterOrEqualTo(deprecatedForm.version)) {
|
3098
3106
|
if (!deprecatedForm.typingImportOnly || isImportFromTyping) {
|
3099
3107
|
if (this._fileInfo.diagnosticRuleSet.reportDeprecated === 'none') {
|
@@ -3135,11 +3143,11 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3135
3143
|
if (type) {
|
3136
3144
|
if ((0, types_1.isUnbound)(type)) {
|
3137
3145
|
if (this._evaluator.isNodeReachable(node)) {
|
3138
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnboundVariable, localize_1.LocMessage.symbolIsUnbound().format({ name: node.value }), node);
|
3146
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnboundVariable, localize_1.LocMessage.symbolIsUnbound().format({ name: node.d.value }), node);
|
3139
3147
|
}
|
3140
3148
|
}
|
3141
3149
|
else if ((0, types_1.isPossiblyUnbound)(type)) {
|
3142
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportPossiblyUnboundVariable, localize_1.LocMessage.symbolIsPossiblyUnbound().format({ name: node.value }), node);
|
3150
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportPossiblyUnboundVariable, localize_1.LocMessage.symbolIsPossiblyUnbound().format({ name: node.d.value }), node);
|
3143
3151
|
}
|
3144
3152
|
}
|
3145
3153
|
}
|
@@ -3183,19 +3191,19 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3183
3191
|
// Skip this check for relative imports.
|
3184
3192
|
const nodeModule = node.nodeType === 26 /* ParseNodeType.ImportFromAs */
|
3185
3193
|
? ((_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
|
3194
|
+
? (_b = node.parent) === null || _b === void 0 ? void 0 : _b.d.module
|
3187
3195
|
: undefined
|
3188
|
-
: node.module;
|
3189
|
-
if (nodeModule === null || nodeModule === void 0 ? void 0 : nodeModule.leadingDots) {
|
3196
|
+
: node.d.module;
|
3197
|
+
if (nodeModule === null || nodeModule === void 0 ? void 0 : nodeModule.d.leadingDots) {
|
3190
3198
|
return;
|
3191
3199
|
}
|
3192
3200
|
// Otherwise use the name to determine if a match for a stdlib module.
|
3193
3201
|
const namePartNodes = node.nodeType === 24 /* ParseNodeType.ImportAs */
|
3194
|
-
? node.module.nameParts
|
3202
|
+
? node.d.module.d.nameParts
|
3195
3203
|
: node.nodeType === 26 /* ParseNodeType.ImportFromAs */
|
3196
|
-
? [node.name]
|
3197
|
-
: node.module.nameParts;
|
3198
|
-
const nameParts = namePartNodes.map((n) => n.value);
|
3204
|
+
? [node.d.name]
|
3205
|
+
: node.d.module.d.nameParts;
|
3206
|
+
const nameParts = namePartNodes.map((n) => n.d.value);
|
3199
3207
|
const module = {
|
3200
3208
|
nameParts,
|
3201
3209
|
leadingDots: 0,
|
@@ -3238,10 +3246,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3238
3246
|
return;
|
3239
3247
|
}
|
3240
3248
|
// 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) {
|
3249
|
+
if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 1 /* ParseNodeType.Argument */ && node.parent.d.name === node) {
|
3242
3250
|
return;
|
3243
3251
|
}
|
3244
|
-
const nameValue = node.value;
|
3252
|
+
const nameValue = node.d.value;
|
3245
3253
|
const isPrivateName = SymbolNameUtils.isPrivateName(nameValue);
|
3246
3254
|
const isProtectedName = SymbolNameUtils.isProtectedName(nameValue);
|
3247
3255
|
// If it's not a protected or private name, don't bother with
|
@@ -3329,9 +3337,9 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3329
3337
|
// Validates that an enum class does not attempt to override another
|
3330
3338
|
// enum class that has already defined values.
|
3331
3339
|
_validateEnumClassOverride(node, classType) {
|
3332
|
-
classType.
|
3340
|
+
classType.shared.baseClasses.forEach((baseClass, index) => {
|
3333
3341
|
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.
|
3342
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.enumClassOverride().format({ name: baseClass.shared.name }), node.d.arguments[index]);
|
3335
3343
|
}
|
3336
3344
|
});
|
3337
3345
|
}
|
@@ -3342,10 +3350,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3342
3350
|
const emitBadStatementError = (node) => {
|
3343
3351
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typedDictBadVar(), node);
|
3344
3352
|
};
|
3345
|
-
suiteNode.statements.forEach((statement) => {
|
3353
|
+
suiteNode.d.statements.forEach((statement) => {
|
3346
3354
|
if (!AnalyzerNodeInfo.isCodeUnreachable(statement)) {
|
3347
3355
|
if (statement.nodeType === 47 /* ParseNodeType.StatementList */) {
|
3348
|
-
for (const substatement of statement.statements) {
|
3356
|
+
for (const substatement of statement.d.statements) {
|
3349
3357
|
if (substatement.nodeType !== 54 /* ParseNodeType.TypeAnnotation */ &&
|
3350
3358
|
substatement.nodeType !== 21 /* ParseNodeType.Ellipsis */ &&
|
3351
3359
|
substatement.nodeType !== 48 /* ParseNodeType.StringList */ &&
|
@@ -3362,11 +3370,13 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3362
3370
|
}
|
3363
3371
|
_validateTypeGuardFunction(node, functionType, isMethod) {
|
3364
3372
|
var _a;
|
3365
|
-
const returnType = functionType.
|
3373
|
+
const returnType = functionType.shared.declaredReturnType;
|
3366
3374
|
if (!returnType) {
|
3367
3375
|
return;
|
3368
3376
|
}
|
3369
|
-
if (!(0, types_1.isClassInstance)(returnType) ||
|
3377
|
+
if (!(0, types_1.isClassInstance)(returnType) ||
|
3378
|
+
!returnType.priv.typeArguments ||
|
3379
|
+
returnType.priv.typeArguments.length < 1) {
|
3370
3380
|
return;
|
3371
3381
|
}
|
3372
3382
|
const isTypeGuard = types_1.ClassType.isBuiltIn(returnType, 'TypeGuard');
|
@@ -3375,7 +3385,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3375
3385
|
return;
|
3376
3386
|
}
|
3377
3387
|
// Make sure there's at least one input parameter provided.
|
3378
|
-
let paramCount = functionType.
|
3388
|
+
let paramCount = functionType.shared.parameters.length;
|
3379
3389
|
if (isMethod) {
|
3380
3390
|
if (types_1.FunctionType.isInstanceMethod(functionType) ||
|
3381
3391
|
types_1.FunctionType.isConstructorMethod(functionType) ||
|
@@ -3384,19 +3394,19 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3384
3394
|
}
|
3385
3395
|
}
|
3386
3396
|
if (paramCount < 1) {
|
3387
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeGuardParamCount(), node.name);
|
3397
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeGuardParamCount(), node.d.name);
|
3388
3398
|
}
|
3389
3399
|
if (isTypeIs) {
|
3390
|
-
const typeGuardType = returnType.typeArguments[0];
|
3400
|
+
const typeGuardType = returnType.priv.typeArguments[0];
|
3391
3401
|
// Determine the type of the first parameter.
|
3392
3402
|
const paramIndex = isMethod && !types_1.FunctionType.isStaticMethod(functionType) ? 1 : 0;
|
3393
|
-
if (paramIndex >= functionType.
|
3403
|
+
if (paramIndex >= functionType.shared.parameters.length) {
|
3394
3404
|
return;
|
3395
3405
|
}
|
3396
3406
|
const paramType = types_1.FunctionType.getEffectiveParameterType(functionType, paramIndex);
|
3397
3407
|
// Verify that the typeGuardType is a narrower type than the paramType.
|
3398
3408
|
if (!this._evaluator.assignType(paramType, typeGuardType)) {
|
3399
|
-
const returnAnnotation = node.
|
3409
|
+
const returnAnnotation = node.d.returnAnnotation || ((_a = node.d.funcAnnotationComment) === null || _a === void 0 ? void 0 : _a.d.returnAnnotation);
|
3400
3410
|
if (returnAnnotation) {
|
3401
3411
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeIsReturnType().format({
|
3402
3412
|
type: this._evaluator.printType(paramType),
|
@@ -3408,11 +3418,11 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3408
3418
|
}
|
3409
3419
|
_validateDunderSignatures(node, functionType, isMethod) {
|
3410
3420
|
var _a;
|
3411
|
-
const functionName = functionType.
|
3421
|
+
const functionName = functionType.shared.name;
|
3412
3422
|
// Is this an '__init__' method? Verify that it returns None.
|
3413
3423
|
if (isMethod && functionName === '__init__') {
|
3414
|
-
const returnAnnotation = node.
|
3415
|
-
const declaredReturnType = functionType.
|
3424
|
+
const returnAnnotation = node.d.returnAnnotation || ((_a = node.d.funcAnnotationComment) === null || _a === void 0 ? void 0 : _a.d.returnAnnotation);
|
3425
|
+
const declaredReturnType = functionType.shared.declaredReturnType;
|
3416
3426
|
if (returnAnnotation && declaredReturnType) {
|
3417
3427
|
if (!(0, typeUtils_1.isNoneInstance)(declaredReturnType) && !(0, types_1.isNever)(declaredReturnType)) {
|
3418
3428
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.initMustReturnNone(), returnAnnotation);
|
@@ -3423,7 +3433,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3423
3433
|
if (!(0, types_1.isNever)(inferredReturnType) &&
|
3424
3434
|
!(0, typeUtils_1.isNoneInstance)(inferredReturnType) &&
|
3425
3435
|
!(0, types_1.isAnyOrUnknown)(inferredReturnType)) {
|
3426
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.initMustReturnNone(), node.name);
|
3436
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.initMustReturnNone(), node.d.name);
|
3427
3437
|
}
|
3428
3438
|
}
|
3429
3439
|
}
|
@@ -3435,11 +3445,11 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3435
3445
|
if (this._fileInfo.isStubFile) {
|
3436
3446
|
return;
|
3437
3447
|
}
|
3438
|
-
const returnAnnotation = node.
|
3448
|
+
const returnAnnotation = node.d.returnAnnotation || ((_a = node.d.funcAnnotationComment) === null || _a === void 0 ? void 0 : _a.d.returnAnnotation);
|
3439
3449
|
if (returnAnnotation) {
|
3440
3450
|
const functionNeverReturns = !this._evaluator.isAfterNodeReachable(node);
|
3441
|
-
const implicitlyReturnsNone = this._evaluator.isAfterNodeReachable(node.suite);
|
3442
|
-
let declaredReturnType = functionType.
|
3451
|
+
const implicitlyReturnsNone = this._evaluator.isAfterNodeReachable(node.d.suite);
|
3452
|
+
let declaredReturnType = functionType.shared.declaredReturnType;
|
3443
3453
|
if (declaredReturnType) {
|
3444
3454
|
this._reportUnknownReturnResult(node, declaredReturnType);
|
3445
3455
|
this._validateReturnTypeIsNotContravariant(declaredReturnType, returnAnnotation);
|
@@ -3456,7 +3466,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3456
3466
|
// If the function consists entirely of "...", assume that it's
|
3457
3467
|
// an abstract method or a protocol method and don't require that
|
3458
3468
|
// the return type matches. This check can also be skipped for an overload.
|
3459
|
-
if (!ParseTreeUtils.isSuiteEmpty(node.suite) &&
|
3469
|
+
if (!ParseTreeUtils.isSuiteEmpty(node.d.suite) &&
|
3460
3470
|
!types_1.FunctionType.isOverloaded(functionType) &&
|
3461
3471
|
!types_1.FunctionType.isAsync(functionType)) {
|
3462
3472
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportReturnType, localize_1.LocMessage.noReturnReturnsNone(), returnAnnotation);
|
@@ -3471,7 +3481,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3471
3481
|
// If the function consists entirely of "...", assume that it's
|
3472
3482
|
// an abstract method or a protocol method and don't require that
|
3473
3483
|
// the return type matches. This check can also be skipped for an overload.
|
3474
|
-
if (!ParseTreeUtils.isSuiteEmpty(node.suite) && !types_1.FunctionType.isOverloaded(functionType)) {
|
3484
|
+
if (!ParseTreeUtils.isSuiteEmpty(node.d.suite) && !types_1.FunctionType.isOverloaded(functionType)) {
|
3475
3485
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportReturnType, localize_1.LocMessage.returnMissing().format({
|
3476
3486
|
returnType: this._evaluator.printType(declaredReturnType),
|
3477
3487
|
}) + diagAddendum.getString(), returnAnnotation);
|
@@ -3483,15 +3493,15 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3483
3493
|
else {
|
3484
3494
|
const inferredReturnType = this._evaluator.getFunctionInferredReturnType(functionType);
|
3485
3495
|
this._reportUnknownReturnResult(node, inferredReturnType);
|
3486
|
-
this._validateReturnTypeIsNotContravariant(inferredReturnType, node.name);
|
3496
|
+
this._validateReturnTypeIsNotContravariant(inferredReturnType, node.d.name);
|
3487
3497
|
}
|
3488
3498
|
}
|
3489
3499
|
_validateReturnTypeIsNotContravariant(returnType, errorNode) {
|
3490
3500
|
let isContraTypeVar = false;
|
3491
3501
|
(0, typeUtils_1.doForEachSubtype)(returnType, (subtype) => {
|
3492
3502
|
if ((0, types_1.isTypeVar)(subtype) &&
|
3493
|
-
subtype.
|
3494
|
-
subtype.scopeType === 0 /* TypeVarScopeType.Class */) {
|
3503
|
+
subtype.shared.declaredVariance === 4 /* Variance.Contravariant */ &&
|
3504
|
+
subtype.priv.scopeType === 0 /* TypeVarScopeType.Class */) {
|
3495
3505
|
isContraTypeVar = true;
|
3496
3506
|
}
|
3497
3507
|
});
|
@@ -3501,12 +3511,12 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3501
3511
|
}
|
3502
3512
|
_reportUnknownReturnResult(node, returnType) {
|
3503
3513
|
if ((0, types_1.isUnknown)(returnType)) {
|
3504
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnknownParameterType, localize_1.LocMessage.returnTypeUnknown(), node.name);
|
3514
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnknownParameterType, localize_1.LocMessage.returnTypeUnknown(), node.d.name);
|
3505
3515
|
}
|
3506
3516
|
else if ((0, typeUtils_1.isPartlyUnknown)(returnType)) {
|
3507
3517
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnknownParameterType, localize_1.LocMessage.returnTypePartiallyUnknown().format({
|
3508
3518
|
returnType: this._evaluator.printType(returnType, { expandTypeAlias: true }),
|
3509
|
-
}), node.name);
|
3519
|
+
}), node.d.name);
|
3510
3520
|
}
|
3511
3521
|
}
|
3512
3522
|
// Validates that any overridden member variables are not marked
|
@@ -3520,7 +3530,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3520
3530
|
const decl = localSymbol.getDeclarations()[0];
|
3521
3531
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.finalRedeclarationBySubclass().format({
|
3522
3532
|
name,
|
3523
|
-
className: parentSymbol.classType.
|
3533
|
+
className: parentSymbol.classType.shared.name,
|
3524
3534
|
}), decl.node);
|
3525
3535
|
}
|
3526
3536
|
else if (types_1.ClassType.isReadOnlyInstanceVariables(parentSymbol.classType) &&
|
@@ -3531,7 +3541,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3531
3541
|
if (decl.type === 1 /* DeclarationType.Variable */) {
|
3532
3542
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompatibleVariableOverride, localize_1.LocMessage.namedTupleEntryRedeclared().format({
|
3533
3543
|
name,
|
3534
|
-
className: parentSymbol.classType.
|
3544
|
+
className: parentSymbol.classType.shared.name,
|
3535
3545
|
}), decl.node);
|
3536
3546
|
}
|
3537
3547
|
}
|
@@ -3548,7 +3558,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3548
3558
|
const declaredValueType = (0, enums_1.getEnumDeclaredValueType)(this._evaluator, classType, /* declaredTypesOnly */ true);
|
3549
3559
|
// Is there a custom "__new__" and/or "__init__" method? If so, we'll
|
3550
3560
|
// verify that the signature of these calls is compatible with the values.
|
3551
|
-
let newMemberTypeResult = (0, constructors_1.getBoundNewMethod)(this._evaluator, node.name, classType,
|
3561
|
+
let newMemberTypeResult = (0, constructors_1.getBoundNewMethod)(this._evaluator, node.d.name, classType,
|
3552
3562
|
/* diag */ undefined, 4 /* MemberAccessFlags.SkipObjectBaseClass */);
|
3553
3563
|
// If this __new__ comes from a built-in class like Enum, we'll ignore it.
|
3554
3564
|
if (newMemberTypeResult === null || newMemberTypeResult === void 0 ? void 0 : newMemberTypeResult.classType) {
|
@@ -3556,7 +3566,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3556
3566
|
newMemberTypeResult = undefined;
|
3557
3567
|
}
|
3558
3568
|
}
|
3559
|
-
let initMemberTypeResult = (0, constructors_1.getBoundInitMethod)(this._evaluator, node.name, types_1.ClassType.cloneAsInstance(classType),
|
3569
|
+
let initMemberTypeResult = (0, constructors_1.getBoundInitMethod)(this._evaluator, node.d.name, types_1.ClassType.cloneAsInstance(classType),
|
3560
3570
|
/* diag */ undefined, 4 /* MemberAccessFlags.SkipObjectBaseClass */);
|
3561
3571
|
// If this __init__ comes from a built-in class like Enum, we'll ignore it.
|
3562
3572
|
if (initMemberTypeResult === null || initMemberTypeResult === void 0 ? void 0 : initMemberTypeResult.classType) {
|
@@ -3577,7 +3587,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3577
3587
|
if (!symbolType ||
|
3578
3588
|
!(0, types_1.isClassInstance)(symbolType) ||
|
3579
3589
|
!types_1.ClassType.isSameGenericClass(symbolType, classType) ||
|
3580
|
-
!(symbolType.literalValue instanceof types_1.EnumLiteral)) {
|
3590
|
+
!(symbolType.priv.literalValue instanceof types_1.EnumLiteral)) {
|
3581
3591
|
return;
|
3582
3592
|
}
|
3583
3593
|
// Enum members should not have type annotations.
|
@@ -3598,9 +3608,9 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3598
3608
|
return;
|
3599
3609
|
}
|
3600
3610
|
const declNode = decls[0].node;
|
3601
|
-
const assignedValueType = symbolType.literalValue.itemType;
|
3611
|
+
const assignedValueType = symbolType.priv.literalValue.itemType;
|
3602
3612
|
const assignmentNode = ParseTreeUtils.getParentNodeOfType(declNode, 3 /* ParseNodeType.Assignment */);
|
3603
|
-
const errorNode = (_a = assignmentNode === null || assignmentNode === void 0 ? void 0 : assignmentNode.
|
3613
|
+
const errorNode = (_a = assignmentNode === null || assignmentNode === void 0 ? void 0 : assignmentNode.d.rightExpr) !== null && _a !== void 0 ? _a : declNode;
|
3604
3614
|
// Validate the __new__ and __init__ methods if present.
|
3605
3615
|
if (newMemberTypeResult || initMemberTypeResult) {
|
3606
3616
|
if (!(0, types_1.isAnyOrUnknown)(assignedValueType)) {
|
@@ -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,8 +4042,8 @@ 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,
|
@@ -4040,11 +4053,11 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4040
4053
|
/* destTypeVarContext */ undefined,
|
4041
4054
|
/* srcTypeVarContext */ undefined, 64 /* AssignTypeFlags.SkipFunctionReturnTypeCheck */)) {
|
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
|
}
|
@@ -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();
|
@@ -4351,9 +4364,9 @@ 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
|
}
|
@@ -4366,13 +4379,13 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
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;
|
@@ -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;
|
@@ -4911,9 +4924,9 @@ 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
|
}
|
@@ -4926,13 +4939,13 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
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,7 +5186,7 @@ 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);
|
@@ -5183,7 +5198,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5183
5198
|
return;
|
5184
5199
|
}
|
5185
5200
|
let generatorType;
|
5186
|
-
if (!enclosingFunctionNode.isAsync &&
|
5201
|
+
if (!enclosingFunctionNode.d.isAsync &&
|
5187
5202
|
(0, types_1.isClassInstance)(declaredReturnType) &&
|
5188
5203
|
types_1.ClassType.isBuiltIn(declaredReturnType, 'AwaitableGenerator')) {
|
5189
5204
|
// Handle the old-style (pre-await) generator case
|
@@ -5191,7 +5206,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5191
5206
|
generatorType = this._evaluator.getTypingType(node, 'AwaitableGenerator');
|
5192
5207
|
}
|
5193
5208
|
else {
|
5194
|
-
generatorType = this._evaluator.getTypingType(node, enclosingFunctionNode.isAsync ? 'AsyncGenerator' : 'Generator');
|
5209
|
+
generatorType = this._evaluator.getTypingType(node, enclosingFunctionNode.d.isAsync ? 'AsyncGenerator' : 'Generator');
|
5195
5210
|
}
|
5196
5211
|
if (!generatorType || !(0, types_1.isInstantiableClass)(generatorType)) {
|
5197
5212
|
return;
|
@@ -5207,11 +5222,11 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5207
5222
|
const specializedGenerator = types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneForSpecialization(generatorType, generatorTypeArgs, /* isTypeArgumentExplicit */ true));
|
5208
5223
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
5209
5224
|
if (!this._evaluator.assignType(declaredReturnType, specializedGenerator, diagAddendum)) {
|
5210
|
-
const errorMessage = enclosingFunctionNode.isAsync
|
5225
|
+
const errorMessage = enclosingFunctionNode.d.isAsync
|
5211
5226
|
? localize_1.LocMessage.generatorAsyncReturnType()
|
5212
5227
|
: localize_1.LocMessage.generatorSyncReturnType();
|
5213
5228
|
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.
|
5229
|
+
((_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
5230
|
}
|
5216
5231
|
}
|
5217
5232
|
// Determines whether any of the except statements are unreachable because
|
@@ -5219,12 +5234,12 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5219
5234
|
_reportUnusedExceptStatements(node) {
|
5220
5235
|
let sawUnknownExceptionType = false;
|
5221
5236
|
const exceptionTypesSoFar = [];
|
5222
|
-
node.exceptClauses.forEach((except) => {
|
5237
|
+
node.d.exceptClauses.forEach((except) => {
|
5223
5238
|
var _a, _b;
|
5224
|
-
if (sawUnknownExceptionType || except.isExceptGroup || !except.
|
5239
|
+
if (sawUnknownExceptionType || except.d.isExceptGroup || !except.d.typeExpr) {
|
5225
5240
|
return;
|
5226
5241
|
}
|
5227
|
-
const exceptionType = this._evaluator.getType(except.
|
5242
|
+
const exceptionType = this._evaluator.getType(except.d.typeExpr);
|
5228
5243
|
if (!exceptionType || (0, types_1.isAnyOrUnknown)(exceptionType)) {
|
5229
5244
|
sawUnknownExceptionType = true;
|
5230
5245
|
return;
|
@@ -5233,7 +5248,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5233
5248
|
if ((0, types_1.isInstantiableClass)(exceptionType)) {
|
5234
5249
|
// If the exception type is a variable whose type could represent
|
5235
5250
|
// subclasses, the actual exception type is statically unknown.
|
5236
|
-
if (exceptionType.includeSubclasses) {
|
5251
|
+
if (exceptionType.priv.includeSubclasses) {
|
5237
5252
|
sawUnknownExceptionType = true;
|
5238
5253
|
}
|
5239
5254
|
typesOfThisExcept.push(exceptionType);
|
@@ -5241,7 +5256,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5241
5256
|
else if ((0, types_1.isClassInstance)(exceptionType)) {
|
5242
5257
|
const iterableType = (_b = (_a = this._evaluator.getTypeOfIterator({ type: exceptionType },
|
5243
5258
|
/* isAsync */ false,
|
5244
|
-
/* errorNode */ except.
|
5259
|
+
/* errorNode */ except.d.typeExpr,
|
5245
5260
|
/* emitNotIterableError */ false)) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : types_1.UnknownType.create();
|
5246
5261
|
(0, typeUtils_1.doForEachSubtype)(iterableType, (subtype) => {
|
5247
5262
|
if ((0, types_1.isAnyOrUnknown)(subtype)) {
|
@@ -5250,7 +5265,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5250
5265
|
if ((0, types_1.isInstantiableClass)(subtype)) {
|
5251
5266
|
// If the exception type is a variable whose type could represent
|
5252
5267
|
// subclasses, the actual exception type is statically unknown.
|
5253
|
-
if (subtype.includeSubclasses) {
|
5268
|
+
if (subtype.priv.includeSubclasses) {
|
5254
5269
|
sawUnknownExceptionType = true;
|
5255
5270
|
}
|
5256
5271
|
typesOfThisExcept.push(subtype);
|
@@ -5277,8 +5292,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5277
5292
|
});
|
5278
5293
|
// Were all of the exception types overridden?
|
5279
5294
|
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);
|
5295
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnusedExcept, localize_1.LocMessage.unreachableExcept() + diagAddendum.getString(), except.d.typeExpr);
|
5296
|
+
this._evaluator.addUnreachableCode(except, except.d.exceptSuite);
|
5282
5297
|
}
|
5283
5298
|
}
|
5284
5299
|
(0, collectionUtils_1.appendArray)(exceptionTypesSoFar, typesOfThisExcept);
|
@@ -5290,22 +5305,22 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5290
5305
|
importStatements.orderedImports.forEach((importStatement) => {
|
5291
5306
|
if (importStatement.node.nodeType === 25 /* ParseNodeType.ImportFrom */) {
|
5292
5307
|
const symbolMap = new Map();
|
5293
|
-
importStatement.node.imports.forEach((importFromAs) => {
|
5308
|
+
importStatement.node.d.imports.forEach((importFromAs) => {
|
5294
5309
|
// Ignore duplicates if they're aliased.
|
5295
|
-
if (!importFromAs.alias) {
|
5296
|
-
const prevImport = symbolMap.get(importFromAs.name.value);
|
5310
|
+
if (!importFromAs.d.alias) {
|
5311
|
+
const prevImport = symbolMap.get(importFromAs.d.name.d.value);
|
5297
5312
|
if (prevImport) {
|
5298
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportDuplicateImport, localize_1.LocMessage.duplicateImport().format({ importName: importFromAs.name.value }), importFromAs.name);
|
5313
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportDuplicateImport, localize_1.LocMessage.duplicateImport().format({ importName: importFromAs.d.name.d.value }), importFromAs.d.name);
|
5299
5314
|
}
|
5300
5315
|
else {
|
5301
|
-
symbolMap.set(importFromAs.name.value, importFromAs);
|
5316
|
+
symbolMap.set(importFromAs.d.name.d.value, importFromAs);
|
5302
5317
|
}
|
5303
5318
|
}
|
5304
5319
|
});
|
5305
5320
|
}
|
5306
5321
|
else if (importStatement.subnode) {
|
5307
5322
|
// Ignore duplicates if they're aliased.
|
5308
|
-
if (!importStatement.subnode.alias) {
|
5323
|
+
if (!importStatement.subnode.d.alias) {
|
5309
5324
|
const prevImport = importModuleMap.get(importStatement.moduleName);
|
5310
5325
|
if (prevImport) {
|
5311
5326
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportDuplicateImport, localize_1.LocMessage.duplicateImport().format({ importName: importStatement.moduleName }), importStatement.subnode);
|