@zzzen/pyright-internal 1.2.0-dev.20240721 → 1.2.0-dev.20240804
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 +2 -2
- package/dist/analyzer/analyzerNodeInfo.js.map +1 -1
- package/dist/analyzer/binder.js +15 -12
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/cacheManager.js +3 -0
- package/dist/analyzer/cacheManager.js.map +1 -1
- package/dist/analyzer/checker.d.ts +5 -3
- package/dist/analyzer/checker.js +238 -193
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.d.ts +2 -2
- package/dist/analyzer/codeFlowEngine.js +53 -46
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/codeFlowTypes.js +1 -1
- package/dist/analyzer/codeFlowTypes.js.map +1 -1
- package/dist/analyzer/constraintSolution.d.ts +21 -0
- package/dist/analyzer/constraintSolution.js +71 -0
- package/dist/analyzer/constraintSolution.js.map +1 -0
- package/dist/analyzer/constraintSolver.d.ts +10 -6
- package/dist/analyzer/constraintSolver.js +520 -462
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constraintTracker.d.ts +44 -0
- package/dist/analyzer/constraintTracker.js +230 -0
- package/dist/analyzer/constraintTracker.js.map +1 -0
- package/dist/analyzer/constructorTransform.d.ts +2 -2
- package/dist/analyzer/constructorTransform.js +25 -25
- package/dist/analyzer/constructorTransform.js.map +1 -1
- package/dist/analyzer/constructors.d.ts +3 -3
- package/dist/analyzer/constructors.js +80 -64
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.d.ts +2 -2
- package/dist/analyzer/dataClasses.js +87 -61
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/declaration.d.ts +9 -9
- package/dist/analyzer/declaration.js +9 -9
- package/dist/analyzer/declaration.js.map +1 -1
- package/dist/analyzer/declarationUtils.d.ts +1 -1
- package/dist/analyzer/declarationUtils.js +6 -6
- package/dist/analyzer/declarationUtils.js.map +1 -1
- package/dist/analyzer/decorators.js +5 -5
- package/dist/analyzer/decorators.js.map +1 -1
- package/dist/analyzer/docStringConversion.js +2 -2
- package/dist/analyzer/docStringConversion.js.map +1 -1
- package/dist/analyzer/enums.d.ts +2 -2
- package/dist/analyzer/enums.js +6 -6
- package/dist/analyzer/enums.js.map +1 -1
- package/dist/analyzer/functionTransform.d.ts +2 -2
- package/dist/analyzer/functionTransform.js +5 -5
- package/dist/analyzer/functionTransform.js.map +1 -1
- package/dist/analyzer/importResolver.js +5 -3
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/namedTuples.d.ts +3 -3
- package/dist/analyzer/namedTuples.js +21 -22
- package/dist/analyzer/namedTuples.js.map +1 -1
- package/dist/analyzer/operations.d.ts +1 -2
- package/dist/analyzer/operations.js +105 -82
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/packageTypeVerifier.js +16 -12
- package/dist/analyzer/packageTypeVerifier.js.map +1 -1
- package/dist/analyzer/parameterUtils.d.ts +12 -12
- package/dist/analyzer/parameterUtils.js +67 -69
- package/dist/analyzer/parameterUtils.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.d.ts +6 -6
- package/dist/analyzer/parseTreeUtils.js +22 -22
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/patternMatching.js +122 -101
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.js +11 -4
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/properties.d.ts +3 -2
- package/dist/analyzer/properties.js +27 -27
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/protocols.d.ts +3 -3
- package/dist/analyzer/protocols.js +58 -57
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/pythonPathUtils.js +1 -1
- package/dist/analyzer/pythonPathUtils.js.map +1 -1
- package/dist/analyzer/service.d.ts +3 -7
- package/dist/analyzer/service.js +28 -30
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/serviceUtils.d.ts +8 -0
- package/dist/analyzer/serviceUtils.js +31 -0
- package/dist/analyzer/serviceUtils.js.map +1 -0
- package/dist/analyzer/sourceFile.js +5 -19
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/sourceMapper.d.ts +1 -1
- package/dist/analyzer/sourceMapper.js +4 -4
- package/dist/analyzer/sourceMapper.js.map +1 -1
- package/dist/analyzer/staticExpressions.js +1 -1
- package/dist/analyzer/staticExpressions.js.map +1 -1
- package/dist/analyzer/tracePrinter.js +4 -4
- package/dist/analyzer/tracePrinter.js.map +1 -1
- package/dist/analyzer/tuples.d.ts +9 -0
- package/dist/analyzer/tuples.js +253 -0
- package/dist/analyzer/tuples.js.map +1 -0
- package/dist/analyzer/typeComplexity.d.ts +2 -0
- package/dist/analyzer/typeComplexity.js +94 -0
- package/dist/analyzer/typeComplexity.js.map +1 -0
- package/dist/analyzer/typeEvaluator.js +1758 -1979
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +69 -45
- package/dist/analyzer/typeEvaluatorTypes.js +7 -1
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +157 -121
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.d.ts +1 -1
- package/dist/analyzer/typePrinter.js +64 -61
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeStubWriter.d.ts +3 -3
- package/dist/analyzer/typeStubWriter.js +15 -15
- package/dist/analyzer/typeStubWriter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +45 -41
- package/dist/analyzer/typeUtils.js +511 -748
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typeWalker.js +4 -4
- package/dist/analyzer/typeWalker.js.map +1 -1
- package/dist/analyzer/typedDicts.d.ts +4 -4
- package/dist/analyzer/typedDicts.js +73 -77
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +97 -72
- package/dist/analyzer/types.js +217 -208
- package/dist/analyzer/types.js.map +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js +11 -11
- package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
- package/dist/common/configOptions.d.ts +1 -0
- package/dist/common/configOptions.js +5 -0
- package/dist/common/configOptions.js.map +1 -1
- package/dist/common/diagnosticRules.d.ts +1 -0
- package/dist/common/diagnosticRules.js +1 -0
- package/dist/common/diagnosticRules.js.map +1 -1
- package/dist/common/fileSystem.d.ts +0 -1
- package/dist/common/fileSystem.js.map +1 -1
- package/dist/common/languageServerInterface.d.ts +13 -0
- package/dist/common/languageServerInterface.js +15 -1
- package/dist/common/languageServerInterface.js.map +1 -1
- package/dist/common/lspUtils.js +2 -2
- package/dist/common/memUtils.d.ts +4 -0
- package/dist/common/memUtils.js +33 -2
- package/dist/common/memUtils.js.map +1 -1
- package/dist/common/serviceKeys.d.ts +3 -0
- package/dist/common/serviceKeys.js +2 -0
- package/dist/common/serviceKeys.js.map +1 -1
- package/dist/common/serviceProviderExtensions.js +7 -0
- package/dist/common/serviceProviderExtensions.js.map +1 -1
- package/dist/languageServerBase.d.ts +5 -4
- package/dist/languageServerBase.js +19 -12
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/autoImporter.d.ts +3 -2
- package/dist/languageService/autoImporter.js +5 -1
- package/dist/languageService/autoImporter.js.map +1 -1
- package/dist/languageService/completionProvider.d.ts +5 -3
- package/dist/languageService/completionProvider.js +39 -38
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/completionProviderUtils.d.ts +1 -1
- package/dist/languageService/completionProviderUtils.js +3 -3
- package/dist/languageService/completionProviderUtils.js.map +1 -1
- package/dist/languageService/fileWatcherDynamicFeature.js +2 -2
- package/dist/languageService/fileWatcherDynamicFeature.js.map +1 -1
- package/dist/languageService/hoverProvider.js +3 -3
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/referencesProvider.js +2 -2
- package/dist/languageService/signatureHelpProvider.js +1 -1
- package/dist/languageService/signatureHelpProvider.js.map +1 -1
- package/dist/languageService/tooltipUtils.js +3 -3
- package/dist/languageService/tooltipUtils.js.map +1 -1
- package/dist/localization/localize.d.ts +5 -0
- package/dist/localization/localize.js +6 -0
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +5 -1
- package/dist/localization/package.nls.de.json +5 -1
- package/dist/localization/package.nls.en-us.json +5 -0
- package/dist/localization/package.nls.es.json +5 -1
- package/dist/localization/package.nls.fr.json +5 -1
- package/dist/localization/package.nls.it.json +5 -1
- package/dist/localization/package.nls.ja.json +5 -1
- package/dist/localization/package.nls.ko.json +5 -1
- package/dist/localization/package.nls.pl.json +5 -1
- package/dist/localization/package.nls.pt-br.json +5 -1
- package/dist/localization/package.nls.qps-ploc.json +5 -1
- package/dist/localization/package.nls.ru.json +5 -1
- package/dist/localization/package.nls.tr.json +5 -1
- package/dist/localization/package.nls.zh-cn.json +5 -1
- package/dist/localization/package.nls.zh-tw.json +5 -1
- package/dist/parser/parseNodes.d.ts +9 -9
- package/dist/parser/parseNodes.js +20 -20
- package/dist/parser/parseNodes.js.map +1 -1
- package/dist/parser/parser.js +30 -30
- package/dist/parser/parser.js.map +1 -1
- package/dist/tests/checker.test.js +12 -4
- package/dist/tests/checker.test.js.map +1 -1
- package/dist/tests/fourslash/signature.builtinDocstrings.fourslash.js +4 -21
- package/dist/tests/fourslash/signature.builtinDocstrings.fourslash.js.map +1 -1
- package/dist/tests/fourslash/signature.complicated.fourslash.js +1 -1
- package/dist/tests/fourslash/signature.complicated.fourslash.js.map +1 -1
- package/dist/tests/harness/fourslash/fourSlashParser.js +1 -1
- package/dist/tests/harness/fourslash/fourSlashParser.js.map +1 -1
- package/dist/tests/harness/fourslash/testStateUtils.js +2 -2
- package/dist/tests/harness/fourslash/testStateUtils.js.map +1 -1
- package/dist/tests/harness/vfs/filesystem.d.ts +0 -1
- package/dist/tests/harness/vfs/filesystem.js +0 -4
- package/dist/tests/harness/vfs/filesystem.js.map +1 -1
- package/dist/tests/importResolver.test.js +62 -15
- package/dist/tests/importResolver.test.js.map +1 -1
- package/dist/tests/lsp/languageServerTestUtils.js +1 -1
- package/dist/tests/lsp/languageServerTestUtils.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +1 -1
- package/dist/tests/typeEvaluator2.test.js +12 -0
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +5 -1
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +10 -2
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator5.test.js +9 -3
- package/dist/tests/typeEvaluator5.test.js.map +1 -1
- package/dist/tests/typeEvaluator6.test.js +72 -60
- package/dist/tests/typeEvaluator6.test.js.map +1 -1
- package/dist/tests/typeEvaluator7.test.js +6 -2
- package/dist/tests/typeEvaluator7.test.js.map +1 -1
- package/dist/tests/typeEvaluator8.test.js +4 -0
- package/dist/tests/typeEvaluator8.test.js.map +1 -1
- package/dist/tests/typePrinter.test.js +13 -18
- package/dist/tests/typePrinter.test.js.map +1 -1
- package/dist/workspaceFactory.d.ts +3 -2
- package/dist/workspaceFactory.js +15 -2
- package/dist/workspaceFactory.js.map +1 -1
- package/package.json +1 -1
- package/dist/analyzer/typeVarContext.d.ts +0 -60
- package/dist/analyzer/typeVarContext.js +0 -392
- package/dist/analyzer/typeVarContext.js.map +0 -1
package/dist/analyzer/checker.js
CHANGED
@@ -50,6 +50,7 @@ const localize_1 = require("../localization/localize");
|
|
50
50
|
const parseNodes_1 = require("../parser/parseNodes");
|
51
51
|
const stringTokenUtils_1 = require("../parser/stringTokenUtils");
|
52
52
|
const AnalyzerNodeInfo = __importStar(require("./analyzerNodeInfo"));
|
53
|
+
const constraintTracker_1 = require("./constraintTracker");
|
53
54
|
const constructors_1 = require("./constructors");
|
54
55
|
const dataClasses_1 = require("./dataClasses");
|
55
56
|
const declaration_1 = require("./declaration");
|
@@ -69,12 +70,12 @@ const sourceMapper_1 = require("./sourceMapper");
|
|
69
70
|
const staticExpressions_1 = require("./staticExpressions");
|
70
71
|
const SymbolNameUtils = __importStar(require("./symbolNameUtils"));
|
71
72
|
const symbolUtils_1 = require("./symbolUtils");
|
73
|
+
const typedDicts_1 = require("./typedDicts");
|
72
74
|
const typeEvaluator_1 = require("./typeEvaluator");
|
75
|
+
const typeEvaluatorTypes_1 = require("./typeEvaluatorTypes");
|
73
76
|
const typeGuards_1 = require("./typeGuards");
|
74
|
-
const typeUtils_1 = require("./typeUtils");
|
75
|
-
const typeVarContext_1 = require("./typeVarContext");
|
76
|
-
const typedDicts_1 = require("./typedDicts");
|
77
77
|
const types_1 = require("./types");
|
78
|
+
const typeUtils_1 = require("./typeUtils");
|
78
79
|
// When enabled, this debug flag causes the code complexity of
|
79
80
|
// functions to be emitted.
|
80
81
|
const isPrintCodeComplexityEnabled = false;
|
@@ -90,7 +91,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
90
91
|
// have their own scopes.
|
91
92
|
this._scopedNodes = [];
|
92
93
|
// A list of all visited type parameter lists.
|
93
|
-
this.
|
94
|
+
this._typeParamLists = [];
|
94
95
|
this._moduleNode = parseResults.parseTree;
|
95
96
|
this._fileInfo = AnalyzerNodeInfo.getFileInfo(this._moduleNode);
|
96
97
|
}
|
@@ -218,43 +219,44 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
218
219
|
// parameters after this need to be flagged as an error.
|
219
220
|
let sawParamSpecArgs = false;
|
220
221
|
const keywordNames = new Set();
|
221
|
-
const paramDetails = (0, parameterUtils_1.
|
222
|
+
const paramDetails = (0, parameterUtils_1.getParamListDetails)(functionTypeResult.functionType);
|
222
223
|
// Report any unknown or missing parameter types.
|
223
224
|
node.d.params.forEach((param, index) => {
|
224
225
|
var _a;
|
225
226
|
if (param.d.name) {
|
226
|
-
if (param.d.category === 0 /*
|
227
|
+
if (param.d.category === 0 /* ParamCategory.Simple */ && index >= paramDetails.positionOnlyParamCount) {
|
227
228
|
keywordNames.add(param.d.name.d.value);
|
228
229
|
}
|
229
230
|
// Determine whether this is a P.args parameter.
|
230
|
-
if (param.d.category === 1 /*
|
231
|
+
if (param.d.category === 1 /* ParamCategory.ArgsList */) {
|
231
232
|
const annotationExpr = (_a = param.d.annotation) !== null && _a !== void 0 ? _a : param.d.annotationComment;
|
232
233
|
if (annotationExpr &&
|
233
234
|
annotationExpr.nodeType === 35 /* ParseNodeType.MemberAccess */ &&
|
234
235
|
annotationExpr.d.member.d.value === 'args') {
|
235
236
|
const baseType = this._evaluator.getType(annotationExpr.d.leftExpr);
|
236
|
-
if (baseType && (0, types_1.
|
237
|
+
if (baseType && (0, types_1.isParamSpec)(baseType)) {
|
237
238
|
sawParamSpecArgs = true;
|
238
239
|
}
|
239
240
|
}
|
240
241
|
}
|
241
|
-
else if (param.d.category === 2 /*
|
242
|
+
else if (param.d.category === 2 /* ParamCategory.KwargsDict */) {
|
242
243
|
sawParamSpecArgs = false;
|
243
244
|
}
|
244
245
|
}
|
245
|
-
if (param.d.name && param.d.category === 0 /*
|
246
|
+
if (param.d.name && param.d.category === 0 /* ParamCategory.Simple */ && sawParamSpecArgs) {
|
246
247
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.namedParamAfterParamSpecArgs().format({ name: param.d.name.d.value }), param.d.name);
|
247
248
|
}
|
248
249
|
// Allow unknown and missing param types if the param is named '_'.
|
249
250
|
if (param.d.name && param.d.name.d.value !== '_') {
|
250
|
-
const
|
251
|
-
if (
|
252
|
-
const
|
251
|
+
const paramIndex = functionTypeResult.functionType.shared.parameters.findIndex((p) => { var _a; return p.name === ((_a = param.d.name) === null || _a === void 0 ? void 0 : _a.d.value); });
|
252
|
+
if (paramIndex >= 0) {
|
253
|
+
const functionTypeParam = functionTypeResult.functionType.shared.parameters[paramIndex];
|
254
|
+
const paramType = types_1.FunctionType.getParamType(functionTypeResult.functionType, paramIndex);
|
253
255
|
if (this._fileInfo.diagnosticRuleSet.reportUnknownParameterType !== 'none') {
|
254
256
|
if ((0, types_1.isUnknown)(paramType) ||
|
255
257
|
((0, types_1.isTypeVar)(paramType) &&
|
256
258
|
paramType.shared.isSynthesized &&
|
257
|
-
!
|
259
|
+
!types_1.TypeVarType.isSelf(paramType))) {
|
258
260
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnknownParameterType, localize_1.LocMessage.paramTypeUnknown().format({ paramName: param.d.name.d.value }), param.d.name);
|
259
261
|
}
|
260
262
|
else if ((0, typeUtils_1.isPartlyUnknown)(paramType)) {
|
@@ -273,7 +275,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
273
275
|
}
|
274
276
|
else {
|
275
277
|
// See if this is a "self" and "cls" parameter. They are exempt from this rule.
|
276
|
-
if ((0, types_1.isTypeVar)(paramType) &&
|
278
|
+
if ((0, types_1.isTypeVar)(paramType) && types_1.TypeVarType.isSelf(paramType)) {
|
277
279
|
hasAnnotation = true;
|
278
280
|
}
|
279
281
|
}
|
@@ -286,7 +288,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
286
288
|
// Verify that an unpacked TypedDict doesn't overlap any keyword parameters.
|
287
289
|
if (paramDetails.hasUnpackedTypedDict) {
|
288
290
|
const kwargsIndex = functionTypeResult.functionType.shared.parameters.length - 1;
|
289
|
-
const kwargsType = types_1.FunctionType.
|
291
|
+
const kwargsType = types_1.FunctionType.getParamType(functionTypeResult.functionType, kwargsIndex);
|
290
292
|
if ((0, types_1.isClass)(kwargsType) && kwargsType.shared.typedDictEntries) {
|
291
293
|
const overlappingEntries = new Set();
|
292
294
|
kwargsType.shared.typedDictEntries.knownItems.forEach((_, name) => {
|
@@ -302,9 +304,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
302
304
|
}
|
303
305
|
}
|
304
306
|
// Check for invalid use of ParamSpec P.args and P.kwargs.
|
305
|
-
const paramSpecParams = functionTypeResult.functionType.shared.parameters.filter((param) => {
|
306
|
-
|
307
|
-
|
307
|
+
const paramSpecParams = functionTypeResult.functionType.shared.parameters.filter((param, index) => {
|
308
|
+
const paramType = types_1.FunctionType.getParamType(functionTypeResult.functionType, index);
|
309
|
+
if (types_1.FunctionParam.isTypeDeclared(param) && (0, types_1.isTypeVar)(paramType) && (0, types_1.isParamSpec)(paramType)) {
|
310
|
+
if (param.category !== 0 /* ParamCategory.Simple */ && param.name && paramType.priv.paramSpecAccess) {
|
308
311
|
return true;
|
309
312
|
}
|
310
313
|
}
|
@@ -342,10 +345,11 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
342
345
|
if (functionTypeResult) {
|
343
346
|
const annotationNode = param.d.annotation || param.d.annotationComment;
|
344
347
|
if (annotationNode && index < functionTypeResult.functionType.shared.parameters.length) {
|
345
|
-
const paramType = functionTypeResult.functionType
|
348
|
+
const paramType = types_1.FunctionType.getParamType(functionTypeResult.functionType, index);
|
346
349
|
const exemptMethods = ['__init__', '__new__'];
|
347
350
|
if (containingClassNode &&
|
348
351
|
(0, types_1.isTypeVar)(paramType) &&
|
352
|
+
paramType.priv.scopeType === 0 /* TypeVarScopeType.Class */ &&
|
349
353
|
paramType.shared.declaredVariance === 3 /* Variance.Covariant */ &&
|
350
354
|
!paramType.shared.isSynthesized &&
|
351
355
|
!exemptMethods.some((name) => name === functionTypeResult.functionType.shared.name)) {
|
@@ -578,34 +582,31 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
578
582
|
}
|
579
583
|
else {
|
580
584
|
const liveScopes = ParseTreeUtils.getTypeVarScopesForNode(node);
|
581
|
-
declaredReturnType =
|
585
|
+
declaredReturnType = this._evaluator.stripTypeGuard(declaredReturnType);
|
586
|
+
let adjReturnType = (0, typeUtils_1.makeTypeVarsBound)(declaredReturnType, liveScopes);
|
582
587
|
let diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
583
588
|
let returnTypeMatches = false;
|
584
|
-
if (this._evaluator.assignType(
|
585
|
-
/* destTypeVarContext */ new typeVarContext_1.TypeVarContext(),
|
586
|
-
/* srcTypeVarContext */ undefined, 128 /* AssignTypeFlags.AllowBoolTypeGuard */)) {
|
589
|
+
if (this._evaluator.assignType(adjReturnType, returnType, diagAddendum)) {
|
587
590
|
returnTypeMatches = true;
|
588
591
|
}
|
589
592
|
else {
|
590
593
|
// See if the declared return type includes one or more constrained TypeVars. If so,
|
591
594
|
// try to narrow these TypeVars to a single type.
|
592
|
-
const uniqueTypeVars = (0, typeUtils_1.
|
593
|
-
if (uniqueTypeVars && uniqueTypeVars.some((typeVar) =>
|
594
|
-
const
|
595
|
+
const uniqueTypeVars = (0, typeUtils_1.getTypeVarArgsRecursive)(declaredReturnType);
|
596
|
+
if (uniqueTypeVars && uniqueTypeVars.some((typeVar) => types_1.TypeVarType.hasConstraints(typeVar))) {
|
597
|
+
const constraints = new constraintTracker_1.ConstraintTracker();
|
595
598
|
for (const typeVar of uniqueTypeVars) {
|
596
|
-
if (
|
597
|
-
const narrowedType = this._evaluator.narrowConstrainedTypeVar(node, typeVar);
|
599
|
+
if (types_1.TypeVarType.hasConstraints(typeVar)) {
|
600
|
+
const narrowedType = this._evaluator.narrowConstrainedTypeVar(node, types_1.TypeVarType.cloneAsBound(typeVar));
|
598
601
|
if (narrowedType) {
|
599
|
-
|
600
|
-
typeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeId)(typeVar));
|
602
|
+
constraints.setBounds(typeVar, narrowedType);
|
601
603
|
}
|
602
604
|
}
|
603
605
|
}
|
604
|
-
if (!
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
/* srcTypeVarContext */ undefined, 128 /* AssignTypeFlags.AllowBoolTypeGuard */)) {
|
606
|
+
if (!constraints.isEmpty()) {
|
607
|
+
adjReturnType = this._evaluator.solveAndApplyConstraints(declaredReturnType, constraints);
|
608
|
+
adjReturnType = (0, typeUtils_1.makeTypeVarsBound)(adjReturnType, liveScopes);
|
609
|
+
if (this._evaluator.assignType(adjReturnType, returnType, diagAddendum)) {
|
609
610
|
returnTypeMatches = true;
|
610
611
|
}
|
611
612
|
}
|
@@ -723,8 +724,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
723
724
|
// assert (x > 3, "bad value x")
|
724
725
|
const type = this._evaluator.getType(node.d.testExpr);
|
725
726
|
if (type && (0, types_1.isClassInstance)(type)) {
|
726
|
-
if ((0, typeUtils_1.isTupleClass)(type) && type.priv.
|
727
|
-
if (type.priv.
|
727
|
+
if ((0, typeUtils_1.isTupleClass)(type) && type.priv.tupleTypeArgs) {
|
728
|
+
if (type.priv.tupleTypeArgs.length > 0) {
|
728
729
|
if (!(0, typeUtils_1.isUnboundedTupleClass)(type)) {
|
729
730
|
this._evaluator.addDiagnosticForTextRange(this._fileInfo, diagnosticRules_1.DiagnosticRule.reportAssertAlwaysTrue, localize_1.LocMessage.assertAlwaysTrue(), node.d.testExpr);
|
730
731
|
}
|
@@ -763,7 +764,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
763
764
|
return true;
|
764
765
|
}
|
765
766
|
visitAugmentedAssignment(node) {
|
766
|
-
this._evaluator.
|
767
|
+
const typeResult = this._evaluator.getTypeResult(node);
|
768
|
+
this._reportDeprecatedUseForOperation(node.d.destExpr, typeResult);
|
767
769
|
return true;
|
768
770
|
}
|
769
771
|
visitIndex(node) {
|
@@ -774,15 +776,13 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
774
776
|
if (baseType) {
|
775
777
|
(0, typeUtils_1.doForEachSubtype)(baseType, (subtype) => {
|
776
778
|
const tupleType = (0, typeUtils_1.getSpecializedTupleType)(subtype);
|
777
|
-
if (!(0, types_1.isClassInstance)(subtype) ||
|
778
|
-
!(tupleType === null || tupleType === void 0 ? void 0 : tupleType.priv.tupleTypeArguments) ||
|
779
|
-
(0, typeUtils_1.isUnboundedTupleClass)(tupleType)) {
|
779
|
+
if (!(0, types_1.isClassInstance)(subtype) || !(tupleType === null || tupleType === void 0 ? void 0 : tupleType.priv.tupleTypeArgs) || (0, typeUtils_1.isUnboundedTupleClass)(tupleType)) {
|
780
780
|
return;
|
781
781
|
}
|
782
|
-
const tupleLength = tupleType.priv.
|
782
|
+
const tupleLength = tupleType.priv.tupleTypeArgs.length;
|
783
783
|
if (node.d.items.length !== 1 ||
|
784
784
|
node.d.trailingComma ||
|
785
|
-
node.d.items[0].d.argCategory !== 0 /*
|
785
|
+
node.d.items[0].d.argCategory !== 0 /* ArgCategory.Simple */ ||
|
786
786
|
node.d.items[0].d.name) {
|
787
787
|
return;
|
788
788
|
}
|
@@ -834,7 +834,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
834
834
|
this._validateContainmentTypes(node);
|
835
835
|
}
|
836
836
|
}
|
837
|
-
this._evaluator.
|
837
|
+
const typeResult = this._evaluator.getTypeResult(node);
|
838
|
+
this._reportDeprecatedUseForOperation(node.d.leftExpr, typeResult);
|
838
839
|
return true;
|
839
840
|
}
|
840
841
|
visitSlice(node) {
|
@@ -853,7 +854,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
853
854
|
if (node.d.operator === 38 /* OperatorType.Not */) {
|
854
855
|
this._validateConditionalIsBool(node.d.expr);
|
855
856
|
}
|
856
|
-
this._evaluator.
|
857
|
+
const typeResult = this._evaluator.getTypeResult(node);
|
858
|
+
this._reportDeprecatedUseForOperation(node.d.expr, typeResult);
|
857
859
|
return true;
|
858
860
|
}
|
859
861
|
visitTernary(node) {
|
@@ -963,7 +965,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
963
965
|
}
|
964
966
|
visitMemberAccess(node) {
|
965
967
|
var _a;
|
966
|
-
const typeResult = this._evaluator.getTypeResult(node);
|
968
|
+
const typeResult = this._evaluator.getTypeResult(node.d.member);
|
967
969
|
const type = (_a = typeResult === null || typeResult === void 0 ? void 0 : typeResult.type) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
|
968
970
|
const leftExprType = this._evaluator.getType(node.d.leftExpr);
|
969
971
|
this._reportDeprecatedUseForType(node.d.member, type, leftExprType && (0, types_1.isModule)(leftExprType) && leftExprType.priv.moduleName === 'typing');
|
@@ -1055,7 +1057,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1055
1057
|
return false;
|
1056
1058
|
}
|
1057
1059
|
visitTypeParameterList(node) {
|
1058
|
-
this.
|
1060
|
+
this._typeParamLists.push(node);
|
1059
1061
|
return true;
|
1060
1062
|
}
|
1061
1063
|
visitTypeParameter(node) {
|
@@ -1071,14 +1073,14 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1071
1073
|
}
|
1072
1074
|
if (typeVarScopeNode.nodeType === 10 /* ParseNodeType.Class */) {
|
1073
1075
|
const classType = (_c = this._evaluator.getTypeOfClass(typeVarScopeNode)) === null || _c === void 0 ? void 0 : _c.classType;
|
1074
|
-
if (classType === null || classType === void 0 ? void 0 : classType.shared.
|
1076
|
+
if (classType === null || classType === void 0 ? void 0 : classType.shared.typeParams.some((param) => param.shared.name === node.d.name.d.value)) {
|
1075
1077
|
foundDuplicate = true;
|
1076
1078
|
break;
|
1077
1079
|
}
|
1078
1080
|
}
|
1079
1081
|
else if (typeVarScopeNode.nodeType === 31 /* ParseNodeType.Function */) {
|
1080
1082
|
const functionType = (_d = this._evaluator.getTypeOfFunction(typeVarScopeNode)) === null || _d === void 0 ? void 0 : _d.functionType;
|
1081
|
-
if (functionType === null || functionType === void 0 ? void 0 : functionType.shared.
|
1083
|
+
if (functionType === null || functionType === void 0 ? void 0 : functionType.shared.typeParams.some((param) => param.shared.name === node.d.name.d.value)) {
|
1082
1084
|
foundDuplicate = true;
|
1083
1085
|
break;
|
1084
1086
|
}
|
@@ -1166,6 +1168,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1166
1168
|
let isTypeBool = true;
|
1167
1169
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
1168
1170
|
this._evaluator.mapSubtypesExpandTypeVars(operandType, /* options */ undefined, (expandedSubtype) => {
|
1171
|
+
var _a;
|
1169
1172
|
if ((0, types_1.isAnyOrUnknown)(expandedSubtype)) {
|
1170
1173
|
return undefined;
|
1171
1174
|
}
|
@@ -1174,8 +1177,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1174
1177
|
return undefined;
|
1175
1178
|
}
|
1176
1179
|
// Invoke the __bool__ method on the type.
|
1177
|
-
const boolReturnType = this._evaluator.getTypeOfMagicMethodCall(expandedSubtype, '__bool__', [], node,
|
1178
|
-
/* inferenceContext */ undefined);
|
1180
|
+
const boolReturnType = (_a = this._evaluator.getTypeOfMagicMethodCall(expandedSubtype, '__bool__', [], node,
|
1181
|
+
/* inferenceContext */ undefined)) === null || _a === void 0 ? void 0 : _a.type;
|
1179
1182
|
if (!boolReturnType || (0, types_1.isAnyOrUnknown)(boolReturnType)) {
|
1180
1183
|
return undefined;
|
1181
1184
|
}
|
@@ -1408,6 +1411,11 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1408
1411
|
isPossiblyTrue = true;
|
1409
1412
|
}
|
1410
1413
|
});
|
1414
|
+
(0, typeUtils_1.doForEachSubtype)(rightType, (rightSubtype) => {
|
1415
|
+
if (this._evaluator.assignType(leftType, rightSubtype)) {
|
1416
|
+
isPossiblyTrue = true;
|
1417
|
+
}
|
1418
|
+
});
|
1411
1419
|
if (!isPossiblyTrue) {
|
1412
1420
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnnecessaryComparison, getMessage().format({
|
1413
1421
|
leftType: this._evaluator.printType(leftType, { expandTypeAlias: true }),
|
@@ -1467,12 +1475,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1467
1475
|
if ((0, types_1.isInstantiableClass)(leftType) || ((0, types_1.isClassInstance)(leftType) && types_1.ClassType.isBuiltIn(leftType, 'type'))) {
|
1468
1476
|
if ((0, types_1.isInstantiableClass)(rightType) ||
|
1469
1477
|
((0, types_1.isClassInstance)(rightType) && types_1.ClassType.isBuiltIn(rightType, 'type'))) {
|
1470
|
-
const genericLeftType = types_1.ClassType.
|
1471
|
-
/*
|
1472
|
-
/* isTypeArgumentExplicit */ false);
|
1473
|
-
const genericRightType = types_1.ClassType.cloneForSpecialization(rightType,
|
1474
|
-
/* typeArguments */ undefined,
|
1475
|
-
/* isTypeArgumentExplicit */ false);
|
1478
|
+
const genericLeftType = types_1.ClassType.specialize(leftType, /* typeArgs */ undefined);
|
1479
|
+
const genericRightType = types_1.ClassType.specialize(rightType, /* typeArgs */ undefined);
|
1476
1480
|
if (this._evaluator.assignType(genericLeftType, genericRightType) ||
|
1477
1481
|
this._evaluator.assignType(genericRightType, genericLeftType)) {
|
1478
1482
|
return true;
|
@@ -1489,12 +1493,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1489
1493
|
}
|
1490
1494
|
if ((0, types_1.isClassInstance)(leftType)) {
|
1491
1495
|
if ((0, types_1.isClassInstance)(rightType)) {
|
1492
|
-
const genericLeftType = types_1.ClassType.
|
1493
|
-
/*
|
1494
|
-
/* isTypeArgumentExplicit */ false);
|
1495
|
-
const genericRightType = types_1.ClassType.cloneForSpecialization(rightType,
|
1496
|
-
/* typeArguments */ undefined,
|
1497
|
-
/* isTypeArgumentExplicit */ false);
|
1496
|
+
const genericLeftType = types_1.ClassType.specialize(leftType, /* typeArgs */ undefined);
|
1497
|
+
const genericRightType = types_1.ClassType.specialize(rightType, /* typeArgs */ undefined);
|
1498
1498
|
if (this._evaluator.assignType(genericLeftType, genericRightType) ||
|
1499
1499
|
this._evaluator.assignType(genericRightType, genericLeftType)) {
|
1500
1500
|
return true;
|
@@ -1551,8 +1551,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1551
1551
|
if (!generatorType || !(0, types_1.isInstantiableClass)(generatorType)) {
|
1552
1552
|
return;
|
1553
1553
|
}
|
1554
|
-
const specializedGenerator = types_1.ClassType.cloneAsInstance(types_1.ClassType.
|
1555
|
-
/* isTypeArgumentExplicit */ true));
|
1554
|
+
const specializedGenerator = types_1.ClassType.cloneAsInstance(types_1.ClassType.specialize(generatorType, [types_1.AnyType.create(), types_1.AnyType.create(), types_1.AnyType.create()]));
|
1556
1555
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
1557
1556
|
if (!this._evaluator.assignType(declaredReturnType, specializedGenerator, diagAddendum)) {
|
1558
1557
|
const errorMessage = node.d.isAsync
|
@@ -1593,13 +1592,13 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1593
1592
|
var _a, _b, _c, _d, _e, _f, _g;
|
1594
1593
|
const nameType = this._evaluator.getType(nameNode);
|
1595
1594
|
``;
|
1596
|
-
if (nameType && (0, types_1.isTypeVar)(nameType) && !
|
1595
|
+
if (nameType && (0, types_1.isTypeVar)(nameType) && !types_1.TypeVarType.isSelf(nameType)) {
|
1597
1596
|
// Does this name refer to a TypeVar that is scoped to this function?
|
1598
1597
|
if (nameType.priv.scopeId === ParseTreeUtils.getScopeIdForNode(node)) {
|
1599
1598
|
// We exempt constrained TypeVars, TypeVars that are type arguments of
|
1600
1599
|
// other types, and ParamSpecs. There are legitimate uses for singleton
|
1601
1600
|
// instances in these particular cases.
|
1602
|
-
let isExempt =
|
1601
|
+
let isExempt = types_1.TypeVarType.hasConstraints(nameType) ||
|
1603
1602
|
nameType.shared.isDefaultExplicit ||
|
1604
1603
|
(exemptBoundTypeVar && subscriptIndex !== undefined) ||
|
1605
1604
|
(0, types_1.isParamSpec)(nameType);
|
@@ -1609,7 +1608,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1609
1608
|
// the TypeVar multiple times.
|
1610
1609
|
const baseType = this._evaluator.getType(baseExpression);
|
1611
1610
|
const aliasInfo = (_a = baseType === null || baseType === void 0 ? void 0 : baseType.props) === null || _a === void 0 ? void 0 : _a.typeAliasInfo;
|
1612
|
-
if ((aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.
|
1611
|
+
if ((aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.typeParams) && subscriptIndex < aliasInfo.typeParams.length) {
|
1613
1612
|
isExempt = true;
|
1614
1613
|
}
|
1615
1614
|
}
|
@@ -1704,7 +1703,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1704
1703
|
// Report error for local type variable that appears only once.
|
1705
1704
|
if (usage.nodes.length === 1 && !usage.isExempt) {
|
1706
1705
|
let altTypeText;
|
1707
|
-
if (usage.typeVar
|
1706
|
+
if ((0, types_1.isTypeVarTuple)(usage.typeVar)) {
|
1708
1707
|
altTypeText = '"tuple[object, ...]"';
|
1709
1708
|
}
|
1710
1709
|
else if (usage.typeVar.shared.boundType) {
|
@@ -1813,8 +1812,9 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1813
1812
|
if (prevReturnType &&
|
1814
1813
|
returnType &&
|
1815
1814
|
!this._evaluator.assignType(returnType, prevReturnType,
|
1816
|
-
/* diag */ undefined,
|
1817
|
-
/*
|
1815
|
+
/* diag */ undefined,
|
1816
|
+
/* destConstraints */ undefined,
|
1817
|
+
/* srcConstraints */ undefined, 0 /* AssignTypeFlags.Default */)) {
|
1818
1818
|
const altNode = this._findNodeForOverload(node, prevOverload);
|
1819
1819
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportOverlappingOverload, localize_1.LocMessage.overloadReturnTypeMismatch().format({
|
1820
1820
|
name: node.d.name.d.value,
|
@@ -1845,6 +1845,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1845
1845
|
return undefined;
|
1846
1846
|
}
|
1847
1847
|
_isOverlappingOverload(functionType, prevOverload, partialOverlap) {
|
1848
|
+
var _a, _b, _c;
|
1848
1849
|
// According to precedent, the __get__ method is special-cased and is
|
1849
1850
|
// exempt from overlapping overload checks. It's not clear why this is
|
1850
1851
|
// the case, but for consistency with other type checkers, we'll honor
|
@@ -1857,24 +1858,49 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1857
1858
|
if (partialOverlap) {
|
1858
1859
|
flags |= 32 /* AssignTypeFlags.PartialOverloadOverlap */;
|
1859
1860
|
}
|
1861
|
+
const functionNode = (_a = functionType.shared.declaration) === null || _a === void 0 ? void 0 : _a.node;
|
1862
|
+
if (functionNode) {
|
1863
|
+
const liveTypeVars = ParseTreeUtils.getTypeVarScopesForNode(functionNode);
|
1864
|
+
functionType = (0, typeUtils_1.makeTypeVarsBound)(functionType, liveTypeVars);
|
1865
|
+
}
|
1866
|
+
// Use the parent node of the declaration in this case so we don't transform
|
1867
|
+
// function-local type variables into bound type variables.
|
1868
|
+
const prevOverloadNode = (_c = (_b = prevOverload.shared.declaration) === null || _b === void 0 ? void 0 : _b.node) === null || _c === void 0 ? void 0 : _c.parent;
|
1869
|
+
if (prevOverloadNode) {
|
1870
|
+
const liveTypeVars = ParseTreeUtils.getTypeVarScopesForNode(prevOverloadNode);
|
1871
|
+
prevOverload = (0, typeUtils_1.makeTypeVarsBound)(prevOverload, liveTypeVars);
|
1872
|
+
}
|
1860
1873
|
return this._evaluator.assignType(functionType, prevOverload,
|
1861
|
-
/* diag */ undefined,
|
1862
|
-
/*
|
1863
|
-
|
1864
|
-
|
1865
|
-
|
1866
|
-
|
1867
|
-
|
1874
|
+
/* diag */ undefined,
|
1875
|
+
/* destConstraints */ undefined,
|
1876
|
+
/* srcConstraints */ undefined, flags);
|
1877
|
+
}
|
1878
|
+
// Determines whether the implementation of an overload is compatible with an
|
1879
|
+
// overload signature. To be compatible, the implementation must accept all
|
1880
|
+
// of the same arguments as the overload and return a type that is consistent
|
1881
|
+
// with the overload's return type.
|
1882
|
+
_validateOverloadImplementation(overload, implementation, diag) {
|
1883
|
+
var _a, _b, _c;
|
1884
|
+
const implConstraints = new constraintTracker_1.ConstraintTracker();
|
1885
|
+
const overloadConstraints = new constraintTracker_1.ConstraintTracker();
|
1868
1886
|
// First check the parameters to see if they are assignable.
|
1869
|
-
let isLegal = this._evaluator.assignType(overload, implementation, diag,
|
1887
|
+
let isLegal = this._evaluator.assignType(overload, implementation, diag, overloadConstraints, implConstraints, 64 /* AssignTypeFlags.SkipReturnTypeCheck */ |
|
1870
1888
|
2 /* AssignTypeFlags.ReverseTypeVarMatching */ |
|
1871
1889
|
512 /* AssignTypeFlags.SkipSelfClsTypeCheck */);
|
1872
1890
|
// Now check the return types.
|
1873
|
-
|
1874
|
-
|
1891
|
+
let overloadReturnType = (_a = overload.shared.declaredReturnType) !== null && _a !== void 0 ? _a : this._evaluator.getFunctionInferredReturnType(overload);
|
1892
|
+
let implementationReturnType = this._evaluator.solveAndApplyConstraints(implementation.shared.declaredReturnType || this._evaluator.getFunctionInferredReturnType(implementation), implConstraints);
|
1893
|
+
if ((_c = (_b = implementation.shared.declaration) === null || _b === void 0 ? void 0 : _b.node) === null || _c === void 0 ? void 0 : _c.parent) {
|
1894
|
+
// Use the parent node of the implementation to determine which type variables
|
1895
|
+
// are live. This will include any class-scoped type variables if this is an
|
1896
|
+
// overloaded method.
|
1897
|
+
const liveScopeIds = ParseTreeUtils.getTypeVarScopesForNode(implementation.shared.declaration.node.parent);
|
1898
|
+
implementationReturnType = (0, typeUtils_1.makeTypeVarsBound)(implementationReturnType, liveScopeIds);
|
1899
|
+
overloadReturnType = (0, typeUtils_1.makeTypeVarsBound)(overloadReturnType, liveScopeIds);
|
1900
|
+
}
|
1875
1901
|
const returnDiag = new diagnostic_1.DiagnosticAddendum();
|
1876
1902
|
if (!(0, types_1.isNever)(overloadReturnType) &&
|
1877
|
-
!this._evaluator.assignType(implementationReturnType, overloadReturnType, returnDiag.createAddendum(),
|
1903
|
+
!this._evaluator.assignType(implementationReturnType, overloadReturnType, returnDiag.createAddendum(), implConstraints, overloadConstraints, 0 /* AssignTypeFlags.Default */)) {
|
1878
1904
|
returnDiag.addMessage(localize_1.LocAddendum.functionReturnTypeMismatch().format({
|
1879
1905
|
sourceType: this._evaluator.printType(overloadReturnType),
|
1880
1906
|
destType: this._evaluator.printType(implementationReturnType),
|
@@ -1891,13 +1917,14 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1891
1917
|
// No need to report unreachable more than once since the first time
|
1892
1918
|
// covers all remaining statements in the statement list.
|
1893
1919
|
if (!reportedUnreachable) {
|
1894
|
-
|
1920
|
+
const reachability = this._evaluator.getNodeReachability(statement, prevStatement);
|
1921
|
+
if (reachability !== typeEvaluatorTypes_1.Reachability.Reachable) {
|
1895
1922
|
// Create a text range that covers the next statement through
|
1896
1923
|
// the end of the statement list.
|
1897
1924
|
const start = statement.start;
|
1898
1925
|
const lastStatement = statements[statements.length - 1];
|
1899
1926
|
const end = textRange_1.TextRange.getEnd(lastStatement);
|
1900
|
-
this._evaluator.addUnreachableCode(statement, { start, length: end - start });
|
1927
|
+
this._evaluator.addUnreachableCode(statement, reachability, { start, length: end - start });
|
1901
1928
|
reportedUnreachable = true;
|
1902
1929
|
}
|
1903
1930
|
}
|
@@ -2016,8 +2043,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2016
2043
|
}
|
2017
2044
|
return;
|
2018
2045
|
}
|
2019
|
-
if (allowTuple && exceptionSubtype.priv.
|
2020
|
-
exceptionSubtype.priv.
|
2046
|
+
if (allowTuple && exceptionSubtype.priv.tupleTypeArgs) {
|
2047
|
+
exceptionSubtype.priv.tupleTypeArgs.forEach((typeArg) => {
|
2021
2048
|
this._validateExceptionTypeRecursive(typeArg.type, diag, baseExceptionType, baseExceptionGroupType,
|
2022
2049
|
/* allowTuple */ false, isExceptGroup);
|
2023
2050
|
});
|
@@ -2066,6 +2093,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2066
2093
|
this._conditionallyReportUnusedSymbol(name, symbol, scope.type, dependentFileInfo);
|
2067
2094
|
this._reportIncompatibleDeclarations(name, symbol);
|
2068
2095
|
this._reportMultipleFinalDeclarations(name, symbol, scope.type);
|
2096
|
+
this._reportFinalInLoop(symbol);
|
2069
2097
|
this._reportMultipleTypeAliasDeclarations(name, symbol);
|
2070
2098
|
this._reportInvalidOverload(name, symbol);
|
2071
2099
|
});
|
@@ -2073,7 +2101,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2073
2101
|
}
|
2074
2102
|
// Report unaccessed type parameters.
|
2075
2103
|
const accessedSymbolSet = this._fileInfo.accessedSymbolSet;
|
2076
|
-
for (const paramList of this.
|
2104
|
+
for (const paramList of this._typeParamLists) {
|
2077
2105
|
const typeParamScope = AnalyzerNodeInfo.getScope(paramList);
|
2078
2106
|
for (const param of paramList.d.params) {
|
2079
2107
|
const symbol = typeParamScope === null || typeParamScope === void 0 ? void 0 : typeParamScope.symbolTable.get(param.d.name.d.value);
|
@@ -2165,7 +2193,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2165
2193
|
types_1.OverloadedFunctionType.getOverloads(type).forEach((overload, index) => {
|
2166
2194
|
var _a, _b, _c, _d;
|
2167
2195
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
2168
|
-
if (!this.
|
2196
|
+
if (!this._validateOverloadImplementation(overload, implementationFunction, diag)) {
|
2169
2197
|
if (implementationFunction.shared.declaration) {
|
2170
2198
|
const diagnostic = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInconsistentOverload, localize_1.LocMessage.overloadImplementationMismatch().format({
|
2171
2199
|
name,
|
@@ -2178,6 +2206,18 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2178
2206
|
}
|
2179
2207
|
});
|
2180
2208
|
}
|
2209
|
+
_reportFinalInLoop(symbol) {
|
2210
|
+
if (!this._evaluator.isFinalVariable(symbol)) {
|
2211
|
+
return;
|
2212
|
+
}
|
2213
|
+
const decls = symbol.getDeclarations();
|
2214
|
+
if (decls.length === 0) {
|
2215
|
+
return;
|
2216
|
+
}
|
2217
|
+
if (ParseTreeUtils.isWithinLoop(decls[0].node)) {
|
2218
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.finalInLoop(), decls[0].node);
|
2219
|
+
}
|
2220
|
+
}
|
2181
2221
|
_reportMultipleFinalDeclarations(name, symbol, scopeType) {
|
2182
2222
|
if (!this._evaluator.isFinalVariable(symbol)) {
|
2183
2223
|
return;
|
@@ -2325,7 +2365,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2325
2365
|
else if (primaryDecl.type === 6 /* DeclarationType.Class */) {
|
2326
2366
|
primaryDeclInfo = localize_1.LocAddendum.seeClassDeclaration();
|
2327
2367
|
}
|
2328
|
-
else if (primaryDecl.type === 2 /* DeclarationType.
|
2368
|
+
else if (primaryDecl.type === 2 /* DeclarationType.Param */) {
|
2329
2369
|
primaryDeclInfo = localize_1.LocAddendum.seeParameterDeclaration();
|
2330
2370
|
}
|
2331
2371
|
else if (primaryDecl.type === 1 /* DeclarationType.Variable */) {
|
@@ -2348,8 +2388,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2348
2388
|
primaryDeclNode = primaryDecl.node;
|
2349
2389
|
}
|
2350
2390
|
}
|
2351
|
-
else if (primaryDecl.type === 2 /* DeclarationType.
|
2352
|
-
primaryDecl.type === 3 /* DeclarationType.
|
2391
|
+
else if (primaryDecl.type === 2 /* DeclarationType.Param */ ||
|
2392
|
+
primaryDecl.type === 3 /* DeclarationType.TypeParam */) {
|
2353
2393
|
if (primaryDecl.node.d.name) {
|
2354
2394
|
primaryDeclNode = primaryDecl.node.d.name;
|
2355
2395
|
}
|
@@ -2362,7 +2402,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2362
2402
|
for (const otherDecl of otherDecls) {
|
2363
2403
|
if (otherDecl.type === 6 /* DeclarationType.Class */) {
|
2364
2404
|
let duplicateIsOk = false;
|
2365
|
-
if (primaryDecl.type === 3 /* DeclarationType.
|
2405
|
+
if (primaryDecl.type === 3 /* DeclarationType.TypeParam */) {
|
2366
2406
|
// The error will be reported elsewhere if a type parameter is
|
2367
2407
|
// involved, so don't report it here.
|
2368
2408
|
duplicateIsOk = true;
|
@@ -2395,7 +2435,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2395
2435
|
if (!isInSameStatementList && primaryType && otherType && (0, types_1.isTypeSame)(primaryType, otherType)) {
|
2396
2436
|
duplicateIsOk = true;
|
2397
2437
|
}
|
2398
|
-
if (primaryDecl.type === 3 /* DeclarationType.
|
2438
|
+
if (primaryDecl.type === 3 /* DeclarationType.TypeParam */) {
|
2399
2439
|
// The error will be reported elsewhere if a type parameter is
|
2400
2440
|
// involved, so don't report it here.
|
2401
2441
|
duplicateIsOk = true;
|
@@ -2407,10 +2447,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2407
2447
|
addPrimaryDeclInfo(diag);
|
2408
2448
|
}
|
2409
2449
|
}
|
2410
|
-
else if (otherDecl.type === 2 /* DeclarationType.
|
2450
|
+
else if (otherDecl.type === 2 /* DeclarationType.Param */) {
|
2411
2451
|
if (otherDecl.node.d.name) {
|
2412
2452
|
let duplicateIsOk = false;
|
2413
|
-
if (primaryDecl.type === 3 /* DeclarationType.
|
2453
|
+
if (primaryDecl.type === 3 /* DeclarationType.TypeParam */) {
|
2414
2454
|
// The error will be reported elsewhere if a type parameter is
|
2415
2455
|
// involved, so don't report it here.
|
2416
2456
|
duplicateIsOk = true;
|
@@ -2432,7 +2472,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2432
2472
|
if (primaryType && otherType && (0, types_1.isTypeSame)(primaryType, otherType)) {
|
2433
2473
|
duplicateIsOk = true;
|
2434
2474
|
}
|
2435
|
-
if (primaryDecl.type === 3 /* DeclarationType.
|
2475
|
+
if (primaryDecl.type === 3 /* DeclarationType.TypeParam */) {
|
2436
2476
|
// The error will be reported elsewhere if a type parameter is
|
2437
2477
|
// involved, so don't report it here.
|
2438
2478
|
duplicateIsOk = true;
|
@@ -2523,7 +2563,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2523
2563
|
break;
|
2524
2564
|
case 4 /* DeclarationType.TypeAlias */:
|
2525
2565
|
case 1 /* DeclarationType.Variable */:
|
2526
|
-
case 2 /* DeclarationType.
|
2566
|
+
case 2 /* DeclarationType.Param */:
|
2527
2567
|
if (!isPrivate) {
|
2528
2568
|
return;
|
2529
2569
|
}
|
@@ -2579,8 +2619,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2579
2619
|
rule = diagnosticRules_1.DiagnosticRule.reportUnusedFunction;
|
2580
2620
|
message = localize_1.LocMessage.unaccessedFunction().format({ name: nameNode.d.value });
|
2581
2621
|
break;
|
2582
|
-
case 3 /* DeclarationType.
|
2583
|
-
// Never report a diagnostic for an unused
|
2622
|
+
case 3 /* DeclarationType.TypeParam */:
|
2623
|
+
// Never report a diagnostic for an unused TypeParam.
|
2584
2624
|
diagnosticLevel = 'none';
|
2585
2625
|
nameNode = decl.node.d.name;
|
2586
2626
|
break;
|
@@ -2624,10 +2664,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2624
2664
|
let isValidType = true;
|
2625
2665
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
2626
2666
|
(0, typeUtils_1.doForEachSubtype)(arg1Type, (arg1Subtype) => {
|
2627
|
-
if ((0, types_1.isClassInstance)(arg1Subtype) &&
|
2628
|
-
|
2629
|
-
arg1Subtype.priv.tupleTypeArguments) {
|
2630
|
-
if (arg1Subtype.priv.tupleTypeArguments.some((typeArg) => !this._isTypeSupportedTypeForIsInstance(typeArg.type, isInstanceCheck, diag))) {
|
2667
|
+
if ((0, types_1.isClassInstance)(arg1Subtype) && types_1.ClassType.isTupleClass(arg1Subtype) && arg1Subtype.priv.tupleTypeArgs) {
|
2668
|
+
if (arg1Subtype.priv.tupleTypeArgs.some((typeArg) => !this._isTypeSupportedTypeForIsInstance(typeArg.type, isInstanceCheck, diag))) {
|
2631
2669
|
isValidType = false;
|
2632
2670
|
}
|
2633
2671
|
}
|
@@ -2653,8 +2691,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2653
2691
|
(0, typeUtils_1.doForEachSubtype)(arg1Type, (arg1Subtype) => {
|
2654
2692
|
if ((0, types_1.isClassInstance)(arg1Subtype) &&
|
2655
2693
|
types_1.ClassType.isTupleClass(arg1Subtype) &&
|
2656
|
-
arg1Subtype.priv.
|
2657
|
-
arg1Subtype.priv.
|
2694
|
+
arg1Subtype.priv.tupleTypeArgs) {
|
2695
|
+
arg1Subtype.priv.tupleTypeArgs.forEach((typeArg) => {
|
2658
2696
|
this._validateNotDataProtocol(typeArg.type, diag);
|
2659
2697
|
});
|
2660
2698
|
}
|
@@ -2709,8 +2747,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2709
2747
|
// The isinstance and issubclass call supports a variation where the second
|
2710
2748
|
// parameter is a tuple of classes.
|
2711
2749
|
if ((0, typeUtils_1.isTupleClass)(arg1Subtype)) {
|
2712
|
-
if (arg1Subtype.priv.
|
2713
|
-
arg1Subtype.priv.
|
2750
|
+
if (arg1Subtype.priv.tupleTypeArgs) {
|
2751
|
+
arg1Subtype.priv.tupleTypeArgs.forEach((typeArg) => {
|
2714
2752
|
if ((0, types_1.isInstantiableClass)(typeArg.type)) {
|
2715
2753
|
classTypeList.push(typeArg.type);
|
2716
2754
|
if (typeArg.type.priv.includeSubclasses) {
|
@@ -2890,7 +2928,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2890
2928
|
diag.addMessage(localize_1.LocAddendum.typedDictClassNotAllowed());
|
2891
2929
|
isSupported = false;
|
2892
2930
|
}
|
2893
|
-
else if (subtype.priv.
|
2931
|
+
else if (subtype.priv.isTypeArgExplicit && !subtype.priv.includeSubclasses) {
|
2894
2932
|
// If it's a class, make sure that it has not been given explicit
|
2895
2933
|
// type arguments. This will result in a TypeError exception.
|
2896
2934
|
diag.addMessage(localize_1.LocAddendum.genericClassNotAllowed());
|
@@ -2990,9 +3028,19 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2990
3028
|
}
|
2991
3029
|
}
|
2992
3030
|
if (errorMessage) {
|
2993
|
-
this._reportDeprecatedDiagnostic(node, errorMessage, info.
|
3031
|
+
this._reportDeprecatedDiagnostic(node, errorMessage, info.deprecatedMessage);
|
2994
3032
|
}
|
2995
3033
|
}
|
3034
|
+
_reportDeprecatedUseForOperation(node, typeResult) {
|
3035
|
+
const deprecationInfo = typeResult === null || typeResult === void 0 ? void 0 : typeResult.magicMethodDeprecationInfo;
|
3036
|
+
if (!deprecationInfo) {
|
3037
|
+
return;
|
3038
|
+
}
|
3039
|
+
this._reportDeprecatedDiagnostic(node, localize_1.LocMessage.deprecatedMethod().format({
|
3040
|
+
className: deprecationInfo.className,
|
3041
|
+
name: deprecationInfo.methodName,
|
3042
|
+
}), deprecationInfo.deprecatedMessage);
|
3043
|
+
}
|
2996
3044
|
_reportDeprecatedUseForType(node, type, isImportFromTyping = false) {
|
2997
3045
|
var _a, _b, _c;
|
2998
3046
|
if (!type) {
|
@@ -3041,7 +3089,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3041
3089
|
deprecatedMessage = overload.shared.deprecatedMessage;
|
3042
3090
|
errorMessage = getDeprecatedMessageForFunction(overload);
|
3043
3091
|
}
|
3044
|
-
else if ((0, types_1.isInstantiableClass)(type) &&
|
3092
|
+
else if ((0, types_1.isInstantiableClass)(type) &&
|
3093
|
+
['__init__', '__new__'].includes(overload.shared.name)) {
|
3045
3094
|
deprecatedMessage = overload.shared.deprecatedMessage;
|
3046
3095
|
errorMessage = localize_1.LocMessage.deprecatedConstructor().format({
|
3047
3096
|
name: type.shared.name,
|
@@ -3106,18 +3155,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3106
3155
|
((_c = (_b = type.props) === null || _b === void 0 ? void 0 : _b.typeAliasInfo) === null || _c === void 0 ? void 0 : _c.fullName) === deprecatedForm.fullName) {
|
3107
3156
|
if (this._fileInfo.executionEnvironment.pythonVersion.isGreaterOrEqualTo(deprecatedForm.version)) {
|
3108
3157
|
if (!deprecatedForm.typingImportOnly || isImportFromTyping) {
|
3109
|
-
|
3110
|
-
|
3111
|
-
|
3112
|
-
|
3113
|
-
}), node);
|
3114
|
-
}
|
3115
|
-
else {
|
3116
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportDeprecated, localize_1.LocMessage.deprecatedType().format({
|
3117
|
-
version: deprecatedForm.version.toString(),
|
3118
|
-
replacement: deprecatedForm.replacementText,
|
3119
|
-
}), node);
|
3120
|
-
}
|
3158
|
+
this._reportDeprecatedDiagnostic(node, localize_1.LocMessage.deprecatedType().format({
|
3159
|
+
version: deprecatedForm.version.toString(),
|
3160
|
+
replacement: deprecatedForm.replacementText,
|
3161
|
+
}));
|
3121
3162
|
}
|
3122
3163
|
}
|
3123
3164
|
}
|
@@ -3376,9 +3417,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3376
3417
|
if (!returnType) {
|
3377
3418
|
return;
|
3378
3419
|
}
|
3379
|
-
if (!(0, types_1.isClassInstance)(returnType) ||
|
3380
|
-
!returnType.priv.typeArguments ||
|
3381
|
-
returnType.priv.typeArguments.length < 1) {
|
3420
|
+
if (!(0, types_1.isClassInstance)(returnType) || !returnType.priv.typeArgs || returnType.priv.typeArgs.length < 1) {
|
3382
3421
|
return;
|
3383
3422
|
}
|
3384
3423
|
const isTypeGuard = types_1.ClassType.isBuiltIn(returnType, 'TypeGuard');
|
@@ -3399,13 +3438,14 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3399
3438
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeGuardParamCount(), node.d.name);
|
3400
3439
|
}
|
3401
3440
|
if (isTypeIs) {
|
3402
|
-
const
|
3441
|
+
const scopeIds = (0, typeUtils_1.getTypeVarScopeIds)(functionType);
|
3442
|
+
const typeGuardType = (0, typeUtils_1.makeTypeVarsBound)(returnType.priv.typeArgs[0], scopeIds);
|
3403
3443
|
// Determine the type of the first parameter.
|
3404
3444
|
const paramIndex = isMethod && !types_1.FunctionType.isStaticMethod(functionType) ? 1 : 0;
|
3405
3445
|
if (paramIndex >= functionType.shared.parameters.length) {
|
3406
3446
|
return;
|
3407
3447
|
}
|
3408
|
-
const paramType = types_1.FunctionType.
|
3448
|
+
const paramType = (0, typeUtils_1.makeTypeVarsBound)(types_1.FunctionType.getParamType(functionType, paramIndex), scopeIds);
|
3409
3449
|
// Verify that the typeGuardType is a narrower type than the paramType.
|
3410
3450
|
if (!this._evaluator.assignType(paramType, typeGuardType)) {
|
3411
3451
|
const returnAnnotation = node.d.returnAnnotation || ((_a = node.d.funcAnnotationComment) === null || _a === void 0 ? void 0 : _a.d.returnAnnotation);
|
@@ -3455,6 +3495,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3455
3495
|
if (declaredReturnType) {
|
3456
3496
|
this._reportUnknownReturnResult(node, declaredReturnType);
|
3457
3497
|
this._validateReturnTypeIsNotContravariant(declaredReturnType, returnAnnotation);
|
3498
|
+
const liveScopes = ParseTreeUtils.getTypeVarScopesForNode(node);
|
3499
|
+
declaredReturnType = (0, typeUtils_1.makeTypeVarsBound)(declaredReturnType, liveScopes);
|
3458
3500
|
}
|
3459
3501
|
// Wrap the declared type in a generator type if the function is a generator.
|
3460
3502
|
if (types_1.FunctionType.isGenerator(functionType)) {
|
@@ -3609,6 +3651,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3609
3651
|
if (decls[0].type !== 1 /* DeclarationType.Variable */) {
|
3610
3652
|
return;
|
3611
3653
|
}
|
3654
|
+
// Look for an enum attribute annotated with "Final".
|
3655
|
+
if (decls[0].isFinal) {
|
3656
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.enumMemberTypeAnnotation(), decls[0].node);
|
3657
|
+
}
|
3612
3658
|
const declNode = decls[0].node;
|
3613
3659
|
const assignedValueType = symbolType.priv.literalValue.itemType;
|
3614
3660
|
const assignmentNode = ParseTreeUtils.getParentNodeOfType(declNode, 3 /* ParseNodeType.Assignment */);
|
@@ -3620,21 +3666,21 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3620
3666
|
// unpack it. Otherwise, only one argument is passed.
|
3621
3667
|
const argList = [
|
3622
3668
|
{
|
3623
|
-
|
3624
|
-
? 1 /*
|
3625
|
-
: 0 /*
|
3669
|
+
argCategory: (0, types_1.isClassInstance)(assignedValueType) && (0, typeUtils_1.isTupleClass)(assignedValueType)
|
3670
|
+
? 1 /* ArgCategory.UnpackedList */
|
3671
|
+
: 0 /* ArgCategory.Simple */,
|
3626
3672
|
typeResult: { type: assignedValueType },
|
3627
3673
|
},
|
3628
3674
|
];
|
3629
3675
|
if (newMemberTypeResult) {
|
3630
|
-
this._evaluator.
|
3631
|
-
/*
|
3676
|
+
this._evaluator.validateCallArgs(errorNode, argList, newMemberTypeResult,
|
3677
|
+
/* constraints */ undefined,
|
3632
3678
|
/* skipUnknownArgCheck */ undefined,
|
3633
3679
|
/* inferenceContext */ undefined);
|
3634
3680
|
}
|
3635
3681
|
if (initMemberTypeResult) {
|
3636
|
-
this._evaluator.
|
3637
|
-
/*
|
3682
|
+
this._evaluator.validateCallArgs(errorNode, argList, initMemberTypeResult,
|
3683
|
+
/* constraints */ undefined,
|
3638
3684
|
/* skipUnknownArgCheck */ undefined,
|
3639
3685
|
/* inferenceContext */ undefined);
|
3640
3686
|
}
|
@@ -3684,7 +3730,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3684
3730
|
!postInitType.shared.declaration) {
|
3685
3731
|
return;
|
3686
3732
|
}
|
3687
|
-
const paramListDetails = (0, parameterUtils_1.
|
3733
|
+
const paramListDetails = (0, parameterUtils_1.getParamListDetails)(postInitType);
|
3688
3734
|
// If there is an *args or **kwargs parameter or a keyword-only separator,
|
3689
3735
|
// don't bother checking.
|
3690
3736
|
if (paramListDetails.argsIndex !== undefined ||
|
@@ -3693,7 +3739,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3693
3739
|
return;
|
3694
3740
|
}
|
3695
3741
|
// Verify that the parameter count matches.
|
3696
|
-
const nonDefaultParams = paramListDetails.params.filter((paramInfo) =>
|
3742
|
+
const nonDefaultParams = paramListDetails.params.filter((paramInfo, index) => types_1.FunctionType.getParamDefaultType(postInitType, index) === undefined);
|
3697
3743
|
// We expect to see one param for "self" plus one for each of the InitVars.
|
3698
3744
|
const expectedParamCount = initOnlySymbolMap.size + 1;
|
3699
3745
|
const postInitNode = postInitType.shared.declaration.node;
|
@@ -3712,7 +3758,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3712
3758
|
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
3759
|
if (types_1.FunctionParam.isTypeDeclared(param) && annotationNode) {
|
3714
3760
|
const fieldType = (_b = this._evaluator.getDeclaredTypeOfSymbol(symbol)) === null || _b === void 0 ? void 0 : _b.type;
|
3715
|
-
const paramType = types_1.FunctionType.
|
3761
|
+
const paramType = types_1.FunctionType.getParamType(postInitType, paramListDetails.params[paramIndex].index);
|
3716
3762
|
const assignTypeDiag = new diagnostic_1.DiagnosticAddendum();
|
3717
3763
|
if (fieldType && !this._evaluator.assignType(paramType, fieldType, assignTypeDiag)) {
|
3718
3764
|
const diagnostic = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.dataClassPostInitType().format({ fieldName }) + assignTypeDiag.getString(), annotationNode);
|
@@ -3885,7 +3931,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3885
3931
|
// for an explanation for why this is important to enforce.
|
3886
3932
|
_validateProtocolTypeParamVariance(errorNode, classType) {
|
3887
3933
|
// If this protocol has no TypeVars with specified variance, there's nothing to do here.
|
3888
|
-
if (classType.shared.
|
3934
|
+
if (classType.shared.typeParams.length === 0) {
|
3889
3935
|
return;
|
3890
3936
|
}
|
3891
3937
|
const objectType = this._evaluator.getBuiltInType(errorNode, 'object');
|
@@ -3894,9 +3940,9 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3894
3940
|
}
|
3895
3941
|
const objectObject = types_1.ClassType.cloneAsInstance(objectType);
|
3896
3942
|
const dummyTypeObject = types_1.ClassType.createInstantiable('__varianceDummy', '', '', uri_1.Uri.empty(), 0, 0, undefined, undefined);
|
3897
|
-
classType.shared.
|
3898
|
-
// Skip
|
3899
|
-
if (param
|
3943
|
+
classType.shared.typeParams.forEach((param, paramIndex) => {
|
3944
|
+
// Skip TypeVarTuples and ParamSpecs.
|
3945
|
+
if ((0, types_1.isTypeVarTuple)(param) || (0, types_1.isParamSpec)(param)) {
|
3900
3946
|
return;
|
3901
3947
|
}
|
3902
3948
|
// Skip type variables with auto-variance.
|
@@ -3905,20 +3951,19 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3905
3951
|
}
|
3906
3952
|
// Replace all type arguments with a dummy type except for the
|
3907
3953
|
// TypeVar of interest, which is replaced with an object instance.
|
3908
|
-
const srcTypeArgs = classType.shared.
|
3909
|
-
if (
|
3954
|
+
const srcTypeArgs = classType.shared.typeParams.map((p, i) => {
|
3955
|
+
if ((0, types_1.isTypeVarTuple)(p)) {
|
3910
3956
|
return p;
|
3911
3957
|
}
|
3912
3958
|
return i === paramIndex ? objectObject : dummyTypeObject;
|
3913
3959
|
});
|
3914
3960
|
// Replace all type arguments with a dummy type except for the
|
3915
3961
|
// TypeVar of interest, which is replaced with itself.
|
3916
|
-
const destTypeArgs = classType.shared.
|
3917
|
-
return i === paramIndex || p
|
3962
|
+
const destTypeArgs = classType.shared.typeParams.map((p, i) => {
|
3963
|
+
return i === paramIndex || (0, types_1.isTypeVarTuple)(p) ? p : dummyTypeObject;
|
3918
3964
|
});
|
3919
|
-
const srcType = types_1.ClassType.
|
3920
|
-
const destType = types_1.ClassType.
|
3921
|
-
/* isTypeArgumentExplicit */ true);
|
3965
|
+
const srcType = types_1.ClassType.specialize(classType, srcTypeArgs);
|
3966
|
+
const destType = types_1.ClassType.specialize(classType, destTypeArgs);
|
3922
3967
|
const isDestSubtypeOfSrc = this._evaluator.assignClassToSelf(srcType, destType, 3 /* Variance.Covariant */);
|
3923
3968
|
let expectedVariance;
|
3924
3969
|
if (isDestSubtypeOfSrc) {
|
@@ -3933,7 +3978,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3933
3978
|
expectedVariance = 2 /* Variance.Invariant */;
|
3934
3979
|
}
|
3935
3980
|
}
|
3936
|
-
if (expectedVariance !== classType.shared.
|
3981
|
+
if (expectedVariance !== classType.shared.typeParams[paramIndex].shared.declaredVariance) {
|
3937
3982
|
let message;
|
3938
3983
|
if (expectedVariance === 3 /* Variance.Covariant */) {
|
3939
3984
|
message = localize_1.LocMessage.protocolVarianceCovariant().format({
|
@@ -4036,22 +4081,17 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4036
4081
|
}
|
4037
4082
|
// If either of the functions has a default parameter signature
|
4038
4083
|
// (* args: Any, ** kwargs: Any), don't proceed with the check.
|
4039
|
-
if (types_1.FunctionType.
|
4084
|
+
if (types_1.FunctionType.hasDefaultParams(initMemberType) || types_1.FunctionType.hasDefaultParams(newMemberType)) {
|
4040
4085
|
return;
|
4041
4086
|
}
|
4042
|
-
// We'll set the "SkipArgsKwargs" flag for pragmatic reasons since __new__
|
4043
|
-
// often has an *args and/or **kwargs. We'll also set the ParamSpecValue
|
4044
|
-
// because we don't care about the return type for this check.
|
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 */);
|
4047
4087
|
if (!this._evaluator.assignType(newMemberType, initMemberType,
|
4048
4088
|
/* diag */ undefined,
|
4049
|
-
/*
|
4050
|
-
/*
|
4089
|
+
/* destConstraints */ undefined,
|
4090
|
+
/* srcConstraints */ undefined, 64 /* AssignTypeFlags.SkipReturnTypeCheck */) ||
|
4051
4091
|
!this._evaluator.assignType(initMemberType, newMemberType,
|
4052
4092
|
/* diag */ undefined,
|
4053
|
-
/*
|
4054
|
-
/*
|
4093
|
+
/* destConstraints */ undefined,
|
4094
|
+
/* srcConstraints */ undefined, 64 /* AssignTypeFlags.SkipReturnTypeCheck */)) {
|
4055
4095
|
const displayOnInit = types_1.ClassType.isSameGenericClass(initMethodResult.classType, classType);
|
4056
4096
|
const initDecl = initMemberType.shared.declaration;
|
4057
4097
|
const newDecl = newMemberType.shared.declaration;
|
@@ -4098,16 +4138,17 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4098
4138
|
}
|
4099
4139
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
4100
4140
|
for (const baseClass of filteredBaseClasses) {
|
4101
|
-
const
|
4141
|
+
const solution = (0, typeUtils_1.buildSolutionFromSpecializedClass)(baseClass);
|
4102
4142
|
for (const baseClassMroClass of baseClass.shared.mro) {
|
4103
4143
|
// There's no need to check for conflicts if this class isn't generic.
|
4104
|
-
if ((0, types_1.isClass)(baseClassMroClass) && baseClassMroClass.shared.
|
4105
|
-
const specializedBaseClassMroClass = (0, typeUtils_1.applySolvedTypeVars)(baseClassMroClass,
|
4144
|
+
if ((0, types_1.isClass)(baseClassMroClass) && baseClassMroClass.shared.typeParams.length > 0) {
|
4145
|
+
const specializedBaseClassMroClass = (0, typeUtils_1.applySolvedTypeVars)(baseClassMroClass, solution);
|
4106
4146
|
// Find the corresponding class in the derived class's MRO list.
|
4107
4147
|
const matchingMroClass = classType.shared.mro.find((mroClass) => (0, types_1.isClass)(mroClass) && types_1.ClassType.isSameGenericClass(mroClass, specializedBaseClassMroClass));
|
4108
4148
|
if (matchingMroClass && (0, types_1.isInstantiableClass)(matchingMroClass)) {
|
4109
|
-
const
|
4110
|
-
const
|
4149
|
+
const scopeIds = (0, typeUtils_1.getTypeVarScopeIds)(classType);
|
4150
|
+
const matchingMroObject = (0, typeUtils_1.makeTypeVarsBound)(types_1.ClassType.cloneAsInstance(matchingMroClass), scopeIds);
|
4151
|
+
const baseClassMroObject = (0, typeUtils_1.makeTypeVarsBound)(types_1.ClassType.cloneAsInstance(specializedBaseClassMroClass), scopeIds);
|
4111
4152
|
if (!this._evaluator.assignType(matchingMroObject, baseClassMroObject)) {
|
4112
4153
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
4113
4154
|
const baseClassObject = (0, typeUtils_1.convertToInstance)(baseClass);
|
@@ -4292,8 +4333,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4292
4333
|
}
|
4293
4334
|
if (!this._evaluator.assignType(overriddenType, childOverrideType !== null && childOverrideType !== void 0 ? childOverrideType : overrideType,
|
4294
4335
|
/* diag */ undefined,
|
4295
|
-
/*
|
4296
|
-
/*
|
4336
|
+
/* destConstraints */ undefined,
|
4337
|
+
/* srcConstraints */ undefined, isInvariant ? 1 /* AssignTypeFlags.EnforceInvariance */ : 0 /* AssignTypeFlags.Default */)) {
|
4297
4338
|
diag = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompatibleVariableOverride, localize_1.LocMessage.baseClassVariableTypeIncompatible().format({
|
4298
4339
|
classType: childClassType.shared.name,
|
4299
4340
|
name: memberName,
|
@@ -4459,9 +4500,9 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4459
4500
|
}
|
4460
4501
|
const baseTypedDictEntries = (0, typedDicts_1.getTypedDictMembersForClass)(this._evaluator, baseClass,
|
4461
4502
|
/* allowNarrowed */ false);
|
4462
|
-
const
|
4503
|
+
const solution = (0, typeUtils_1.buildSolutionFromSpecializedClass)(baseClass);
|
4463
4504
|
const baseExtraItemsType = baseTypedDictEntries.extraItems
|
4464
|
-
? (0, typeUtils_1.applySolvedTypeVars)(baseTypedDictEntries.extraItems.valueType,
|
4505
|
+
? (0, typeUtils_1.applySolvedTypeVars)(baseTypedDictEntries.extraItems.valueType, solution)
|
4465
4506
|
: types_1.UnknownType.create();
|
4466
4507
|
for (const [name, entry] of typedDictEntries.knownItems) {
|
4467
4508
|
const baseEntry = baseTypedDictEntries.knownItems.get(name);
|
@@ -4473,8 +4514,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4473
4514
|
}
|
4474
4515
|
else if (!this._evaluator.assignType(baseExtraItemsType, entry.valueType,
|
4475
4516
|
/* diag */ undefined,
|
4476
|
-
/*
|
4477
|
-
/*
|
4517
|
+
/* destConstraints */ undefined,
|
4518
|
+
/* srcConstraints */ undefined, !baseTypedDictEntries.extraItems.isReadOnly
|
4478
4519
|
? 1 /* AssignTypeFlags.EnforceInvariance */
|
4479
4520
|
: 0 /* AssignTypeFlags.Default */)) {
|
4480
4521
|
diag.addMessage(localize_1.LocAddendum.typedDictClosedExtraTypeMismatch().format({
|
@@ -4492,8 +4533,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4492
4533
|
if (typedDictEntries.extraItems && baseTypedDictEntries.extraItems) {
|
4493
4534
|
if (!this._evaluator.assignType(baseExtraItemsType, typedDictEntries.extraItems.valueType,
|
4494
4535
|
/* diag */ undefined,
|
4495
|
-
/*
|
4496
|
-
/*
|
4536
|
+
/* destConstraints */ undefined,
|
4537
|
+
/* srcConstraints */ undefined, !baseTypedDictEntries.extraItems.isReadOnly
|
4497
4538
|
? 1 /* AssignTypeFlags.EnforceInvariance */
|
4498
4539
|
: 0 /* AssignTypeFlags.Default */)) {
|
4499
4540
|
diag.addMessage(localize_1.LocAddendum.typedDictClosedExtraTypeMismatch().format({
|
@@ -4805,8 +4846,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4805
4846
|
}
|
4806
4847
|
let diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
4807
4848
|
if (!this._evaluator.assignType(baseType, overrideType, diagAddendum,
|
4808
|
-
/*
|
4809
|
-
/*
|
4849
|
+
/* destConstraints */ undefined,
|
4850
|
+
/* srcConstraints */ undefined, isInvariant ? 1 /* AssignTypeFlags.EnforceInvariance */ : 0 /* AssignTypeFlags.Default */)) {
|
4810
4851
|
if (isInvariant) {
|
4811
4852
|
diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
4812
4853
|
diagAddendum.addMessage(localize_1.LocAddendum.overrideIsInvariant());
|
@@ -4981,7 +5022,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4981
5022
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportSelfClsParameterName, localize_1.LocMessage.newClsParam(), node.d.params.length > 0 ? node.d.params[0] : node.d.name);
|
4982
5023
|
}
|
4983
5024
|
if (classType) {
|
4984
|
-
this.
|
5025
|
+
this._validateClsSelfParamType(node, functionType, classType, /* isCls */ true);
|
4985
5026
|
}
|
4986
5027
|
}
|
4987
5028
|
else if (((_b = node.d.name) === null || _b === void 0 ? void 0 : _b.d.value) === '_generate_next_value_') {
|
@@ -5010,7 +5051,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5010
5051
|
}
|
5011
5052
|
}
|
5012
5053
|
if (classType) {
|
5013
|
-
this.
|
5054
|
+
this._validateClsSelfParamType(node, functionType, classType, /* isCls */ true);
|
5014
5055
|
}
|
5015
5056
|
}
|
5016
5057
|
else {
|
@@ -5026,7 +5067,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5026
5067
|
if (node.d.params[0].d.name) {
|
5027
5068
|
paramName = node.d.params[0].d.name.d.value;
|
5028
5069
|
}
|
5029
|
-
if (node.d.params[0].d.category !== 0 /*
|
5070
|
+
if (node.d.params[0].d.category !== 0 /* ParamCategory.Simple */) {
|
5030
5071
|
firstParamIsSimple = false;
|
5031
5072
|
}
|
5032
5073
|
}
|
@@ -5055,7 +5096,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5055
5096
|
}
|
5056
5097
|
}
|
5057
5098
|
if (classType) {
|
5058
|
-
this.
|
5099
|
+
this._validateClsSelfParamType(node, functionType, classType, /* isCls */ false);
|
5059
5100
|
}
|
5060
5101
|
}
|
5061
5102
|
}
|
@@ -5114,7 +5155,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5114
5155
|
}
|
5115
5156
|
// Validates that the annotated type of a "self" or "cls" parameter is
|
5116
5157
|
// compatible with the type of the class that contains it.
|
5117
|
-
|
5158
|
+
_validateClsSelfParamType(node, functionType, classType, isCls) {
|
5118
5159
|
var _a;
|
5119
5160
|
if (node.d.params.length < 1 || functionType.shared.parameters.length < 1) {
|
5120
5161
|
return;
|
@@ -5122,6 +5163,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5122
5163
|
// If there is no type annotation, there's nothing to check because
|
5123
5164
|
// the type will be inferred.d.typeAnnotation
|
5124
5165
|
const paramInfo = functionType.shared.parameters[0];
|
5166
|
+
const paramType = types_1.FunctionType.getParamType(functionType, 0);
|
5125
5167
|
const paramAnnotation = (_a = node.d.params[0].d.annotation) !== null && _a !== void 0 ? _a : node.d.params[0].d.annotationComment;
|
5126
5168
|
if (!paramAnnotation || !paramInfo.name) {
|
5127
5169
|
return;
|
@@ -5130,8 +5172,12 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5130
5172
|
// use of class-scoped TypeVars, which are not allowed in this context
|
5131
5173
|
// according to the typing spec.
|
5132
5174
|
if (functionType.shared.name === '__init__' && functionType.shared.methodClass) {
|
5133
|
-
const typeVars = (0, typeUtils_1.
|
5134
|
-
if (typeVars.some((typeVar) => {
|
5175
|
+
const typeVars = (0, typeUtils_1.getTypeVarArgsRecursive)(paramType);
|
5176
|
+
if (typeVars.some((typeVar) => {
|
5177
|
+
var _a;
|
5178
|
+
return typeVar.priv.scopeId === ((_a = functionType.shared.methodClass) === null || _a === void 0 ? void 0 : _a.shared.typeVarScopeId) &&
|
5179
|
+
!types_1.TypeVarType.isSelf(typeVar);
|
5180
|
+
})) {
|
5135
5181
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeVarUse, localize_1.LocMessage.initMethodSelfParamTypeVar(), paramAnnotation);
|
5136
5182
|
}
|
5137
5183
|
}
|
@@ -5140,20 +5186,20 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5140
5186
|
if (types_1.ClassType.isProtocolClass(classType)) {
|
5141
5187
|
return;
|
5142
5188
|
}
|
5143
|
-
const
|
5189
|
+
const concreteParamType = this._evaluator.makeTopLevelTypeVarsConcrete(paramType);
|
5144
5190
|
const expectedType = isCls ? classType : (0, typeUtils_1.convertToInstance)(classType);
|
5145
5191
|
// If the declared type is a protocol class or instance, skip
|
5146
5192
|
// the check. This has legitimate uses for mix-in classes.
|
5147
|
-
if ((0, types_1.isInstantiableClass)(
|
5193
|
+
if ((0, types_1.isInstantiableClass)(concreteParamType) && types_1.ClassType.isProtocolClass(concreteParamType)) {
|
5148
5194
|
return;
|
5149
5195
|
}
|
5150
|
-
if ((0, types_1.isClassInstance)(
|
5196
|
+
if ((0, types_1.isClassInstance)(concreteParamType) && types_1.ClassType.isProtocolClass(concreteParamType)) {
|
5151
5197
|
return;
|
5152
5198
|
}
|
5153
5199
|
// If the method starts with a `*args: P.args`, skip the check.
|
5154
|
-
if (paramInfo.category === 1 /*
|
5155
|
-
(0, types_1.isParamSpec)(
|
5156
|
-
|
5200
|
+
if (paramInfo.category === 1 /* ParamCategory.ArgsList */ &&
|
5201
|
+
(0, types_1.isParamSpec)(paramType) &&
|
5202
|
+
paramType.priv.paramSpecAccess === 'args') {
|
5157
5203
|
return;
|
5158
5204
|
}
|
5159
5205
|
// Don't enforce this for an overloaded method because the "self" param
|
@@ -5170,8 +5216,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5170
5216
|
types_1.ClassType.isBuiltIn(classType, 'str')) {
|
5171
5217
|
return;
|
5172
5218
|
}
|
5173
|
-
|
5174
|
-
if (!this._evaluator.assignType(paramType, expectedType, /* diag */ undefined, typeVarContext)) {
|
5219
|
+
if (!this._evaluator.assignType(paramType, expectedType)) {
|
5175
5220
|
// We exempt Never from this check because it has a legitimate use in this case.
|
5176
5221
|
if (!(0, types_1.isNever)(paramType)) {
|
5177
5222
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.clsSelfParamTypeMismatch().format({
|
@@ -5198,7 +5243,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5198
5243
|
return;
|
5199
5244
|
}
|
5200
5245
|
const liveScopes = ParseTreeUtils.getTypeVarScopesForNode(node);
|
5201
|
-
declaredReturnType = (0, typeUtils_1.
|
5246
|
+
declaredReturnType = (0, typeUtils_1.makeTypeVarsBound)(declaredReturnType, liveScopes);
|
5202
5247
|
let generatorType;
|
5203
5248
|
if (!enclosingFunctionNode.d.isAsync &&
|
5204
5249
|
(0, types_1.isClassInstance)(declaredReturnType) &&
|
@@ -5221,7 +5266,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5221
5266
|
return;
|
5222
5267
|
}
|
5223
5268
|
const generatorTypeArgs = [yieldType, sendType !== null && sendType !== void 0 ? sendType : types_1.UnknownType.create(), types_1.UnknownType.create()];
|
5224
|
-
const specializedGenerator = types_1.ClassType.cloneAsInstance(types_1.ClassType.
|
5269
|
+
const specializedGenerator = types_1.ClassType.cloneAsInstance(types_1.ClassType.specialize(generatorType, generatorTypeArgs));
|
5225
5270
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
5226
5271
|
if (!this._evaluator.assignType(declaredReturnType, specializedGenerator, diagAddendum)) {
|
5227
5272
|
const errorMessage = enclosingFunctionNode.d.isAsync
|
@@ -5295,7 +5340,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5295
5340
|
// Were all of the exception types overridden?
|
5296
5341
|
if (typesOfThisExcept.length > 0 && typesOfThisExcept.length === overriddenExceptionCount) {
|
5297
5342
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnusedExcept, localize_1.LocMessage.unreachableExcept() + diagAddendum.getString(), except.d.typeExpr);
|
5298
|
-
this._evaluator.addUnreachableCode(except, except.d.exceptSuite);
|
5343
|
+
this._evaluator.addUnreachableCode(except, typeEvaluatorTypes_1.Reachability.UnreachableByAnalysis, except.d.exceptSuite);
|
5299
5344
|
}
|
5300
5345
|
}
|
5301
5346
|
(0, collectionUtils_1.appendArray)(exceptionTypesSoFar, typesOfThisExcept);
|