@zzzen/pyright-internal 1.2.0-dev.20240707 → 1.2.0-dev.20240714
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyzer/analyzerNodeInfo.js +74 -46
- package/dist/analyzer/analyzerNodeInfo.js.map +1 -1
- package/dist/analyzer/binder.js +506 -512
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.js +649 -634
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.d.ts +5 -3
- package/dist/analyzer/codeFlowEngine.js +87 -101
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/codeFlowTypes.js +30 -28
- package/dist/analyzer/codeFlowTypes.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +68 -64
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constructorTransform.js +22 -22
- package/dist/analyzer/constructorTransform.js.map +1 -1
- package/dist/analyzer/constructors.js +51 -48
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.js +109 -175
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/declarationUtils.js +14 -15
- package/dist/analyzer/declarationUtils.js.map +1 -1
- package/dist/analyzer/decorators.js +77 -77
- package/dist/analyzer/decorators.js.map +1 -1
- package/dist/analyzer/enums.js +70 -56
- package/dist/analyzer/enums.js.map +1 -1
- package/dist/analyzer/functionTransform.js +8 -18
- package/dist/analyzer/functionTransform.js.map +1 -1
- package/dist/analyzer/importResolver.d.ts +2 -1
- package/dist/analyzer/importResolver.js +40 -29
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/importStatementUtils.js +27 -27
- package/dist/analyzer/importStatementUtils.js.map +1 -1
- package/dist/analyzer/namedTuples.js +33 -59
- package/dist/analyzer/namedTuples.js.map +1 -1
- package/dist/analyzer/operations.js +66 -66
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/packageTypeVerifier.js +66 -62
- package/dist/analyzer/packageTypeVerifier.js.map +1 -1
- package/dist/analyzer/parameterUtils.d.ts +4 -4
- package/dist/analyzer/parameterUtils.js +28 -46
- package/dist/analyzer/parameterUtils.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.js +268 -269
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/parseTreeWalker.js +76 -76
- package/dist/analyzer/parseTreeWalker.js.map +1 -1
- package/dist/analyzer/patternMatching.js +176 -143
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.js +1 -1
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/properties.js +78 -147
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/protocols.js +21 -21
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/sourceFile.js +3 -3
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/sourceMapper.js +20 -19
- package/dist/analyzer/sourceMapper.js.map +1 -1
- package/dist/analyzer/staticExpressions.js +83 -84
- package/dist/analyzer/staticExpressions.js.map +1 -1
- package/dist/analyzer/testWalker.js +2 -2
- package/dist/analyzer/testWalker.js.map +1 -1
- package/dist/analyzer/tracePrinter.js +20 -20
- package/dist/analyzer/tracePrinter.js.map +1 -1
- package/dist/analyzer/typeDocStringUtils.js +25 -25
- package/dist/analyzer/typeDocStringUtils.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +1884 -1937
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +6 -5
- package/dist/analyzer/typeEvaluatorTypes.js +4 -1
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +211 -211
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.js +118 -115
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeStubWriter.js +104 -103
- package/dist/analyzer/typeStubWriter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +14 -3
- package/dist/analyzer/typeUtils.js +432 -402
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typeVarContext.js +8 -8
- package/dist/analyzer/typeVarContext.js.map +1 -1
- package/dist/analyzer/typeWalker.js +13 -10
- package/dist/analyzer/typeWalker.js.map +1 -1
- package/dist/analyzer/typedDicts.js +96 -198
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +144 -102
- package/dist/analyzer/types.js +662 -494
- package/dist/analyzer/types.js.map +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js +33 -33
- package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
- package/dist/common/fileSystem.d.ts +1 -0
- package/dist/common/fileSystem.js.map +1 -1
- package/dist/common/fullAccessHost.js +6 -4
- package/dist/common/fullAccessHost.js.map +1 -1
- package/dist/common/realFileSystem.d.ts +1 -0
- package/dist/common/realFileSystem.js +4 -0
- package/dist/common/realFileSystem.js.map +1 -1
- package/dist/common/textEditTracker.js +14 -14
- package/dist/common/textEditTracker.js.map +1 -1
- package/dist/languageService/autoImporter.js +10 -10
- package/dist/languageService/autoImporter.js.map +1 -1
- package/dist/languageService/callHierarchyProvider.js +23 -23
- package/dist/languageService/callHierarchyProvider.js.map +1 -1
- package/dist/languageService/completionProvider.js +153 -151
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/definitionProvider.d.ts +1 -1
- package/dist/languageService/definitionProvider.js +3 -1
- package/dist/languageService/definitionProvider.js.map +1 -1
- package/dist/languageService/documentSymbolCollector.js +19 -19
- package/dist/languageService/documentSymbolCollector.js.map +1 -1
- package/dist/languageService/hoverProvider.js +25 -24
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/importSorter.js +8 -8
- package/dist/languageService/importSorter.js.map +1 -1
- package/dist/languageService/referencesProvider.js +8 -8
- package/dist/languageService/referencesProvider.js.map +1 -1
- package/dist/languageService/signatureHelpProvider.d.ts +1 -1
- package/dist/languageService/signatureHelpProvider.js +6 -6
- package/dist/languageService/signatureHelpProvider.js.map +1 -1
- package/dist/languageService/symbolIndexer.js +3 -3
- package/dist/languageService/symbolIndexer.js.map +1 -1
- package/dist/languageService/tooltipUtils.js +13 -13
- package/dist/languageService/tooltipUtils.js.map +1 -1
- package/dist/parser/parseNodes.d.ts +468 -401
- package/dist/parser/parseNodes.js +626 -355
- package/dist/parser/parseNodes.js.map +1 -1
- package/dist/parser/parser.d.ts +1 -0
- package/dist/parser/parser.js +316 -294
- package/dist/parser/parser.js.map +1 -1
- package/dist/tests/classDeclaration.test.js +14 -14
- package/dist/tests/classDeclaration.test.js.map +1 -1
- package/dist/tests/harness/vfs/filesystem.d.ts +3 -2
- package/dist/tests/harness/vfs/filesystem.js +6 -2
- package/dist/tests/harness/vfs/filesystem.js.map +1 -1
- package/dist/tests/importResolver.test.js +4 -3
- package/dist/tests/importResolver.test.js.map +1 -1
- package/dist/tests/parseTreeUtils.test.js +5 -5
- package/dist/tests/parseTreeUtils.test.js.map +1 -1
- package/dist/tests/parser.test.js +8 -8
- package/dist/tests/parser.test.js.map +1 -1
- package/dist/tests/sourceMapperUtils.test.js +7 -7
- package/dist/tests/sourceMapperUtils.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +8 -3
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typePrinter.test.js +14 -39
- package/dist/tests/typePrinter.test.js.map +1 -1
- package/package.json +1 -1
@@ -56,34 +56,24 @@ function synthesizeDataClassMethods(evaluator, node, classType, isNamedTuple, sk
|
|
56
56
|
(0, debug_1.assert)(types_1.ClassType.isDataClass(classType) || isNamedTuple);
|
57
57
|
const classTypeVar = (0, typeUtils_1.synthesizeTypeVarForSelfCls)(classType, /* isClsParam */ true);
|
58
58
|
const newType = types_1.FunctionType.createSynthesizedInstance('__new__', 1 /* FunctionTypeFlags.ConstructorMethod */);
|
59
|
-
newType.
|
59
|
+
newType.priv.constructorTypeVarScopeId = (0, typeUtils_1.getTypeVarScopeId)(classType);
|
60
60
|
const initType = types_1.FunctionType.createSynthesizedInstance('__init__');
|
61
|
-
initType.
|
61
|
+
initType.priv.constructorTypeVarScopeId = (0, typeUtils_1.getTypeVarScopeId)(classType);
|
62
62
|
// Generate both a __new__ and an __init__ method. The parameters of the
|
63
63
|
// __new__ method are based on field definitions for NamedTuple classes,
|
64
64
|
// and the parameters of the __init__ method are based on field definitions
|
65
65
|
// in other cases.
|
66
|
-
types_1.FunctionType.addParameter(newType,
|
67
|
-
category: 0 /* ParameterCategory.Simple */,
|
68
|
-
name: 'cls',
|
69
|
-
type: classTypeVar,
|
70
|
-
hasDeclaredType: true,
|
71
|
-
});
|
66
|
+
types_1.FunctionType.addParameter(newType, types_1.FunctionParam.create(0 /* ParameterCategory.Simple */, classTypeVar, types_1.FunctionParamFlags.TypeDeclared, 'cls'));
|
72
67
|
if (!isNamedTuple) {
|
73
68
|
types_1.FunctionType.addDefaultParameters(newType);
|
74
69
|
}
|
75
|
-
newType.
|
76
|
-
const selfParam =
|
77
|
-
category: 0 /* ParameterCategory.Simple */,
|
78
|
-
name: 'self',
|
79
|
-
type: (0, typeUtils_1.synthesizeTypeVarForSelfCls)(classType, /* isClsParam */ false),
|
80
|
-
hasDeclaredType: true,
|
81
|
-
};
|
70
|
+
newType.shared.declaredReturnType = (0, typeUtils_1.convertToInstance)(classTypeVar);
|
71
|
+
const selfParam = types_1.FunctionParam.create(0 /* ParameterCategory.Simple */, (0, typeUtils_1.synthesizeTypeVarForSelfCls)(classType, /* isClsParam */ false), types_1.FunctionParamFlags.TypeDeclared, 'self');
|
82
72
|
types_1.FunctionType.addParameter(initType, selfParam);
|
83
73
|
if (isNamedTuple) {
|
84
74
|
types_1.FunctionType.addDefaultParameters(initType);
|
85
75
|
}
|
86
|
-
initType.
|
76
|
+
initType.shared.declaredReturnType = evaluator.getNoneType();
|
87
77
|
// Maintain a list of all dataclass entries (including
|
88
78
|
// those from inherited classes) plus a list of only those
|
89
79
|
// entries added by this class.
|
@@ -144,70 +134,65 @@ function synthesizeDataClassMethods(evaluator, node, classType, isNamedTuple, sk
|
|
144
134
|
let variableTypeEvaluator;
|
145
135
|
let hasDefaultValue = false;
|
146
136
|
let isKeywordOnly = types_1.ClassType.isDataClassKeywordOnly(classType) || sawKeywordOnlySeparator;
|
147
|
-
let defaultValueExpression;
|
148
137
|
let includeInInit = true;
|
149
138
|
let converter;
|
150
139
|
if (statement.nodeType === 3 /* ParseNodeType.Assignment */) {
|
151
|
-
if (statement.
|
152
|
-
statement.
|
153
|
-
variableNameNode = statement.
|
140
|
+
if (statement.d.leftExpr.nodeType === 54 /* ParseNodeType.TypeAnnotation */ &&
|
141
|
+
statement.d.leftExpr.d.valueExpr.nodeType === 38 /* ParseNodeType.Name */) {
|
142
|
+
variableNameNode = statement.d.leftExpr.d.valueExpr;
|
154
143
|
const assignmentStatement = statement;
|
155
|
-
variableTypeEvaluator = () => evaluator.getTypeOfAnnotation(assignmentStatement.
|
144
|
+
variableTypeEvaluator = () => evaluator.getTypeOfAnnotation(assignmentStatement.d.leftExpr.d.annotation, {
|
156
145
|
isVariableAnnotation: true,
|
157
146
|
allowFinal: true,
|
158
147
|
allowClassVar: true,
|
159
148
|
});
|
160
149
|
}
|
161
150
|
hasDefaultValue = true;
|
162
|
-
defaultValueExpression = statement.rightExpression;
|
163
151
|
// If the RHS of the assignment is assigning a field instance where the
|
164
152
|
// "init" parameter is set to false, do not include it in the init method.
|
165
|
-
if (statement.
|
166
|
-
const callTypeResult = evaluator.getTypeOfExpression(statement.
|
153
|
+
if (statement.d.rightExpr.nodeType === 9 /* ParseNodeType.Call */) {
|
154
|
+
const callTypeResult = evaluator.getTypeOfExpression(statement.d.rightExpr.d.leftExpr, 2 /* EvalFlags.CallBaseDefaults */);
|
167
155
|
const callType = callTypeResult.type;
|
168
156
|
if (!isNamedTuple &&
|
169
|
-
isDataclassFieldConstructor(callType, ((_b = classType.
|
170
|
-
const initArg = statement.
|
171
|
-
if (initArg && initArg.
|
157
|
+
isDataclassFieldConstructor(callType, ((_b = classType.shared.dataClassBehaviors) === null || _b === void 0 ? void 0 : _b.fieldDescriptorNames) || [])) {
|
158
|
+
const initArg = statement.d.rightExpr.d.args.find((arg) => { var _a; return ((_a = arg.d.name) === null || _a === void 0 ? void 0 : _a.d.value) === 'init'; });
|
159
|
+
if (initArg && initArg.d.valueExpr) {
|
172
160
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
173
161
|
includeInInit =
|
174
|
-
(_c = (0, staticExpressions_1.evaluateStaticBoolExpression)(initArg.
|
162
|
+
(_c = (0, staticExpressions_1.evaluateStaticBoolExpression)(initArg.d.valueExpr, fileInfo.executionEnvironment, fileInfo.definedConstants)) !== null && _c !== void 0 ? _c : includeInInit;
|
175
163
|
}
|
176
164
|
else {
|
177
165
|
includeInInit =
|
178
|
-
(_d = getDefaultArgValueForFieldSpecifier(evaluator, statement.
|
166
|
+
(_d = getDefaultArgValueForFieldSpecifier(evaluator, statement.d.rightExpr, callTypeResult, 'init')) !== null && _d !== void 0 ? _d : includeInInit;
|
179
167
|
}
|
180
|
-
const kwOnlyArg = statement.
|
181
|
-
if (kwOnlyArg && kwOnlyArg.
|
168
|
+
const kwOnlyArg = statement.d.rightExpr.d.args.find((arg) => { var _a; return ((_a = arg.d.name) === null || _a === void 0 ? void 0 : _a.d.value) === 'kw_only'; });
|
169
|
+
if (kwOnlyArg && kwOnlyArg.d.valueExpr) {
|
182
170
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
183
171
|
isKeywordOnly =
|
184
|
-
(_e = (0, staticExpressions_1.evaluateStaticBoolExpression)(kwOnlyArg.
|
172
|
+
(_e = (0, staticExpressions_1.evaluateStaticBoolExpression)(kwOnlyArg.d.valueExpr, fileInfo.executionEnvironment, fileInfo.definedConstants)) !== null && _e !== void 0 ? _e : isKeywordOnly;
|
185
173
|
}
|
186
174
|
else {
|
187
175
|
isKeywordOnly =
|
188
|
-
(_f = getDefaultArgValueForFieldSpecifier(evaluator, statement.
|
176
|
+
(_f = getDefaultArgValueForFieldSpecifier(evaluator, statement.d.rightExpr, callTypeResult, 'kw_only')) !== null && _f !== void 0 ? _f : isKeywordOnly;
|
189
177
|
}
|
190
|
-
const defaultArg = statement.
|
178
|
+
const defaultArg = statement.d.rightExpr.d.args.find((arg) => {
|
191
179
|
var _a, _b, _c;
|
192
|
-
return ((_a = arg.name) === null || _a === void 0 ? void 0 : _a.value) === 'default' ||
|
193
|
-
((_b = arg.name) === null || _b === void 0 ? void 0 : _b.value) === 'default_factory' ||
|
194
|
-
((_c = arg.name) === null || _c === void 0 ? void 0 : _c.value) === 'factory';
|
180
|
+
return ((_a = arg.d.name) === null || _a === void 0 ? void 0 : _a.d.value) === 'default' ||
|
181
|
+
((_b = arg.d.name) === null || _b === void 0 ? void 0 : _b.d.value) === 'default_factory' ||
|
182
|
+
((_c = arg.d.name) === null || _c === void 0 ? void 0 : _c.d.value) === 'factory';
|
195
183
|
});
|
196
184
|
hasDefaultValue = !!defaultArg;
|
197
|
-
|
198
|
-
defaultValueExpression = defaultArg.valueExpression;
|
199
|
-
}
|
200
|
-
const aliasArg = statement.rightExpression.arguments.find((arg) => { var _a; return ((_a = arg.name) === null || _a === void 0 ? void 0 : _a.value) === 'alias'; });
|
185
|
+
const aliasArg = statement.d.rightExpr.d.args.find((arg) => { var _a; return ((_a = arg.d.name) === null || _a === void 0 ? void 0 : _a.d.value) === 'alias'; });
|
201
186
|
if (aliasArg) {
|
202
|
-
const valueType = evaluator.getTypeOfExpression(aliasArg.
|
187
|
+
const valueType = evaluator.getTypeOfExpression(aliasArg.d.valueExpr).type;
|
203
188
|
if ((0, types_1.isClassInstance)(valueType) &&
|
204
189
|
types_1.ClassType.isBuiltIn(valueType, 'str') &&
|
205
190
|
(0, typeUtils_1.isLiteralType)(valueType)) {
|
206
|
-
aliasName = valueType.literalValue;
|
191
|
+
aliasName = valueType.priv.literalValue;
|
207
192
|
}
|
208
193
|
}
|
209
|
-
const converterArg = statement.
|
210
|
-
if (converterArg && converterArg.
|
194
|
+
const converterArg = statement.d.rightExpr.d.args.find((arg) => { var _a; return ((_a = arg.d.name) === null || _a === void 0 ? void 0 : _a.d.value) === 'converter'; });
|
195
|
+
if (converterArg && converterArg.d.valueExpr) {
|
211
196
|
// Converter support is dependent on PEP 712, which has not yet been approved.
|
212
197
|
if (AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.enableExperimentalFeatures) {
|
213
198
|
converter = converterArg;
|
@@ -217,16 +202,16 @@ function synthesizeDataClassMethods(evaluator, node, classType, isNamedTuple, sk
|
|
217
202
|
}
|
218
203
|
}
|
219
204
|
else if (statement.nodeType === 54 /* ParseNodeType.TypeAnnotation */) {
|
220
|
-
if (statement.
|
221
|
-
variableNameNode = statement.
|
205
|
+
if (statement.d.valueExpr.nodeType === 38 /* ParseNodeType.Name */) {
|
206
|
+
variableNameNode = statement.d.valueExpr;
|
222
207
|
const annotationStatement = statement;
|
223
|
-
variableTypeEvaluator = () => evaluator.getTypeOfAnnotation(annotationStatement.
|
208
|
+
variableTypeEvaluator = () => evaluator.getTypeOfAnnotation(annotationStatement.d.annotation, {
|
224
209
|
isVariableAnnotation: true,
|
225
210
|
allowFinal: true,
|
226
211
|
allowClassVar: true,
|
227
212
|
});
|
228
213
|
// Is this a KW_ONLY separator introduced in Python 3.10?
|
229
|
-
if (!isNamedTuple && statement.
|
214
|
+
if (!isNamedTuple && statement.d.valueExpr.d.value === '_') {
|
230
215
|
const annotatedType = variableTypeEvaluator();
|
231
216
|
if ((0, types_1.isClassInstance)(annotatedType) && types_1.ClassType.isBuiltIn(annotatedType, 'KW_ONLY')) {
|
232
217
|
sawKeywordOnlySeparator = true;
|
@@ -237,7 +222,7 @@ function synthesizeDataClassMethods(evaluator, node, classType, isNamedTuple, sk
|
|
237
222
|
}
|
238
223
|
}
|
239
224
|
if (variableNameNode && variableTypeEvaluator) {
|
240
|
-
const variableName = variableNameNode.value;
|
225
|
+
const variableName = variableNameNode.d.value;
|
241
226
|
// Don't include class vars. PEP 557 indicates that they shouldn't
|
242
227
|
// be considered data class entries.
|
243
228
|
const variableSymbol = types_1.ClassType.getSymbolTable(classType).get(variableName);
|
@@ -256,7 +241,6 @@ function synthesizeDataClassMethods(evaluator, node, classType, isNamedTuple, sk
|
|
256
241
|
alias: aliasName,
|
257
242
|
isKeywordOnly: false,
|
258
243
|
hasDefault: hasDefaultValue,
|
259
|
-
defaultValueExpression,
|
260
244
|
includeInInit,
|
261
245
|
nameNode: variableNameNode,
|
262
246
|
type: types_1.UnknownType.create(),
|
@@ -275,7 +259,6 @@ function synthesizeDataClassMethods(evaluator, node, classType, isNamedTuple, sk
|
|
275
259
|
alias: aliasName,
|
276
260
|
isKeywordOnly,
|
277
261
|
hasDefault: hasDefaultValue,
|
278
|
-
defaultValueExpression,
|
279
262
|
includeInInit,
|
280
263
|
nameNode: variableNameNode,
|
281
264
|
type: types_1.UnknownType.create(),
|
@@ -299,7 +282,6 @@ function synthesizeDataClassMethods(evaluator, node, classType, isNamedTuple, sk
|
|
299
282
|
// causes overridden variables to "inherit" default values from parent classes.
|
300
283
|
if (!dataClassEntry.hasDefault && oldEntry.hasDefault && oldEntry.includeInInit) {
|
301
284
|
dataClassEntry.hasDefault = true;
|
302
|
-
dataClassEntry.defaultValueExpression = oldEntry.defaultValueExpression;
|
303
285
|
hasDefaultValue = true;
|
304
286
|
// Warn the user of this case because it can result in type errors if the
|
305
287
|
// default value is incompatible with the new type.
|
@@ -340,16 +322,16 @@ function synthesizeDataClassMethods(evaluator, node, classType, isNamedTuple, sk
|
|
340
322
|
}
|
341
323
|
// If the RHS of the assignment is assigning a field instance where the
|
342
324
|
// "init" parameter is set to false, do not include it in the init method.
|
343
|
-
if (statement.
|
344
|
-
const callType = evaluator.getTypeOfExpression(statement.
|
345
|
-
if (isDataclassFieldConstructor(callType, ((_g = classType.
|
346
|
-
evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.dataClassFieldWithoutAnnotation(), statement.
|
325
|
+
if (statement.d.rightExpr.nodeType === 9 /* ParseNodeType.Call */) {
|
326
|
+
const callType = evaluator.getTypeOfExpression(statement.d.rightExpr.d.leftExpr, 2 /* EvalFlags.CallBaseDefaults */).type;
|
327
|
+
if (isDataclassFieldConstructor(callType, ((_g = classType.shared.dataClassBehaviors) === null || _g === void 0 ? void 0 : _g.fieldDescriptorNames) || [])) {
|
328
|
+
evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.dataClassFieldWithoutAnnotation(), statement.d.rightExpr);
|
347
329
|
}
|
348
330
|
}
|
349
331
|
}
|
350
332
|
});
|
351
333
|
if (!isNamedTuple) {
|
352
|
-
classType.
|
334
|
+
classType.shared.dataClassEntries = localDataClassEntries;
|
353
335
|
}
|
354
336
|
// Now that the dataClassEntries field has been set with a complete list
|
355
337
|
// of local data class entries for this class, perform deferred type
|
@@ -382,17 +364,10 @@ function synthesizeDataClassMethods(evaluator, node, classType, isNamedTuple, sk
|
|
382
364
|
symbolTable.set(entry.name, getDescriptorForConverterField(evaluator, node, entry.converter, entry.name, fieldType, effectiveType));
|
383
365
|
}
|
384
366
|
const effectiveName = entry.alias || entry.name;
|
385
|
-
if (!entry.alias && entry.nameNode && (0, symbolNameUtils_1.isPrivateName)(entry.nameNode.value)) {
|
367
|
+
if (!entry.alias && entry.nameNode && (0, symbolNameUtils_1.isPrivateName)(entry.nameNode.d.value)) {
|
386
368
|
evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.dataClassFieldWithPrivateName(), entry.nameNode);
|
387
369
|
}
|
388
|
-
const functionParam =
|
389
|
-
category: 0 /* ParameterCategory.Simple */,
|
390
|
-
name: effectiveName,
|
391
|
-
hasDefault: entry.hasDefault,
|
392
|
-
defaultValueExpression: entry.defaultValueExpression,
|
393
|
-
type: effectiveType,
|
394
|
-
hasDeclaredType: true,
|
395
|
-
};
|
370
|
+
const functionParam = types_1.FunctionParam.create(0 /* ParameterCategory.Simple */, effectiveType, types_1.FunctionParamFlags.TypeDeclared, effectiveName, entry.hasDefault ? entry.type : undefined);
|
396
371
|
if (entry.isKeywordOnly) {
|
397
372
|
keywordOnlyParams.push(functionParam);
|
398
373
|
}
|
@@ -435,13 +410,8 @@ function synthesizeDataClassMethods(evaluator, node, classType, isNamedTuple, sk
|
|
435
410
|
const synthesizeComparisonMethod = (operator, paramType) => {
|
436
411
|
const operatorMethod = types_1.FunctionType.createSynthesizedInstance(operator);
|
437
412
|
types_1.FunctionType.addParameter(operatorMethod, selfParam);
|
438
|
-
types_1.FunctionType.addParameter(operatorMethod,
|
439
|
-
|
440
|
-
name: 'other',
|
441
|
-
type: paramType,
|
442
|
-
hasDeclaredType: true,
|
443
|
-
});
|
444
|
-
operatorMethod.details.declaredReturnType = evaluator.getBuiltInObject(node, 'bool');
|
413
|
+
types_1.FunctionType.addParameter(operatorMethod, types_1.FunctionParam.create(0 /* ParameterCategory.Simple */, paramType, types_1.FunctionParamFlags.TypeDeclared, 'other'));
|
414
|
+
operatorMethod.shared.declaredReturnType = evaluator.getBuiltInObject(node, 'bool');
|
445
415
|
// If a method of this name already exists, don't override it.
|
446
416
|
if (!symbolTable.get(operator)) {
|
447
417
|
symbolTable.set(operator, symbol_1.Symbol.createWithType(4 /* SymbolFlags.ClassMember */, operatorMethod));
|
@@ -470,7 +440,7 @@ function synthesizeDataClassMethods(evaluator, node, classType, isNamedTuple, sk
|
|
470
440
|
if (synthesizeHashFunction) {
|
471
441
|
const hashMethod = types_1.FunctionType.createSynthesizedInstance('__hash__');
|
472
442
|
types_1.FunctionType.addParameter(hashMethod, selfParam);
|
473
|
-
hashMethod.
|
443
|
+
hashMethod.shared.declaredReturnType = evaluator.getBuiltInObject(node, 'int');
|
474
444
|
symbolTable.set('__hash__', symbol_1.Symbol.createWithType(4 /* SymbolFlags.ClassMember */ | 4096 /* SymbolFlags.IgnoredForOverrideChecks */, hashMethod));
|
475
445
|
}
|
476
446
|
else if (synthesizeHashNone && !skipSynthesizeHash) {
|
@@ -484,8 +454,8 @@ function synthesizeDataClassMethods(evaluator, node, classType, isNamedTuple, sk
|
|
484
454
|
if (!isNamedTuple) {
|
485
455
|
symbolTable.set('__dataclass_fields__', symbol_1.Symbol.createWithType(4 /* SymbolFlags.ClassMember */ | 128 /* SymbolFlags.ClassVar */, dictType));
|
486
456
|
}
|
487
|
-
if (types_1.ClassType.isDataClassGenerateSlots(classType) && classType.
|
488
|
-
classType.
|
457
|
+
if (types_1.ClassType.isDataClassGenerateSlots(classType) && classType.shared.localSlotsNames === undefined) {
|
458
|
+
classType.shared.localSlotsNames = localDataClassEntries.map((entry) => entry.name);
|
489
459
|
}
|
490
460
|
// Should we synthesize a __slots__ symbol?
|
491
461
|
if (types_1.ClassType.isDataClassGenerateSlots(classType)) {
|
@@ -516,7 +486,7 @@ function getDefaultArgValueForFieldSpecifier(evaluator, callNode, callTypeResult
|
|
516
486
|
callTarget = callType;
|
517
487
|
}
|
518
488
|
else if ((0, types_1.isOverloadedFunction)(callType)) {
|
519
|
-
callTarget = evaluator.getBestOverloadForArguments(callNode, { type: callType, isIncomplete: callTypeResult.isIncomplete }, callNode.
|
489
|
+
callTarget = evaluator.getBestOverloadForArguments(callNode, { type: callType, isIncomplete: callTypeResult.isIncomplete }, callNode.d.args.map((arg) => (0, typeUtils_1.convertArgumentNodeToFunctionArgument)(arg)));
|
520
490
|
}
|
521
491
|
else if ((0, types_1.isInstantiableClass)(callType)) {
|
522
492
|
const initMethodResult = (0, constructors_1.getBoundInitMethod)(evaluator, callNode, callType);
|
@@ -525,25 +495,24 @@ function getDefaultArgValueForFieldSpecifier(evaluator, callNode, callTypeResult
|
|
525
495
|
callTarget = initMethodResult.type;
|
526
496
|
}
|
527
497
|
else if ((0, types_1.isOverloadedFunction)(initMethodResult.type)) {
|
528
|
-
callTarget = evaluator.getBestOverloadForArguments(callNode, { type: initMethodResult.type }, callNode.
|
498
|
+
callTarget = evaluator.getBestOverloadForArguments(callNode, { type: initMethodResult.type }, callNode.d.args.map((arg) => (0, typeUtils_1.convertArgumentNodeToFunctionArgument)(arg)));
|
529
499
|
}
|
530
500
|
}
|
531
501
|
}
|
532
502
|
if (callTarget) {
|
533
|
-
const initParam = callTarget.
|
503
|
+
const initParam = callTarget.shared.parameters.find((p) => p.name === paramName);
|
534
504
|
if (initParam) {
|
535
505
|
// Is the parameter type a literal bool?
|
536
|
-
if (initParam
|
506
|
+
if (types_1.FunctionParam.isTypeDeclared(initParam) &&
|
537
507
|
(0, types_1.isClass)(initParam.type) &&
|
538
|
-
typeof initParam.type.literalValue === 'boolean') {
|
539
|
-
return initParam.type.literalValue;
|
508
|
+
typeof initParam.type.priv.literalValue === 'boolean') {
|
509
|
+
return initParam.type.priv.literalValue;
|
540
510
|
}
|
541
511
|
// Is the default argument value a literal bool?
|
542
|
-
if (initParam.
|
543
|
-
initParam.defaultType &&
|
512
|
+
if (initParam.defaultType &&
|
544
513
|
(0, types_1.isClass)(initParam.defaultType) &&
|
545
|
-
typeof initParam.defaultType.literalValue === 'boolean') {
|
546
|
-
return initParam.defaultType.literalValue;
|
514
|
+
typeof initParam.defaultType.priv.literalValue === 'boolean') {
|
515
|
+
return initParam.defaultType.priv.literalValue;
|
547
516
|
}
|
548
517
|
}
|
549
518
|
}
|
@@ -553,23 +522,18 @@ function getDefaultArgValueForFieldSpecifier(evaluator, callNode, callTypeResult
|
|
553
522
|
// fieldType is returned.
|
554
523
|
function getConverterInputType(evaluator, converterNode, fieldType, fieldName) {
|
555
524
|
var _a;
|
556
|
-
const converterType = getConverterAsFunction(evaluator, evaluator.getTypeOfExpression(converterNode.
|
525
|
+
const converterType = getConverterAsFunction(evaluator, evaluator.getTypeOfExpression(converterNode.d.valueExpr).type);
|
557
526
|
if (!converterType) {
|
558
527
|
return fieldType;
|
559
528
|
}
|
560
529
|
// Create synthesized function of the form Callable[[T], fieldType] which
|
561
530
|
// will be used to check compatibility of the provided converter.
|
562
531
|
const typeVar = types_1.TypeVarType.createInstance('__converterInput');
|
563
|
-
typeVar.scopeId = (0, parseTreeUtils_1.getScopeIdForNode)(converterNode);
|
532
|
+
typeVar.priv.scopeId = (0, parseTreeUtils_1.getScopeIdForNode)(converterNode);
|
564
533
|
const targetFunction = types_1.FunctionType.createSynthesizedInstance('');
|
565
|
-
targetFunction.
|
566
|
-
targetFunction.
|
567
|
-
types_1.FunctionType.addParameter(targetFunction,
|
568
|
-
category: 0 /* ParameterCategory.Simple */,
|
569
|
-
name: '__input',
|
570
|
-
type: typeVar,
|
571
|
-
hasDeclaredType: true,
|
572
|
-
});
|
534
|
+
targetFunction.shared.typeVarScopeId = typeVar.priv.scopeId;
|
535
|
+
targetFunction.shared.declaredReturnType = fieldType;
|
536
|
+
types_1.FunctionType.addParameter(targetFunction, types_1.FunctionParam.create(0 /* ParameterCategory.Simple */, typeVar, types_1.FunctionParamFlags.TypeDeclared | types_1.FunctionParamFlags.NameSynthesized, '__input'));
|
573
537
|
types_1.FunctionType.addPositionOnlyParameterSeparator(targetFunction);
|
574
538
|
if ((0, types_1.isFunction)(converterType) || (0, types_1.isOverloadedFunction)(converterType)) {
|
575
539
|
const acceptedTypes = [];
|
@@ -581,7 +545,7 @@ function getConverterInputType(evaluator, converterNode, fieldType, fieldName) {
|
|
581
545
|
/* diag */ undefined, returnTypeVarContext)) {
|
582
546
|
signature = (0, typeUtils_1.applySolvedTypeVars)(signature, returnTypeVarContext);
|
583
547
|
}
|
584
|
-
const inputTypeVarContext = new typeVarContext_1.TypeVarContext(typeVar.scopeId);
|
548
|
+
const inputTypeVarContext = new typeVarContext_1.TypeVarContext(typeVar.priv.scopeId);
|
585
549
|
if (evaluator.assignType(targetFunction, signature, diagAddendum, inputTypeVarContext)) {
|
586
550
|
const overloadSolution = (0, typeUtils_1.applySolvedTypeVars)(typeVar, inputTypeVarContext, {
|
587
551
|
unknownIfNotFound: true,
|
@@ -602,7 +566,7 @@ function getConverterInputType(evaluator, converterNode, fieldType, fieldName) {
|
|
602
566
|
}
|
603
567
|
else {
|
604
568
|
evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.dataClassConverterOverloads().format({
|
605
|
-
funcName: converterType.overloads[0].
|
569
|
+
funcName: converterType.priv.overloads[0].shared.name || '<anonymous function>',
|
606
570
|
fieldType: evaluator.printType(fieldType),
|
607
571
|
fieldName: fieldName,
|
608
572
|
}) + diagAddendum.getString(), converterNode);
|
@@ -624,7 +588,7 @@ function getConverterAsFunction(evaluator, converterType) {
|
|
624
588
|
// choose the first of the two subtypes, which typically corresponds
|
625
589
|
// to the __init__ method (rather than the __new__ method).
|
626
590
|
if ((0, types_1.isUnion)(fromConstructor)) {
|
627
|
-
fromConstructor = fromConstructor.subtypes[0];
|
591
|
+
fromConstructor = fromConstructor.priv.subtypes[0];
|
628
592
|
}
|
629
593
|
if ((0, types_1.isFunction)(fromConstructor) || (0, types_1.isOverloadedFunction)(fromConstructor)) {
|
630
594
|
return fromConstructor;
|
@@ -644,52 +608,22 @@ function getDescriptorForConverterField(evaluator, dataclassNode, converterNode,
|
|
644
608
|
const descriptorName = `__converterDescriptor_${fieldName}`;
|
645
609
|
const descriptorClass = types_1.ClassType.createInstantiable(descriptorName, (0, parseTreeUtils_1.getClassFullName)(converterNode, fileInfo.moduleName, descriptorName), fileInfo.moduleName, fileInfo.fileUri, 0 /* ClassTypeFlags.None */, (0, parseTreeUtils_1.getTypeSourceId)(converterNode),
|
646
610
|
/* declaredMetaclass */ undefined, (0, types_1.isInstantiableClass)(typeMetaclass) ? typeMetaclass : types_1.UnknownType.create());
|
647
|
-
descriptorClass.
|
611
|
+
descriptorClass.shared.baseClasses.push(evaluator.getBuiltInType(dataclassNode, 'object'));
|
648
612
|
(0, typeUtils_1.computeMroLinearization)(descriptorClass);
|
649
613
|
const fields = types_1.ClassType.getSymbolTable(descriptorClass);
|
650
614
|
const selfType = (0, typeUtils_1.synthesizeTypeVarForSelfCls)(descriptorClass, /* isClsParam */ false);
|
651
615
|
const setFunction = types_1.FunctionType.createSynthesizedInstance('__set__');
|
652
|
-
types_1.FunctionType.addParameter(setFunction,
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
hasDeclaredType: true,
|
657
|
-
});
|
658
|
-
types_1.FunctionType.addParameter(setFunction, {
|
659
|
-
category: 0 /* ParameterCategory.Simple */,
|
660
|
-
name: 'obj',
|
661
|
-
type: types_1.AnyType.create(),
|
662
|
-
hasDeclaredType: true,
|
663
|
-
});
|
664
|
-
types_1.FunctionType.addParameter(setFunction, {
|
665
|
-
category: 0 /* ParameterCategory.Simple */,
|
666
|
-
name: 'value',
|
667
|
-
type: setType,
|
668
|
-
hasDeclaredType: true,
|
669
|
-
});
|
670
|
-
setFunction.details.declaredReturnType = evaluator.getNoneType();
|
616
|
+
types_1.FunctionType.addParameter(setFunction, types_1.FunctionParam.create(0 /* ParameterCategory.Simple */, selfType, types_1.FunctionParamFlags.TypeDeclared, 'self'));
|
617
|
+
types_1.FunctionType.addParameter(setFunction, types_1.FunctionParam.create(0 /* ParameterCategory.Simple */, types_1.AnyType.create(), types_1.FunctionParamFlags.TypeDeclared, 'obj'));
|
618
|
+
types_1.FunctionType.addParameter(setFunction, types_1.FunctionParam.create(0 /* ParameterCategory.Simple */, setType, types_1.FunctionParamFlags.TypeDeclared, 'value'));
|
619
|
+
setFunction.shared.declaredReturnType = evaluator.getNoneType();
|
671
620
|
const setSymbol = symbol_1.Symbol.createWithType(4 /* SymbolFlags.ClassMember */, setFunction);
|
672
621
|
fields.set('__set__', setSymbol);
|
673
622
|
const getFunction = types_1.FunctionType.createSynthesizedInstance('__get__');
|
674
|
-
types_1.FunctionType.addParameter(getFunction,
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
hasDeclaredType: true,
|
679
|
-
});
|
680
|
-
types_1.FunctionType.addParameter(getFunction, {
|
681
|
-
category: 0 /* ParameterCategory.Simple */,
|
682
|
-
name: 'obj',
|
683
|
-
type: types_1.AnyType.create(),
|
684
|
-
hasDeclaredType: true,
|
685
|
-
});
|
686
|
-
types_1.FunctionType.addParameter(getFunction, {
|
687
|
-
category: 0 /* ParameterCategory.Simple */,
|
688
|
-
name: 'objtype',
|
689
|
-
type: types_1.AnyType.create(),
|
690
|
-
hasDeclaredType: true,
|
691
|
-
});
|
692
|
-
getFunction.details.declaredReturnType = getType;
|
623
|
+
types_1.FunctionType.addParameter(getFunction, types_1.FunctionParam.create(0 /* ParameterCategory.Simple */, selfType, types_1.FunctionParamFlags.TypeDeclared, 'self'));
|
624
|
+
types_1.FunctionType.addParameter(getFunction, types_1.FunctionParam.create(0 /* ParameterCategory.Simple */, types_1.AnyType.create(), types_1.FunctionParamFlags.TypeDeclared, 'obj'));
|
625
|
+
types_1.FunctionType.addParameter(getFunction, types_1.FunctionParam.create(0 /* ParameterCategory.Simple */, types_1.AnyType.create(), types_1.FunctionParamFlags.TypeDeclared, 'objtype'));
|
626
|
+
getFunction.shared.declaredReturnType = getType;
|
693
627
|
const getSymbol = symbol_1.Symbol.createWithType(4 /* SymbolFlags.ClassMember */, getFunction);
|
694
628
|
fields.set('__get__', getSymbol);
|
695
629
|
return symbol_1.Symbol.createWithType(4 /* SymbolFlags.ClassMember */, types_1.ClassType.cloneAsInstance(descriptorClass));
|
@@ -754,13 +688,13 @@ exports.addInheritedDataClassEntries = addInheritedDataClassEntries;
|
|
754
688
|
function isDataclassFieldConstructor(type, fieldDescriptorNames) {
|
755
689
|
let callName;
|
756
690
|
if ((0, types_1.isFunction)(type)) {
|
757
|
-
callName = type.
|
691
|
+
callName = type.shared.fullName;
|
758
692
|
}
|
759
693
|
else if ((0, types_1.isOverloadedFunction)(type)) {
|
760
|
-
callName = type.overloads[0].
|
694
|
+
callName = type.priv.overloads[0].shared.fullName;
|
761
695
|
}
|
762
696
|
else if ((0, types_1.isInstantiableClass)(type)) {
|
763
|
-
callName = type.
|
697
|
+
callName = type.shared.fullName;
|
764
698
|
}
|
765
699
|
if (!callName) {
|
766
700
|
return false;
|
@@ -781,43 +715,43 @@ function validateDataClassTransformDecorator(evaluator, node) {
|
|
781
715
|
};
|
782
716
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
783
717
|
// Parse the arguments to the call.
|
784
|
-
node.
|
785
|
-
if (!arg.name || arg.
|
718
|
+
node.d.args.forEach((arg) => {
|
719
|
+
if (!arg.d.name || arg.d.argCategory !== 0 /* ArgumentCategory.Simple */) {
|
786
720
|
evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.dataClassTransformPositionalParam(), arg);
|
787
721
|
return;
|
788
722
|
}
|
789
|
-
switch (arg.name.value) {
|
723
|
+
switch (arg.d.name.d.value) {
|
790
724
|
case 'kw_only_default': {
|
791
|
-
const value = (0, staticExpressions_1.evaluateStaticBoolExpression)(arg.
|
725
|
+
const value = (0, staticExpressions_1.evaluateStaticBoolExpression)(arg.d.valueExpr, fileInfo.executionEnvironment, fileInfo.definedConstants);
|
792
726
|
if (value === undefined) {
|
793
|
-
evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.dataClassTransformExpectedBoolLiteral(), arg.
|
727
|
+
evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.dataClassTransformExpectedBoolLiteral(), arg.d.valueExpr);
|
794
728
|
return;
|
795
729
|
}
|
796
730
|
behaviors.keywordOnly = value;
|
797
731
|
break;
|
798
732
|
}
|
799
733
|
case 'eq_default': {
|
800
|
-
const value = (0, staticExpressions_1.evaluateStaticBoolExpression)(arg.
|
734
|
+
const value = (0, staticExpressions_1.evaluateStaticBoolExpression)(arg.d.valueExpr, fileInfo.executionEnvironment, fileInfo.definedConstants);
|
801
735
|
if (value === undefined) {
|
802
|
-
evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.dataClassTransformExpectedBoolLiteral(), arg.
|
736
|
+
evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.dataClassTransformExpectedBoolLiteral(), arg.d.valueExpr);
|
803
737
|
return;
|
804
738
|
}
|
805
739
|
behaviors.skipGenerateEq = !value;
|
806
740
|
break;
|
807
741
|
}
|
808
742
|
case 'order_default': {
|
809
|
-
const value = (0, staticExpressions_1.evaluateStaticBoolExpression)(arg.
|
743
|
+
const value = (0, staticExpressions_1.evaluateStaticBoolExpression)(arg.d.valueExpr, fileInfo.executionEnvironment, fileInfo.definedConstants);
|
810
744
|
if (value === undefined) {
|
811
|
-
evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.dataClassTransformExpectedBoolLiteral(), arg.
|
745
|
+
evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.dataClassTransformExpectedBoolLiteral(), arg.d.valueExpr);
|
812
746
|
return;
|
813
747
|
}
|
814
748
|
behaviors.generateOrder = value;
|
815
749
|
break;
|
816
750
|
}
|
817
751
|
case 'frozen_default': {
|
818
|
-
const value = (0, staticExpressions_1.evaluateStaticBoolExpression)(arg.
|
752
|
+
const value = (0, staticExpressions_1.evaluateStaticBoolExpression)(arg.d.valueExpr, fileInfo.executionEnvironment, fileInfo.definedConstants);
|
819
753
|
if (value === undefined) {
|
820
|
-
evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.dataClassTransformExpectedBoolLiteral(), arg.
|
754
|
+
evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.dataClassTransformExpectedBoolLiteral(), arg.d.valueExpr);
|
821
755
|
return;
|
822
756
|
}
|
823
757
|
behaviors.frozen = value;
|
@@ -833,30 +767,30 @@ function validateDataClassTransformDecorator(evaluator, node) {
|
|
833
767
|
// form that supported this older parameter name.
|
834
768
|
case 'field_descriptors':
|
835
769
|
case 'field_specifiers': {
|
836
|
-
const valueType = evaluator.getTypeOfExpression(arg.
|
770
|
+
const valueType = evaluator.getTypeOfExpression(arg.d.valueExpr).type;
|
837
771
|
if (!(0, types_1.isClassInstance)(valueType) ||
|
838
772
|
!types_1.ClassType.isBuiltIn(valueType, 'tuple') ||
|
839
|
-
!valueType.tupleTypeArguments ||
|
840
|
-
valueType.tupleTypeArguments.some((entry) => !(0, types_1.isInstantiableClass)(entry.type) &&
|
773
|
+
!valueType.priv.tupleTypeArguments ||
|
774
|
+
valueType.priv.tupleTypeArguments.some((entry) => !(0, types_1.isInstantiableClass)(entry.type) &&
|
841
775
|
!(0, types_1.isFunction)(entry.type) &&
|
842
776
|
!(0, types_1.isOverloadedFunction)(entry.type))) {
|
843
777
|
evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.dataClassTransformFieldSpecifier().format({
|
844
778
|
type: evaluator.printType(valueType),
|
845
|
-
}), arg.
|
779
|
+
}), arg.d.valueExpr);
|
846
780
|
return;
|
847
781
|
}
|
848
|
-
valueType.tupleTypeArguments.forEach((arg) => {
|
782
|
+
valueType.priv.tupleTypeArguments.forEach((arg) => {
|
849
783
|
if ((0, types_1.isInstantiableClass)(arg.type) || (0, types_1.isFunction)(arg.type)) {
|
850
|
-
behaviors.fieldDescriptorNames.push(arg.type.
|
784
|
+
behaviors.fieldDescriptorNames.push(arg.type.shared.fullName);
|
851
785
|
}
|
852
786
|
else if ((0, types_1.isOverloadedFunction)(arg.type)) {
|
853
|
-
behaviors.fieldDescriptorNames.push(arg.type.overloads[0].
|
787
|
+
behaviors.fieldDescriptorNames.push(arg.type.priv.overloads[0].shared.fullName);
|
854
788
|
}
|
855
789
|
});
|
856
790
|
break;
|
857
791
|
}
|
858
792
|
default:
|
859
|
-
evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.dataClassTransformUnknownArgument().format({ name: arg.name.value }), arg.
|
793
|
+
evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.dataClassTransformUnknownArgument().format({ name: arg.d.name.d.value }), arg.d.valueExpr);
|
860
794
|
break;
|
861
795
|
}
|
862
796
|
});
|
@@ -874,16 +808,16 @@ function getDataclassDecoratorBehaviors(type) {
|
|
874
808
|
// dataclass_transform decorator. If more than one have such a decorator,
|
875
809
|
// only the first one will be honored, as per PEP 681.
|
876
810
|
functionType =
|
877
|
-
(_a = type.overloads.find((overload) => !!overload.
|
811
|
+
(_a = type.priv.overloads.find((overload) => !!overload.shared.decoratorDataClassBehaviors)) !== null && _a !== void 0 ? _a : type.priv.overloads[0];
|
878
812
|
}
|
879
813
|
if (!functionType) {
|
880
814
|
return undefined;
|
881
815
|
}
|
882
|
-
if (functionType.
|
883
|
-
return functionType.
|
816
|
+
if (functionType.shared.decoratorDataClassBehaviors) {
|
817
|
+
return functionType.shared.decoratorDataClassBehaviors;
|
884
818
|
}
|
885
819
|
// Is this the built-in dataclass? If so, return the default behaviors.
|
886
|
-
if (functionType.
|
820
|
+
if (functionType.shared.fullName === 'dataclasses.dataclass') {
|
887
821
|
return {
|
888
822
|
fieldDescriptorNames: ['dataclasses.field', 'dataclasses.Field'],
|
889
823
|
};
|
@@ -914,15 +848,15 @@ function applyDataClassBehaviorOverrideValue(evaluator, errorNode, classType, ar
|
|
914
848
|
if (argValue !== undefined) {
|
915
849
|
behaviors.frozen = argValue;
|
916
850
|
}
|
917
|
-
classType.
|
851
|
+
classType.shared.baseClasses.forEach((baseClass) => {
|
918
852
|
if ((0, types_1.isInstantiableClass)(baseClass) && types_1.ClassType.isDataClass(baseClass)) {
|
919
853
|
if (types_1.ClassType.isDataClassFrozen(baseClass)) {
|
920
854
|
hasFrozenBaseClass = true;
|
921
855
|
}
|
922
|
-
else if (!baseClass.
|
923
|
-
!(baseClass.
|
924
|
-
(0, types_1.isInstantiableClass)(baseClass.
|
925
|
-
!!baseClass.
|
856
|
+
else if (!baseClass.shared.classDataClassTransform &&
|
857
|
+
!(baseClass.shared.declaredMetaclass &&
|
858
|
+
(0, types_1.isInstantiableClass)(baseClass.shared.declaredMetaclass) &&
|
859
|
+
!!baseClass.shared.declaredMetaclass.shared.classDataClassTransform)) {
|
926
860
|
// If this base class is unfrozen and isn't the class that directly
|
927
861
|
// references the metaclass that provides dataclass-like behaviors,
|
928
862
|
// we'll assume we're deriving from an unfrozen dataclass.
|
@@ -957,7 +891,7 @@ function applyDataClassBehaviorOverrideValue(evaluator, errorNode, classType, ar
|
|
957
891
|
case 'slots':
|
958
892
|
if (argValue === true) {
|
959
893
|
behaviors.generateSlots = true;
|
960
|
-
if (classType.
|
894
|
+
if (classType.shared.localSlotsNames) {
|
961
895
|
evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.dataClassSlotsOverwrite(), errorNode);
|
962
896
|
}
|
963
897
|
}
|
@@ -979,11 +913,11 @@ function applyDataClassClassBehaviorOverrides(evaluator, errorNode, classType, a
|
|
979
913
|
// The "frozen" behavior is not inherited from the parent class.
|
980
914
|
// Instead, it comes from the default.
|
981
915
|
behaviors.frozen = behaviors.frozenDefault;
|
982
|
-
classType.
|
916
|
+
classType.shared.dataClassBehaviors = behaviors;
|
983
917
|
args.forEach((arg) => {
|
984
918
|
if (arg.valueExpression && arg.name) {
|
985
|
-
applyDataClassBehaviorOverride(evaluator, arg.name, classType, arg.name.value, arg.valueExpression, behaviors);
|
986
|
-
if (arg.name.value === 'frozen') {
|
919
|
+
applyDataClassBehaviorOverride(evaluator, arg.name, classType, arg.name.d.value, arg.valueExpression, behaviors);
|
920
|
+
if (arg.name.d.value === 'frozen') {
|
987
921
|
sawFrozenArg = true;
|
988
922
|
}
|
989
923
|
}
|
@@ -998,7 +932,7 @@ function applyDataClassClassBehaviorOverrides(evaluator, errorNode, classType, a
|
|
998
932
|
exports.applyDataClassClassBehaviorOverrides = applyDataClassClassBehaviorOverrides;
|
999
933
|
function applyDataClassDecorator(evaluator, errorNode, classType, defaultBehaviors, callNode) {
|
1000
934
|
var _a;
|
1001
|
-
applyDataClassClassBehaviorOverrides(evaluator, errorNode, classType, (_a = callNode === null || callNode === void 0 ? void 0 : callNode.
|
935
|
+
applyDataClassClassBehaviorOverrides(evaluator, errorNode, classType, ((_a = callNode === null || callNode === void 0 ? void 0 : callNode.d.args) !== null && _a !== void 0 ? _a : []).map((arg) => (0, typeUtils_1.convertArgumentNodeToFunctionArgument)(arg)), defaultBehaviors);
|
1002
936
|
}
|
1003
937
|
exports.applyDataClassDecorator = applyDataClassDecorator;
|
1004
938
|
//# sourceMappingURL=dataClasses.js.map
|