@zzzen/pyright-internal 1.2.0-dev.20240630 → 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 +507 -513
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.js +652 -633
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.d.ts +5 -3
- package/dist/analyzer/codeFlowEngine.js +143 -122
- 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.d.ts +1 -1
- package/dist/analyzer/constraintSolver.js +71 -67
- 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 +85 -77
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.js +113 -176
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/declaration.d.ts +1 -1
- package/dist/analyzer/declarationUtils.js +14 -15
- package/dist/analyzer/declarationUtils.js.map +1 -1
- package/dist/analyzer/decorators.js +85 -85
- package/dist/analyzer/decorators.js.map +1 -1
- package/dist/analyzer/enums.js +71 -57
- 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.d.ts +4 -4
- package/dist/analyzer/operations.js +70 -70
- 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 +195 -147
- 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 +22 -22
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/sourceFile.d.ts +3 -2
- package/dist/analyzer/sourceFile.js +8 -8
- 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 +2330 -2367
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +33 -31
- package/dist/analyzer/typeEvaluatorTypes.js +48 -41
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +221 -217
- 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 +26 -9
- package/dist/analyzer/typeUtils.js +460 -404
- 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 +147 -103
- package/dist/analyzer/types.js +668 -493
- 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/diagnostic.d.ts +14 -0
- package/dist/common/diagnostic.js +41 -1
- package/dist/common/diagnostic.js.map +1 -1
- package/dist/common/diagnosticSink.d.ts +4 -0
- package/dist/common/diagnosticSink.js +21 -1
- package/dist/common/diagnosticSink.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.d.ts +1 -1
- package/dist/languageService/completionProvider.js +156 -154
- 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/localization/localize.d.ts +3 -0
- package/dist/localization/localize.js +1 -0
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.en-us.json +2 -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 +322 -297
- package/dist/parser/parser.js.map +1 -1
- package/dist/pyright.js +265 -5
- package/dist/pyright.js.map +1 -1
- package/dist/tests/classDeclaration.test.js +14 -14
- package/dist/tests/classDeclaration.test.js.map +1 -1
- package/dist/tests/fourslash/hover.init.fourslash.js +1 -1
- package/dist/tests/fourslash/hover.init.fourslash.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/typeEvaluator2.test.js +2 -2
- package/dist/tests/typeEvaluator3.test.js +10 -5
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +1 -1
- package/dist/tests/typeEvaluator7.test.js +2 -2
- package/dist/tests/typeEvaluator7.test.js.map +1 -1
- package/dist/tests/typePrinter.test.js +14 -39
- package/dist/tests/typePrinter.test.js.map +1 -1
- package/package.json +1 -1
package/dist/analyzer/checker.js
CHANGED
@@ -105,7 +105,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
105
105
|
if (codeComplexity > typeEvaluator_1.maxCodeComplexity) {
|
106
106
|
this._evaluator.addDiagnosticForTextRange(this._fileInfo, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.codeTooComplexToAnalyze(), { start: 0, length: 0 });
|
107
107
|
}
|
108
|
-
this._walkStatementsAndReportUnreachable(this._moduleNode.statements);
|
108
|
+
this._walkStatementsAndReportUnreachable(this._moduleNode.d.statements);
|
109
109
|
// Mark symbols accessed by __all__ as accessed.
|
110
110
|
const dunderAllInfo = AnalyzerNodeInfo.getDunderAllInfo(this._moduleNode);
|
111
111
|
if (dunderAllInfo) {
|
@@ -128,11 +128,11 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
128
128
|
}
|
129
129
|
}
|
130
130
|
visitSuite(node) {
|
131
|
-
this._walkStatementsAndReportUnreachable(node.statements);
|
131
|
+
this._walkStatementsAndReportUnreachable(node.d.statements);
|
132
132
|
return false;
|
133
133
|
}
|
134
134
|
visitStatementList(node) {
|
135
|
-
node.statements.forEach((statement) => {
|
135
|
+
node.d.statements.forEach((statement) => {
|
136
136
|
if ((0, parseNodes_1.isExpressionNode)(statement)) {
|
137
137
|
// Evaluate the expression in case it wasn't otherwise evaluated
|
138
138
|
// through lazy analysis. This will mark referenced symbols as
|
@@ -145,27 +145,27 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
145
145
|
}
|
146
146
|
visitClass(node) {
|
147
147
|
const classTypeResult = this._evaluator.getTypeOfClass(node);
|
148
|
-
if (node.
|
149
|
-
this.walk(node.
|
148
|
+
if (node.d.typeParams) {
|
149
|
+
this.walk(node.d.typeParams);
|
150
150
|
}
|
151
|
-
this.walk(node.suite);
|
152
|
-
this.walkMultiple(node.decorators);
|
153
|
-
this.walkMultiple(node.arguments);
|
151
|
+
this.walk(node.d.suite);
|
152
|
+
this.walkMultiple(node.d.decorators);
|
153
|
+
this.walkMultiple(node.d.arguments);
|
154
154
|
if (classTypeResult) {
|
155
155
|
// Protocol classes cannot derive from non-protocol classes.
|
156
156
|
if (types_1.ClassType.isProtocolClass(classTypeResult.classType)) {
|
157
|
-
node.arguments.forEach((arg) => {
|
158
|
-
if (!arg.name) {
|
159
|
-
const baseClassType = this._evaluator.getType(arg.
|
157
|
+
node.d.arguments.forEach((arg) => {
|
158
|
+
if (!arg.d.name) {
|
159
|
+
const baseClassType = this._evaluator.getType(arg.d.valueExpr);
|
160
160
|
if (baseClassType &&
|
161
161
|
(0, types_1.isInstantiableClass)(baseClassType) &&
|
162
162
|
!types_1.ClassType.isBuiltIn(baseClassType, 'Protocol') &&
|
163
163
|
!types_1.ClassType.isBuiltIn(baseClassType, 'Generic')) {
|
164
164
|
if (!types_1.ClassType.isProtocolClass(baseClassType)) {
|
165
165
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.protocolBaseClass().format({
|
166
|
-
classType: classTypeResult.classType.
|
167
|
-
baseType: baseClassType.
|
168
|
-
}), arg.
|
166
|
+
classType: classTypeResult.classType.shared.name,
|
167
|
+
baseType: baseClassType.shared.name,
|
168
|
+
}), arg.d.valueExpr);
|
169
169
|
}
|
170
170
|
}
|
171
171
|
}
|
@@ -182,16 +182,16 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
182
182
|
this._validateBaseClassOverrides(classTypeResult.classType);
|
183
183
|
this._validateTypedDictOverrides(classTypeResult.classType);
|
184
184
|
this._validateOverloadDecoratorConsistency(classTypeResult.classType);
|
185
|
-
this._validateMultipleInheritanceBaseClasses(classTypeResult.classType, node.name);
|
186
|
-
this._validateMultipleInheritanceCompatibility(classTypeResult.classType, node.name);
|
187
|
-
this._validateConstructorConsistency(classTypeResult.classType, node.name);
|
185
|
+
this._validateMultipleInheritanceBaseClasses(classTypeResult.classType, node.d.name);
|
186
|
+
this._validateMultipleInheritanceCompatibility(classTypeResult.classType, node.d.name);
|
187
|
+
this._validateConstructorConsistency(classTypeResult.classType, node.d.name);
|
188
188
|
this._validateFinalMemberOverrides(classTypeResult.classType);
|
189
189
|
this._validateInstanceVariableInitialization(node, classTypeResult.classType);
|
190
190
|
this._validateFinalClassNotAbstract(classTypeResult.classType, node);
|
191
|
-
this._validateDataClassPostInit(classTypeResult.classType
|
191
|
+
this._validateDataClassPostInit(classTypeResult.classType);
|
192
192
|
this._validateEnumMembers(classTypeResult.classType, node);
|
193
193
|
if (types_1.ClassType.isTypedDictClass(classTypeResult.classType)) {
|
194
|
-
this._validateTypedDictClassSuite(node.suite);
|
194
|
+
this._validateTypedDictClassSuite(node.d.suite);
|
195
195
|
}
|
196
196
|
if (types_1.ClassType.isEnumClass(classTypeResult.classType)) {
|
197
197
|
this._validateEnumClassOverride(node, classTypeResult.classType);
|
@@ -202,13 +202,13 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
202
202
|
return false;
|
203
203
|
}
|
204
204
|
visitFunction(node) {
|
205
|
-
var _a, _b;
|
206
|
-
if (node.
|
207
|
-
this.walk(node.
|
205
|
+
var _a, _b, _c;
|
206
|
+
if (node.d.typeParams) {
|
207
|
+
this.walk(node.d.typeParams);
|
208
208
|
}
|
209
209
|
if (!this._fileInfo.diagnosticRuleSet.analyzeUnannotatedFunctions && !this._fileInfo.isStubFile) {
|
210
210
|
if (ParseTreeUtils.isUnannotatedFunction(node)) {
|
211
|
-
this._evaluator.addInformation(localize_1.LocMessage.unannotatedFunctionSkipped().format({ name: node.name.value }), node.name);
|
211
|
+
this._evaluator.addInformation(localize_1.LocMessage.unannotatedFunctionSkipped().format({ name: node.d.name.d.value }), node.d.name);
|
212
212
|
}
|
213
213
|
}
|
214
214
|
const functionTypeResult = this._evaluator.getTypeOfFunction(node);
|
@@ -220,41 +220,42 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
220
220
|
const keywordNames = new Set();
|
221
221
|
const paramDetails = (0, parameterUtils_1.getParameterListDetails)(functionTypeResult.functionType);
|
222
222
|
// Report any unknown or missing parameter types.
|
223
|
-
node.
|
224
|
-
|
225
|
-
|
226
|
-
|
223
|
+
node.d.params.forEach((param, index) => {
|
224
|
+
var _a;
|
225
|
+
if (param.d.name) {
|
226
|
+
if (param.d.category === 0 /* ParameterCategory.Simple */ && index >= paramDetails.positionOnlyParamCount) {
|
227
|
+
keywordNames.add(param.d.name.d.value);
|
227
228
|
}
|
228
229
|
// Determine whether this is a P.args parameter.
|
229
|
-
if (param.category === 1 /* ParameterCategory.ArgsList */) {
|
230
|
-
const annotationExpr = param.
|
230
|
+
if (param.d.category === 1 /* ParameterCategory.ArgsList */) {
|
231
|
+
const annotationExpr = (_a = param.d.annotation) !== null && _a !== void 0 ? _a : param.d.annotationComment;
|
231
232
|
if (annotationExpr &&
|
232
233
|
annotationExpr.nodeType === 35 /* ParseNodeType.MemberAccess */ &&
|
233
|
-
annotationExpr.
|
234
|
-
const baseType = this._evaluator.getType(annotationExpr.
|
235
|
-
if (baseType && (0, types_1.isTypeVar)(baseType) && baseType.
|
234
|
+
annotationExpr.d.member.d.value === 'args') {
|
235
|
+
const baseType = this._evaluator.getType(annotationExpr.d.leftExpr);
|
236
|
+
if (baseType && (0, types_1.isTypeVar)(baseType) && baseType.shared.isParamSpec) {
|
236
237
|
sawParamSpecArgs = true;
|
237
238
|
}
|
238
239
|
}
|
239
240
|
}
|
240
|
-
else if (param.category === 2 /* ParameterCategory.KwargsDict */) {
|
241
|
+
else if (param.d.category === 2 /* ParameterCategory.KwargsDict */) {
|
241
242
|
sawParamSpecArgs = false;
|
242
243
|
}
|
243
244
|
}
|
244
|
-
if (param.name && param.category === 0 /* ParameterCategory.Simple */ && sawParamSpecArgs) {
|
245
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.namedParamAfterParamSpecArgs().format({ name: param.name.value }), param.name);
|
245
|
+
if (param.d.name && param.d.category === 0 /* ParameterCategory.Simple */ && sawParamSpecArgs) {
|
246
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.namedParamAfterParamSpecArgs().format({ name: param.d.name.d.value }), param.d.name);
|
246
247
|
}
|
247
248
|
// Allow unknown and missing param types if the param is named '_'.
|
248
|
-
if (param.name && param.name.value !== '_') {
|
249
|
-
const functionTypeParam = functionTypeResult.functionType.
|
249
|
+
if (param.d.name && param.d.name.d.value !== '_') {
|
250
|
+
const functionTypeParam = functionTypeResult.functionType.shared.parameters.find((p) => { var _a; return p.name === ((_a = param.d.name) === null || _a === void 0 ? void 0 : _a.d.value); });
|
250
251
|
if (functionTypeParam) {
|
251
252
|
const paramType = functionTypeParam.type;
|
252
253
|
if (this._fileInfo.diagnosticRuleSet.reportUnknownParameterType !== 'none') {
|
253
254
|
if ((0, types_1.isUnknown)(paramType) ||
|
254
255
|
((0, types_1.isTypeVar)(paramType) &&
|
255
|
-
paramType.
|
256
|
-
!paramType.
|
257
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnknownParameterType, localize_1.LocMessage.paramTypeUnknown().format({ paramName: param.name.value }), param.name);
|
256
|
+
paramType.shared.isSynthesized &&
|
257
|
+
!paramType.shared.isSynthesizedSelf)) {
|
258
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnknownParameterType, localize_1.LocMessage.paramTypeUnknown().format({ paramName: param.d.name.d.value }), param.d.name);
|
258
259
|
}
|
259
260
|
else if ((0, typeUtils_1.isPartlyUnknown)(paramType)) {
|
260
261
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
@@ -262,33 +263,33 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
262
263
|
paramType: this._evaluator.printType(paramType, { expandTypeAlias: true }),
|
263
264
|
}));
|
264
265
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnknownParameterType, localize_1.LocMessage.paramTypePartiallyUnknown().format({
|
265
|
-
paramName: param.name.value,
|
266
|
-
}) + diagAddendum.getString(), param.name);
|
266
|
+
paramName: param.d.name.d.value,
|
267
|
+
}) + diagAddendum.getString(), param.d.name);
|
267
268
|
}
|
268
269
|
}
|
269
270
|
let hasAnnotation = false;
|
270
|
-
if (functionTypeParam
|
271
|
+
if (types_1.FunctionParam.isTypeDeclared(functionTypeParam)) {
|
271
272
|
hasAnnotation = true;
|
272
273
|
}
|
273
274
|
else {
|
274
275
|
// See if this is a "self" and "cls" parameter. They are exempt from this rule.
|
275
|
-
if ((0, types_1.isTypeVar)(paramType) && paramType.
|
276
|
+
if ((0, types_1.isTypeVar)(paramType) && paramType.shared.isSynthesizedSelf) {
|
276
277
|
hasAnnotation = true;
|
277
278
|
}
|
278
279
|
}
|
279
280
|
if (!hasAnnotation && this._fileInfo.diagnosticRuleSet.reportMissingParameterType !== 'none') {
|
280
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportMissingParameterType, localize_1.LocMessage.paramAnnotationMissing().format({ name: param.name.value }), param.name);
|
281
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportMissingParameterType, localize_1.LocMessage.paramAnnotationMissing().format({ name: param.d.name.d.value }), param.d.name);
|
281
282
|
}
|
282
283
|
}
|
283
284
|
}
|
284
285
|
});
|
285
286
|
// Verify that an unpacked TypedDict doesn't overlap any keyword parameters.
|
286
287
|
if (paramDetails.hasUnpackedTypedDict) {
|
287
|
-
const kwargsIndex = functionTypeResult.functionType.
|
288
|
+
const kwargsIndex = functionTypeResult.functionType.shared.parameters.length - 1;
|
288
289
|
const kwargsType = types_1.FunctionType.getEffectiveParameterType(functionTypeResult.functionType, kwargsIndex);
|
289
|
-
if ((0, types_1.isClass)(kwargsType) && kwargsType.
|
290
|
+
if ((0, types_1.isClass)(kwargsType) && kwargsType.shared.typedDictEntries) {
|
290
291
|
const overlappingEntries = new Set();
|
291
|
-
kwargsType.
|
292
|
+
kwargsType.shared.typedDictEntries.knownItems.forEach((_, name) => {
|
292
293
|
if (keywordNames.has(name)) {
|
293
294
|
overlappingEntries.add(name);
|
294
295
|
}
|
@@ -296,85 +297,89 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
296
297
|
if (overlappingEntries.size > 0) {
|
297
298
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.overlappingKeywordArgs().format({
|
298
299
|
names: [...overlappingEntries.values()].join(', '),
|
299
|
-
}), (_a = node.
|
300
|
+
}), (_a = node.d.params[kwargsIndex].d.annotation) !== null && _a !== void 0 ? _a : node.d.params[kwargsIndex]);
|
300
301
|
}
|
301
302
|
}
|
302
303
|
}
|
303
304
|
// Check for invalid use of ParamSpec P.args and P.kwargs.
|
304
|
-
const paramSpecParams = functionTypeResult.functionType.
|
305
|
-
if (param
|
306
|
-
if (param.category !== 0 /* ParameterCategory.Simple */ && param.name && param.type.paramSpecAccess) {
|
305
|
+
const paramSpecParams = functionTypeResult.functionType.shared.parameters.filter((param) => {
|
306
|
+
if (types_1.FunctionParam.isTypeDeclared(param) && (0, types_1.isTypeVar)(param.type) && (0, types_1.isParamSpec)(param.type)) {
|
307
|
+
if (param.category !== 0 /* ParameterCategory.Simple */ && param.name && param.type.priv.paramSpecAccess) {
|
307
308
|
return true;
|
308
309
|
}
|
309
310
|
}
|
310
311
|
return false;
|
311
312
|
});
|
312
|
-
if (paramSpecParams.length === 1 && paramSpecParams[0].
|
313
|
-
|
313
|
+
if (paramSpecParams.length === 1 && paramSpecParams[0].name) {
|
314
|
+
const paramNode = node.d.params.find((param) => { var _a; return ((_a = param.d.name) === null || _a === void 0 ? void 0 : _a.d.value) === paramSpecParams[0].name; });
|
315
|
+
const annotationNode = (_b = paramNode === null || paramNode === void 0 ? void 0 : paramNode.d.annotation) !== null && _b !== void 0 ? _b : paramNode === null || paramNode === void 0 ? void 0 : paramNode.d.annotationComment;
|
316
|
+
if (annotationNode) {
|
317
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.paramSpecArgsKwargsUsage(), annotationNode);
|
318
|
+
}
|
314
319
|
}
|
315
320
|
// If this is a stub, ensure that the return type is specified.
|
316
321
|
if (this._fileInfo.isStubFile) {
|
317
|
-
const returnAnnotation = node.
|
322
|
+
const returnAnnotation = node.d.returnAnnotation || ((_c = node.d.funcAnnotationComment) === null || _c === void 0 ? void 0 : _c.d.returnAnnotation);
|
318
323
|
if (!returnAnnotation) {
|
319
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnknownParameterType, localize_1.LocMessage.returnTypeUnknown(), node.name);
|
324
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnknownParameterType, localize_1.LocMessage.returnTypeUnknown(), node.d.name);
|
320
325
|
}
|
321
326
|
}
|
322
327
|
if (containingClassNode) {
|
323
328
|
this._validateMethod(node, functionTypeResult.functionType, containingClassNode);
|
324
329
|
}
|
325
330
|
}
|
326
|
-
node.
|
327
|
-
if (param.defaultValue) {
|
328
|
-
this.walk(param.defaultValue);
|
331
|
+
node.d.params.forEach((param, index) => {
|
332
|
+
if (param.d.defaultValue) {
|
333
|
+
this.walk(param.d.defaultValue);
|
329
334
|
}
|
330
|
-
if (param.
|
331
|
-
this.walk(param.
|
335
|
+
if (param.d.annotation) {
|
336
|
+
this.walk(param.d.annotation);
|
332
337
|
}
|
333
|
-
if (param.
|
334
|
-
this.walk(param.
|
338
|
+
if (param.d.annotationComment) {
|
339
|
+
this.walk(param.d.annotationComment);
|
335
340
|
}
|
336
341
|
// Look for method parameters that are typed with TypeVars that have the wrong variance.
|
337
342
|
if (functionTypeResult) {
|
338
|
-
const annotationNode = param.
|
339
|
-
if (annotationNode && index < functionTypeResult.functionType.
|
340
|
-
const paramType = functionTypeResult.functionType.
|
343
|
+
const annotationNode = param.d.annotation || param.d.annotationComment;
|
344
|
+
if (annotationNode && index < functionTypeResult.functionType.shared.parameters.length) {
|
345
|
+
const paramType = functionTypeResult.functionType.shared.parameters[index].type;
|
341
346
|
const exemptMethods = ['__init__', '__new__'];
|
342
347
|
if (containingClassNode &&
|
343
348
|
(0, types_1.isTypeVar)(paramType) &&
|
344
|
-
paramType.
|
345
|
-
!paramType.
|
346
|
-
!exemptMethods.some((name) => name === functionTypeResult.functionType.
|
349
|
+
paramType.shared.declaredVariance === 3 /* Variance.Covariant */ &&
|
350
|
+
!paramType.shared.isSynthesized &&
|
351
|
+
!exemptMethods.some((name) => name === functionTypeResult.functionType.shared.name)) {
|
347
352
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.paramTypeCovariant(), annotationNode);
|
348
353
|
}
|
349
354
|
}
|
350
355
|
}
|
351
356
|
});
|
352
|
-
if (node.
|
353
|
-
this.walk(node.
|
357
|
+
if (node.d.returnAnnotation) {
|
358
|
+
this.walk(node.d.returnAnnotation);
|
354
359
|
}
|
355
|
-
if (node.
|
356
|
-
this.walk(node.
|
360
|
+
if (node.d.funcAnnotationComment) {
|
361
|
+
this.walk(node.d.funcAnnotationComment);
|
357
362
|
if (this._fileInfo.diagnosticRuleSet.reportTypeCommentUsage !== 'none' &&
|
358
363
|
this._fileInfo.executionEnvironment.pythonVersion.isGreaterOrEqualTo(pythonVersion_1.pythonVersion3_5)) {
|
359
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportTypeCommentUsage, localize_1.LocMessage.typeCommentDeprecated(), node.
|
364
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportTypeCommentUsage, localize_1.LocMessage.typeCommentDeprecated(), node.d.funcAnnotationComment);
|
360
365
|
}
|
361
366
|
}
|
362
|
-
this.walkMultiple(node.decorators);
|
363
|
-
node.
|
364
|
-
if (param.name) {
|
365
|
-
this.walk(param.name);
|
367
|
+
this.walkMultiple(node.d.decorators);
|
368
|
+
node.d.params.forEach((param) => {
|
369
|
+
if (param.d.name) {
|
370
|
+
this.walk(param.d.name);
|
366
371
|
}
|
367
372
|
});
|
368
373
|
const codeComplexity = AnalyzerNodeInfo.getCodeFlowComplexity(node);
|
369
374
|
const isTooComplexToAnalyze = codeComplexity > typeEvaluator_1.maxCodeComplexity;
|
370
375
|
if (isPrintCodeComplexityEnabled) {
|
371
|
-
console.log(`Code complexity of function ${node.name.value} is ${codeComplexity.toString()}`);
|
376
|
+
console.log(`Code complexity of function ${node.d.name.d.value} is ${codeComplexity.toString()}`);
|
372
377
|
}
|
373
378
|
if (isTooComplexToAnalyze) {
|
374
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.codeTooComplexToAnalyze(), node.name);
|
379
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.codeTooComplexToAnalyze(), node.d.name);
|
375
380
|
}
|
376
381
|
else {
|
377
|
-
this.walk(node.suite);
|
382
|
+
this.walk(node.d.suite);
|
378
383
|
}
|
379
384
|
if (functionTypeResult) {
|
380
385
|
// Validate that the function returns the declared type.
|
@@ -390,16 +395,16 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
390
395
|
this._reportDeprecatedClassProperty(node, functionTypeResult);
|
391
396
|
// If this is not a method, @final is disallowed.
|
392
397
|
if (!containingClassNode && types_1.FunctionType.isFinal(functionTypeResult.functionType)) {
|
393
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.finalNonMethod().format({ name: node.name.value }), node.name);
|
398
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.finalNonMethod().format({ name: node.d.name.d.value }), node.d.name);
|
394
399
|
}
|
395
400
|
}
|
396
401
|
// If we're at the module level within a stub file, report a diagnostic
|
397
402
|
// if there is a '__getattr__' function defined when in strict mode.
|
398
403
|
// This signifies an incomplete stub file that obscures type errors.
|
399
|
-
if (this._fileInfo.isStubFile && node.name.value === '__getattr__') {
|
404
|
+
if (this._fileInfo.isStubFile && node.d.name.d.value === '__getattr__') {
|
400
405
|
const scope = (0, scopeUtils_1.getScopeForNode)(node);
|
401
406
|
if ((scope === null || scope === void 0 ? void 0 : scope.type) === 4 /* ScopeType.Module */) {
|
402
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompleteStub, localize_1.LocMessage.stubUsesGetAttr(), node.name);
|
407
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompleteStub, localize_1.LocMessage.stubUsesGetAttr(), node.d.name);
|
403
408
|
}
|
404
409
|
}
|
405
410
|
this._scopedNodes.push(node);
|
@@ -426,29 +431,29 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
426
431
|
visitLambda(node) {
|
427
432
|
this._evaluator.getType(node);
|
428
433
|
// Walk the children.
|
429
|
-
this.walkMultiple([...node.
|
430
|
-
node.
|
431
|
-
if (param.name) {
|
432
|
-
const paramType = this._evaluator.getType(param.name);
|
434
|
+
this.walkMultiple([...node.d.params, node.d.expr]);
|
435
|
+
node.d.params.forEach((param) => {
|
436
|
+
if (param.d.name) {
|
437
|
+
const paramType = this._evaluator.getType(param.d.name);
|
433
438
|
if (paramType) {
|
434
439
|
if ((0, types_1.isUnknown)(paramType)) {
|
435
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnknownLambdaType, localize_1.LocMessage.paramTypeUnknown().format({ paramName: param.name.value }), param.name);
|
440
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnknownLambdaType, localize_1.LocMessage.paramTypeUnknown().format({ paramName: param.d.name.d.value }), param.d.name);
|
436
441
|
}
|
437
442
|
else if ((0, typeUtils_1.isPartlyUnknown)(paramType)) {
|
438
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnknownLambdaType, localize_1.LocMessage.paramTypePartiallyUnknown().format({ paramName: param.name.value }), param.name);
|
443
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnknownLambdaType, localize_1.LocMessage.paramTypePartiallyUnknown().format({ paramName: param.d.name.d.value }), param.d.name);
|
439
444
|
}
|
440
445
|
}
|
441
446
|
}
|
442
447
|
});
|
443
|
-
const returnType = this._evaluator.getType(node.
|
448
|
+
const returnType = this._evaluator.getType(node.d.expr);
|
444
449
|
if (returnType) {
|
445
450
|
if ((0, types_1.isUnknown)(returnType)) {
|
446
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnknownLambdaType, localize_1.LocMessage.lambdaReturnTypeUnknown(), node.
|
451
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnknownLambdaType, localize_1.LocMessage.lambdaReturnTypeUnknown(), node.d.expr);
|
447
452
|
}
|
448
453
|
else if ((0, typeUtils_1.isPartlyUnknown)(returnType)) {
|
449
454
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnknownLambdaType, localize_1.LocMessage.lambdaReturnTypePartiallyUnknown().format({
|
450
455
|
returnType: this._evaluator.printType(returnType, { expandTypeAlias: true }),
|
451
|
-
}), node.
|
456
|
+
}), node.d.expr);
|
452
457
|
}
|
453
458
|
}
|
454
459
|
this._scopedNodes.push(node);
|
@@ -462,7 +467,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
462
467
|
if (this._fileInfo.diagnosticRuleSet.reportUnusedCallResult !== 'none' ||
|
463
468
|
this._fileInfo.diagnosticRuleSet.reportUnusedCoroutine !== 'none') {
|
464
469
|
if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 47 /* ParseNodeType.StatementList */) {
|
465
|
-
const isRevealTypeCall = node.
|
470
|
+
const isRevealTypeCall = node.d.leftExpr.nodeType === 38 /* ParseNodeType.Name */ && node.d.leftExpr.d.value === 'reveal_type';
|
466
471
|
const returnType = this._evaluator.getType(node);
|
467
472
|
if (!isRevealTypeCall && returnType && this._isTypeValidForUnusedValueTest(returnType)) {
|
468
473
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnusedCallResult, localize_1.LocMessage.unusedCallResult().format({
|
@@ -479,8 +484,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
479
484
|
visitAwait(node) {
|
480
485
|
var _a;
|
481
486
|
if (this._fileInfo.diagnosticRuleSet.reportUnusedCallResult !== 'none') {
|
482
|
-
if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 47 /* ParseNodeType.StatementList */ &&
|
483
|
-
node.expression.nodeType === 9 /* ParseNodeType.Call */) {
|
487
|
+
if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 47 /* ParseNodeType.StatementList */ && node.d.expr.nodeType === 9 /* ParseNodeType.Call */) {
|
484
488
|
const returnType = this._evaluator.getType(node);
|
485
489
|
if (returnType && this._isTypeValidForUnusedValueTest(returnType)) {
|
486
490
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnusedCallResult, localize_1.LocMessage.unusedCallResult().format({
|
@@ -493,8 +497,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
493
497
|
}
|
494
498
|
visitFor(node) {
|
495
499
|
this._evaluator.evaluateTypesForStatement(node);
|
496
|
-
if (node.typeComment) {
|
497
|
-
this._evaluator.addDiagnosticForTextRange(this._fileInfo, diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.annotationNotSupported(), node.typeComment);
|
500
|
+
if (node.d.typeComment) {
|
501
|
+
this._evaluator.addDiagnosticForTextRange(this._fileInfo, diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.annotationNotSupported(), node.d.typeComment);
|
498
502
|
}
|
499
503
|
return true;
|
500
504
|
}
|
@@ -515,39 +519,39 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
515
519
|
return true;
|
516
520
|
}
|
517
521
|
visitComprehensionIf(node) {
|
518
|
-
this._validateConditionalIsBool(node.
|
519
|
-
this._reportUnnecessaryConditionExpression(node.
|
522
|
+
this._validateConditionalIsBool(node.d.testExpr);
|
523
|
+
this._reportUnnecessaryConditionExpression(node.d.testExpr);
|
520
524
|
return true;
|
521
525
|
}
|
522
526
|
visitIf(node) {
|
523
|
-
this._validateConditionalIsBool(node.
|
524
|
-
this._reportUnnecessaryConditionExpression(node.
|
527
|
+
this._validateConditionalIsBool(node.d.testExpr);
|
528
|
+
this._reportUnnecessaryConditionExpression(node.d.testExpr);
|
525
529
|
return true;
|
526
530
|
}
|
527
531
|
visitWhile(node) {
|
528
|
-
this._validateConditionalIsBool(node.
|
529
|
-
this._reportUnnecessaryConditionExpression(node.
|
532
|
+
this._validateConditionalIsBool(node.d.testExpr);
|
533
|
+
this._reportUnnecessaryConditionExpression(node.d.testExpr);
|
530
534
|
return true;
|
531
535
|
}
|
532
536
|
visitWith(node) {
|
533
|
-
node.withItems.forEach((item) => {
|
537
|
+
node.d.withItems.forEach((item) => {
|
534
538
|
this._evaluator.evaluateTypesForStatement(item);
|
535
539
|
});
|
536
|
-
if (node.typeComment) {
|
537
|
-
this._evaluator.addDiagnosticForTextRange(this._fileInfo, diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.annotationNotSupported(), node.typeComment);
|
540
|
+
if (node.d.typeComment) {
|
541
|
+
this._evaluator.addDiagnosticForTextRange(this._fileInfo, diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.annotationNotSupported(), node.d.typeComment);
|
538
542
|
}
|
539
543
|
return true;
|
540
544
|
}
|
541
545
|
visitReturn(node) {
|
542
|
-
var _a, _b, _c, _d, _e;
|
546
|
+
var _a, _b, _c, _d, _e, _f;
|
543
547
|
let returnTypeResult;
|
544
548
|
let returnType;
|
545
549
|
const enclosingFunctionNode = ParseTreeUtils.getEnclosingFunction(node);
|
546
550
|
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,15 +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
|
}
|
2897
|
+
else if (types_1.ClassType.isIllegalIsinstanceClass(subtype)) {
|
2898
|
+
diag.addMessage(localize_1.LocAddendum.isinstanceClassNotSupported().format({ type: subtype.shared.name }));
|
2899
|
+
isSupported = false;
|
2900
|
+
}
|
2889
2901
|
else if (types_1.ClassType.isProtocolClass(subtype) &&
|
2890
2902
|
!types_1.ClassType.isRuntimeCheckable(subtype) &&
|
2891
|
-
!subtype.includeSubclasses) {
|
2903
|
+
!subtype.priv.includeSubclasses) {
|
2892
2904
|
// According to PEP 544, protocol classes cannot be used as the right-hand
|
2893
2905
|
// argument to isinstance or issubclass unless they are annotated as
|
2894
2906
|
// "runtime checkable".
|
@@ -2899,15 +2911,15 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2899
2911
|
diag.addMessage(localize_1.LocAddendum.newTypeClassNotAllowed());
|
2900
2912
|
isSupported = false;
|
2901
2913
|
}
|
2902
|
-
else if (subtype.specialForm &&
|
2903
|
-
(0, types_1.isInstantiableClass)(subtype.specialForm) &&
|
2904
|
-
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')) {
|
2905
2917
|
diag.addMessage(localize_1.LocAddendum.annotatedNotAllowed());
|
2906
2918
|
isSupported = false;
|
2907
2919
|
}
|
2908
2920
|
break;
|
2909
2921
|
case 4 /* TypeCategory.Function */:
|
2910
|
-
if (!types_1.TypeBase.isInstantiable(subtype) || subtype.isCallableWithTypeArgs) {
|
2922
|
+
if (!types_1.TypeBase.isInstantiable(subtype) || subtype.priv.isCallableWithTypeArgs) {
|
2911
2923
|
diag.addMessage(localize_1.LocAddendum.genericClassNotAllowed());
|
2912
2924
|
isSupported = false;
|
2913
2925
|
}
|
@@ -2923,7 +2935,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2923
2935
|
_validateNotDataProtocol(type, diag) {
|
2924
2936
|
if ((0, types_1.isInstantiableClass)(type) && types_1.ClassType.isProtocolClass(type) && !(0, protocols_1.isMethodOnlyProtocol)(type)) {
|
2925
2937
|
diag.addMessage(localize_1.LocAddendum.dataProtocolUnsupported().format({
|
2926
|
-
name: type.
|
2938
|
+
name: type.shared.name,
|
2927
2939
|
}));
|
2928
2940
|
}
|
2929
2941
|
}
|
@@ -2949,30 +2961,30 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2949
2961
|
!types_1.ClassType.isClassProperty(functionTypeResult.decoratedType)) {
|
2950
2962
|
return;
|
2951
2963
|
}
|
2952
|
-
this._reportDeprecatedDiagnostic(node.name, localize_1.LocMessage.classPropertyDeprecated());
|
2964
|
+
this._reportDeprecatedDiagnostic(node.d.name, localize_1.LocMessage.classPropertyDeprecated());
|
2953
2965
|
}
|
2954
2966
|
_reportDeprecatedUseForMemberAccess(node, info) {
|
2955
2967
|
let errorMessage;
|
2956
2968
|
if (info.accessType === 'property') {
|
2957
2969
|
if (info.accessMethod === 'get') {
|
2958
|
-
errorMessage = localize_1.LocMessage.deprecatedPropertyGetter().format({ name: node.value });
|
2970
|
+
errorMessage = localize_1.LocMessage.deprecatedPropertyGetter().format({ name: node.d.value });
|
2959
2971
|
}
|
2960
2972
|
else if (info.accessMethod === 'set') {
|
2961
|
-
errorMessage = localize_1.LocMessage.deprecatedPropertySetter().format({ name: node.value });
|
2973
|
+
errorMessage = localize_1.LocMessage.deprecatedPropertySetter().format({ name: node.d.value });
|
2962
2974
|
}
|
2963
2975
|
else {
|
2964
|
-
errorMessage = localize_1.LocMessage.deprecatedPropertyDeleter().format({ name: node.value });
|
2976
|
+
errorMessage = localize_1.LocMessage.deprecatedPropertyDeleter().format({ name: node.d.value });
|
2965
2977
|
}
|
2966
2978
|
}
|
2967
2979
|
else if (info.accessType === 'descriptor') {
|
2968
2980
|
if (info.accessMethod === 'get') {
|
2969
|
-
errorMessage = localize_1.LocMessage.deprecatedDescriptorGetter().format({ name: node.value });
|
2981
|
+
errorMessage = localize_1.LocMessage.deprecatedDescriptorGetter().format({ name: node.d.value });
|
2970
2982
|
}
|
2971
2983
|
else if (info.accessMethod === 'set') {
|
2972
|
-
errorMessage = localize_1.LocMessage.deprecatedDescriptorSetter().format({ name: node.value });
|
2984
|
+
errorMessage = localize_1.LocMessage.deprecatedDescriptorSetter().format({ name: node.d.value });
|
2973
2985
|
}
|
2974
2986
|
else {
|
2975
|
-
errorMessage = localize_1.LocMessage.deprecatedDescriptorDeleter().format({ name: node.value });
|
2987
|
+
errorMessage = localize_1.LocMessage.deprecatedDescriptorDeleter().format({ name: node.d.value });
|
2976
2988
|
}
|
2977
2989
|
}
|
2978
2990
|
if (errorMessage) {
|
@@ -2980,26 +2992,26 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2980
2992
|
}
|
2981
2993
|
}
|
2982
2994
|
_reportDeprecatedUseForType(node, type, isImportFromTyping = false) {
|
2983
|
-
var _a, _b;
|
2995
|
+
var _a, _b, _c;
|
2984
2996
|
if (!type) {
|
2985
2997
|
return;
|
2986
2998
|
}
|
2987
2999
|
let errorMessage;
|
2988
3000
|
let deprecatedMessage;
|
2989
3001
|
function getDeprecatedMessageForFunction(functionType) {
|
2990
|
-
if (functionType.
|
2991
|
-
functionType.
|
2992
|
-
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,
|
2993
3005
|
/* stopAtFunction */ true);
|
2994
3006
|
if (containingClass) {
|
2995
3007
|
return localize_1.LocMessage.deprecatedMethod().format({
|
2996
|
-
name: functionType.
|
2997
|
-
className: containingClass.name.value,
|
3008
|
+
name: functionType.shared.name || '<anonymous>',
|
3009
|
+
className: containingClass.d.name.d.value,
|
2998
3010
|
});
|
2999
3011
|
}
|
3000
3012
|
}
|
3001
3013
|
return localize_1.LocMessage.deprecatedFunction().format({
|
3002
|
-
name: functionType.
|
3014
|
+
name: functionType.shared.name,
|
3003
3015
|
});
|
3004
3016
|
}
|
3005
3017
|
function getDeprecatedMessageForOverloadedCall(evaluator, type) {
|
@@ -3022,21 +3034,21 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3022
3034
|
callTypeResult.overloadsUsedForCall &&
|
3023
3035
|
callTypeResult.overloadsUsedForCall.length > 0) {
|
3024
3036
|
callTypeResult.overloadsUsedForCall.forEach((overload) => {
|
3025
|
-
if (overload.
|
3026
|
-
if (node.value === overload.
|
3027
|
-
deprecatedMessage = overload.
|
3037
|
+
if (overload.shared.deprecatedMessage !== undefined) {
|
3038
|
+
if (node.d.value === overload.shared.name) {
|
3039
|
+
deprecatedMessage = overload.shared.deprecatedMessage;
|
3028
3040
|
errorMessage = getDeprecatedMessageForFunction(overload);
|
3029
3041
|
}
|
3030
|
-
else if ((0, types_1.isInstantiableClass)(type) && overload.
|
3031
|
-
deprecatedMessage = overload.
|
3042
|
+
else if ((0, types_1.isInstantiableClass)(type) && overload.shared.name === '__init__') {
|
3043
|
+
deprecatedMessage = overload.shared.deprecatedMessage;
|
3032
3044
|
errorMessage = localize_1.LocMessage.deprecatedConstructor().format({
|
3033
|
-
name: type.
|
3045
|
+
name: type.shared.name,
|
3034
3046
|
});
|
3035
3047
|
}
|
3036
|
-
else if ((0, types_1.isClassInstance)(type) && overload.
|
3037
|
-
deprecatedMessage = overload.
|
3048
|
+
else if ((0, types_1.isClassInstance)(type) && overload.shared.name === '__call__') {
|
3049
|
+
deprecatedMessage = overload.shared.deprecatedMessage;
|
3038
3050
|
errorMessage = localize_1.LocMessage.deprecatedFunction().format({
|
3039
|
-
name: node.value,
|
3051
|
+
name: node.d.value,
|
3040
3052
|
});
|
3041
3053
|
}
|
3042
3054
|
}
|
@@ -3045,22 +3057,22 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3045
3057
|
}
|
3046
3058
|
(0, typeUtils_1.doForEachSubtype)(type, (subtype) => {
|
3047
3059
|
if ((0, types_1.isClass)(subtype)) {
|
3048
|
-
if (!subtype.includeSubclasses &&
|
3049
|
-
subtype.
|
3050
|
-
node.value === subtype.
|
3051
|
-
deprecatedMessage = subtype.
|
3052
|
-
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 });
|
3053
3065
|
return;
|
3054
3066
|
}
|
3055
3067
|
getDeprecatedMessageForOverloadedCall(this._evaluator, subtype);
|
3056
3068
|
return;
|
3057
3069
|
}
|
3058
3070
|
if ((0, types_1.isFunction)(subtype)) {
|
3059
|
-
if (subtype.
|
3060
|
-
if (!subtype.
|
3061
|
-
subtype.
|
3062
|
-
node.value === subtype.
|
3063
|
-
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;
|
3064
3076
|
errorMessage = getDeprecatedMessageForFunction(subtype);
|
3065
3077
|
}
|
3066
3078
|
}
|
@@ -3074,9 +3086,9 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3074
3086
|
// If there the implementation itself is deprecated, assume it
|
3075
3087
|
// is deprecated even if it's outside of a call expression.
|
3076
3088
|
const overloadImpl = types_1.OverloadedFunctionType.getImplementation(subtype);
|
3077
|
-
if ((overloadImpl === null || overloadImpl === void 0 ? void 0 : overloadImpl.
|
3078
|
-
if (!overloadImpl.
|
3079
|
-
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;
|
3080
3092
|
errorMessage = getDeprecatedMessageForFunction(overloadImpl);
|
3081
3093
|
}
|
3082
3094
|
}
|
@@ -3086,10 +3098,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3086
3098
|
this._reportDeprecatedDiagnostic(node, errorMessage, deprecatedMessage);
|
3087
3099
|
}
|
3088
3100
|
if (this._fileInfo.diagnosticRuleSet.deprecateTypingAliases) {
|
3089
|
-
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);
|
3090
3102
|
if (deprecatedForm) {
|
3091
|
-
if (((0, types_1.isInstantiableClass)(type) && type.
|
3092
|
-
((_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) {
|
3093
3105
|
if (this._fileInfo.executionEnvironment.pythonVersion.isGreaterOrEqualTo(deprecatedForm.version)) {
|
3094
3106
|
if (!deprecatedForm.typingImportOnly || isImportFromTyping) {
|
3095
3107
|
if (this._fileInfo.diagnosticRuleSet.reportDeprecated === 'none') {
|
@@ -3131,11 +3143,11 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3131
3143
|
if (type) {
|
3132
3144
|
if ((0, types_1.isUnbound)(type)) {
|
3133
3145
|
if (this._evaluator.isNodeReachable(node)) {
|
3134
|
-
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);
|
3135
3147
|
}
|
3136
3148
|
}
|
3137
3149
|
else if ((0, types_1.isPossiblyUnbound)(type)) {
|
3138
|
-
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);
|
3139
3151
|
}
|
3140
3152
|
}
|
3141
3153
|
}
|
@@ -3179,19 +3191,19 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3179
3191
|
// Skip this check for relative imports.
|
3180
3192
|
const nodeModule = node.nodeType === 26 /* ParseNodeType.ImportFromAs */
|
3181
3193
|
? ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 25 /* ParseNodeType.ImportFrom */
|
3182
|
-
? (_b = node.parent) === null || _b === void 0 ? void 0 : _b.module
|
3194
|
+
? (_b = node.parent) === null || _b === void 0 ? void 0 : _b.d.module
|
3183
3195
|
: undefined
|
3184
|
-
: node.module;
|
3185
|
-
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) {
|
3186
3198
|
return;
|
3187
3199
|
}
|
3188
3200
|
// Otherwise use the name to determine if a match for a stdlib module.
|
3189
3201
|
const namePartNodes = node.nodeType === 24 /* ParseNodeType.ImportAs */
|
3190
|
-
? node.module.nameParts
|
3202
|
+
? node.d.module.d.nameParts
|
3191
3203
|
: node.nodeType === 26 /* ParseNodeType.ImportFromAs */
|
3192
|
-
? [node.name]
|
3193
|
-
: node.module.nameParts;
|
3194
|
-
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);
|
3195
3207
|
const module = {
|
3196
3208
|
nameParts,
|
3197
3209
|
leadingDots: 0,
|
@@ -3234,10 +3246,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3234
3246
|
return;
|
3235
3247
|
}
|
3236
3248
|
// Ignore privates in named arguments.
|
3237
|
-
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) {
|
3238
3250
|
return;
|
3239
3251
|
}
|
3240
|
-
const nameValue = node.value;
|
3252
|
+
const nameValue = node.d.value;
|
3241
3253
|
const isPrivateName = SymbolNameUtils.isPrivateName(nameValue);
|
3242
3254
|
const isProtectedName = SymbolNameUtils.isProtectedName(nameValue);
|
3243
3255
|
// If it's not a protected or private name, don't bother with
|
@@ -3325,9 +3337,9 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3325
3337
|
// Validates that an enum class does not attempt to override another
|
3326
3338
|
// enum class that has already defined values.
|
3327
3339
|
_validateEnumClassOverride(node, classType) {
|
3328
|
-
classType.
|
3340
|
+
classType.shared.baseClasses.forEach((baseClass, index) => {
|
3329
3341
|
if ((0, types_1.isClass)(baseClass) && (0, enums_1.isEnumClassWithMembers)(this._evaluator, baseClass)) {
|
3330
|
-
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]);
|
3331
3343
|
}
|
3332
3344
|
});
|
3333
3345
|
}
|
@@ -3338,10 +3350,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3338
3350
|
const emitBadStatementError = (node) => {
|
3339
3351
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typedDictBadVar(), node);
|
3340
3352
|
};
|
3341
|
-
suiteNode.statements.forEach((statement) => {
|
3353
|
+
suiteNode.d.statements.forEach((statement) => {
|
3342
3354
|
if (!AnalyzerNodeInfo.isCodeUnreachable(statement)) {
|
3343
3355
|
if (statement.nodeType === 47 /* ParseNodeType.StatementList */) {
|
3344
|
-
for (const substatement of statement.statements) {
|
3356
|
+
for (const substatement of statement.d.statements) {
|
3345
3357
|
if (substatement.nodeType !== 54 /* ParseNodeType.TypeAnnotation */ &&
|
3346
3358
|
substatement.nodeType !== 21 /* ParseNodeType.Ellipsis */ &&
|
3347
3359
|
substatement.nodeType !== 48 /* ParseNodeType.StringList */ &&
|
@@ -3358,11 +3370,13 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3358
3370
|
}
|
3359
3371
|
_validateTypeGuardFunction(node, functionType, isMethod) {
|
3360
3372
|
var _a;
|
3361
|
-
const returnType = functionType.
|
3373
|
+
const returnType = functionType.shared.declaredReturnType;
|
3362
3374
|
if (!returnType) {
|
3363
3375
|
return;
|
3364
3376
|
}
|
3365
|
-
if (!(0, types_1.isClassInstance)(returnType) ||
|
3377
|
+
if (!(0, types_1.isClassInstance)(returnType) ||
|
3378
|
+
!returnType.priv.typeArguments ||
|
3379
|
+
returnType.priv.typeArguments.length < 1) {
|
3366
3380
|
return;
|
3367
3381
|
}
|
3368
3382
|
const isTypeGuard = types_1.ClassType.isBuiltIn(returnType, 'TypeGuard');
|
@@ -3371,7 +3385,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3371
3385
|
return;
|
3372
3386
|
}
|
3373
3387
|
// Make sure there's at least one input parameter provided.
|
3374
|
-
let paramCount = functionType.
|
3388
|
+
let paramCount = functionType.shared.parameters.length;
|
3375
3389
|
if (isMethod) {
|
3376
3390
|
if (types_1.FunctionType.isInstanceMethod(functionType) ||
|
3377
3391
|
types_1.FunctionType.isConstructorMethod(functionType) ||
|
@@ -3380,19 +3394,19 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3380
3394
|
}
|
3381
3395
|
}
|
3382
3396
|
if (paramCount < 1) {
|
3383
|
-
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);
|
3384
3398
|
}
|
3385
3399
|
if (isTypeIs) {
|
3386
|
-
const typeGuardType = returnType.typeArguments[0];
|
3400
|
+
const typeGuardType = returnType.priv.typeArguments[0];
|
3387
3401
|
// Determine the type of the first parameter.
|
3388
3402
|
const paramIndex = isMethod && !types_1.FunctionType.isStaticMethod(functionType) ? 1 : 0;
|
3389
|
-
if (paramIndex >= functionType.
|
3403
|
+
if (paramIndex >= functionType.shared.parameters.length) {
|
3390
3404
|
return;
|
3391
3405
|
}
|
3392
3406
|
const paramType = types_1.FunctionType.getEffectiveParameterType(functionType, paramIndex);
|
3393
3407
|
// Verify that the typeGuardType is a narrower type than the paramType.
|
3394
3408
|
if (!this._evaluator.assignType(paramType, typeGuardType)) {
|
3395
|
-
const returnAnnotation = node.
|
3409
|
+
const returnAnnotation = node.d.returnAnnotation || ((_a = node.d.funcAnnotationComment) === null || _a === void 0 ? void 0 : _a.d.returnAnnotation);
|
3396
3410
|
if (returnAnnotation) {
|
3397
3411
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeIsReturnType().format({
|
3398
3412
|
type: this._evaluator.printType(paramType),
|
@@ -3404,11 +3418,11 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3404
3418
|
}
|
3405
3419
|
_validateDunderSignatures(node, functionType, isMethod) {
|
3406
3420
|
var _a;
|
3407
|
-
const functionName = functionType.
|
3421
|
+
const functionName = functionType.shared.name;
|
3408
3422
|
// Is this an '__init__' method? Verify that it returns None.
|
3409
3423
|
if (isMethod && functionName === '__init__') {
|
3410
|
-
const returnAnnotation = node.
|
3411
|
-
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;
|
3412
3426
|
if (returnAnnotation && declaredReturnType) {
|
3413
3427
|
if (!(0, typeUtils_1.isNoneInstance)(declaredReturnType) && !(0, types_1.isNever)(declaredReturnType)) {
|
3414
3428
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.initMustReturnNone(), returnAnnotation);
|
@@ -3419,7 +3433,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3419
3433
|
if (!(0, types_1.isNever)(inferredReturnType) &&
|
3420
3434
|
!(0, typeUtils_1.isNoneInstance)(inferredReturnType) &&
|
3421
3435
|
!(0, types_1.isAnyOrUnknown)(inferredReturnType)) {
|
3422
|
-
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);
|
3423
3437
|
}
|
3424
3438
|
}
|
3425
3439
|
}
|
@@ -3431,11 +3445,11 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3431
3445
|
if (this._fileInfo.isStubFile) {
|
3432
3446
|
return;
|
3433
3447
|
}
|
3434
|
-
const returnAnnotation = node.
|
3448
|
+
const returnAnnotation = node.d.returnAnnotation || ((_a = node.d.funcAnnotationComment) === null || _a === void 0 ? void 0 : _a.d.returnAnnotation);
|
3435
3449
|
if (returnAnnotation) {
|
3436
3450
|
const functionNeverReturns = !this._evaluator.isAfterNodeReachable(node);
|
3437
|
-
const implicitlyReturnsNone = this._evaluator.isAfterNodeReachable(node.suite);
|
3438
|
-
let declaredReturnType = functionType.
|
3451
|
+
const implicitlyReturnsNone = this._evaluator.isAfterNodeReachable(node.d.suite);
|
3452
|
+
let declaredReturnType = functionType.shared.declaredReturnType;
|
3439
3453
|
if (declaredReturnType) {
|
3440
3454
|
this._reportUnknownReturnResult(node, declaredReturnType);
|
3441
3455
|
this._validateReturnTypeIsNotContravariant(declaredReturnType, returnAnnotation);
|
@@ -3452,7 +3466,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3452
3466
|
// If the function consists entirely of "...", assume that it's
|
3453
3467
|
// an abstract method or a protocol method and don't require that
|
3454
3468
|
// the return type matches. This check can also be skipped for an overload.
|
3455
|
-
if (!ParseTreeUtils.isSuiteEmpty(node.suite) &&
|
3469
|
+
if (!ParseTreeUtils.isSuiteEmpty(node.d.suite) &&
|
3456
3470
|
!types_1.FunctionType.isOverloaded(functionType) &&
|
3457
3471
|
!types_1.FunctionType.isAsync(functionType)) {
|
3458
3472
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportReturnType, localize_1.LocMessage.noReturnReturnsNone(), returnAnnotation);
|
@@ -3467,7 +3481,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3467
3481
|
// If the function consists entirely of "...", assume that it's
|
3468
3482
|
// an abstract method or a protocol method and don't require that
|
3469
3483
|
// the return type matches. This check can also be skipped for an overload.
|
3470
|
-
if (!ParseTreeUtils.isSuiteEmpty(node.suite) && !types_1.FunctionType.isOverloaded(functionType)) {
|
3484
|
+
if (!ParseTreeUtils.isSuiteEmpty(node.d.suite) && !types_1.FunctionType.isOverloaded(functionType)) {
|
3471
3485
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportReturnType, localize_1.LocMessage.returnMissing().format({
|
3472
3486
|
returnType: this._evaluator.printType(declaredReturnType),
|
3473
3487
|
}) + diagAddendum.getString(), returnAnnotation);
|
@@ -3479,15 +3493,15 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3479
3493
|
else {
|
3480
3494
|
const inferredReturnType = this._evaluator.getFunctionInferredReturnType(functionType);
|
3481
3495
|
this._reportUnknownReturnResult(node, inferredReturnType);
|
3482
|
-
this._validateReturnTypeIsNotContravariant(inferredReturnType, node.name);
|
3496
|
+
this._validateReturnTypeIsNotContravariant(inferredReturnType, node.d.name);
|
3483
3497
|
}
|
3484
3498
|
}
|
3485
3499
|
_validateReturnTypeIsNotContravariant(returnType, errorNode) {
|
3486
3500
|
let isContraTypeVar = false;
|
3487
3501
|
(0, typeUtils_1.doForEachSubtype)(returnType, (subtype) => {
|
3488
3502
|
if ((0, types_1.isTypeVar)(subtype) &&
|
3489
|
-
subtype.
|
3490
|
-
subtype.scopeType === 0 /* TypeVarScopeType.Class */) {
|
3503
|
+
subtype.shared.declaredVariance === 4 /* Variance.Contravariant */ &&
|
3504
|
+
subtype.priv.scopeType === 0 /* TypeVarScopeType.Class */) {
|
3491
3505
|
isContraTypeVar = true;
|
3492
3506
|
}
|
3493
3507
|
});
|
@@ -3497,12 +3511,12 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3497
3511
|
}
|
3498
3512
|
_reportUnknownReturnResult(node, returnType) {
|
3499
3513
|
if ((0, types_1.isUnknown)(returnType)) {
|
3500
|
-
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);
|
3501
3515
|
}
|
3502
3516
|
else if ((0, typeUtils_1.isPartlyUnknown)(returnType)) {
|
3503
3517
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnknownParameterType, localize_1.LocMessage.returnTypePartiallyUnknown().format({
|
3504
3518
|
returnType: this._evaluator.printType(returnType, { expandTypeAlias: true }),
|
3505
|
-
}), node.name);
|
3519
|
+
}), node.d.name);
|
3506
3520
|
}
|
3507
3521
|
}
|
3508
3522
|
// Validates that any overridden member variables are not marked
|
@@ -3516,7 +3530,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3516
3530
|
const decl = localSymbol.getDeclarations()[0];
|
3517
3531
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.finalRedeclarationBySubclass().format({
|
3518
3532
|
name,
|
3519
|
-
className: parentSymbol.classType.
|
3533
|
+
className: parentSymbol.classType.shared.name,
|
3520
3534
|
}), decl.node);
|
3521
3535
|
}
|
3522
3536
|
else if (types_1.ClassType.isReadOnlyInstanceVariables(parentSymbol.classType) &&
|
@@ -3527,7 +3541,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3527
3541
|
if (decl.type === 1 /* DeclarationType.Variable */) {
|
3528
3542
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompatibleVariableOverride, localize_1.LocMessage.namedTupleEntryRedeclared().format({
|
3529
3543
|
name,
|
3530
|
-
className: parentSymbol.classType.
|
3544
|
+
className: parentSymbol.classType.shared.name,
|
3531
3545
|
}), decl.node);
|
3532
3546
|
}
|
3533
3547
|
}
|
@@ -3544,7 +3558,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3544
3558
|
const declaredValueType = (0, enums_1.getEnumDeclaredValueType)(this._evaluator, classType, /* declaredTypesOnly */ true);
|
3545
3559
|
// Is there a custom "__new__" and/or "__init__" method? If so, we'll
|
3546
3560
|
// verify that the signature of these calls is compatible with the values.
|
3547
|
-
let newMemberTypeResult = (0, constructors_1.getBoundNewMethod)(this._evaluator, node.name, classType,
|
3561
|
+
let newMemberTypeResult = (0, constructors_1.getBoundNewMethod)(this._evaluator, node.d.name, classType,
|
3548
3562
|
/* diag */ undefined, 4 /* MemberAccessFlags.SkipObjectBaseClass */);
|
3549
3563
|
// If this __new__ comes from a built-in class like Enum, we'll ignore it.
|
3550
3564
|
if (newMemberTypeResult === null || newMemberTypeResult === void 0 ? void 0 : newMemberTypeResult.classType) {
|
@@ -3552,7 +3566,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3552
3566
|
newMemberTypeResult = undefined;
|
3553
3567
|
}
|
3554
3568
|
}
|
3555
|
-
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),
|
3556
3570
|
/* diag */ undefined, 4 /* MemberAccessFlags.SkipObjectBaseClass */);
|
3557
3571
|
// If this __init__ comes from a built-in class like Enum, we'll ignore it.
|
3558
3572
|
if (initMemberTypeResult === null || initMemberTypeResult === void 0 ? void 0 : initMemberTypeResult.classType) {
|
@@ -3573,7 +3587,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3573
3587
|
if (!symbolType ||
|
3574
3588
|
!(0, types_1.isClassInstance)(symbolType) ||
|
3575
3589
|
!types_1.ClassType.isSameGenericClass(symbolType, classType) ||
|
3576
|
-
!(symbolType.literalValue instanceof types_1.EnumLiteral)) {
|
3590
|
+
!(symbolType.priv.literalValue instanceof types_1.EnumLiteral)) {
|
3577
3591
|
return;
|
3578
3592
|
}
|
3579
3593
|
// Enum members should not have type annotations.
|
@@ -3594,9 +3608,9 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3594
3608
|
return;
|
3595
3609
|
}
|
3596
3610
|
const declNode = decls[0].node;
|
3597
|
-
const assignedValueType = symbolType.literalValue.itemType;
|
3611
|
+
const assignedValueType = symbolType.priv.literalValue.itemType;
|
3598
3612
|
const assignmentNode = ParseTreeUtils.getParentNodeOfType(declNode, 3 /* ParseNodeType.Assignment */);
|
3599
|
-
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;
|
3600
3614
|
// Validate the __new__ and __init__ methods if present.
|
3601
3615
|
if (newMemberTypeResult || initMemberTypeResult) {
|
3602
3616
|
if (!(0, types_1.isAnyOrUnknown)(assignedValueType)) {
|
@@ -3640,7 +3654,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3640
3654
|
}
|
3641
3655
|
// If a class is a dataclass with a `__post_init__` method, verify that its
|
3642
3656
|
// signature is correct.
|
3643
|
-
_validateDataClassPostInit(classType
|
3657
|
+
_validateDataClassPostInit(classType) {
|
3644
3658
|
if (!types_1.ClassType.isDataClass(classType)) {
|
3645
3659
|
return;
|
3646
3660
|
}
|
@@ -3667,7 +3681,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3667
3681
|
const postInitType = this._evaluator.getTypeOfMember(postInitMember);
|
3668
3682
|
if (!(0, types_1.isFunction)(postInitType) ||
|
3669
3683
|
!types_1.FunctionType.isInstanceMethod(postInitType) ||
|
3670
|
-
!postInitType.
|
3684
|
+
!postInitType.shared.declaration) {
|
3671
3685
|
return;
|
3672
3686
|
}
|
3673
3687
|
const paramListDetails = (0, parameterUtils_1.getParameterListDetails)(postInitType);
|
@@ -3679,26 +3693,29 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3679
3693
|
return;
|
3680
3694
|
}
|
3681
3695
|
// Verify that the parameter count matches.
|
3682
|
-
const nonDefaultParams = paramListDetails.params.filter((paramInfo) => !paramInfo.param.
|
3696
|
+
const nonDefaultParams = paramListDetails.params.filter((paramInfo) => !paramInfo.param.defaultType);
|
3683
3697
|
// We expect to see one param for "self" plus one for each of the InitVars.
|
3684
3698
|
const expectedParamCount = initOnlySymbolMap.size + 1;
|
3699
|
+
const postInitNode = postInitType.shared.declaration.node;
|
3685
3700
|
if (expectedParamCount < nonDefaultParams.length || expectedParamCount > paramListDetails.params.length) {
|
3686
|
-
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);
|
3687
3702
|
}
|
3688
3703
|
// Verify that the parameter types match.
|
3689
3704
|
let paramIndex = 1;
|
3690
3705
|
initOnlySymbolMap.forEach((symbol, fieldName) => {
|
3691
|
-
var _a;
|
3706
|
+
var _a, _b;
|
3692
3707
|
if (paramIndex >= paramListDetails.params.length) {
|
3693
3708
|
return;
|
3694
3709
|
}
|
3695
3710
|
const param = paramListDetails.params[paramIndex].param;
|
3696
|
-
|
3697
|
-
|
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;
|
3698
3715
|
const paramType = types_1.FunctionType.getEffectiveParameterType(postInitType, paramListDetails.params[paramIndex].index);
|
3699
3716
|
const assignTypeDiag = new diagnostic_1.DiagnosticAddendum();
|
3700
3717
|
if (fieldType && !this._evaluator.assignType(paramType, fieldType, assignTypeDiag)) {
|
3701
|
-
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);
|
3702
3719
|
if (diagnostic) {
|
3703
3720
|
const fieldDecls = symbol.getTypedDeclarations();
|
3704
3721
|
if (fieldDecls.length > 0) {
|
@@ -3733,7 +3750,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3733
3750
|
}
|
3734
3751
|
else if (index < errorsToDisplay) {
|
3735
3752
|
if ((0, types_1.isInstantiableClass)(abstractMethod.classType)) {
|
3736
|
-
const className = abstractMethod.classType.
|
3753
|
+
const className = abstractMethod.classType.shared.name;
|
3737
3754
|
diagAddendum.addMessage(localize_1.LocAddendum.memberIsAbstract().format({
|
3738
3755
|
type: className,
|
3739
3756
|
name: abstractMethod.symbolName,
|
@@ -3742,8 +3759,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3742
3759
|
}
|
3743
3760
|
});
|
3744
3761
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.finalClassIsAbstract().format({
|
3745
|
-
type: classType.
|
3746
|
-
}) + diagAddendum.getString(), errorNode.name);
|
3762
|
+
type: classType.shared.name,
|
3763
|
+
}) + diagAddendum.getString(), errorNode.d.name);
|
3747
3764
|
}
|
3748
3765
|
// Reports the case where an instance variable is not declared or initialized
|
3749
3766
|
// within the class body or constructor method.
|
@@ -3812,7 +3829,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3812
3829
|
return true;
|
3813
3830
|
}
|
3814
3831
|
}
|
3815
|
-
if (containingClass.name.value === '__init__') {
|
3832
|
+
if (containingClass.d.name.d.value === '__init__') {
|
3816
3833
|
return true;
|
3817
3834
|
}
|
3818
3835
|
return false;
|
@@ -3855,12 +3872,12 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3855
3872
|
}
|
3856
3873
|
diagAddendum.addMessage(localize_1.LocAddendum.uninitializedAbstractVariable().format({
|
3857
3874
|
name,
|
3858
|
-
classType: member.classType.
|
3875
|
+
classType: member.classType.shared.name,
|
3859
3876
|
}));
|
3860
3877
|
});
|
3861
3878
|
if (!diagAddendum.isEmpty()) {
|
3862
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUninitializedInstanceVariable, localize_1.LocMessage.uninitializedAbstractVariables().format({ classType: classType.
|
3863
|
-
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);
|
3864
3881
|
}
|
3865
3882
|
}
|
3866
3883
|
// Validates that the type variables used in a generic protocol class have
|
@@ -3868,7 +3885,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3868
3885
|
// for an explanation for why this is important to enforce.
|
3869
3886
|
_validateProtocolTypeParamVariance(errorNode, classType) {
|
3870
3887
|
// If this protocol has no TypeVars with specified variance, there's nothing to do here.
|
3871
|
-
if (classType.
|
3888
|
+
if (classType.shared.typeParameters.length === 0) {
|
3872
3889
|
return;
|
3873
3890
|
}
|
3874
3891
|
const objectType = this._evaluator.getBuiltInType(errorNode, 'object');
|
@@ -3877,27 +3894,27 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3877
3894
|
}
|
3878
3895
|
const objectObject = types_1.ClassType.cloneAsInstance(objectType);
|
3879
3896
|
const dummyTypeObject = types_1.ClassType.createInstantiable('__varianceDummy', '', '', uri_1.Uri.empty(), 0, 0, undefined, undefined);
|
3880
|
-
classType.
|
3897
|
+
classType.shared.typeParameters.forEach((param, paramIndex) => {
|
3881
3898
|
// Skip variadics and ParamSpecs.
|
3882
|
-
if (param.
|
3899
|
+
if (param.shared.isVariadic || param.shared.isParamSpec) {
|
3883
3900
|
return;
|
3884
3901
|
}
|
3885
3902
|
// Skip type variables with auto-variance.
|
3886
|
-
if (param.
|
3903
|
+
if (param.shared.declaredVariance === 0 /* Variance.Auto */) {
|
3887
3904
|
return;
|
3888
3905
|
}
|
3889
3906
|
// Replace all type arguments with a dummy type except for the
|
3890
3907
|
// TypeVar of interest, which is replaced with an object instance.
|
3891
|
-
const srcTypeArgs = classType.
|
3892
|
-
if (p.
|
3908
|
+
const srcTypeArgs = classType.shared.typeParameters.map((p, i) => {
|
3909
|
+
if (p.shared.isVariadic) {
|
3893
3910
|
return p;
|
3894
3911
|
}
|
3895
3912
|
return i === paramIndex ? objectObject : dummyTypeObject;
|
3896
3913
|
});
|
3897
3914
|
// Replace all type arguments with a dummy type except for the
|
3898
3915
|
// TypeVar of interest, which is replaced with itself.
|
3899
|
-
const destTypeArgs = classType.
|
3900
|
-
return i === paramIndex || p.
|
3916
|
+
const destTypeArgs = classType.shared.typeParameters.map((p, i) => {
|
3917
|
+
return i === paramIndex || p.shared.isVariadic ? p : dummyTypeObject;
|
3901
3918
|
});
|
3902
3919
|
const srcType = types_1.ClassType.cloneForSpecialization(classType, srcTypeArgs, /* isTypeArgumentExplicit */ true);
|
3903
3920
|
const destType = types_1.ClassType.cloneForSpecialization(classType, destTypeArgs,
|
@@ -3916,34 +3933,34 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3916
3933
|
expectedVariance = 2 /* Variance.Invariant */;
|
3917
3934
|
}
|
3918
3935
|
}
|
3919
|
-
if (expectedVariance !== classType.
|
3936
|
+
if (expectedVariance !== classType.shared.typeParameters[paramIndex].shared.declaredVariance) {
|
3920
3937
|
let message;
|
3921
3938
|
if (expectedVariance === 3 /* Variance.Covariant */) {
|
3922
3939
|
message = localize_1.LocMessage.protocolVarianceCovariant().format({
|
3923
|
-
variable: param.
|
3924
|
-
class: classType.
|
3940
|
+
variable: param.shared.name,
|
3941
|
+
class: classType.shared.name,
|
3925
3942
|
});
|
3926
3943
|
}
|
3927
3944
|
else if (expectedVariance === 4 /* Variance.Contravariant */) {
|
3928
3945
|
message = localize_1.LocMessage.protocolVarianceContravariant().format({
|
3929
|
-
variable: param.
|
3930
|
-
class: classType.
|
3946
|
+
variable: param.shared.name,
|
3947
|
+
class: classType.shared.name,
|
3931
3948
|
});
|
3932
3949
|
}
|
3933
3950
|
else {
|
3934
3951
|
message = localize_1.LocMessage.protocolVarianceInvariant().format({
|
3935
|
-
variable: param.
|
3936
|
-
class: classType.
|
3952
|
+
variable: param.shared.name,
|
3953
|
+
class: classType.shared.name,
|
3937
3954
|
});
|
3938
3955
|
}
|
3939
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeVarUse, message, errorNode.name);
|
3956
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeVarUse, message, errorNode.d.name);
|
3940
3957
|
}
|
3941
3958
|
});
|
3942
3959
|
}
|
3943
3960
|
// Validates that a class variable doesn't conflict with a __slots__
|
3944
3961
|
// name. This will generate a runtime exception.
|
3945
3962
|
_validateSlotsClassVarConflict(classType) {
|
3946
|
-
if (!classType.
|
3963
|
+
if (!classType.shared.localSlotsNames) {
|
3947
3964
|
// Nothing to check, since this class doesn't use __slots__.
|
3948
3965
|
return;
|
3949
3966
|
}
|
@@ -4025,8 +4042,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4025
4042
|
// We'll set the "SkipArgsKwargs" flag for pragmatic reasons since __new__
|
4026
4043
|
// often has an *args and/or **kwargs. We'll also set the ParamSpecValue
|
4027
4044
|
// because we don't care about the return type for this check.
|
4028
|
-
initMemberType = types_1.FunctionType.cloneWithNewFlags(initMemberType, initMemberType.
|
4029
|
-
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 */);
|
4030
4047
|
if (!this._evaluator.assignType(newMemberType, initMemberType,
|
4031
4048
|
/* diag */ undefined,
|
4032
4049
|
/* destTypeVarContext */ undefined,
|
@@ -4036,11 +4053,11 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4036
4053
|
/* destTypeVarContext */ undefined,
|
4037
4054
|
/* srcTypeVarContext */ undefined, 64 /* AssignTypeFlags.SkipFunctionReturnTypeCheck */)) {
|
4038
4055
|
const displayOnInit = types_1.ClassType.isSameGenericClass(initMethodResult.classType, classType);
|
4039
|
-
const initDecl = initMemberType.
|
4040
|
-
const newDecl = newMemberType.
|
4056
|
+
const initDecl = initMemberType.shared.declaration;
|
4057
|
+
const newDecl = newMemberType.shared.declaration;
|
4041
4058
|
if (initDecl && newDecl) {
|
4042
4059
|
const mainDecl = displayOnInit ? initDecl : newDecl;
|
4043
|
-
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;
|
4044
4061
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
4045
4062
|
const initSignature = this._evaluator.printType(initMemberType);
|
4046
4063
|
const newSignature = this._evaluator.printType(newMemberType);
|
@@ -4068,7 +4085,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4068
4085
|
// Skip this check if the class has only one base class or one or more
|
4069
4086
|
// of the base classes are Any.
|
4070
4087
|
const filteredBaseClasses = [];
|
4071
|
-
for (const baseClass of classType.
|
4088
|
+
for (const baseClass of classType.shared.baseClasses) {
|
4072
4089
|
if (!(0, types_1.isClass)(baseClass)) {
|
4073
4090
|
return;
|
4074
4091
|
}
|
@@ -4082,12 +4099,12 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4082
4099
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
4083
4100
|
for (const baseClass of filteredBaseClasses) {
|
4084
4101
|
const typeVarContext = (0, typeUtils_1.buildTypeVarContextFromSpecializedClass)(baseClass);
|
4085
|
-
for (const baseClassMroClass of baseClass.
|
4102
|
+
for (const baseClassMroClass of baseClass.shared.mro) {
|
4086
4103
|
// There's no need to check for conflicts if this class isn't generic.
|
4087
|
-
if ((0, types_1.isClass)(baseClassMroClass) && baseClassMroClass.
|
4104
|
+
if ((0, types_1.isClass)(baseClassMroClass) && baseClassMroClass.shared.typeParameters.length > 0) {
|
4088
4105
|
const specializedBaseClassMroClass = (0, typeUtils_1.applySolvedTypeVars)(baseClassMroClass, typeVarContext);
|
4089
4106
|
// Find the corresponding class in the derived class's MRO list.
|
4090
|
-
const matchingMroClass = classType.
|
4107
|
+
const matchingMroClass = classType.shared.mro.find((mroClass) => (0, types_1.isClass)(mroClass) && types_1.ClassType.isSameGenericClass(mroClass, specializedBaseClassMroClass));
|
4091
4108
|
if (matchingMroClass && (0, types_1.isInstantiableClass)(matchingMroClass)) {
|
4092
4109
|
const matchingMroObject = types_1.ClassType.cloneAsInstance(matchingMroClass);
|
4093
4110
|
const baseClassMroObject = types_1.ClassType.cloneAsInstance(specializedBaseClassMroClass);
|
@@ -4116,7 +4133,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4116
4133
|
}
|
4117
4134
|
}
|
4118
4135
|
if (!diagAddendum.isEmpty()) {
|
4119
|
-
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);
|
4120
4137
|
}
|
4121
4138
|
}
|
4122
4139
|
// Validates that any methods and variables in multiple base classes are
|
@@ -4131,7 +4148,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4131
4148
|
const baseClasses = [];
|
4132
4149
|
// Filter any unknown base classes. Also remove Generic and Protocol
|
4133
4150
|
// base classes.
|
4134
|
-
classType.
|
4151
|
+
classType.shared.baseClasses.forEach((baseClass) => {
|
4135
4152
|
if ((0, types_1.isClass)(baseClass) &&
|
4136
4153
|
!types_1.ClassType.isBuiltIn(baseClass, 'Generic') &&
|
4137
4154
|
!types_1.ClassType.isBuiltIn(baseClass, 'Protocol')) {
|
@@ -4144,7 +4161,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4144
4161
|
}
|
4145
4162
|
// Build maps of symbols for each of the base classes.
|
4146
4163
|
const baseClassSymbolMaps = baseClasses.map((baseClass) => {
|
4147
|
-
const specializedBaseClass = classType.
|
4164
|
+
const specializedBaseClass = classType.shared.mro.find((c) => (0, types_1.isClass)(c) && types_1.ClassType.isSameGenericClass(c, baseClass));
|
4148
4165
|
if (!specializedBaseClass || !(0, types_1.isClass)(specializedBaseClass)) {
|
4149
4166
|
return new Map();
|
4150
4167
|
}
|
@@ -4220,10 +4237,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4220
4237
|
if (!this._evaluator.validateOverrideMethod(overriddenType, overrideFunction,
|
4221
4238
|
/* baseClass */ undefined, diagAddendum,
|
4222
4239
|
/* enforceParamNameMatch */ true)) {
|
4223
|
-
const decl = overrideFunction.
|
4240
|
+
const decl = overrideFunction.shared.declaration;
|
4224
4241
|
if (decl && decl.type === 5 /* DeclarationType.Function */) {
|
4225
4242
|
diag = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompatibleMethodOverride, localize_1.LocMessage.baseClassMethodTypeIncompatible().format({
|
4226
|
-
classType: childClassType.
|
4243
|
+
classType: childClassType.shared.name,
|
4227
4244
|
name: memberName,
|
4228
4245
|
}) + diagAddendum.getString(), errorNode);
|
4229
4246
|
}
|
@@ -4236,7 +4253,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4236
4253
|
const decls = overrideSymbol.getDeclarations();
|
4237
4254
|
if (decls.length > 0) {
|
4238
4255
|
diag = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompatibleVariableOverride, localize_1.LocMessage.baseClassVariableTypeIncompatible().format({
|
4239
|
-
classType: childClassType.
|
4256
|
+
classType: childClassType.shared.name,
|
4240
4257
|
name: memberName,
|
4241
4258
|
}), errorNode);
|
4242
4259
|
}
|
@@ -4254,31 +4271,31 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4254
4271
|
// If the entry is a member of a frozen dataclass, it is immutable,
|
4255
4272
|
// so it does not need to be invariant.
|
4256
4273
|
if (types_1.ClassType.isDataClassFrozen(overriddenClassAndSymbol.classType) &&
|
4257
|
-
overriddenClassAndSymbol.classType.
|
4258
|
-
const dataclassEntry = overriddenClassAndSymbol.classType.
|
4274
|
+
overriddenClassAndSymbol.classType.shared.dataClassEntries) {
|
4275
|
+
const dataclassEntry = overriddenClassAndSymbol.classType.shared.dataClassEntries.find((entry) => entry.name === memberName);
|
4259
4276
|
if (dataclassEntry) {
|
4260
4277
|
isInvariant = false;
|
4261
4278
|
}
|
4262
4279
|
}
|
4263
4280
|
let overriddenTDEntry;
|
4264
|
-
if (overriddenClassAndSymbol.classType.
|
4281
|
+
if (overriddenClassAndSymbol.classType.shared.typedDictEntries) {
|
4265
4282
|
overriddenTDEntry =
|
4266
|
-
(_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);
|
4267
4284
|
if (overriddenTDEntry === null || overriddenTDEntry === void 0 ? void 0 : overriddenTDEntry.isReadOnly) {
|
4268
4285
|
isInvariant = false;
|
4269
4286
|
}
|
4270
4287
|
}
|
4271
4288
|
let overrideTDEntry;
|
4272
|
-
if (overrideClassAndSymbol.classType.
|
4289
|
+
if (overrideClassAndSymbol.classType.shared.typedDictEntries) {
|
4273
4290
|
overrideTDEntry =
|
4274
|
-
(_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);
|
4275
4292
|
}
|
4276
4293
|
if (!this._evaluator.assignType(overriddenType, childOverrideType !== null && childOverrideType !== void 0 ? childOverrideType : overrideType,
|
4277
4294
|
/* diag */ undefined,
|
4278
4295
|
/* destTypeVarContext */ undefined,
|
4279
4296
|
/* srcTypeVarContext */ undefined, isInvariant ? 1 /* AssignTypeFlags.EnforceInvariance */ : 0 /* AssignTypeFlags.Default */)) {
|
4280
4297
|
diag = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompatibleVariableOverride, localize_1.LocMessage.baseClassVariableTypeIncompatible().format({
|
4281
|
-
classType: childClassType.
|
4298
|
+
classType: childClassType.shared.name,
|
4282
4299
|
name: memberName,
|
4283
4300
|
}), errorNode);
|
4284
4301
|
}
|
@@ -4324,9 +4341,9 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4324
4341
|
}
|
4325
4342
|
_validateMultipleInheritancePropertyOverride(overriddenClassType, overrideClassType, overriddenSymbolType, overrideSymbolType, overrideSymbol, memberName, errorNode) {
|
4326
4343
|
const propMethodInfo = [
|
4327
|
-
['fget', (c) => { var _a; return (_a = c.fgetInfo) === null || _a === void 0 ? void 0 : _a.methodType; }],
|
4328
|
-
['fset', (c) => { var _a; return (_a = c.fsetInfo) === null || _a === void 0 ? void 0 : _a.methodType; }],
|
4329
|
-
['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; }],
|
4330
4347
|
];
|
4331
4348
|
propMethodInfo.forEach((info) => {
|
4332
4349
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
@@ -4347,9 +4364,9 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4347
4364
|
const lastDecl = decls[decls.length - 1];
|
4348
4365
|
const diag = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompatibleMethodOverride, localize_1.LocMessage.propertyOverridden().format({
|
4349
4366
|
name: memberName,
|
4350
|
-
className: overriddenClassType.
|
4367
|
+
className: overriddenClassType.shared.name,
|
4351
4368
|
}) + diagAddendum.getString(), errorNode);
|
4352
|
-
const origDecl = baseClassMethodType.
|
4369
|
+
const origDecl = baseClassMethodType.shared.declaration;
|
4353
4370
|
if (diag && origDecl) {
|
4354
4371
|
this._addMultipleInheritanceRelatedInfo(diag, overriddenClassType, overriddenSymbolType, origDecl, overrideClassType, overrideSymbolType, lastDecl);
|
4355
4372
|
}
|
@@ -4362,13 +4379,13 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4362
4379
|
diagAddendum.addMessage(localize_1.LocAddendum.propertyMethodIncompatible().format({
|
4363
4380
|
name: methodName,
|
4364
4381
|
}));
|
4365
|
-
const decl = subclassMethodType.
|
4382
|
+
const decl = subclassMethodType.shared.declaration;
|
4366
4383
|
if (decl && decl.type === 5 /* DeclarationType.Function */) {
|
4367
4384
|
const diag = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompatibleMethodOverride, localize_1.LocMessage.propertyOverridden().format({
|
4368
4385
|
name: memberName,
|
4369
|
-
className: overriddenClassType.
|
4386
|
+
className: overriddenClassType.shared.name,
|
4370
4387
|
}) + diagAddendum.getString(), errorNode);
|
4371
|
-
const origDecl = baseClassMethodType.
|
4388
|
+
const origDecl = baseClassMethodType.shared.declaration;
|
4372
4389
|
if (diag && origDecl) {
|
4373
4390
|
this._addMultipleInheritanceRelatedInfo(diag, overriddenClassType, overriddenSymbolType, origDecl, overrideClassType, overrideSymbolType, decl);
|
4374
4391
|
}
|
@@ -4403,10 +4420,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4403
4420
|
if (!types_1.FunctionType.isFinal(implementation)) {
|
4404
4421
|
overloads.forEach((overload) => {
|
4405
4422
|
var _a, _b;
|
4406
|
-
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)) {
|
4407
4424
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInconsistentOverload, localize_1.LocMessage.overloadFinalInconsistencyImpl().format({
|
4408
|
-
name: overload.
|
4409
|
-
}), (_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);
|
4410
4427
|
}
|
4411
4428
|
});
|
4412
4429
|
}
|
@@ -4415,11 +4432,11 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4415
4432
|
if (!types_1.FunctionType.isFinal(overloads[0])) {
|
4416
4433
|
overloads.slice(1).forEach((overload, index) => {
|
4417
4434
|
var _a, _b;
|
4418
|
-
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)) {
|
4419
4436
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInconsistentOverload, localize_1.LocMessage.overloadFinalInconsistencyNoImpl().format({
|
4420
|
-
name: overload.
|
4437
|
+
name: overload.shared.name,
|
4421
4438
|
index: index + 2,
|
4422
|
-
}), (_b = (0, declarationUtils_1.getNameNodeForDeclaration)(overload.
|
4439
|
+
}), (_b = (0, declarationUtils_1.getNameNodeForDeclaration)(overload.shared.declaration)) !== null && _b !== void 0 ? _b : overload.shared.declaration.node);
|
4423
4440
|
}
|
4424
4441
|
});
|
4425
4442
|
}
|
@@ -4433,7 +4450,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4433
4450
|
return;
|
4434
4451
|
}
|
4435
4452
|
const typedDictEntries = (0, typedDicts_1.getTypedDictMembersForClass)(this._evaluator, classType, /* allowNarrowed */ false);
|
4436
|
-
for (const baseClass of classType.
|
4453
|
+
for (const baseClass of classType.shared.baseClasses) {
|
4437
4454
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
4438
4455
|
if (!(0, types_1.isClass)(baseClass) ||
|
4439
4456
|
!types_1.ClassType.isTypedDictClass(baseClass) ||
|
@@ -4485,18 +4502,18 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4485
4502
|
}));
|
4486
4503
|
}
|
4487
4504
|
}
|
4488
|
-
if (!diag.isEmpty() && classType.
|
4489
|
-
const declNode = (0, declarationUtils_1.getNameNodeForDeclaration)(classType.
|
4505
|
+
if (!diag.isEmpty() && classType.shared.declaration) {
|
4506
|
+
const declNode = (0, declarationUtils_1.getNameNodeForDeclaration)(classType.shared.declaration);
|
4490
4507
|
if (declNode) {
|
4491
4508
|
if (baseTypedDictEntries.extraItems) {
|
4492
4509
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompatibleVariableOverride, localize_1.LocMessage.typedDictClosedExtras().format({
|
4493
|
-
name: baseClass.
|
4510
|
+
name: baseClass.shared.name,
|
4494
4511
|
type: this._evaluator.printType(baseExtraItemsType),
|
4495
4512
|
}) + diag.getString(), declNode);
|
4496
4513
|
}
|
4497
4514
|
else {
|
4498
4515
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompatibleVariableOverride, localize_1.LocMessage.typedDictClosedNoExtras().format({
|
4499
|
-
name: baseClass.
|
4516
|
+
name: baseClass.shared.name,
|
4500
4517
|
}) + diag.getString(), declNode);
|
4501
4518
|
}
|
4502
4519
|
}
|
@@ -4528,13 +4545,13 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4528
4545
|
return;
|
4529
4546
|
}
|
4530
4547
|
let firstOverride;
|
4531
|
-
for (const baseClass of classType.
|
4548
|
+
for (const baseClass of classType.shared.baseClasses) {
|
4532
4549
|
if (!(0, types_1.isClass)(baseClass)) {
|
4533
4550
|
continue;
|
4534
4551
|
}
|
4535
4552
|
// Look up the base class in the MRO list. It's the same generic class
|
4536
4553
|
// but has already been specialized using the type variables of the classType.
|
4537
|
-
const mroBaseClass = classType.
|
4554
|
+
const mroBaseClass = classType.shared.mro.find((mroClass) => (0, types_1.isClass)(mroClass) && types_1.ClassType.isSameGenericClass(mroClass, baseClass));
|
4538
4555
|
if (!mroBaseClass) {
|
4539
4556
|
continue;
|
4540
4557
|
}
|
@@ -4569,31 +4586,31 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4569
4586
|
overrideFunction = types_1.OverloadedFunctionType.getImplementation(overrideType);
|
4570
4587
|
}
|
4571
4588
|
else if ((0, types_1.isClassInstance)(overrideType) && types_1.ClassType.isPropertyClass(overrideType)) {
|
4572
|
-
if (overrideType.fgetInfo) {
|
4573
|
-
overrideFunction = overrideType.fgetInfo.methodType;
|
4589
|
+
if (overrideType.priv.fgetInfo) {
|
4590
|
+
overrideFunction = overrideType.priv.fgetInfo.methodType;
|
4574
4591
|
}
|
4575
4592
|
}
|
4576
|
-
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)) {
|
4577
4594
|
return;
|
4578
4595
|
}
|
4579
4596
|
// Constructors are exempt.
|
4580
|
-
if (this._isMethodExemptFromLsp(overrideFunction.
|
4597
|
+
if (this._isMethodExemptFromLsp(overrideFunction.shared.name)) {
|
4581
4598
|
return;
|
4582
4599
|
}
|
4583
4600
|
// If the declaration for the override function is not the same as the
|
4584
4601
|
// declaration for the symbol, the function was probably replaced by a decorator.
|
4585
|
-
if (!symbol.getDeclarations().some((decl) => decl === overrideFunction.
|
4602
|
+
if (!symbol.getDeclarations().some((decl) => decl === overrideFunction.shared.declaration)) {
|
4586
4603
|
return;
|
4587
4604
|
}
|
4588
4605
|
// If the base class is unknown, don't report a missing decorator.
|
4589
4606
|
if ((0, types_1.isAnyOrUnknown)(baseMember.classType)) {
|
4590
4607
|
return;
|
4591
4608
|
}
|
4592
|
-
const funcNode = overrideFunction.
|
4609
|
+
const funcNode = overrideFunction.shared.declaration.node;
|
4593
4610
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportImplicitOverride, localize_1.LocMessage.overrideDecoratorMissing().format({
|
4594
|
-
name: funcNode.name.value,
|
4611
|
+
name: funcNode.d.name.d.value,
|
4595
4612
|
className: this._evaluator.printType((0, typeUtils_1.convertToInstance)(baseMember.classType)),
|
4596
|
-
}), funcNode.name);
|
4613
|
+
}), funcNode.d.name);
|
4597
4614
|
}
|
4598
4615
|
// Determines whether the name is exempt from Liskov Substitution Principle rules.
|
4599
4616
|
_isMethodExemptFromLsp(name) {
|
@@ -4612,20 +4629,20 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4612
4629
|
overrideFunction = types_1.OverloadedFunctionType.getImplementation(overrideType);
|
4613
4630
|
}
|
4614
4631
|
else if ((0, types_1.isClassInstance)(overrideType) && types_1.ClassType.isPropertyClass(overrideType)) {
|
4615
|
-
if (overrideType.fgetInfo) {
|
4616
|
-
overrideFunction = overrideType.fgetInfo.methodType;
|
4632
|
+
if (overrideType.priv.fgetInfo) {
|
4633
|
+
overrideFunction = overrideType.priv.fgetInfo.methodType;
|
4617
4634
|
}
|
4618
4635
|
}
|
4619
|
-
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)) {
|
4620
4637
|
return;
|
4621
4638
|
}
|
4622
4639
|
// If the declaration for the override function is not the same as the
|
4623
4640
|
// declaration for the symbol, the function was probably replaced by a decorator.
|
4624
|
-
if (!symbol.getDeclarations().some((decl) => decl === overrideFunction.
|
4641
|
+
if (!symbol.getDeclarations().some((decl) => decl === overrideFunction.shared.declaration)) {
|
4625
4642
|
return;
|
4626
4643
|
}
|
4627
|
-
const funcNode = overrideFunction.
|
4628
|
-
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);
|
4629
4646
|
}
|
4630
4647
|
_validateBaseClassOverride(baseClassAndSymbol, overrideSymbol, overrideType, childClassType, memberName) {
|
4631
4648
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
@@ -4660,7 +4677,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4660
4677
|
reportFinalMethodOverride = true;
|
4661
4678
|
}
|
4662
4679
|
else if ((0, types_1.isOverloadedFunction)(baseType) &&
|
4663
|
-
baseType.overloads.some((overload) => types_1.FunctionType.isFinal(overload))) {
|
4680
|
+
baseType.priv.overloads.some((overload) => types_1.FunctionType.isFinal(overload))) {
|
4664
4681
|
reportFinalMethodOverride = true;
|
4665
4682
|
}
|
4666
4683
|
}
|
@@ -4669,8 +4686,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4669
4686
|
if (decl && decl.type === 5 /* DeclarationType.Function */) {
|
4670
4687
|
const diag = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompatibleMethodOverride, localize_1.LocMessage.finalMethodOverride().format({
|
4671
4688
|
name: memberName,
|
4672
|
-
className: baseClass.
|
4673
|
-
}), decl.node.name);
|
4689
|
+
className: baseClass.shared.name,
|
4690
|
+
}), decl.node.d.name);
|
4674
4691
|
const origDecl = (0, symbolUtils_1.getLastTypedDeclarationForSymbol)(baseClassAndSymbol.symbol);
|
4675
4692
|
if (diag && origDecl) {
|
4676
4693
|
diag.addRelatedInfo(localize_1.LocAddendum.finalMethod(), origDecl.uri, origDecl.range);
|
@@ -4690,13 +4707,13 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4690
4707
|
!SymbolNameUtils.isPrivateName(memberName) &&
|
4691
4708
|
!types_1.ClassType.isTypedDictClass(childClassType)) {
|
4692
4709
|
if (!this._evaluator.validateOverrideMethod(baseType, overrideType, childClassType, diagAddendum, enforceParamNameMatch)) {
|
4693
|
-
const decl = (0, types_1.isFunction)(overrideType) && overrideType.
|
4694
|
-
? overrideType.
|
4710
|
+
const decl = (0, types_1.isFunction)(overrideType) && overrideType.shared.declaration
|
4711
|
+
? overrideType.shared.declaration
|
4695
4712
|
: (0, symbolUtils_1.getLastTypedDeclarationForSymbol)(overrideSymbol);
|
4696
4713
|
if (decl) {
|
4697
4714
|
const diag = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompatibleMethodOverride, localize_1.LocMessage.incompatibleMethodOverride().format({
|
4698
4715
|
name: memberName,
|
4699
|
-
className: baseClass.
|
4716
|
+
className: baseClass.shared.name,
|
4700
4717
|
}) + diagAddendum.getString(), (_a = (0, declarationUtils_1.getNameNodeForDeclaration)(decl)) !== null && _a !== void 0 ? _a : decl.node);
|
4701
4718
|
const origDecl = (0, symbolUtils_1.getLastTypedDeclarationForSymbol)(baseClassAndSymbol.symbol);
|
4702
4719
|
if (diag && origDecl) {
|
@@ -4716,7 +4733,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4716
4733
|
const lastDecl = decls[decls.length - 1];
|
4717
4734
|
const diag = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompatibleMethodOverride, localize_1.LocMessage.methodOverridden().format({
|
4718
4735
|
name: memberName,
|
4719
|
-
className: baseClass.
|
4736
|
+
className: baseClass.shared.name,
|
4720
4737
|
type: this._evaluator.printType(overrideType),
|
4721
4738
|
}), (_b = (0, declarationUtils_1.getNameNodeForDeclaration)(lastDecl)) !== null && _b !== void 0 ? _b : lastDecl.node);
|
4722
4739
|
const origDecl = (0, symbolUtils_1.getLastTypedDeclarationForSymbol)(baseClassAndSymbol.symbol);
|
@@ -4735,7 +4752,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4735
4752
|
const lastDecl = decls[decls.length - 1];
|
4736
4753
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompatibleMethodOverride, localize_1.LocMessage.propertyOverridden().format({
|
4737
4754
|
name: memberName,
|
4738
|
-
className: baseClass.
|
4755
|
+
className: baseClass.shared.name,
|
4739
4756
|
}), (_c = (0, declarationUtils_1.getNameNodeForDeclaration)(lastDecl)) !== null && _c !== void 0 ? _c : lastDecl.node);
|
4740
4757
|
}
|
4741
4758
|
}
|
@@ -4756,8 +4773,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4756
4773
|
let isInvariant = (primaryDecl === null || primaryDecl === void 0 ? void 0 : primaryDecl.type) === 1 /* DeclarationType.Variable */ && !primaryDecl.isFinal;
|
4757
4774
|
// If the entry is a member of a frozen dataclass, it is immutable,
|
4758
4775
|
// so it does not need to be invariant.
|
4759
|
-
if (types_1.ClassType.isDataClassFrozen(baseClass) && baseClass.
|
4760
|
-
const dataclassEntry = baseClass.
|
4776
|
+
if (types_1.ClassType.isDataClassFrozen(baseClass) && baseClass.shared.dataClassEntries) {
|
4777
|
+
const dataclassEntry = baseClass.shared.dataClassEntries.find((entry) => entry.name === memberName);
|
4761
4778
|
if (dataclassEntry) {
|
4762
4779
|
isInvariant = false;
|
4763
4780
|
}
|
@@ -4765,14 +4782,14 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4765
4782
|
let overriddenTDEntry;
|
4766
4783
|
let overrideTDEntry;
|
4767
4784
|
if (!overrideSymbol.isIgnoredForProtocolMatch()) {
|
4768
|
-
if (baseClass.
|
4785
|
+
if (baseClass.shared.typedDictEntries) {
|
4769
4786
|
overriddenTDEntry =
|
4770
|
-
(_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);
|
4771
4788
|
if (overriddenTDEntry === null || overriddenTDEntry === void 0 ? void 0 : overriddenTDEntry.isReadOnly) {
|
4772
4789
|
isInvariant = false;
|
4773
4790
|
}
|
4774
4791
|
}
|
4775
|
-
if (childClassType.
|
4792
|
+
if (childClassType.shared.typedDictEntries) {
|
4776
4793
|
// Exempt __extra_items__ here. We'll check this separately
|
4777
4794
|
// in _validateTypedDictOverrides. If we don't skip it here,
|
4778
4795
|
// redundant errors will be produced.
|
@@ -4782,7 +4799,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4782
4799
|
}
|
4783
4800
|
else {
|
4784
4801
|
overrideTDEntry =
|
4785
|
-
(_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);
|
4786
4803
|
}
|
4787
4804
|
}
|
4788
4805
|
}
|
@@ -4800,7 +4817,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4800
4817
|
}
|
4801
4818
|
const diag = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompatibleVariableOverride, localize_1.LocMessage.symbolOverridden().format({
|
4802
4819
|
name: memberName,
|
4803
|
-
className: baseClass.
|
4820
|
+
className: baseClass.shared.name,
|
4804
4821
|
}) + diagAddendum.getString(), (_h = (0, declarationUtils_1.getNameNodeForDeclaration)(lastDecl)) !== null && _h !== void 0 ? _h : lastDecl.node);
|
4805
4822
|
const origDecl = (0, symbolUtils_1.getLastTypedDeclarationForSymbol)(baseClassAndSymbol.symbol);
|
4806
4823
|
if (diag && origDecl) {
|
@@ -4838,7 +4855,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4838
4855
|
if (!isBaseVarFinal && overrideFinalVarDecl) {
|
4839
4856
|
const diag = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompatibleVariableOverride, localize_1.LocMessage.variableFinalOverride().format({
|
4840
4857
|
name: memberName,
|
4841
|
-
className: baseClass.
|
4858
|
+
className: baseClass.shared.name,
|
4842
4859
|
}), (_l = (0, declarationUtils_1.getNameNodeForDeclaration)(lastDecl)) !== null && _l !== void 0 ? _l : lastDecl.node);
|
4843
4860
|
if (diag) {
|
4844
4861
|
diag.addRelatedInfo(localize_1.LocAddendum.overriddenSymbol(), overrideFinalVarDecl.uri, overrideFinalVarDecl.range);
|
@@ -4870,7 +4887,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4870
4887
|
: localize_1.LocMessage.instanceVarOverridesClassVar();
|
4871
4888
|
const diag = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompatibleVariableOverride, unformattedMessage.format({
|
4872
4889
|
name: memberName,
|
4873
|
-
className: baseClass.
|
4890
|
+
className: baseClass.shared.name,
|
4874
4891
|
}), (_m = (0, declarationUtils_1.getNameNodeForDeclaration)(lastDecl)) !== null && _m !== void 0 ? _m : lastDecl.node);
|
4875
4892
|
const origDecl = (0, symbolUtils_1.getLastTypedDeclarationForSymbol)(baseClassAndSymbol.symbol);
|
4876
4893
|
if (diag && origDecl) {
|
@@ -4883,9 +4900,9 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4883
4900
|
}
|
4884
4901
|
_validatePropertyOverride(baseClassType, childClassType, baseType, childType, overrideSymbol, memberName) {
|
4885
4902
|
const propMethodInfo = [
|
4886
|
-
['fget', (c) => { var _a; return (_a = c.fgetInfo) === null || _a === void 0 ? void 0 : _a.methodType; }],
|
4887
|
-
['fset', (c) => { var _a; return (_a = c.fsetInfo) === null || _a === void 0 ? void 0 : _a.methodType; }],
|
4888
|
-
['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; }],
|
4889
4906
|
];
|
4890
4907
|
propMethodInfo.forEach((info) => {
|
4891
4908
|
var _a;
|
@@ -4907,9 +4924,9 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4907
4924
|
const lastDecl = decls[decls.length - 1];
|
4908
4925
|
const diag = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompatibleMethodOverride, localize_1.LocMessage.propertyOverridden().format({
|
4909
4926
|
name: memberName,
|
4910
|
-
className: baseClassType.
|
4927
|
+
className: baseClassType.shared.name,
|
4911
4928
|
}) + diagAddendum.getString(), (_a = (0, declarationUtils_1.getNameNodeForDeclaration)(lastDecl)) !== null && _a !== void 0 ? _a : lastDecl.node);
|
4912
|
-
const origDecl = baseClassMethodType.
|
4929
|
+
const origDecl = baseClassMethodType.shared.declaration;
|
4913
4930
|
if (diag && origDecl) {
|
4914
4931
|
diag.addRelatedInfo(localize_1.LocAddendum.overriddenMethod(), origDecl.uri, origDecl.range);
|
4915
4932
|
}
|
@@ -4922,13 +4939,13 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4922
4939
|
diagAddendum.addMessage(localize_1.LocAddendum.propertyMethodIncompatible().format({
|
4923
4940
|
name: methodName,
|
4924
4941
|
}));
|
4925
|
-
const decl = subclassMethodType.
|
4942
|
+
const decl = subclassMethodType.shared.declaration;
|
4926
4943
|
if (decl && decl.type === 5 /* DeclarationType.Function */) {
|
4927
4944
|
const diag = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompatibleMethodOverride, localize_1.LocMessage.propertyOverridden().format({
|
4928
4945
|
name: memberName,
|
4929
|
-
className: baseClassType.
|
4930
|
-
}) + diagAddendum.getString(), decl.node.name);
|
4931
|
-
const origDecl = baseClassMethodType.
|
4946
|
+
className: baseClassType.shared.name,
|
4947
|
+
}) + diagAddendum.getString(), decl.node.d.name);
|
4948
|
+
const origDecl = baseClassMethodType.shared.declaration;
|
4932
4949
|
if (diag && origDecl) {
|
4933
4950
|
diag.addRelatedInfo(localize_1.LocAddendum.overriddenMethod(), origDecl.uri, origDecl.range);
|
4934
4951
|
}
|
@@ -4946,9 +4963,9 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4946
4963
|
var _a, _b;
|
4947
4964
|
const classTypeInfo = this._evaluator.getTypeOfClass(classNode);
|
4948
4965
|
const classType = classTypeInfo === null || classTypeInfo === void 0 ? void 0 : classTypeInfo.classType;
|
4949
|
-
if (node.name && classType) {
|
4966
|
+
if (node.d.name && classType) {
|
4950
4967
|
const superCheckMethods = ['__init__', '__init_subclass__', '__enter__', '__exit__'];
|
4951
|
-
if (superCheckMethods.some((name) => name === node.name.value)) {
|
4968
|
+
if (superCheckMethods.some((name) => name === node.d.name.d.value)) {
|
4952
4969
|
if (!types_1.FunctionType.isAbstractMethod(functionType) &&
|
4953
4970
|
!types_1.FunctionType.isOverloaded(functionType) &&
|
4954
4971
|
!this._fileInfo.isStubFile) {
|
@@ -4956,48 +4973,48 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4956
4973
|
}
|
4957
4974
|
}
|
4958
4975
|
}
|
4959
|
-
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__') {
|
4960
4977
|
// __new__ overrides should have a "cls" parameter.
|
4961
|
-
if (node.
|
4962
|
-
!node.
|
4963
|
-
!['cls', '_cls', '__cls', '__mcls', 'mcls', 'mcs', 'metacls'].some((name) => node.
|
4964
|
-
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);
|
4965
4982
|
}
|
4966
4983
|
if (classType) {
|
4967
|
-
this._validateClsSelfParameterType(functionType, classType, /* isCls */ true);
|
4984
|
+
this._validateClsSelfParameterType(node, functionType, classType, /* isCls */ true);
|
4968
4985
|
}
|
4969
4986
|
}
|
4970
|
-
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_') {
|
4971
4988
|
// Skip this check for _generate_next_value_.
|
4972
4989
|
}
|
4973
4990
|
else if (types_1.FunctionType.isStaticMethod(functionType)) {
|
4974
4991
|
// Static methods should not have "self" or "cls" parameters.
|
4975
|
-
if (node.
|
4976
|
-
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;
|
4977
4994
|
if (paramName === 'self' || paramName === 'cls') {
|
4978
|
-
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);
|
4979
4996
|
}
|
4980
4997
|
}
|
4981
4998
|
}
|
4982
4999
|
else if (types_1.FunctionType.isClassMethod(functionType)) {
|
4983
5000
|
let paramName = '';
|
4984
|
-
if (node.
|
4985
|
-
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;
|
4986
5003
|
}
|
4987
5004
|
// Class methods should have a "cls" parameter. We'll exempt parameter
|
4988
5005
|
// names that start with an underscore since those are used in a few
|
4989
5006
|
// cases in the stdlib pyi files.
|
4990
5007
|
if (paramName !== 'cls') {
|
4991
5008
|
if (!this._fileInfo.isStubFile || (!paramName.startsWith('_') && paramName !== 'metacls')) {
|
4992
|
-
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);
|
4993
5010
|
}
|
4994
5011
|
}
|
4995
5012
|
if (classType) {
|
4996
|
-
this._validateClsSelfParameterType(functionType, classType, /* isCls */ true);
|
5013
|
+
this._validateClsSelfParameterType(node, functionType, classType, /* isCls */ true);
|
4997
5014
|
}
|
4998
5015
|
}
|
4999
5016
|
else {
|
5000
|
-
const decoratorIsPresent = node.decorators.length > 0;
|
5017
|
+
const decoratorIsPresent = node.d.decorators.length > 0;
|
5001
5018
|
const isOverloaded = types_1.FunctionType.isOverloaded(functionType);
|
5002
5019
|
// The presence of a decorator can change the behavior, so we need
|
5003
5020
|
// to back off from this check if a decorator is present. An overload
|
@@ -5005,11 +5022,11 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5005
5022
|
if (isOverloaded || !decoratorIsPresent) {
|
5006
5023
|
let paramName = '';
|
5007
5024
|
let firstParamIsSimple = true;
|
5008
|
-
if (node.
|
5009
|
-
if (node.
|
5010
|
-
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;
|
5011
5028
|
}
|
5012
|
-
if (node.
|
5029
|
+
if (node.d.params[0].d.category !== 0 /* ParameterCategory.Simple */) {
|
5013
5030
|
firstParamIsSimple = false;
|
5014
5031
|
}
|
5015
5032
|
}
|
@@ -5033,12 +5050,12 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5033
5050
|
// a parameter that cannot be positional.
|
5034
5051
|
const isPrivateName = SymbolNameUtils.isPrivateOrProtectedName(paramName);
|
5035
5052
|
if (!isLegalMetaclassName && !isPrivateName) {
|
5036
|
-
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);
|
5037
5054
|
}
|
5038
5055
|
}
|
5039
5056
|
}
|
5040
5057
|
if (classType) {
|
5041
|
-
this._validateClsSelfParameterType(functionType, classType, /* isCls */ false);
|
5058
|
+
this._validateClsSelfParameterType(node, functionType, classType, /* isCls */ false);
|
5042
5059
|
}
|
5043
5060
|
}
|
5044
5061
|
}
|
@@ -5059,7 +5076,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5059
5076
|
if (types_1.ClassType.isFinal(classType)) {
|
5060
5077
|
effectiveFlags |= 4 /* MemberAccessFlags.SkipObjectBaseClass */;
|
5061
5078
|
}
|
5062
|
-
const methodMember = (0, typeUtils_1.lookUpClassMember)(classType, methodType.
|
5079
|
+
const methodMember = (0, typeUtils_1.lookUpClassMember)(classType, methodType.shared.name, effectiveFlags);
|
5063
5080
|
if (!methodMember) {
|
5064
5081
|
return;
|
5065
5082
|
}
|
@@ -5067,14 +5084,14 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5067
5084
|
// Now scan the implementation of the method to determine whether
|
5068
5085
|
// super().<method> has been called for all of the required base classes.
|
5069
5086
|
const callNodeWalker = new ParseTreeUtils.CallNodeWalker((node) => {
|
5070
|
-
if (node.
|
5087
|
+
if (node.d.leftExpr.nodeType === 35 /* ParseNodeType.MemberAccess */) {
|
5071
5088
|
// Is it accessing the method by the same name?
|
5072
|
-
if (node.
|
5073
|
-
const memberBaseExpr = node.
|
5089
|
+
if (node.d.leftExpr.d.member.d.value === methodType.shared.name) {
|
5090
|
+
const memberBaseExpr = node.d.leftExpr.d.leftExpr;
|
5074
5091
|
// Is it a "super" call?
|
5075
5092
|
if (memberBaseExpr.nodeType === 9 /* ParseNodeType.Call */ &&
|
5076
|
-
memberBaseExpr.
|
5077
|
-
memberBaseExpr.
|
5093
|
+
memberBaseExpr.d.leftExpr.nodeType === 38 /* ParseNodeType.Name */ &&
|
5094
|
+
memberBaseExpr.d.leftExpr.d.value === 'super') {
|
5078
5095
|
foundCallOfMember = true;
|
5079
5096
|
}
|
5080
5097
|
else {
|
@@ -5087,33 +5104,35 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5087
5104
|
}
|
5088
5105
|
}
|
5089
5106
|
});
|
5090
|
-
callNodeWalker.walk(node.suite);
|
5107
|
+
callNodeWalker.walk(node.d.suite);
|
5091
5108
|
// If we didn't find a call to at least one base class, report the problem.
|
5092
5109
|
if (!foundCallOfMember) {
|
5093
5110
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportMissingSuperCall, localize_1.LocMessage.missingSuperCall().format({
|
5094
|
-
methodName: methodType.
|
5095
|
-
}), node.name);
|
5111
|
+
methodName: methodType.shared.name,
|
5112
|
+
}), node.d.name);
|
5096
5113
|
}
|
5097
5114
|
}
|
5098
5115
|
// Validates that the annotated type of a "self" or "cls" parameter is
|
5099
5116
|
// compatible with the type of the class that contains it.
|
5100
|
-
_validateClsSelfParameterType(functionType, classType, isCls) {
|
5101
|
-
|
5117
|
+
_validateClsSelfParameterType(node, functionType, classType, isCls) {
|
5118
|
+
var _a;
|
5119
|
+
if (node.d.params.length < 1 || functionType.shared.parameters.length < 1) {
|
5102
5120
|
return;
|
5103
5121
|
}
|
5104
5122
|
// If there is no type annotation, there's nothing to check because
|
5105
|
-
// the type will be inferred.
|
5106
|
-
const paramInfo = functionType.
|
5107
|
-
|
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) {
|
5108
5127
|
return;
|
5109
5128
|
}
|
5110
5129
|
// If this is an __init__ method, we need to specifically check for the
|
5111
5130
|
// use of class-scoped TypeVars, which are not allowed in this context
|
5112
5131
|
// according to the typing spec.
|
5113
|
-
if (functionType.
|
5132
|
+
if (functionType.shared.name === '__init__' && functionType.shared.methodClass) {
|
5114
5133
|
const typeVars = (0, typeUtils_1.getTypeVarArgumentsRecursive)(paramInfo.type);
|
5115
|
-
if (typeVars.some((typeVar) => { var _a; return typeVar.scopeId === ((_a = functionType.
|
5116
|
-
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);
|
5117
5136
|
}
|
5118
5137
|
}
|
5119
5138
|
// If this is a protocol class, the self and cls parameters can be bound
|
@@ -5134,7 +5153,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5134
5153
|
// If the method starts with a `*args: P.args`, skip the check.
|
5135
5154
|
if (paramInfo.category === 1 /* ParameterCategory.ArgsList */ &&
|
5136
5155
|
(0, types_1.isParamSpec)(paramInfo.type) &&
|
5137
|
-
paramInfo.type.paramSpecAccess === 'args') {
|
5156
|
+
paramInfo.type.priv.paramSpecAccess === 'args') {
|
5138
5157
|
return;
|
5139
5158
|
}
|
5140
5159
|
// Don't enforce this for an overloaded method because the "self" param
|
@@ -5158,7 +5177,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5158
5177
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.clsSelfParamTypeMismatch().format({
|
5159
5178
|
name: paramInfo.name,
|
5160
5179
|
classType: this._evaluator.printType(expectedType),
|
5161
|
-
}),
|
5180
|
+
}), paramAnnotation);
|
5162
5181
|
}
|
5163
5182
|
}
|
5164
5183
|
}
|
@@ -5167,7 +5186,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5167
5186
|
_validateYieldType(node, yieldType, expectedDiagAddendum, sendType) {
|
5168
5187
|
var _a, _b, _c, _d;
|
5169
5188
|
const enclosingFunctionNode = ParseTreeUtils.getEnclosingFunction(node);
|
5170
|
-
if (!enclosingFunctionNode || !enclosingFunctionNode.
|
5189
|
+
if (!enclosingFunctionNode || !enclosingFunctionNode.d.returnAnnotation) {
|
5171
5190
|
return;
|
5172
5191
|
}
|
5173
5192
|
const functionTypeResult = this._evaluator.getTypeOfFunction(enclosingFunctionNode);
|
@@ -5179,7 +5198,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5179
5198
|
return;
|
5180
5199
|
}
|
5181
5200
|
let generatorType;
|
5182
|
-
if (!enclosingFunctionNode.isAsync &&
|
5201
|
+
if (!enclosingFunctionNode.d.isAsync &&
|
5183
5202
|
(0, types_1.isClassInstance)(declaredReturnType) &&
|
5184
5203
|
types_1.ClassType.isBuiltIn(declaredReturnType, 'AwaitableGenerator')) {
|
5185
5204
|
// Handle the old-style (pre-await) generator case
|
@@ -5187,7 +5206,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5187
5206
|
generatorType = this._evaluator.getTypingType(node, 'AwaitableGenerator');
|
5188
5207
|
}
|
5189
5208
|
else {
|
5190
|
-
generatorType = this._evaluator.getTypingType(node, enclosingFunctionNode.isAsync ? 'AsyncGenerator' : 'Generator');
|
5209
|
+
generatorType = this._evaluator.getTypingType(node, enclosingFunctionNode.d.isAsync ? 'AsyncGenerator' : 'Generator');
|
5191
5210
|
}
|
5192
5211
|
if (!generatorType || !(0, types_1.isInstantiableClass)(generatorType)) {
|
5193
5212
|
return;
|
@@ -5203,11 +5222,11 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5203
5222
|
const specializedGenerator = types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneForSpecialization(generatorType, generatorTypeArgs, /* isTypeArgumentExplicit */ true));
|
5204
5223
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
5205
5224
|
if (!this._evaluator.assignType(declaredReturnType, specializedGenerator, diagAddendum)) {
|
5206
|
-
const errorMessage = enclosingFunctionNode.isAsync
|
5225
|
+
const errorMessage = enclosingFunctionNode.d.isAsync
|
5207
5226
|
? localize_1.LocMessage.generatorAsyncReturnType()
|
5208
5227
|
: localize_1.LocMessage.generatorSyncReturnType();
|
5209
5228
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportReturnType, errorMessage.format({ yieldType: this._evaluator.printType(yieldType) }) +
|
5210
|
-
((_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);
|
5211
5230
|
}
|
5212
5231
|
}
|
5213
5232
|
// Determines whether any of the except statements are unreachable because
|
@@ -5215,12 +5234,12 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5215
5234
|
_reportUnusedExceptStatements(node) {
|
5216
5235
|
let sawUnknownExceptionType = false;
|
5217
5236
|
const exceptionTypesSoFar = [];
|
5218
|
-
node.exceptClauses.forEach((except) => {
|
5237
|
+
node.d.exceptClauses.forEach((except) => {
|
5219
5238
|
var _a, _b;
|
5220
|
-
if (sawUnknownExceptionType || except.isExceptGroup || !except.
|
5239
|
+
if (sawUnknownExceptionType || except.d.isExceptGroup || !except.d.typeExpr) {
|
5221
5240
|
return;
|
5222
5241
|
}
|
5223
|
-
const exceptionType = this._evaluator.getType(except.
|
5242
|
+
const exceptionType = this._evaluator.getType(except.d.typeExpr);
|
5224
5243
|
if (!exceptionType || (0, types_1.isAnyOrUnknown)(exceptionType)) {
|
5225
5244
|
sawUnknownExceptionType = true;
|
5226
5245
|
return;
|
@@ -5229,7 +5248,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5229
5248
|
if ((0, types_1.isInstantiableClass)(exceptionType)) {
|
5230
5249
|
// If the exception type is a variable whose type could represent
|
5231
5250
|
// subclasses, the actual exception type is statically unknown.
|
5232
|
-
if (exceptionType.includeSubclasses) {
|
5251
|
+
if (exceptionType.priv.includeSubclasses) {
|
5233
5252
|
sawUnknownExceptionType = true;
|
5234
5253
|
}
|
5235
5254
|
typesOfThisExcept.push(exceptionType);
|
@@ -5237,7 +5256,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5237
5256
|
else if ((0, types_1.isClassInstance)(exceptionType)) {
|
5238
5257
|
const iterableType = (_b = (_a = this._evaluator.getTypeOfIterator({ type: exceptionType },
|
5239
5258
|
/* isAsync */ false,
|
5240
|
-
/* errorNode */ except.
|
5259
|
+
/* errorNode */ except.d.typeExpr,
|
5241
5260
|
/* emitNotIterableError */ false)) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : types_1.UnknownType.create();
|
5242
5261
|
(0, typeUtils_1.doForEachSubtype)(iterableType, (subtype) => {
|
5243
5262
|
if ((0, types_1.isAnyOrUnknown)(subtype)) {
|
@@ -5246,7 +5265,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5246
5265
|
if ((0, types_1.isInstantiableClass)(subtype)) {
|
5247
5266
|
// If the exception type is a variable whose type could represent
|
5248
5267
|
// subclasses, the actual exception type is statically unknown.
|
5249
|
-
if (subtype.includeSubclasses) {
|
5268
|
+
if (subtype.priv.includeSubclasses) {
|
5250
5269
|
sawUnknownExceptionType = true;
|
5251
5270
|
}
|
5252
5271
|
typesOfThisExcept.push(subtype);
|
@@ -5273,8 +5292,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5273
5292
|
});
|
5274
5293
|
// Were all of the exception types overridden?
|
5275
5294
|
if (typesOfThisExcept.length > 0 && typesOfThisExcept.length === overriddenExceptionCount) {
|
5276
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnusedExcept, localize_1.LocMessage.unreachableExcept() + diagAddendum.getString(), except.
|
5277
|
-
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);
|
5278
5297
|
}
|
5279
5298
|
}
|
5280
5299
|
(0, collectionUtils_1.appendArray)(exceptionTypesSoFar, typesOfThisExcept);
|
@@ -5286,22 +5305,22 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5286
5305
|
importStatements.orderedImports.forEach((importStatement) => {
|
5287
5306
|
if (importStatement.node.nodeType === 25 /* ParseNodeType.ImportFrom */) {
|
5288
5307
|
const symbolMap = new Map();
|
5289
|
-
importStatement.node.imports.forEach((importFromAs) => {
|
5308
|
+
importStatement.node.d.imports.forEach((importFromAs) => {
|
5290
5309
|
// Ignore duplicates if they're aliased.
|
5291
|
-
if (!importFromAs.alias) {
|
5292
|
-
const prevImport = symbolMap.get(importFromAs.name.value);
|
5310
|
+
if (!importFromAs.d.alias) {
|
5311
|
+
const prevImport = symbolMap.get(importFromAs.d.name.d.value);
|
5293
5312
|
if (prevImport) {
|
5294
|
-
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);
|
5295
5314
|
}
|
5296
5315
|
else {
|
5297
|
-
symbolMap.set(importFromAs.name.value, importFromAs);
|
5316
|
+
symbolMap.set(importFromAs.d.name.d.value, importFromAs);
|
5298
5317
|
}
|
5299
5318
|
}
|
5300
5319
|
});
|
5301
5320
|
}
|
5302
5321
|
else if (importStatement.subnode) {
|
5303
5322
|
// Ignore duplicates if they're aliased.
|
5304
|
-
if (!importStatement.subnode.alias) {
|
5323
|
+
if (!importStatement.subnode.d.alias) {
|
5305
5324
|
const prevImport = importModuleMap.get(importStatement.moduleName);
|
5306
5325
|
if (prevImport) {
|
5307
5326
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportDuplicateImport, localize_1.LocMessage.duplicateImport().format({ importName: importStatement.moduleName }), importStatement.subnode);
|