@zzzen/pyright-internal 1.2.0-dev.20240721 → 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 +115 -122
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.d.ts +2 -2
- package/dist/analyzer/codeFlowEngine.js +49 -42
- 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 +164 -204
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constructorTransform.d.ts +2 -2
- package/dist/analyzer/constructorTransform.js +15 -15
- package/dist/analyzer/constructorTransform.js.map +1 -1
- package/dist/analyzer/constructors.d.ts +2 -2
- package/dist/analyzer/constructors.js +28 -33
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.d.ts +2 -2
- package/dist/analyzer/dataClasses.js +59 -36
- 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 +4 -4
- 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 +10 -10
- 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 +58 -58
- 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 +108 -89
- 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 +19 -19
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/protocols.js +14 -15
- 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 +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 +1062 -1311
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +44 -40
- package/dist/analyzer/typeEvaluatorTypes.js +7 -1
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +114 -85
- 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 +20 -18
- package/dist/analyzer/typeUtils.js +316 -321
- 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 +48 -52
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +79 -57
- package/dist/analyzer/types.js +125 -113
- 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 +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 +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 +2 -2
- 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/typeEvaluator3.test.js +1 -1
- package/dist/tests/typeEvaluator4.test.js +9 -1
- 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 +72 -60
- package/dist/tests/typeEvaluator6.test.js.map +1 -1
- package/dist/tests/typeEvaluator7.test.js +2 -2
- 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
|
}
|
@@ -579,33 +580,32 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
579
580
|
else {
|
580
581
|
const liveScopes = ParseTreeUtils.getTypeVarScopesForNode(node);
|
581
582
|
declaredReturnType = (0, typeUtils_1.updateTypeWithInternalTypeVars)(declaredReturnType, liveScopes);
|
583
|
+
declaredReturnType = this._evaluator.stripTypeGuard(declaredReturnType);
|
582
584
|
let diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
583
585
|
let returnTypeMatches = false;
|
584
586
|
if (this._evaluator.assignType(declaredReturnType, returnType, diagAddendum,
|
585
|
-
/* destTypeVarContext */ new typeVarContext_1.TypeVarContext()
|
586
|
-
/* srcTypeVarContext */ undefined, 128 /* AssignTypeFlags.AllowBoolTypeGuard */)) {
|
587
|
+
/* destTypeVarContext */ new typeVarContext_1.TypeVarContext())) {
|
587
588
|
returnTypeMatches = true;
|
588
589
|
}
|
589
590
|
else {
|
590
591
|
// See if the declared return type includes one or more constrained TypeVars. If so,
|
591
592
|
// try to narrow these TypeVars to a single type.
|
592
|
-
const uniqueTypeVars = (0, typeUtils_1.
|
593
|
+
const uniqueTypeVars = (0, typeUtils_1.getTypeVarArgsRecursive)(declaredReturnType);
|
593
594
|
if (uniqueTypeVars && uniqueTypeVars.some((typeVar) => typeVar.shared.constraints.length > 0)) {
|
594
595
|
const typeVarContext = new typeVarContext_1.TypeVarContext();
|
595
596
|
for (const typeVar of uniqueTypeVars) {
|
596
597
|
if (typeVar.shared.constraints.length > 0) {
|
597
598
|
const narrowedType = this._evaluator.narrowConstrainedTypeVar(node, typeVar);
|
598
599
|
if (narrowedType) {
|
599
|
-
|
600
|
+
(0, typeUtils_1.setTypeVarType)(typeVarContext, typeVar, narrowedType);
|
600
601
|
typeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeId)(typeVar));
|
601
602
|
}
|
602
603
|
}
|
603
604
|
}
|
604
605
|
if (!typeVarContext.isEmpty()) {
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
/* 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)) {
|
609
609
|
returnTypeMatches = true;
|
610
610
|
}
|
611
611
|
}
|
@@ -723,8 +723,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
723
723
|
// assert (x > 3, "bad value x")
|
724
724
|
const type = this._evaluator.getType(node.d.testExpr);
|
725
725
|
if (type && (0, types_1.isClassInstance)(type)) {
|
726
|
-
if ((0, typeUtils_1.isTupleClass)(type) && type.priv.
|
727
|
-
if (type.priv.
|
726
|
+
if ((0, typeUtils_1.isTupleClass)(type) && type.priv.tupleTypeArgs) {
|
727
|
+
if (type.priv.tupleTypeArgs.length > 0) {
|
728
728
|
if (!(0, typeUtils_1.isUnboundedTupleClass)(type)) {
|
729
729
|
this._evaluator.addDiagnosticForTextRange(this._fileInfo, diagnosticRules_1.DiagnosticRule.reportAssertAlwaysTrue, localize_1.LocMessage.assertAlwaysTrue(), node.d.testExpr);
|
730
730
|
}
|
@@ -774,15 +774,13 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
774
774
|
if (baseType) {
|
775
775
|
(0, typeUtils_1.doForEachSubtype)(baseType, (subtype) => {
|
776
776
|
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)) {
|
777
|
+
if (!(0, types_1.isClassInstance)(subtype) || !(tupleType === null || tupleType === void 0 ? void 0 : tupleType.priv.tupleTypeArgs) || (0, typeUtils_1.isUnboundedTupleClass)(tupleType)) {
|
780
778
|
return;
|
781
779
|
}
|
782
|
-
const tupleLength = tupleType.priv.
|
780
|
+
const tupleLength = tupleType.priv.tupleTypeArgs.length;
|
783
781
|
if (node.d.items.length !== 1 ||
|
784
782
|
node.d.trailingComma ||
|
785
|
-
node.d.items[0].d.argCategory !== 0 /*
|
783
|
+
node.d.items[0].d.argCategory !== 0 /* ArgCategory.Simple */ ||
|
786
784
|
node.d.items[0].d.name) {
|
787
785
|
return;
|
788
786
|
}
|
@@ -963,7 +961,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
963
961
|
}
|
964
962
|
visitMemberAccess(node) {
|
965
963
|
var _a;
|
966
|
-
const typeResult = this._evaluator.getTypeResult(node);
|
964
|
+
const typeResult = this._evaluator.getTypeResult(node.d.member);
|
967
965
|
const type = (_a = typeResult === null || typeResult === void 0 ? void 0 : typeResult.type) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
|
968
966
|
const leftExprType = this._evaluator.getType(node.d.leftExpr);
|
969
967
|
this._reportDeprecatedUseForType(node.d.member, type, leftExprType && (0, types_1.isModule)(leftExprType) && leftExprType.priv.moduleName === 'typing');
|
@@ -1055,7 +1053,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1055
1053
|
return false;
|
1056
1054
|
}
|
1057
1055
|
visitTypeParameterList(node) {
|
1058
|
-
this.
|
1056
|
+
this._typeParamLists.push(node);
|
1059
1057
|
return true;
|
1060
1058
|
}
|
1061
1059
|
visitTypeParameter(node) {
|
@@ -1071,14 +1069,14 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1071
1069
|
}
|
1072
1070
|
if (typeVarScopeNode.nodeType === 10 /* ParseNodeType.Class */) {
|
1073
1071
|
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.
|
1072
|
+
if (classType === null || classType === void 0 ? void 0 : classType.shared.typeParams.some((param) => param.shared.name === node.d.name.d.value)) {
|
1075
1073
|
foundDuplicate = true;
|
1076
1074
|
break;
|
1077
1075
|
}
|
1078
1076
|
}
|
1079
1077
|
else if (typeVarScopeNode.nodeType === 31 /* ParseNodeType.Function */) {
|
1080
1078
|
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.
|
1079
|
+
if (functionType === null || functionType === void 0 ? void 0 : functionType.shared.typeParams.some((param) => param.shared.name === node.d.name.d.value)) {
|
1082
1080
|
foundDuplicate = true;
|
1083
1081
|
break;
|
1084
1082
|
}
|
@@ -1467,12 +1465,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1467
1465
|
if ((0, types_1.isInstantiableClass)(leftType) || ((0, types_1.isClassInstance)(leftType) && types_1.ClassType.isBuiltIn(leftType, 'type'))) {
|
1468
1466
|
if ((0, types_1.isInstantiableClass)(rightType) ||
|
1469
1467
|
((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);
|
1468
|
+
const genericLeftType = types_1.ClassType.specialize(leftType, /* typeArgs */ undefined);
|
1469
|
+
const genericRightType = types_1.ClassType.specialize(rightType, /* typeArgs */ undefined);
|
1476
1470
|
if (this._evaluator.assignType(genericLeftType, genericRightType) ||
|
1477
1471
|
this._evaluator.assignType(genericRightType, genericLeftType)) {
|
1478
1472
|
return true;
|
@@ -1489,12 +1483,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1489
1483
|
}
|
1490
1484
|
if ((0, types_1.isClassInstance)(leftType)) {
|
1491
1485
|
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);
|
1486
|
+
const genericLeftType = types_1.ClassType.specialize(leftType, /* typeArgs */ undefined);
|
1487
|
+
const genericRightType = types_1.ClassType.specialize(rightType, /* typeArgs */ undefined);
|
1498
1488
|
if (this._evaluator.assignType(genericLeftType, genericRightType) ||
|
1499
1489
|
this._evaluator.assignType(genericRightType, genericLeftType)) {
|
1500
1490
|
return true;
|
@@ -1551,8 +1541,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1551
1541
|
if (!generatorType || !(0, types_1.isInstantiableClass)(generatorType)) {
|
1552
1542
|
return;
|
1553
1543
|
}
|
1554
|
-
const specializedGenerator = types_1.ClassType.cloneAsInstance(types_1.ClassType.
|
1555
|
-
/* 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()]));
|
1556
1545
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
1557
1546
|
if (!this._evaluator.assignType(declaredReturnType, specializedGenerator, diagAddendum)) {
|
1558
1547
|
const errorMessage = node.d.isAsync
|
@@ -1609,7 +1598,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1609
1598
|
// the TypeVar multiple times.
|
1610
1599
|
const baseType = this._evaluator.getType(baseExpression);
|
1611
1600
|
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.
|
1601
|
+
if ((aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.typeParams) && subscriptIndex < aliasInfo.typeParams.length) {
|
1613
1602
|
isExempt = true;
|
1614
1603
|
}
|
1615
1604
|
}
|
@@ -1704,7 +1693,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1704
1693
|
// Report error for local type variable that appears only once.
|
1705
1694
|
if (usage.nodes.length === 1 && !usage.isExempt) {
|
1706
1695
|
let altTypeText;
|
1707
|
-
if (usage.typeVar
|
1696
|
+
if ((0, types_1.isTypeVarTuple)(usage.typeVar)) {
|
1708
1697
|
altTypeText = '"tuple[object, ...]"';
|
1709
1698
|
}
|
1710
1699
|
else if (usage.typeVar.shared.boundType) {
|
@@ -1891,13 +1880,14 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1891
1880
|
// No need to report unreachable more than once since the first time
|
1892
1881
|
// covers all remaining statements in the statement list.
|
1893
1882
|
if (!reportedUnreachable) {
|
1894
|
-
|
1883
|
+
const reachability = this._evaluator.getNodeReachability(statement, prevStatement);
|
1884
|
+
if (reachability !== typeEvaluatorTypes_1.Reachability.Reachable) {
|
1895
1885
|
// Create a text range that covers the next statement through
|
1896
1886
|
// the end of the statement list.
|
1897
1887
|
const start = statement.start;
|
1898
1888
|
const lastStatement = statements[statements.length - 1];
|
1899
1889
|
const end = textRange_1.TextRange.getEnd(lastStatement);
|
1900
|
-
this._evaluator.addUnreachableCode(statement, { start, length: end - start });
|
1890
|
+
this._evaluator.addUnreachableCode(statement, reachability, { start, length: end - start });
|
1901
1891
|
reportedUnreachable = true;
|
1902
1892
|
}
|
1903
1893
|
}
|
@@ -2016,8 +2006,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2016
2006
|
}
|
2017
2007
|
return;
|
2018
2008
|
}
|
2019
|
-
if (allowTuple && exceptionSubtype.priv.
|
2020
|
-
exceptionSubtype.priv.
|
2009
|
+
if (allowTuple && exceptionSubtype.priv.tupleTypeArgs) {
|
2010
|
+
exceptionSubtype.priv.tupleTypeArgs.forEach((typeArg) => {
|
2021
2011
|
this._validateExceptionTypeRecursive(typeArg.type, diag, baseExceptionType, baseExceptionGroupType,
|
2022
2012
|
/* allowTuple */ false, isExceptGroup);
|
2023
2013
|
});
|
@@ -2066,6 +2056,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2066
2056
|
this._conditionallyReportUnusedSymbol(name, symbol, scope.type, dependentFileInfo);
|
2067
2057
|
this._reportIncompatibleDeclarations(name, symbol);
|
2068
2058
|
this._reportMultipleFinalDeclarations(name, symbol, scope.type);
|
2059
|
+
this._reportFinalInLoop(symbol);
|
2069
2060
|
this._reportMultipleTypeAliasDeclarations(name, symbol);
|
2070
2061
|
this._reportInvalidOverload(name, symbol);
|
2071
2062
|
});
|
@@ -2073,7 +2064,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2073
2064
|
}
|
2074
2065
|
// Report unaccessed type parameters.
|
2075
2066
|
const accessedSymbolSet = this._fileInfo.accessedSymbolSet;
|
2076
|
-
for (const paramList of this.
|
2067
|
+
for (const paramList of this._typeParamLists) {
|
2077
2068
|
const typeParamScope = AnalyzerNodeInfo.getScope(paramList);
|
2078
2069
|
for (const param of paramList.d.params) {
|
2079
2070
|
const symbol = typeParamScope === null || typeParamScope === void 0 ? void 0 : typeParamScope.symbolTable.get(param.d.name.d.value);
|
@@ -2178,6 +2169,18 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2178
2169
|
}
|
2179
2170
|
});
|
2180
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
|
+
}
|
2181
2184
|
_reportMultipleFinalDeclarations(name, symbol, scopeType) {
|
2182
2185
|
if (!this._evaluator.isFinalVariable(symbol)) {
|
2183
2186
|
return;
|
@@ -2325,7 +2328,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2325
2328
|
else if (primaryDecl.type === 6 /* DeclarationType.Class */) {
|
2326
2329
|
primaryDeclInfo = localize_1.LocAddendum.seeClassDeclaration();
|
2327
2330
|
}
|
2328
|
-
else if (primaryDecl.type === 2 /* DeclarationType.
|
2331
|
+
else if (primaryDecl.type === 2 /* DeclarationType.Param */) {
|
2329
2332
|
primaryDeclInfo = localize_1.LocAddendum.seeParameterDeclaration();
|
2330
2333
|
}
|
2331
2334
|
else if (primaryDecl.type === 1 /* DeclarationType.Variable */) {
|
@@ -2348,8 +2351,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2348
2351
|
primaryDeclNode = primaryDecl.node;
|
2349
2352
|
}
|
2350
2353
|
}
|
2351
|
-
else if (primaryDecl.type === 2 /* DeclarationType.
|
2352
|
-
primaryDecl.type === 3 /* DeclarationType.
|
2354
|
+
else if (primaryDecl.type === 2 /* DeclarationType.Param */ ||
|
2355
|
+
primaryDecl.type === 3 /* DeclarationType.TypeParam */) {
|
2353
2356
|
if (primaryDecl.node.d.name) {
|
2354
2357
|
primaryDeclNode = primaryDecl.node.d.name;
|
2355
2358
|
}
|
@@ -2362,7 +2365,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2362
2365
|
for (const otherDecl of otherDecls) {
|
2363
2366
|
if (otherDecl.type === 6 /* DeclarationType.Class */) {
|
2364
2367
|
let duplicateIsOk = false;
|
2365
|
-
if (primaryDecl.type === 3 /* DeclarationType.
|
2368
|
+
if (primaryDecl.type === 3 /* DeclarationType.TypeParam */) {
|
2366
2369
|
// The error will be reported elsewhere if a type parameter is
|
2367
2370
|
// involved, so don't report it here.
|
2368
2371
|
duplicateIsOk = true;
|
@@ -2395,7 +2398,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2395
2398
|
if (!isInSameStatementList && primaryType && otherType && (0, types_1.isTypeSame)(primaryType, otherType)) {
|
2396
2399
|
duplicateIsOk = true;
|
2397
2400
|
}
|
2398
|
-
if (primaryDecl.type === 3 /* DeclarationType.
|
2401
|
+
if (primaryDecl.type === 3 /* DeclarationType.TypeParam */) {
|
2399
2402
|
// The error will be reported elsewhere if a type parameter is
|
2400
2403
|
// involved, so don't report it here.
|
2401
2404
|
duplicateIsOk = true;
|
@@ -2407,10 +2410,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2407
2410
|
addPrimaryDeclInfo(diag);
|
2408
2411
|
}
|
2409
2412
|
}
|
2410
|
-
else if (otherDecl.type === 2 /* DeclarationType.
|
2413
|
+
else if (otherDecl.type === 2 /* DeclarationType.Param */) {
|
2411
2414
|
if (otherDecl.node.d.name) {
|
2412
2415
|
let duplicateIsOk = false;
|
2413
|
-
if (primaryDecl.type === 3 /* DeclarationType.
|
2416
|
+
if (primaryDecl.type === 3 /* DeclarationType.TypeParam */) {
|
2414
2417
|
// The error will be reported elsewhere if a type parameter is
|
2415
2418
|
// involved, so don't report it here.
|
2416
2419
|
duplicateIsOk = true;
|
@@ -2432,7 +2435,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2432
2435
|
if (primaryType && otherType && (0, types_1.isTypeSame)(primaryType, otherType)) {
|
2433
2436
|
duplicateIsOk = true;
|
2434
2437
|
}
|
2435
|
-
if (primaryDecl.type === 3 /* DeclarationType.
|
2438
|
+
if (primaryDecl.type === 3 /* DeclarationType.TypeParam */) {
|
2436
2439
|
// The error will be reported elsewhere if a type parameter is
|
2437
2440
|
// involved, so don't report it here.
|
2438
2441
|
duplicateIsOk = true;
|
@@ -2523,7 +2526,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2523
2526
|
break;
|
2524
2527
|
case 4 /* DeclarationType.TypeAlias */:
|
2525
2528
|
case 1 /* DeclarationType.Variable */:
|
2526
|
-
case 2 /* DeclarationType.
|
2529
|
+
case 2 /* DeclarationType.Param */:
|
2527
2530
|
if (!isPrivate) {
|
2528
2531
|
return;
|
2529
2532
|
}
|
@@ -2579,8 +2582,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2579
2582
|
rule = diagnosticRules_1.DiagnosticRule.reportUnusedFunction;
|
2580
2583
|
message = localize_1.LocMessage.unaccessedFunction().format({ name: nameNode.d.value });
|
2581
2584
|
break;
|
2582
|
-
case 3 /* DeclarationType.
|
2583
|
-
// Never report a diagnostic for an unused
|
2585
|
+
case 3 /* DeclarationType.TypeParam */:
|
2586
|
+
// Never report a diagnostic for an unused TypeParam.
|
2584
2587
|
diagnosticLevel = 'none';
|
2585
2588
|
nameNode = decl.node.d.name;
|
2586
2589
|
break;
|
@@ -2624,10 +2627,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2624
2627
|
let isValidType = true;
|
2625
2628
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
2626
2629
|
(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))) {
|
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))) {
|
2631
2632
|
isValidType = false;
|
2632
2633
|
}
|
2633
2634
|
}
|
@@ -2653,8 +2654,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2653
2654
|
(0, typeUtils_1.doForEachSubtype)(arg1Type, (arg1Subtype) => {
|
2654
2655
|
if ((0, types_1.isClassInstance)(arg1Subtype) &&
|
2655
2656
|
types_1.ClassType.isTupleClass(arg1Subtype) &&
|
2656
|
-
arg1Subtype.priv.
|
2657
|
-
arg1Subtype.priv.
|
2657
|
+
arg1Subtype.priv.tupleTypeArgs) {
|
2658
|
+
arg1Subtype.priv.tupleTypeArgs.forEach((typeArg) => {
|
2658
2659
|
this._validateNotDataProtocol(typeArg.type, diag);
|
2659
2660
|
});
|
2660
2661
|
}
|
@@ -2709,8 +2710,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2709
2710
|
// The isinstance and issubclass call supports a variation where the second
|
2710
2711
|
// parameter is a tuple of classes.
|
2711
2712
|
if ((0, typeUtils_1.isTupleClass)(arg1Subtype)) {
|
2712
|
-
if (arg1Subtype.priv.
|
2713
|
-
arg1Subtype.priv.
|
2713
|
+
if (arg1Subtype.priv.tupleTypeArgs) {
|
2714
|
+
arg1Subtype.priv.tupleTypeArgs.forEach((typeArg) => {
|
2714
2715
|
if ((0, types_1.isInstantiableClass)(typeArg.type)) {
|
2715
2716
|
classTypeList.push(typeArg.type);
|
2716
2717
|
if (typeArg.type.priv.includeSubclasses) {
|
@@ -2890,7 +2891,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2890
2891
|
diag.addMessage(localize_1.LocAddendum.typedDictClassNotAllowed());
|
2891
2892
|
isSupported = false;
|
2892
2893
|
}
|
2893
|
-
else if (subtype.priv.
|
2894
|
+
else if (subtype.priv.isTypeArgExplicit && !subtype.priv.includeSubclasses) {
|
2894
2895
|
// If it's a class, make sure that it has not been given explicit
|
2895
2896
|
// type arguments. This will result in a TypeError exception.
|
2896
2897
|
diag.addMessage(localize_1.LocAddendum.genericClassNotAllowed());
|
@@ -2990,7 +2991,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2990
2991
|
}
|
2991
2992
|
}
|
2992
2993
|
if (errorMessage) {
|
2993
|
-
this._reportDeprecatedDiagnostic(node, errorMessage, info.
|
2994
|
+
this._reportDeprecatedDiagnostic(node, errorMessage, info.deprecatedMessage);
|
2994
2995
|
}
|
2995
2996
|
}
|
2996
2997
|
_reportDeprecatedUseForType(node, type, isImportFromTyping = false) {
|
@@ -3106,18 +3107,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3106
3107
|
((_c = (_b = type.props) === null || _b === void 0 ? void 0 : _b.typeAliasInfo) === null || _c === void 0 ? void 0 : _c.fullName) === deprecatedForm.fullName) {
|
3107
3108
|
if (this._fileInfo.executionEnvironment.pythonVersion.isGreaterOrEqualTo(deprecatedForm.version)) {
|
3108
3109
|
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
|
-
}
|
3110
|
+
this._reportDeprecatedDiagnostic(node, localize_1.LocMessage.deprecatedType().format({
|
3111
|
+
version: deprecatedForm.version.toString(),
|
3112
|
+
replacement: deprecatedForm.replacementText,
|
3113
|
+
}));
|
3121
3114
|
}
|
3122
3115
|
}
|
3123
3116
|
}
|
@@ -3376,9 +3369,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3376
3369
|
if (!returnType) {
|
3377
3370
|
return;
|
3378
3371
|
}
|
3379
|
-
if (!(0, types_1.isClassInstance)(returnType) ||
|
3380
|
-
!returnType.priv.typeArguments ||
|
3381
|
-
returnType.priv.typeArguments.length < 1) {
|
3372
|
+
if (!(0, types_1.isClassInstance)(returnType) || !returnType.priv.typeArgs || returnType.priv.typeArgs.length < 1) {
|
3382
3373
|
return;
|
3383
3374
|
}
|
3384
3375
|
const isTypeGuard = types_1.ClassType.isBuiltIn(returnType, 'TypeGuard');
|
@@ -3399,13 +3390,13 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3399
3390
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeGuardParamCount(), node.d.name);
|
3400
3391
|
}
|
3401
3392
|
if (isTypeIs) {
|
3402
|
-
const typeGuardType = returnType.priv.
|
3393
|
+
const typeGuardType = returnType.priv.typeArgs[0];
|
3403
3394
|
// Determine the type of the first parameter.
|
3404
3395
|
const paramIndex = isMethod && !types_1.FunctionType.isStaticMethod(functionType) ? 1 : 0;
|
3405
3396
|
if (paramIndex >= functionType.shared.parameters.length) {
|
3406
3397
|
return;
|
3407
3398
|
}
|
3408
|
-
const paramType = types_1.FunctionType.
|
3399
|
+
const paramType = types_1.FunctionType.getEffectiveParamType(functionType, paramIndex);
|
3409
3400
|
// Verify that the typeGuardType is a narrower type than the paramType.
|
3410
3401
|
if (!this._evaluator.assignType(paramType, typeGuardType)) {
|
3411
3402
|
const returnAnnotation = node.d.returnAnnotation || ((_a = node.d.funcAnnotationComment) === null || _a === void 0 ? void 0 : _a.d.returnAnnotation);
|
@@ -3609,6 +3600,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3609
3600
|
if (decls[0].type !== 1 /* DeclarationType.Variable */) {
|
3610
3601
|
return;
|
3611
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
|
+
}
|
3612
3607
|
const declNode = decls[0].node;
|
3613
3608
|
const assignedValueType = symbolType.priv.literalValue.itemType;
|
3614
3609
|
const assignmentNode = ParseTreeUtils.getParentNodeOfType(declNode, 3 /* ParseNodeType.Assignment */);
|
@@ -3620,20 +3615,20 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3620
3615
|
// unpack it. Otherwise, only one argument is passed.
|
3621
3616
|
const argList = [
|
3622
3617
|
{
|
3623
|
-
|
3624
|
-
? 1 /*
|
3625
|
-
: 0 /*
|
3618
|
+
argCategory: (0, types_1.isClassInstance)(assignedValueType) && (0, typeUtils_1.isTupleClass)(assignedValueType)
|
3619
|
+
? 1 /* ArgCategory.UnpackedList */
|
3620
|
+
: 0 /* ArgCategory.Simple */,
|
3626
3621
|
typeResult: { type: assignedValueType },
|
3627
3622
|
},
|
3628
3623
|
];
|
3629
3624
|
if (newMemberTypeResult) {
|
3630
|
-
this._evaluator.
|
3625
|
+
this._evaluator.validateCallArgs(errorNode, argList, newMemberTypeResult,
|
3631
3626
|
/* typeVarContext */ undefined,
|
3632
3627
|
/* skipUnknownArgCheck */ undefined,
|
3633
3628
|
/* inferenceContext */ undefined);
|
3634
3629
|
}
|
3635
3630
|
if (initMemberTypeResult) {
|
3636
|
-
this._evaluator.
|
3631
|
+
this._evaluator.validateCallArgs(errorNode, argList, initMemberTypeResult,
|
3637
3632
|
/* typeVarContext */ undefined,
|
3638
3633
|
/* skipUnknownArgCheck */ undefined,
|
3639
3634
|
/* inferenceContext */ undefined);
|
@@ -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,14 +4030,9 @@ 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,
|
@@ -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));
|
@@ -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;
|
@@ -5221,7 +5214,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5221
5214
|
return;
|
5222
5215
|
}
|
5223
5216
|
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.
|
5217
|
+
const specializedGenerator = types_1.ClassType.cloneAsInstance(types_1.ClassType.specialize(generatorType, generatorTypeArgs));
|
5225
5218
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
5226
5219
|
if (!this._evaluator.assignType(declaredReturnType, specializedGenerator, diagAddendum)) {
|
5227
5220
|
const errorMessage = enclosingFunctionNode.d.isAsync
|
@@ -5295,7 +5288,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
5295
5288
|
// Were all of the exception types overridden?
|
5296
5289
|
if (typesOfThisExcept.length > 0 && typesOfThisExcept.length === overriddenExceptionCount) {
|
5297
5290
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnusedExcept, localize_1.LocMessage.unreachableExcept() + diagAddendum.getString(), except.d.typeExpr);
|
5298
|
-
this._evaluator.addUnreachableCode(except, except.d.exceptSuite);
|
5291
|
+
this._evaluator.addUnreachableCode(except, typeEvaluatorTypes_1.Reachability.UnreachableByAnalysis, except.d.exceptSuite);
|
5299
5292
|
}
|
5300
5293
|
}
|
5301
5294
|
(0, collectionUtils_1.appendArray)(exceptionTypesSoFar, typesOfThisExcept);
|