@zzzen/pyright-internal 1.2.0-dev.20240714 → 1.2.0-dev.20240728
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 +8 -8
- 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 +3 -2
- package/dist/analyzer/checker.js +137 -142
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.d.ts +2 -2
- package/dist/analyzer/codeFlowEngine.js +74 -44
- 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/constraintSolver.d.ts +2 -2
- package/dist/analyzer/constraintSolver.js +166 -206
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constructorTransform.d.ts +2 -3
- package/dist/analyzer/constructorTransform.js +18 -19
- package/dist/analyzer/constructorTransform.js.map +1 -1
- package/dist/analyzer/constructors.d.ts +3 -3
- package/dist/analyzer/constructors.js +72 -175
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.d.ts +2 -2
- package/dist/analyzer/dataClasses.js +60 -40
- 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 -6
- 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 +4 -4
- 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.js +145 -96
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/packageTypeVerifier.js +8 -8
- package/dist/analyzer/packageTypeVerifier.js.map +1 -1
- package/dist/analyzer/parameterUtils.d.ts +10 -10
- package/dist/analyzer/parameterUtils.js +60 -59
- package/dist/analyzer/parameterUtils.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.d.ts +7 -6
- package/dist/analyzer/parseTreeUtils.js +47 -24
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/patternMatching.js +109 -90
- 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.js +23 -19
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/protocols.js +23 -20
- 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/testWalker.js +13 -1
- package/dist/analyzer/testWalker.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 +252 -0
- package/dist/analyzer/tuples.js.map +1 -0
- package/dist/analyzer/typeComplexity.d.ts +2 -0
- package/dist/analyzer/typeComplexity.js +86 -0
- package/dist/analyzer/typeComplexity.js.map +1 -0
- package/dist/analyzer/typeEvaluator.js +1721 -1824
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +47 -40
- package/dist/analyzer/typeEvaluatorTypes.js +10 -1
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +116 -90
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.d.ts +1 -1
- package/dist/analyzer/typePrinter.js +54 -53
- 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 +35 -29
- package/dist/analyzer/typeUtils.js +420 -357
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typeVarContext.d.ts +24 -36
- package/dist/analyzer/typeVarContext.js +89 -193
- package/dist/analyzer/typeVarContext.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 +2 -2
- package/dist/analyzer/typedDicts.js +49 -53
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +89 -63
- package/dist/analyzer/types.js +163 -120
- package/dist/analyzer/types.js.map +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js +12 -12
- 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 +4 -3
- package/dist/languageServerBase.js +14 -10
- 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 +38 -37
- 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 +14 -6
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/referencesProvider.d.ts +10 -4
- package/dist/languageService/referencesProvider.js +24 -12
- package/dist/languageService/referencesProvider.js.map +1 -1
- package/dist/languageService/renameProvider.js +21 -4
- package/dist/languageService/renameProvider.js.map +1 -1
- package/dist/languageService/signatureHelpProvider.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 +9 -3
- package/dist/localization/localize.js +8 -1
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +5 -2
- package/dist/localization/package.nls.de.json +5 -2
- package/dist/localization/package.nls.en-us.json +7 -1
- package/dist/localization/package.nls.es.json +5 -2
- package/dist/localization/package.nls.fr.json +5 -2
- package/dist/localization/package.nls.it.json +5 -2
- package/dist/localization/package.nls.ja.json +5 -2
- package/dist/localization/package.nls.ko.json +5 -2
- package/dist/localization/package.nls.pl.json +5 -2
- package/dist/localization/package.nls.pt-br.json +5 -2
- package/dist/localization/package.nls.qps-ploc.json +5 -2
- package/dist/localization/package.nls.ru.json +5 -2
- package/dist/localization/package.nls.tr.json +5 -2
- package/dist/localization/package.nls.zh-cn.json +5 -2
- package/dist/localization/package.nls.zh-tw.json +5 -2
- package/dist/parser/parseNodes.d.ts +12 -10
- package/dist/parser/parseNodes.js +23 -21
- package/dist/parser/parseNodes.js.map +1 -1
- package/dist/parser/parser.js +66 -43
- package/dist/parser/parser.js.map +1 -1
- package/dist/tests/checker.test.js +2 -2
- package/dist/tests/fourslash/rename.args.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/rename.args.fourslash.js +71 -0
- package/dist/tests/fourslash/rename.args.fourslash.js.map +1 -0
- package/dist/tests/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 +17 -0
- package/dist/tests/typeEvaluator1.test.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +4 -0
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +1 -1
- package/dist/tests/typeEvaluator4.test.js +19 -7
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator5.test.js +8 -2
- package/dist/tests/typeEvaluator5.test.js.map +1 -1
- package/dist/tests/typeEvaluator6.test.js +76 -60
- package/dist/tests/typeEvaluator6.test.js.map +1 -1
- package/dist/tests/typeEvaluator7.test.js +5 -1
- package/dist/tests/typeEvaluator7.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/checker.js
CHANGED
@@ -70,6 +70,7 @@ const staticExpressions_1 = require("./staticExpressions");
|
|
70
70
|
const SymbolNameUtils = __importStar(require("./symbolNameUtils"));
|
71
71
|
const symbolUtils_1 = require("./symbolUtils");
|
72
72
|
const typeEvaluator_1 = require("./typeEvaluator");
|
73
|
+
const typeEvaluatorTypes_1 = require("./typeEvaluatorTypes");
|
73
74
|
const typeGuards_1 = require("./typeGuards");
|
74
75
|
const typeUtils_1 = require("./typeUtils");
|
75
76
|
const typeVarContext_1 = require("./typeVarContext");
|
@@ -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,31 +219,31 @@ 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 '_'.
|
@@ -286,7 +287,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
286
287
|
// Verify that an unpacked TypedDict doesn't overlap any keyword parameters.
|
287
288
|
if (paramDetails.hasUnpackedTypedDict) {
|
288
289
|
const kwargsIndex = functionTypeResult.functionType.shared.parameters.length - 1;
|
289
|
-
const kwargsType = types_1.FunctionType.
|
290
|
+
const kwargsType = types_1.FunctionType.getEffectiveParamType(functionTypeResult.functionType, kwargsIndex);
|
290
291
|
if ((0, types_1.isClass)(kwargsType) && kwargsType.shared.typedDictEntries) {
|
291
292
|
const overlappingEntries = new Set();
|
292
293
|
kwargsType.shared.typedDictEntries.knownItems.forEach((_, name) => {
|
@@ -304,7 +305,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
304
305
|
// Check for invalid use of ParamSpec P.args and P.kwargs.
|
305
306
|
const paramSpecParams = functionTypeResult.functionType.shared.parameters.filter((param) => {
|
306
307
|
if (types_1.FunctionParam.isTypeDeclared(param) && (0, types_1.isTypeVar)(param.type) && (0, types_1.isParamSpec)(param.type)) {
|
307
|
-
if (param.category !== 0 /*
|
308
|
+
if (param.category !== 0 /* ParamCategory.Simple */ && param.name && param.type.priv.paramSpecAccess) {
|
308
309
|
return true;
|
309
310
|
}
|
310
311
|
}
|
@@ -547,7 +548,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
547
548
|
let returnTypeResult;
|
548
549
|
let returnType;
|
549
550
|
const enclosingFunctionNode = ParseTreeUtils.getEnclosingFunction(node);
|
550
|
-
|
551
|
+
let declaredReturnType = enclosingFunctionNode
|
551
552
|
? this._evaluator.getFunctionDeclaredReturnType(enclosingFunctionNode)
|
552
553
|
: undefined;
|
553
554
|
if (node.d.expr) {
|
@@ -577,33 +578,34 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
577
578
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.noReturnContainsReturn(), node);
|
578
579
|
}
|
579
580
|
else {
|
581
|
+
const liveScopes = ParseTreeUtils.getTypeVarScopesForNode(node);
|
582
|
+
declaredReturnType = (0, typeUtils_1.updateTypeWithInternalTypeVars)(declaredReturnType, liveScopes);
|
583
|
+
declaredReturnType = this._evaluator.stripTypeGuard(declaredReturnType);
|
580
584
|
let diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
581
585
|
let returnTypeMatches = false;
|
582
586
|
if (this._evaluator.assignType(declaredReturnType, returnType, diagAddendum,
|
583
|
-
/* destTypeVarContext */
|
584
|
-
/* srcTypeVarContext */ undefined, 128 /* AssignTypeFlags.AllowBoolTypeGuard */)) {
|
587
|
+
/* destTypeVarContext */ new typeVarContext_1.TypeVarContext())) {
|
585
588
|
returnTypeMatches = true;
|
586
589
|
}
|
587
590
|
else {
|
588
591
|
// See if the declared return type includes one or more constrained TypeVars. If so,
|
589
592
|
// try to narrow these TypeVars to a single type.
|
590
|
-
const uniqueTypeVars = (0, typeUtils_1.
|
593
|
+
const uniqueTypeVars = (0, typeUtils_1.getTypeVarArgsRecursive)(declaredReturnType);
|
591
594
|
if (uniqueTypeVars && uniqueTypeVars.some((typeVar) => typeVar.shared.constraints.length > 0)) {
|
592
595
|
const typeVarContext = new typeVarContext_1.TypeVarContext();
|
593
596
|
for (const typeVar of uniqueTypeVars) {
|
594
597
|
if (typeVar.shared.constraints.length > 0) {
|
595
598
|
const narrowedType = this._evaluator.narrowConstrainedTypeVar(node, typeVar);
|
596
599
|
if (narrowedType) {
|
597
|
-
|
600
|
+
(0, typeUtils_1.setTypeVarType)(typeVarContext, typeVar, narrowedType);
|
598
601
|
typeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeId)(typeVar));
|
599
602
|
}
|
600
603
|
}
|
601
604
|
}
|
602
605
|
if (!typeVarContext.isEmpty()) {
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
/* srcTypeVarContext */ undefined, 128 /* AssignTypeFlags.AllowBoolTypeGuard */)) {
|
606
|
+
let adjustedReturnType = (0, typeUtils_1.applySolvedTypeVars)(declaredReturnType, typeVarContext);
|
607
|
+
adjustedReturnType = this._evaluator.stripTypeGuard(adjustedReturnType);
|
608
|
+
if (this._evaluator.assignType(adjustedReturnType, returnType, diagAddendum)) {
|
607
609
|
returnTypeMatches = true;
|
608
610
|
}
|
609
611
|
}
|
@@ -721,8 +723,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
721
723
|
// assert (x > 3, "bad value x")
|
722
724
|
const type = this._evaluator.getType(node.d.testExpr);
|
723
725
|
if (type && (0, types_1.isClassInstance)(type)) {
|
724
|
-
if ((0, typeUtils_1.isTupleClass)(type) && type.priv.
|
725
|
-
if (type.priv.
|
726
|
+
if ((0, typeUtils_1.isTupleClass)(type) && type.priv.tupleTypeArgs) {
|
727
|
+
if (type.priv.tupleTypeArgs.length > 0) {
|
726
728
|
if (!(0, typeUtils_1.isUnboundedTupleClass)(type)) {
|
727
729
|
this._evaluator.addDiagnosticForTextRange(this._fileInfo, diagnosticRules_1.DiagnosticRule.reportAssertAlwaysTrue, localize_1.LocMessage.assertAlwaysTrue(), node.d.testExpr);
|
728
730
|
}
|
@@ -772,15 +774,13 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
772
774
|
if (baseType) {
|
773
775
|
(0, typeUtils_1.doForEachSubtype)(baseType, (subtype) => {
|
774
776
|
const tupleType = (0, typeUtils_1.getSpecializedTupleType)(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)) {
|
777
|
+
if (!(0, types_1.isClassInstance)(subtype) || !(tupleType === null || tupleType === void 0 ? void 0 : tupleType.priv.tupleTypeArgs) || (0, typeUtils_1.isUnboundedTupleClass)(tupleType)) {
|
778
778
|
return;
|
779
779
|
}
|
780
|
-
const tupleLength = tupleType.priv.
|
780
|
+
const tupleLength = tupleType.priv.tupleTypeArgs.length;
|
781
781
|
if (node.d.items.length !== 1 ||
|
782
782
|
node.d.trailingComma ||
|
783
|
-
node.d.items[0].d.argCategory !== 0 /*
|
783
|
+
node.d.items[0].d.argCategory !== 0 /* ArgCategory.Simple */ ||
|
784
784
|
node.d.items[0].d.name) {
|
785
785
|
return;
|
786
786
|
}
|
@@ -961,7 +961,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
961
961
|
}
|
962
962
|
visitMemberAccess(node) {
|
963
963
|
var _a;
|
964
|
-
const typeResult = this._evaluator.getTypeResult(node);
|
964
|
+
const typeResult = this._evaluator.getTypeResult(node.d.member);
|
965
965
|
const type = (_a = typeResult === null || typeResult === void 0 ? void 0 : typeResult.type) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
|
966
966
|
const leftExprType = this._evaluator.getType(node.d.leftExpr);
|
967
967
|
this._reportDeprecatedUseForType(node.d.member, type, leftExprType && (0, types_1.isModule)(leftExprType) && leftExprType.priv.moduleName === 'typing');
|
@@ -1053,7 +1053,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1053
1053
|
return false;
|
1054
1054
|
}
|
1055
1055
|
visitTypeParameterList(node) {
|
1056
|
-
this.
|
1056
|
+
this._typeParamLists.push(node);
|
1057
1057
|
return true;
|
1058
1058
|
}
|
1059
1059
|
visitTypeParameter(node) {
|
@@ -1069,14 +1069,14 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1069
1069
|
}
|
1070
1070
|
if (typeVarScopeNode.nodeType === 10 /* ParseNodeType.Class */) {
|
1071
1071
|
const classType = (_c = this._evaluator.getTypeOfClass(typeVarScopeNode)) === null || _c === void 0 ? void 0 : _c.classType;
|
1072
|
-
if (classType === null || classType === void 0 ? void 0 : classType.shared.
|
1072
|
+
if (classType === null || classType === void 0 ? void 0 : classType.shared.typeParams.some((param) => param.shared.name === node.d.name.d.value)) {
|
1073
1073
|
foundDuplicate = true;
|
1074
1074
|
break;
|
1075
1075
|
}
|
1076
1076
|
}
|
1077
1077
|
else if (typeVarScopeNode.nodeType === 31 /* ParseNodeType.Function */) {
|
1078
1078
|
const functionType = (_d = this._evaluator.getTypeOfFunction(typeVarScopeNode)) === null || _d === void 0 ? void 0 : _d.functionType;
|
1079
|
-
if (functionType === null || functionType === void 0 ? void 0 : functionType.shared.
|
1079
|
+
if (functionType === null || functionType === void 0 ? void 0 : functionType.shared.typeParams.some((param) => param.shared.name === node.d.name.d.value)) {
|
1080
1080
|
foundDuplicate = true;
|
1081
1081
|
break;
|
1082
1082
|
}
|
@@ -1465,12 +1465,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1465
1465
|
if ((0, types_1.isInstantiableClass)(leftType) || ((0, types_1.isClassInstance)(leftType) && types_1.ClassType.isBuiltIn(leftType, 'type'))) {
|
1466
1466
|
if ((0, types_1.isInstantiableClass)(rightType) ||
|
1467
1467
|
((0, types_1.isClassInstance)(rightType) && types_1.ClassType.isBuiltIn(rightType, 'type'))) {
|
1468
|
-
const genericLeftType = types_1.ClassType.
|
1469
|
-
/*
|
1470
|
-
/* isTypeArgumentExplicit */ false);
|
1471
|
-
const genericRightType = types_1.ClassType.cloneForSpecialization(rightType,
|
1472
|
-
/* typeArguments */ undefined,
|
1473
|
-
/* isTypeArgumentExplicit */ false);
|
1468
|
+
const genericLeftType = types_1.ClassType.specialize(leftType, /* typeArgs */ undefined);
|
1469
|
+
const genericRightType = types_1.ClassType.specialize(rightType, /* typeArgs */ undefined);
|
1474
1470
|
if (this._evaluator.assignType(genericLeftType, genericRightType) ||
|
1475
1471
|
this._evaluator.assignType(genericRightType, genericLeftType)) {
|
1476
1472
|
return true;
|
@@ -1487,12 +1483,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1487
1483
|
}
|
1488
1484
|
if ((0, types_1.isClassInstance)(leftType)) {
|
1489
1485
|
if ((0, types_1.isClassInstance)(rightType)) {
|
1490
|
-
const genericLeftType = types_1.ClassType.
|
1491
|
-
/*
|
1492
|
-
/* isTypeArgumentExplicit */ false);
|
1493
|
-
const genericRightType = types_1.ClassType.cloneForSpecialization(rightType,
|
1494
|
-
/* typeArguments */ undefined,
|
1495
|
-
/* isTypeArgumentExplicit */ false);
|
1486
|
+
const genericLeftType = types_1.ClassType.specialize(leftType, /* typeArgs */ undefined);
|
1487
|
+
const genericRightType = types_1.ClassType.specialize(rightType, /* typeArgs */ undefined);
|
1496
1488
|
if (this._evaluator.assignType(genericLeftType, genericRightType) ||
|
1497
1489
|
this._evaluator.assignType(genericRightType, genericLeftType)) {
|
1498
1490
|
return true;
|
@@ -1549,8 +1541,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1549
1541
|
if (!generatorType || !(0, types_1.isInstantiableClass)(generatorType)) {
|
1550
1542
|
return;
|
1551
1543
|
}
|
1552
|
-
const specializedGenerator = types_1.ClassType.cloneAsInstance(types_1.ClassType.
|
1553
|
-
/* isTypeArgumentExplicit */ true));
|
1544
|
+
const specializedGenerator = types_1.ClassType.cloneAsInstance(types_1.ClassType.specialize(generatorType, [types_1.AnyType.create(), types_1.AnyType.create(), types_1.AnyType.create()]));
|
1554
1545
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
1555
1546
|
if (!this._evaluator.assignType(declaredReturnType, specializedGenerator, diagAddendum)) {
|
1556
1547
|
const errorMessage = node.d.isAsync
|
@@ -1607,7 +1598,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1607
1598
|
// the TypeVar multiple times.
|
1608
1599
|
const baseType = this._evaluator.getType(baseExpression);
|
1609
1600
|
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.
|
1601
|
+
if ((aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.typeParams) && subscriptIndex < aliasInfo.typeParams.length) {
|
1611
1602
|
isExempt = true;
|
1612
1603
|
}
|
1613
1604
|
}
|
@@ -1702,7 +1693,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1702
1693
|
// Report error for local type variable that appears only once.
|
1703
1694
|
if (usage.nodes.length === 1 && !usage.isExempt) {
|
1704
1695
|
let altTypeText;
|
1705
|
-
if (usage.typeVar
|
1696
|
+
if ((0, types_1.isTypeVarTuple)(usage.typeVar)) {
|
1706
1697
|
altTypeText = '"tuple[object, ...]"';
|
1707
1698
|
}
|
1708
1699
|
else if (usage.typeVar.shared.boundType) {
|
@@ -1851,12 +1842,12 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1851
1842
|
if (types_1.FunctionType.isInstanceMethod(functionType) && functionType.shared.name === '__get__') {
|
1852
1843
|
return false;
|
1853
1844
|
}
|
1854
|
-
let flags = 64 /* AssignTypeFlags.
|
1845
|
+
let flags = 64 /* AssignTypeFlags.SkipReturnTypeCheck */ | 16 /* AssignTypeFlags.OverloadOverlap */;
|
1855
1846
|
if (partialOverlap) {
|
1856
|
-
flags |= 32 /* AssignTypeFlags.
|
1847
|
+
flags |= 32 /* AssignTypeFlags.PartialOverloadOverlap */;
|
1857
1848
|
}
|
1858
1849
|
return this._evaluator.assignType(functionType, prevOverload,
|
1859
|
-
/* diag */ undefined, new typeVarContext_1.TypeVarContext(
|
1850
|
+
/* diag */ undefined, new typeVarContext_1.TypeVarContext(),
|
1860
1851
|
/* srcTypeVarContext */ undefined, flags);
|
1861
1852
|
}
|
1862
1853
|
_isLegalOverloadImplementation(overload, implementation, diag) {
|
@@ -1864,7 +1855,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1864
1855
|
const implTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(implementation));
|
1865
1856
|
const overloadTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(overload));
|
1866
1857
|
// First check the parameters to see if they are assignable.
|
1867
|
-
let isLegal = this._evaluator.assignType(overload, implementation, diag, overloadTypeVarContext, implTypeVarContext, 64 /* AssignTypeFlags.
|
1858
|
+
let isLegal = this._evaluator.assignType(overload, implementation, diag, overloadTypeVarContext, implTypeVarContext, 64 /* AssignTypeFlags.SkipReturnTypeCheck */ |
|
1868
1859
|
2 /* AssignTypeFlags.ReverseTypeVarMatching */ |
|
1869
1860
|
512 /* AssignTypeFlags.SkipSelfClsTypeCheck */);
|
1870
1861
|
// Now check the return types.
|
@@ -1889,13 +1880,14 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1889
1880
|
// No need to report unreachable more than once since the first time
|
1890
1881
|
// covers all remaining statements in the statement list.
|
1891
1882
|
if (!reportedUnreachable) {
|
1892
|
-
|
1883
|
+
const reachability = this._evaluator.getNodeReachability(statement, prevStatement);
|
1884
|
+
if (reachability !== typeEvaluatorTypes_1.Reachability.Reachable) {
|
1893
1885
|
// Create a text range that covers the next statement through
|
1894
1886
|
// the end of the statement list.
|
1895
1887
|
const start = statement.start;
|
1896
1888
|
const lastStatement = statements[statements.length - 1];
|
1897
1889
|
const end = textRange_1.TextRange.getEnd(lastStatement);
|
1898
|
-
this._evaluator.addUnreachableCode(statement, { start, length: end - start });
|
1890
|
+
this._evaluator.addUnreachableCode(statement, reachability, { start, length: end - start });
|
1899
1891
|
reportedUnreachable = true;
|
1900
1892
|
}
|
1901
1893
|
}
|
@@ -2014,8 +2006,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2014
2006
|
}
|
2015
2007
|
return;
|
2016
2008
|
}
|
2017
|
-
if (allowTuple && exceptionSubtype.priv.
|
2018
|
-
exceptionSubtype.priv.
|
2009
|
+
if (allowTuple && exceptionSubtype.priv.tupleTypeArgs) {
|
2010
|
+
exceptionSubtype.priv.tupleTypeArgs.forEach((typeArg) => {
|
2019
2011
|
this._validateExceptionTypeRecursive(typeArg.type, diag, baseExceptionType, baseExceptionGroupType,
|
2020
2012
|
/* allowTuple */ false, isExceptGroup);
|
2021
2013
|
});
|
@@ -2064,6 +2056,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2064
2056
|
this._conditionallyReportUnusedSymbol(name, symbol, scope.type, dependentFileInfo);
|
2065
2057
|
this._reportIncompatibleDeclarations(name, symbol);
|
2066
2058
|
this._reportMultipleFinalDeclarations(name, symbol, scope.type);
|
2059
|
+
this._reportFinalInLoop(symbol);
|
2067
2060
|
this._reportMultipleTypeAliasDeclarations(name, symbol);
|
2068
2061
|
this._reportInvalidOverload(name, symbol);
|
2069
2062
|
});
|
@@ -2071,7 +2064,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2071
2064
|
}
|
2072
2065
|
// Report unaccessed type parameters.
|
2073
2066
|
const accessedSymbolSet = this._fileInfo.accessedSymbolSet;
|
2074
|
-
for (const paramList of this.
|
2067
|
+
for (const paramList of this._typeParamLists) {
|
2075
2068
|
const typeParamScope = AnalyzerNodeInfo.getScope(paramList);
|
2076
2069
|
for (const param of paramList.d.params) {
|
2077
2070
|
const symbol = typeParamScope === null || typeParamScope === void 0 ? void 0 : typeParamScope.symbolTable.get(param.d.name.d.value);
|
@@ -2176,6 +2169,18 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2176
2169
|
}
|
2177
2170
|
});
|
2178
2171
|
}
|
2172
|
+
_reportFinalInLoop(symbol) {
|
2173
|
+
if (!this._evaluator.isFinalVariable(symbol)) {
|
2174
|
+
return;
|
2175
|
+
}
|
2176
|
+
const decls = symbol.getDeclarations();
|
2177
|
+
if (decls.length === 0) {
|
2178
|
+
return;
|
2179
|
+
}
|
2180
|
+
if (ParseTreeUtils.isWithinLoop(decls[0].node)) {
|
2181
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.finalInLoop(), decls[0].node);
|
2182
|
+
}
|
2183
|
+
}
|
2179
2184
|
_reportMultipleFinalDeclarations(name, symbol, scopeType) {
|
2180
2185
|
if (!this._evaluator.isFinalVariable(symbol)) {
|
2181
2186
|
return;
|
@@ -2323,7 +2328,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2323
2328
|
else if (primaryDecl.type === 6 /* DeclarationType.Class */) {
|
2324
2329
|
primaryDeclInfo = localize_1.LocAddendum.seeClassDeclaration();
|
2325
2330
|
}
|
2326
|
-
else if (primaryDecl.type === 2 /* DeclarationType.
|
2331
|
+
else if (primaryDecl.type === 2 /* DeclarationType.Param */) {
|
2327
2332
|
primaryDeclInfo = localize_1.LocAddendum.seeParameterDeclaration();
|
2328
2333
|
}
|
2329
2334
|
else if (primaryDecl.type === 1 /* DeclarationType.Variable */) {
|
@@ -2346,8 +2351,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2346
2351
|
primaryDeclNode = primaryDecl.node;
|
2347
2352
|
}
|
2348
2353
|
}
|
2349
|
-
else if (primaryDecl.type === 2 /* DeclarationType.
|
2350
|
-
primaryDecl.type === 3 /* DeclarationType.
|
2354
|
+
else if (primaryDecl.type === 2 /* DeclarationType.Param */ ||
|
2355
|
+
primaryDecl.type === 3 /* DeclarationType.TypeParam */) {
|
2351
2356
|
if (primaryDecl.node.d.name) {
|
2352
2357
|
primaryDeclNode = primaryDecl.node.d.name;
|
2353
2358
|
}
|
@@ -2360,7 +2365,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2360
2365
|
for (const otherDecl of otherDecls) {
|
2361
2366
|
if (otherDecl.type === 6 /* DeclarationType.Class */) {
|
2362
2367
|
let duplicateIsOk = false;
|
2363
|
-
if (primaryDecl.type === 3 /* DeclarationType.
|
2368
|
+
if (primaryDecl.type === 3 /* DeclarationType.TypeParam */) {
|
2364
2369
|
// The error will be reported elsewhere if a type parameter is
|
2365
2370
|
// involved, so don't report it here.
|
2366
2371
|
duplicateIsOk = true;
|
@@ -2393,7 +2398,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2393
2398
|
if (!isInSameStatementList && primaryType && otherType && (0, types_1.isTypeSame)(primaryType, otherType)) {
|
2394
2399
|
duplicateIsOk = true;
|
2395
2400
|
}
|
2396
|
-
if (primaryDecl.type === 3 /* DeclarationType.
|
2401
|
+
if (primaryDecl.type === 3 /* DeclarationType.TypeParam */) {
|
2397
2402
|
// The error will be reported elsewhere if a type parameter is
|
2398
2403
|
// involved, so don't report it here.
|
2399
2404
|
duplicateIsOk = true;
|
@@ -2405,10 +2410,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2405
2410
|
addPrimaryDeclInfo(diag);
|
2406
2411
|
}
|
2407
2412
|
}
|
2408
|
-
else if (otherDecl.type === 2 /* DeclarationType.
|
2413
|
+
else if (otherDecl.type === 2 /* DeclarationType.Param */) {
|
2409
2414
|
if (otherDecl.node.d.name) {
|
2410
2415
|
let duplicateIsOk = false;
|
2411
|
-
if (primaryDecl.type === 3 /* DeclarationType.
|
2416
|
+
if (primaryDecl.type === 3 /* DeclarationType.TypeParam */) {
|
2412
2417
|
// The error will be reported elsewhere if a type parameter is
|
2413
2418
|
// involved, so don't report it here.
|
2414
2419
|
duplicateIsOk = true;
|
@@ -2430,7 +2435,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2430
2435
|
if (primaryType && otherType && (0, types_1.isTypeSame)(primaryType, otherType)) {
|
2431
2436
|
duplicateIsOk = true;
|
2432
2437
|
}
|
2433
|
-
if (primaryDecl.type === 3 /* DeclarationType.
|
2438
|
+
if (primaryDecl.type === 3 /* DeclarationType.TypeParam */) {
|
2434
2439
|
// The error will be reported elsewhere if a type parameter is
|
2435
2440
|
// involved, so don't report it here.
|
2436
2441
|
duplicateIsOk = true;
|
@@ -2521,7 +2526,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2521
2526
|
break;
|
2522
2527
|
case 4 /* DeclarationType.TypeAlias */:
|
2523
2528
|
case 1 /* DeclarationType.Variable */:
|
2524
|
-
case 2 /* DeclarationType.
|
2529
|
+
case 2 /* DeclarationType.Param */:
|
2525
2530
|
if (!isPrivate) {
|
2526
2531
|
return;
|
2527
2532
|
}
|
@@ -2577,8 +2582,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2577
2582
|
rule = diagnosticRules_1.DiagnosticRule.reportUnusedFunction;
|
2578
2583
|
message = localize_1.LocMessage.unaccessedFunction().format({ name: nameNode.d.value });
|
2579
2584
|
break;
|
2580
|
-
case 3 /* DeclarationType.
|
2581
|
-
// Never report a diagnostic for an unused
|
2585
|
+
case 3 /* DeclarationType.TypeParam */:
|
2586
|
+
// Never report a diagnostic for an unused TypeParam.
|
2582
2587
|
diagnosticLevel = 'none';
|
2583
2588
|
nameNode = decl.node.d.name;
|
2584
2589
|
break;
|
@@ -2622,10 +2627,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2622
2627
|
let isValidType = true;
|
2623
2628
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
2624
2629
|
(0, typeUtils_1.doForEachSubtype)(arg1Type, (arg1Subtype) => {
|
2625
|
-
if ((0, types_1.isClassInstance)(arg1Subtype) &&
|
2626
|
-
|
2627
|
-
arg1Subtype.priv.tupleTypeArguments) {
|
2628
|
-
if (arg1Subtype.priv.tupleTypeArguments.some((typeArg) => !this._isTypeSupportedTypeForIsInstance(typeArg.type, isInstanceCheck, diag))) {
|
2630
|
+
if ((0, types_1.isClassInstance)(arg1Subtype) && types_1.ClassType.isTupleClass(arg1Subtype) && arg1Subtype.priv.tupleTypeArgs) {
|
2631
|
+
if (arg1Subtype.priv.tupleTypeArgs.some((typeArg) => !this._isTypeSupportedTypeForIsInstance(typeArg.type, isInstanceCheck, diag))) {
|
2629
2632
|
isValidType = false;
|
2630
2633
|
}
|
2631
2634
|
}
|
@@ -2651,8 +2654,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2651
2654
|
(0, typeUtils_1.doForEachSubtype)(arg1Type, (arg1Subtype) => {
|
2652
2655
|
if ((0, types_1.isClassInstance)(arg1Subtype) &&
|
2653
2656
|
types_1.ClassType.isTupleClass(arg1Subtype) &&
|
2654
|
-
arg1Subtype.priv.
|
2655
|
-
arg1Subtype.priv.
|
2657
|
+
arg1Subtype.priv.tupleTypeArgs) {
|
2658
|
+
arg1Subtype.priv.tupleTypeArgs.forEach((typeArg) => {
|
2656
2659
|
this._validateNotDataProtocol(typeArg.type, diag);
|
2657
2660
|
});
|
2658
2661
|
}
|
@@ -2707,8 +2710,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2707
2710
|
// The isinstance and issubclass call supports a variation where the second
|
2708
2711
|
// parameter is a tuple of classes.
|
2709
2712
|
if ((0, typeUtils_1.isTupleClass)(arg1Subtype)) {
|
2710
|
-
if (arg1Subtype.priv.
|
2711
|
-
arg1Subtype.priv.
|
2713
|
+
if (arg1Subtype.priv.tupleTypeArgs) {
|
2714
|
+
arg1Subtype.priv.tupleTypeArgs.forEach((typeArg) => {
|
2712
2715
|
if ((0, types_1.isInstantiableClass)(typeArg.type)) {
|
2713
2716
|
classTypeList.push(typeArg.type);
|
2714
2717
|
if (typeArg.type.priv.includeSubclasses) {
|
@@ -2888,7 +2891,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2888
2891
|
diag.addMessage(localize_1.LocAddendum.typedDictClassNotAllowed());
|
2889
2892
|
isSupported = false;
|
2890
2893
|
}
|
2891
|
-
else if (subtype.priv.
|
2894
|
+
else if (subtype.priv.isTypeArgExplicit && !subtype.priv.includeSubclasses) {
|
2892
2895
|
// If it's a class, make sure that it has not been given explicit
|
2893
2896
|
// type arguments. This will result in a TypeError exception.
|
2894
2897
|
diag.addMessage(localize_1.LocAddendum.genericClassNotAllowed());
|
@@ -2988,7 +2991,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2988
2991
|
}
|
2989
2992
|
}
|
2990
2993
|
if (errorMessage) {
|
2991
|
-
this._reportDeprecatedDiagnostic(node, errorMessage, info.
|
2994
|
+
this._reportDeprecatedDiagnostic(node, errorMessage, info.deprecatedMessage);
|
2992
2995
|
}
|
2993
2996
|
}
|
2994
2997
|
_reportDeprecatedUseForType(node, type, isImportFromTyping = false) {
|
@@ -3104,18 +3107,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3104
3107
|
((_c = (_b = type.props) === null || _b === void 0 ? void 0 : _b.typeAliasInfo) === null || _c === void 0 ? void 0 : _c.fullName) === deprecatedForm.fullName) {
|
3105
3108
|
if (this._fileInfo.executionEnvironment.pythonVersion.isGreaterOrEqualTo(deprecatedForm.version)) {
|
3106
3109
|
if (!deprecatedForm.typingImportOnly || isImportFromTyping) {
|
3107
|
-
|
3108
|
-
|
3109
|
-
|
3110
|
-
|
3111
|
-
}), node);
|
3112
|
-
}
|
3113
|
-
else {
|
3114
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportDeprecated, localize_1.LocMessage.deprecatedType().format({
|
3115
|
-
version: deprecatedForm.version.toString(),
|
3116
|
-
replacement: deprecatedForm.replacementText,
|
3117
|
-
}), node);
|
3118
|
-
}
|
3110
|
+
this._reportDeprecatedDiagnostic(node, localize_1.LocMessage.deprecatedType().format({
|
3111
|
+
version: deprecatedForm.version.toString(),
|
3112
|
+
replacement: deprecatedForm.replacementText,
|
3113
|
+
}));
|
3119
3114
|
}
|
3120
3115
|
}
|
3121
3116
|
}
|
@@ -3374,9 +3369,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3374
3369
|
if (!returnType) {
|
3375
3370
|
return;
|
3376
3371
|
}
|
3377
|
-
if (!(0, types_1.isClassInstance)(returnType) ||
|
3378
|
-
!returnType.priv.typeArguments ||
|
3379
|
-
returnType.priv.typeArguments.length < 1) {
|
3372
|
+
if (!(0, types_1.isClassInstance)(returnType) || !returnType.priv.typeArgs || returnType.priv.typeArgs.length < 1) {
|
3380
3373
|
return;
|
3381
3374
|
}
|
3382
3375
|
const isTypeGuard = types_1.ClassType.isBuiltIn(returnType, 'TypeGuard');
|
@@ -3397,13 +3390,13 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3397
3390
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeGuardParamCount(), node.d.name);
|
3398
3391
|
}
|
3399
3392
|
if (isTypeIs) {
|
3400
|
-
const typeGuardType = returnType.priv.
|
3393
|
+
const typeGuardType = returnType.priv.typeArgs[0];
|
3401
3394
|
// Determine the type of the first parameter.
|
3402
3395
|
const paramIndex = isMethod && !types_1.FunctionType.isStaticMethod(functionType) ? 1 : 0;
|
3403
3396
|
if (paramIndex >= functionType.shared.parameters.length) {
|
3404
3397
|
return;
|
3405
3398
|
}
|
3406
|
-
const paramType = types_1.FunctionType.
|
3399
|
+
const paramType = types_1.FunctionType.getEffectiveParamType(functionType, paramIndex);
|
3407
3400
|
// Verify that the typeGuardType is a narrower type than the paramType.
|
3408
3401
|
if (!this._evaluator.assignType(paramType, typeGuardType)) {
|
3409
3402
|
const returnAnnotation = node.d.returnAnnotation || ((_a = node.d.funcAnnotationComment) === null || _a === void 0 ? void 0 : _a.d.returnAnnotation);
|
@@ -3607,6 +3600,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3607
3600
|
if (decls[0].type !== 1 /* DeclarationType.Variable */) {
|
3608
3601
|
return;
|
3609
3602
|
}
|
3603
|
+
// Look for an enum attribute annotated with "Final".
|
3604
|
+
if (decls[0].isFinal) {
|
3605
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.enumMemberTypeAnnotation(), decls[0].node);
|
3606
|
+
}
|
3610
3607
|
const declNode = decls[0].node;
|
3611
3608
|
const assignedValueType = symbolType.priv.literalValue.itemType;
|
3612
3609
|
const assignmentNode = ParseTreeUtils.getParentNodeOfType(declNode, 3 /* ParseNodeType.Assignment */);
|
@@ -3618,25 +3615,23 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3618
3615
|
// unpack it. Otherwise, only one argument is passed.
|
3619
3616
|
const argList = [
|
3620
3617
|
{
|
3621
|
-
|
3622
|
-
? 1 /*
|
3623
|
-
: 0 /*
|
3618
|
+
argCategory: (0, types_1.isClassInstance)(assignedValueType) && (0, typeUtils_1.isTupleClass)(assignedValueType)
|
3619
|
+
? 1 /* ArgCategory.UnpackedList */
|
3620
|
+
: 0 /* ArgCategory.Simple */,
|
3624
3621
|
typeResult: { type: assignedValueType },
|
3625
3622
|
},
|
3626
3623
|
];
|
3627
3624
|
if (newMemberTypeResult) {
|
3628
|
-
this._evaluator.
|
3625
|
+
this._evaluator.validateCallArgs(errorNode, argList, newMemberTypeResult,
|
3629
3626
|
/* typeVarContext */ undefined,
|
3630
3627
|
/* skipUnknownArgCheck */ undefined,
|
3631
|
-
/* inferenceContext */ undefined
|
3632
|
-
/* signatureTracker */ undefined);
|
3628
|
+
/* inferenceContext */ undefined);
|
3633
3629
|
}
|
3634
3630
|
if (initMemberTypeResult) {
|
3635
|
-
this._evaluator.
|
3631
|
+
this._evaluator.validateCallArgs(errorNode, argList, initMemberTypeResult,
|
3636
3632
|
/* typeVarContext */ undefined,
|
3637
3633
|
/* skipUnknownArgCheck */ undefined,
|
3638
|
-
/* inferenceContext */ undefined
|
3639
|
-
/* signatureTracker */ undefined);
|
3634
|
+
/* inferenceContext */ undefined);
|
3640
3635
|
}
|
3641
3636
|
}
|
3642
3637
|
}
|
@@ -3684,7 +3679,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3684
3679
|
!postInitType.shared.declaration) {
|
3685
3680
|
return;
|
3686
3681
|
}
|
3687
|
-
const paramListDetails = (0, parameterUtils_1.
|
3682
|
+
const paramListDetails = (0, parameterUtils_1.getParamListDetails)(postInitType);
|
3688
3683
|
// If there is an *args or **kwargs parameter or a keyword-only separator,
|
3689
3684
|
// don't bother checking.
|
3690
3685
|
if (paramListDetails.argsIndex !== undefined ||
|
@@ -3712,7 +3707,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3712
3707
|
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
3708
|
if (types_1.FunctionParam.isTypeDeclared(param) && annotationNode) {
|
3714
3709
|
const fieldType = (_b = this._evaluator.getDeclaredTypeOfSymbol(symbol)) === null || _b === void 0 ? void 0 : _b.type;
|
3715
|
-
const paramType = types_1.FunctionType.
|
3710
|
+
const paramType = types_1.FunctionType.getEffectiveParamType(postInitType, paramListDetails.params[paramIndex].index);
|
3716
3711
|
const assignTypeDiag = new diagnostic_1.DiagnosticAddendum();
|
3717
3712
|
if (fieldType && !this._evaluator.assignType(paramType, fieldType, assignTypeDiag)) {
|
3718
3713
|
const diagnostic = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.dataClassPostInitType().format({ fieldName }) + assignTypeDiag.getString(), annotationNode);
|
@@ -3885,7 +3880,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3885
3880
|
// for an explanation for why this is important to enforce.
|
3886
3881
|
_validateProtocolTypeParamVariance(errorNode, classType) {
|
3887
3882
|
// If this protocol has no TypeVars with specified variance, there's nothing to do here.
|
3888
|
-
if (classType.shared.
|
3883
|
+
if (classType.shared.typeParams.length === 0) {
|
3889
3884
|
return;
|
3890
3885
|
}
|
3891
3886
|
const objectType = this._evaluator.getBuiltInType(errorNode, 'object');
|
@@ -3894,9 +3889,9 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3894
3889
|
}
|
3895
3890
|
const objectObject = types_1.ClassType.cloneAsInstance(objectType);
|
3896
3891
|
const dummyTypeObject = types_1.ClassType.createInstantiable('__varianceDummy', '', '', uri_1.Uri.empty(), 0, 0, undefined, undefined);
|
3897
|
-
classType.shared.
|
3892
|
+
classType.shared.typeParams.forEach((param, paramIndex) => {
|
3898
3893
|
// Skip variadics and ParamSpecs.
|
3899
|
-
if (param
|
3894
|
+
if ((0, types_1.isTypeVarTuple)(param) || (0, types_1.isParamSpec)(param)) {
|
3900
3895
|
return;
|
3901
3896
|
}
|
3902
3897
|
// Skip type variables with auto-variance.
|
@@ -3905,20 +3900,19 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3905
3900
|
}
|
3906
3901
|
// Replace all type arguments with a dummy type except for the
|
3907
3902
|
// TypeVar of interest, which is replaced with an object instance.
|
3908
|
-
const srcTypeArgs = classType.shared.
|
3909
|
-
if (
|
3903
|
+
const srcTypeArgs = classType.shared.typeParams.map((p, i) => {
|
3904
|
+
if ((0, types_1.isTypeVarTuple)(p)) {
|
3910
3905
|
return p;
|
3911
3906
|
}
|
3912
3907
|
return i === paramIndex ? objectObject : dummyTypeObject;
|
3913
3908
|
});
|
3914
3909
|
// Replace all type arguments with a dummy type except for the
|
3915
3910
|
// TypeVar of interest, which is replaced with itself.
|
3916
|
-
const destTypeArgs = classType.shared.
|
3917
|
-
return i === paramIndex || p
|
3911
|
+
const destTypeArgs = classType.shared.typeParams.map((p, i) => {
|
3912
|
+
return i === paramIndex || (0, types_1.isTypeVarTuple)(p) ? p : dummyTypeObject;
|
3918
3913
|
});
|
3919
|
-
const srcType = types_1.ClassType.
|
3920
|
-
const destType = types_1.ClassType.
|
3921
|
-
/* isTypeArgumentExplicit */ true);
|
3914
|
+
const srcType = types_1.ClassType.specialize(classType, srcTypeArgs);
|
3915
|
+
const destType = types_1.ClassType.specialize(classType, destTypeArgs);
|
3922
3916
|
const isDestSubtypeOfSrc = this._evaluator.assignClassToSelf(srcType, destType, 3 /* Variance.Covariant */);
|
3923
3917
|
let expectedVariance;
|
3924
3918
|
if (isDestSubtypeOfSrc) {
|
@@ -3933,7 +3927,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3933
3927
|
expectedVariance = 2 /* Variance.Invariant */;
|
3934
3928
|
}
|
3935
3929
|
}
|
3936
|
-
if (expectedVariance !== classType.shared.
|
3930
|
+
if (expectedVariance !== classType.shared.typeParams[paramIndex].shared.declaredVariance) {
|
3937
3931
|
let message;
|
3938
3932
|
if (expectedVariance === 3 /* Variance.Covariant */) {
|
3939
3933
|
message = localize_1.LocMessage.protocolVarianceCovariant().format({
|
@@ -4036,22 +4030,17 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4036
4030
|
}
|
4037
4031
|
// If either of the functions has a default parameter signature
|
4038
4032
|
// (* args: Any, ** kwargs: Any), don't proceed with the check.
|
4039
|
-
if (types_1.FunctionType.
|
4033
|
+
if (types_1.FunctionType.hasDefaultParams(initMemberType) || types_1.FunctionType.hasDefaultParams(newMemberType)) {
|
4040
4034
|
return;
|
4041
4035
|
}
|
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
4036
|
if (!this._evaluator.assignType(newMemberType, initMemberType,
|
4048
4037
|
/* diag */ undefined,
|
4049
4038
|
/* destTypeVarContext */ undefined,
|
4050
|
-
/* srcTypeVarContext */ undefined, 64 /* AssignTypeFlags.
|
4039
|
+
/* srcTypeVarContext */ undefined, 64 /* AssignTypeFlags.SkipReturnTypeCheck */) ||
|
4051
4040
|
!this._evaluator.assignType(initMemberType, newMemberType,
|
4052
4041
|
/* diag */ undefined,
|
4053
4042
|
/* destTypeVarContext */ undefined,
|
4054
|
-
/* srcTypeVarContext */ undefined, 64 /* AssignTypeFlags.
|
4043
|
+
/* srcTypeVarContext */ undefined, 64 /* AssignTypeFlags.SkipReturnTypeCheck */)) {
|
4055
4044
|
const displayOnInit = types_1.ClassType.isSameGenericClass(initMethodResult.classType, classType);
|
4056
4045
|
const initDecl = initMemberType.shared.declaration;
|
4057
4046
|
const newDecl = newMemberType.shared.declaration;
|
@@ -4101,7 +4090,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4101
4090
|
const typeVarContext = (0, typeUtils_1.buildTypeVarContextFromSpecializedClass)(baseClass);
|
4102
4091
|
for (const baseClassMroClass of baseClass.shared.mro) {
|
4103
4092
|
// There's no need to check for conflicts if this class isn't generic.
|
4104
|
-
if ((0, types_1.isClass)(baseClassMroClass) && baseClassMroClass.shared.
|
4093
|
+
if ((0, types_1.isClass)(baseClassMroClass) && baseClassMroClass.shared.typeParams.length > 0) {
|
4105
4094
|
const specializedBaseClassMroClass = (0, typeUtils_1.applySolvedTypeVars)(baseClassMroClass, typeVarContext);
|
4106
4095
|
// Find the corresponding class in the derived class's MRO list.
|
4107
4096
|
const matchingMroClass = classType.shared.mro.find((mroClass) => (0, types_1.isClass)(mroClass) && types_1.ClassType.isSameGenericClass(mroClass, specializedBaseClassMroClass));
|
@@ -4208,10 +4197,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4208
4197
|
return;
|
4209
4198
|
}
|
4210
4199
|
let overriddenType = this._evaluator.getEffectiveTypeOfSymbol(overriddenClassAndSymbol.symbol);
|
4211
|
-
overriddenType = (0, typeUtils_1.partiallySpecializeType)(overriddenType, overriddenClassAndSymbol.classType);
|
4200
|
+
overriddenType = (0, typeUtils_1.partiallySpecializeType)(overriddenType, overriddenClassAndSymbol.classType, this._evaluator.getTypeClassType());
|
4212
4201
|
const overrideSymbol = overrideClassAndSymbol.symbol;
|
4213
4202
|
let overrideType = this._evaluator.getEffectiveTypeOfSymbol(overrideSymbol);
|
4214
|
-
overrideType = (0, typeUtils_1.partiallySpecializeType)(overrideType, overrideClassAndSymbol.classType);
|
4203
|
+
overrideType = (0, typeUtils_1.partiallySpecializeType)(overrideType, overrideClassAndSymbol.classType, this._evaluator.getTypeClassType());
|
4215
4204
|
const childOverrideSymbol = types_1.ClassType.getSymbolTable(childClassType).get(memberName);
|
4216
4205
|
const childOverrideType = childOverrideSymbol
|
4217
4206
|
? this._evaluator.getEffectiveTypeOfSymbol(childOverrideSymbol)
|
@@ -4352,7 +4341,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4352
4341
|
const subclassPropMethod = methodAccessor(overrideSymbolType);
|
4353
4342
|
// Is the method present on the base class but missing in the subclass?
|
4354
4343
|
if (baseClassPropMethod) {
|
4355
|
-
const baseClassMethodType = (0, typeUtils_1.partiallySpecializeType)(baseClassPropMethod, overriddenClassType);
|
4344
|
+
const baseClassMethodType = (0, typeUtils_1.partiallySpecializeType)(baseClassPropMethod, overriddenClassType, this._evaluator.getTypeClassType());
|
4356
4345
|
if ((0, types_1.isFunction)(baseClassMethodType)) {
|
4357
4346
|
if (!subclassPropMethod) {
|
4358
4347
|
// The method is missing.
|
@@ -4373,7 +4362,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4373
4362
|
}
|
4374
4363
|
}
|
4375
4364
|
else {
|
4376
|
-
const subclassMethodType = (0, typeUtils_1.partiallySpecializeType)(subclassPropMethod, overrideClassType);
|
4365
|
+
const subclassMethodType = (0, typeUtils_1.partiallySpecializeType)(subclassPropMethod, overrideClassType, this._evaluator.getTypeClassType());
|
4377
4366
|
if ((0, types_1.isFunction)(subclassMethodType)) {
|
4378
4367
|
if (!this._evaluator.validateOverrideMethod(baseClassMethodType, subclassMethodType, overrideClassType, diagAddendum.createAddendum())) {
|
4379
4368
|
diagAddendum.addMessage(localize_1.LocAddendum.propertyMethodIncompatible().format({
|
@@ -4665,8 +4654,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4665
4654
|
}
|
4666
4655
|
const baseClass = baseClassAndSymbol.classType;
|
4667
4656
|
const childClassSelf = types_1.ClassType.cloneAsInstance((0, typeUtils_1.selfSpecializeClass)(childClassType));
|
4668
|
-
const baseType = (0, typeUtils_1.partiallySpecializeType)(this._evaluator.getEffectiveTypeOfSymbol(baseClassAndSymbol.symbol), baseClass, childClassSelf);
|
4669
|
-
overrideType = (0, typeUtils_1.partiallySpecializeType)(overrideType, childClassType, childClassSelf);
|
4657
|
+
const baseType = (0, typeUtils_1.partiallySpecializeType)(this._evaluator.getEffectiveTypeOfSymbol(baseClassAndSymbol.symbol), baseClass, this._evaluator.getTypeClassType(), childClassSelf);
|
4658
|
+
overrideType = (0, typeUtils_1.partiallySpecializeType)(overrideType, childClassType, this._evaluator.getTypeClassType(), childClassSelf);
|
4670
4659
|
if ((0, types_1.isFunction)(baseType) || (0, types_1.isOverloadedFunction)(baseType)) {
|
4671
4660
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
4672
4661
|
// Determine whether this is an attempt to override a method marked @final.
|
@@ -4912,7 +4901,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4912
4901
|
const subclassPropMethod = methodAccessor(childType);
|
4913
4902
|
// Is the method present on the base class but missing in the subclass?
|
4914
4903
|
if (baseClassPropMethod) {
|
4915
|
-
const baseClassMethodType = (0, typeUtils_1.partiallySpecializeType)(baseClassPropMethod, baseClassType);
|
4904
|
+
const baseClassMethodType = (0, typeUtils_1.partiallySpecializeType)(baseClassPropMethod, baseClassType, this._evaluator.getTypeClassType());
|
4916
4905
|
if ((0, types_1.isFunction)(baseClassMethodType)) {
|
4917
4906
|
if (!subclassPropMethod) {
|
4918
4907
|
// The method is missing.
|
@@ -4933,7 +4922,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4933
4922
|
}
|
4934
4923
|
}
|
4935
4924
|
else {
|
4936
|
-
const subclassMethodType = (0, typeUtils_1.partiallySpecializeType)(subclassPropMethod, childClassType);
|
4925
|
+
const subclassMethodType = (0, typeUtils_1.partiallySpecializeType)(subclassPropMethod, childClassType, this._evaluator.getTypeClassType());
|
4937
4926
|
if ((0, types_1.isFunction)(subclassMethodType)) {
|
4938
4927
|
if (!this._evaluator.validateOverrideMethod(baseClassMethodType, subclassMethodType, childClassType, diagAddendum.createAddendum())) {
|
4939
4928
|
diagAddendum.addMessage(localize_1.LocAddendum.propertyMethodIncompatible().format({
|
@@ -4981,7 +4970,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4981
4970
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportSelfClsParameterName, localize_1.LocMessage.newClsParam(), node.d.params.length > 0 ? node.d.params[0] : node.d.name);
|
4982
4971
|
}
|
4983
4972
|
if (classType) {
|
4984
|
-
this.
|
4973
|
+
this._validateClsSelfParamType(node, functionType, classType, /* isCls */ true);
|
4985
4974
|
}
|
4986
4975
|
}
|
4987
4976
|
else if (((_b = node.d.name) === null || _b === void 0 ? void 0 : _b.d.value) === '_generate_next_value_') {
|
@@ -5010,7 +4999,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5010
4999
|
}
|
5011
5000
|
}
|
5012
5001
|
if (classType) {
|
5013
|
-
this.
|
5002
|
+
this._validateClsSelfParamType(node, functionType, classType, /* isCls */ true);
|
5014
5003
|
}
|
5015
5004
|
}
|
5016
5005
|
else {
|
@@ -5026,7 +5015,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5026
5015
|
if (node.d.params[0].d.name) {
|
5027
5016
|
paramName = node.d.params[0].d.name.d.value;
|
5028
5017
|
}
|
5029
|
-
if (node.d.params[0].d.category !== 0 /*
|
5018
|
+
if (node.d.params[0].d.category !== 0 /* ParamCategory.Simple */) {
|
5030
5019
|
firstParamIsSimple = false;
|
5031
5020
|
}
|
5032
5021
|
}
|
@@ -5055,7 +5044,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5055
5044
|
}
|
5056
5045
|
}
|
5057
5046
|
if (classType) {
|
5058
|
-
this.
|
5047
|
+
this._validateClsSelfParamType(node, functionType, classType, /* isCls */ false);
|
5059
5048
|
}
|
5060
5049
|
}
|
5061
5050
|
}
|
@@ -5114,7 +5103,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5114
5103
|
}
|
5115
5104
|
// Validates that the annotated type of a "self" or "cls" parameter is
|
5116
5105
|
// compatible with the type of the class that contains it.
|
5117
|
-
|
5106
|
+
_validateClsSelfParamType(node, functionType, classType, isCls) {
|
5118
5107
|
var _a;
|
5119
5108
|
if (node.d.params.length < 1 || functionType.shared.parameters.length < 1) {
|
5120
5109
|
return;
|
@@ -5130,8 +5119,12 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5130
5119
|
// use of class-scoped TypeVars, which are not allowed in this context
|
5131
5120
|
// according to the typing spec.
|
5132
5121
|
if (functionType.shared.name === '__init__' && functionType.shared.methodClass) {
|
5133
|
-
const typeVars = (0, typeUtils_1.
|
5134
|
-
if (typeVars.some((typeVar) => {
|
5122
|
+
const typeVars = (0, typeUtils_1.getTypeVarArgsRecursive)(paramInfo.type);
|
5123
|
+
if (typeVars.some((typeVar) => {
|
5124
|
+
var _a;
|
5125
|
+
return typeVar.priv.scopeId === ((_a = functionType.shared.methodClass) === null || _a === void 0 ? void 0 : _a.shared.typeVarScopeId) &&
|
5126
|
+
!typeVar.shared.isSynthesizedSelf;
|
5127
|
+
})) {
|
5135
5128
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeVarUse, localize_1.LocMessage.initMethodSelfParamTypeVar(), paramAnnotation);
|
5136
5129
|
}
|
5137
5130
|
}
|
@@ -5151,7 +5144,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5151
5144
|
return;
|
5152
5145
|
}
|
5153
5146
|
// If the method starts with a `*args: P.args`, skip the check.
|
5154
|
-
if (paramInfo.category === 1 /*
|
5147
|
+
if (paramInfo.category === 1 /* ParamCategory.ArgsList */ &&
|
5155
5148
|
(0, types_1.isParamSpec)(paramInfo.type) &&
|
5156
5149
|
paramInfo.type.priv.paramSpecAccess === 'args') {
|
5157
5150
|
return;
|
@@ -5193,10 +5186,12 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5193
5186
|
if (!functionTypeResult) {
|
5194
5187
|
return;
|
5195
5188
|
}
|
5196
|
-
|
5189
|
+
let declaredReturnType = types_1.FunctionType.getEffectiveReturnType(functionTypeResult.functionType);
|
5197
5190
|
if (!declaredReturnType) {
|
5198
5191
|
return;
|
5199
5192
|
}
|
5193
|
+
const liveScopes = ParseTreeUtils.getTypeVarScopesForNode(node);
|
5194
|
+
declaredReturnType = (0, typeUtils_1.updateTypeWithInternalTypeVars)(declaredReturnType, liveScopes);
|
5200
5195
|
let generatorType;
|
5201
5196
|
if (!enclosingFunctionNode.d.isAsync &&
|
5202
5197
|
(0, types_1.isClassInstance)(declaredReturnType) &&
|
@@ -5219,7 +5214,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5219
5214
|
return;
|
5220
5215
|
}
|
5221
5216
|
const generatorTypeArgs = [yieldType, sendType !== null && sendType !== void 0 ? sendType : types_1.UnknownType.create(), types_1.UnknownType.create()];
|
5222
|
-
const specializedGenerator = types_1.ClassType.cloneAsInstance(types_1.ClassType.
|
5217
|
+
const specializedGenerator = types_1.ClassType.cloneAsInstance(types_1.ClassType.specialize(generatorType, generatorTypeArgs));
|
5223
5218
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
5224
5219
|
if (!this._evaluator.assignType(declaredReturnType, specializedGenerator, diagAddendum)) {
|
5225
5220
|
const errorMessage = enclosingFunctionNode.d.isAsync
|
@@ -5293,7 +5288,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5293
5288
|
// Were all of the exception types overridden?
|
5294
5289
|
if (typesOfThisExcept.length > 0 && typesOfThisExcept.length === overriddenExceptionCount) {
|
5295
5290
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnusedExcept, localize_1.LocMessage.unreachableExcept() + diagAddendum.getString(), except.d.typeExpr);
|
5296
|
-
this._evaluator.addUnreachableCode(except, except.d.exceptSuite);
|
5291
|
+
this._evaluator.addUnreachableCode(except, typeEvaluatorTypes_1.Reachability.UnreachableByAnalysis, except.d.exceptSuite);
|
5297
5292
|
}
|
5298
5293
|
}
|
5299
5294
|
(0, collectionUtils_1.appendArray)(exceptionTypesSoFar, typesOfThisExcept);
|