@zzzen/pyright-internal 1.2.0-dev.20240630 → 1.2.0-dev.20240714
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyzer/analyzerNodeInfo.js +74 -46
- package/dist/analyzer/analyzerNodeInfo.js.map +1 -1
- package/dist/analyzer/binder.js +507 -513
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.js +652 -633
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.d.ts +5 -3
- package/dist/analyzer/codeFlowEngine.js +143 -122
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/codeFlowTypes.js +30 -28
- package/dist/analyzer/codeFlowTypes.js.map +1 -1
- package/dist/analyzer/constraintSolver.d.ts +1 -1
- package/dist/analyzer/constraintSolver.js +71 -67
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constructorTransform.js +22 -22
- package/dist/analyzer/constructorTransform.js.map +1 -1
- package/dist/analyzer/constructors.js +85 -77
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.js +113 -176
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/declaration.d.ts +1 -1
- package/dist/analyzer/declarationUtils.js +14 -15
- package/dist/analyzer/declarationUtils.js.map +1 -1
- package/dist/analyzer/decorators.js +85 -85
- package/dist/analyzer/decorators.js.map +1 -1
- package/dist/analyzer/enums.js +71 -57
- package/dist/analyzer/enums.js.map +1 -1
- package/dist/analyzer/functionTransform.js +8 -18
- package/dist/analyzer/functionTransform.js.map +1 -1
- package/dist/analyzer/importResolver.d.ts +2 -1
- package/dist/analyzer/importResolver.js +40 -29
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/importStatementUtils.js +27 -27
- package/dist/analyzer/importStatementUtils.js.map +1 -1
- package/dist/analyzer/namedTuples.js +33 -59
- package/dist/analyzer/namedTuples.js.map +1 -1
- package/dist/analyzer/operations.d.ts +4 -4
- package/dist/analyzer/operations.js +70 -70
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/packageTypeVerifier.js +66 -62
- package/dist/analyzer/packageTypeVerifier.js.map +1 -1
- package/dist/analyzer/parameterUtils.d.ts +4 -4
- package/dist/analyzer/parameterUtils.js +28 -46
- package/dist/analyzer/parameterUtils.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.js +268 -269
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/parseTreeWalker.js +76 -76
- package/dist/analyzer/parseTreeWalker.js.map +1 -1
- package/dist/analyzer/patternMatching.js +195 -147
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.js +1 -1
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/properties.js +78 -147
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/protocols.js +22 -22
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/sourceFile.d.ts +3 -2
- package/dist/analyzer/sourceFile.js +8 -8
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/sourceMapper.js +20 -19
- package/dist/analyzer/sourceMapper.js.map +1 -1
- package/dist/analyzer/staticExpressions.js +83 -84
- package/dist/analyzer/staticExpressions.js.map +1 -1
- package/dist/analyzer/testWalker.js +2 -2
- package/dist/analyzer/testWalker.js.map +1 -1
- package/dist/analyzer/tracePrinter.js +20 -20
- package/dist/analyzer/tracePrinter.js.map +1 -1
- package/dist/analyzer/typeDocStringUtils.js +25 -25
- package/dist/analyzer/typeDocStringUtils.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +2330 -2367
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +33 -31
- package/dist/analyzer/typeEvaluatorTypes.js +48 -41
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +221 -217
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.js +118 -115
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeStubWriter.js +104 -103
- package/dist/analyzer/typeStubWriter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +26 -9
- package/dist/analyzer/typeUtils.js +460 -404
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typeVarContext.js +8 -8
- package/dist/analyzer/typeVarContext.js.map +1 -1
- package/dist/analyzer/typeWalker.js +13 -10
- package/dist/analyzer/typeWalker.js.map +1 -1
- package/dist/analyzer/typedDicts.js +96 -198
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +147 -103
- package/dist/analyzer/types.js +668 -493
- package/dist/analyzer/types.js.map +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js +33 -33
- package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
- package/dist/common/diagnostic.d.ts +14 -0
- package/dist/common/diagnostic.js +41 -1
- package/dist/common/diagnostic.js.map +1 -1
- package/dist/common/diagnosticSink.d.ts +4 -0
- package/dist/common/diagnosticSink.js +21 -1
- package/dist/common/diagnosticSink.js.map +1 -1
- package/dist/common/fileSystem.d.ts +1 -0
- package/dist/common/fileSystem.js.map +1 -1
- package/dist/common/fullAccessHost.js +6 -4
- package/dist/common/fullAccessHost.js.map +1 -1
- package/dist/common/realFileSystem.d.ts +1 -0
- package/dist/common/realFileSystem.js +4 -0
- package/dist/common/realFileSystem.js.map +1 -1
- package/dist/common/textEditTracker.js +14 -14
- package/dist/common/textEditTracker.js.map +1 -1
- package/dist/languageService/autoImporter.js +10 -10
- package/dist/languageService/autoImporter.js.map +1 -1
- package/dist/languageService/callHierarchyProvider.js +23 -23
- package/dist/languageService/callHierarchyProvider.js.map +1 -1
- package/dist/languageService/completionProvider.d.ts +1 -1
- package/dist/languageService/completionProvider.js +156 -154
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/definitionProvider.d.ts +1 -1
- package/dist/languageService/definitionProvider.js +3 -1
- package/dist/languageService/definitionProvider.js.map +1 -1
- package/dist/languageService/documentSymbolCollector.js +19 -19
- package/dist/languageService/documentSymbolCollector.js.map +1 -1
- package/dist/languageService/hoverProvider.js +25 -24
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/importSorter.js +8 -8
- package/dist/languageService/importSorter.js.map +1 -1
- package/dist/languageService/referencesProvider.js +8 -8
- package/dist/languageService/referencesProvider.js.map +1 -1
- package/dist/languageService/signatureHelpProvider.d.ts +1 -1
- package/dist/languageService/signatureHelpProvider.js +6 -6
- package/dist/languageService/signatureHelpProvider.js.map +1 -1
- package/dist/languageService/symbolIndexer.js +3 -3
- package/dist/languageService/symbolIndexer.js.map +1 -1
- package/dist/languageService/tooltipUtils.js +13 -13
- package/dist/languageService/tooltipUtils.js.map +1 -1
- package/dist/localization/localize.d.ts +3 -0
- package/dist/localization/localize.js +1 -0
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.en-us.json +2 -1
- package/dist/parser/parseNodes.d.ts +468 -401
- package/dist/parser/parseNodes.js +626 -355
- package/dist/parser/parseNodes.js.map +1 -1
- package/dist/parser/parser.d.ts +1 -0
- package/dist/parser/parser.js +322 -297
- package/dist/parser/parser.js.map +1 -1
- package/dist/pyright.js +265 -5
- package/dist/pyright.js.map +1 -1
- package/dist/tests/classDeclaration.test.js +14 -14
- package/dist/tests/classDeclaration.test.js.map +1 -1
- package/dist/tests/fourslash/hover.init.fourslash.js +1 -1
- package/dist/tests/fourslash/hover.init.fourslash.js.map +1 -1
- package/dist/tests/harness/vfs/filesystem.d.ts +3 -2
- package/dist/tests/harness/vfs/filesystem.js +6 -2
- package/dist/tests/harness/vfs/filesystem.js.map +1 -1
- package/dist/tests/importResolver.test.js +4 -3
- package/dist/tests/importResolver.test.js.map +1 -1
- package/dist/tests/parseTreeUtils.test.js +5 -5
- package/dist/tests/parseTreeUtils.test.js.map +1 -1
- package/dist/tests/parser.test.js +8 -8
- package/dist/tests/parser.test.js.map +1 -1
- package/dist/tests/sourceMapperUtils.test.js +7 -7
- package/dist/tests/sourceMapperUtils.test.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +2 -2
- package/dist/tests/typeEvaluator3.test.js +10 -5
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +1 -1
- package/dist/tests/typeEvaluator7.test.js +2 -2
- package/dist/tests/typeEvaluator7.test.js.map +1 -1
- package/dist/tests/typePrinter.test.js +14 -39
- package/dist/tests/typePrinter.test.js.map +1 -1
- package/package.json +1 -1
@@ -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,9 +545,12 @@ 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
|
-
const overloadSolution = (0, typeUtils_1.applySolvedTypeVars)(typeVar, inputTypeVarContext, {
|
550
|
+
const overloadSolution = (0, typeUtils_1.applySolvedTypeVars)(typeVar, inputTypeVarContext, {
|
551
|
+
unknownIfNotFound: true,
|
552
|
+
tupleClassType: evaluator.getTupleClassType(),
|
553
|
+
});
|
587
554
|
acceptedTypes.push(overloadSolution);
|
588
555
|
}
|
589
556
|
});
|
@@ -599,7 +566,7 @@ function getConverterInputType(evaluator, converterNode, fieldType, fieldName) {
|
|
599
566
|
}
|
600
567
|
else {
|
601
568
|
evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.dataClassConverterOverloads().format({
|
602
|
-
funcName: converterType.overloads[0].
|
569
|
+
funcName: converterType.priv.overloads[0].shared.name || '<anonymous function>',
|
603
570
|
fieldType: evaluator.printType(fieldType),
|
604
571
|
fieldName: fieldName,
|
605
572
|
}) + diagAddendum.getString(), converterNode);
|
@@ -621,7 +588,7 @@ function getConverterAsFunction(evaluator, converterType) {
|
|
621
588
|
// choose the first of the two subtypes, which typically corresponds
|
622
589
|
// to the __init__ method (rather than the __new__ method).
|
623
590
|
if ((0, types_1.isUnion)(fromConstructor)) {
|
624
|
-
fromConstructor = fromConstructor.subtypes[0];
|
591
|
+
fromConstructor = fromConstructor.priv.subtypes[0];
|
625
592
|
}
|
626
593
|
if ((0, types_1.isFunction)(fromConstructor) || (0, types_1.isOverloadedFunction)(fromConstructor)) {
|
627
594
|
return fromConstructor;
|
@@ -641,52 +608,22 @@ function getDescriptorForConverterField(evaluator, dataclassNode, converterNode,
|
|
641
608
|
const descriptorName = `__converterDescriptor_${fieldName}`;
|
642
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),
|
643
610
|
/* declaredMetaclass */ undefined, (0, types_1.isInstantiableClass)(typeMetaclass) ? typeMetaclass : types_1.UnknownType.create());
|
644
|
-
descriptorClass.
|
611
|
+
descriptorClass.shared.baseClasses.push(evaluator.getBuiltInType(dataclassNode, 'object'));
|
645
612
|
(0, typeUtils_1.computeMroLinearization)(descriptorClass);
|
646
613
|
const fields = types_1.ClassType.getSymbolTable(descriptorClass);
|
647
614
|
const selfType = (0, typeUtils_1.synthesizeTypeVarForSelfCls)(descriptorClass, /* isClsParam */ false);
|
648
615
|
const setFunction = types_1.FunctionType.createSynthesizedInstance('__set__');
|
649
|
-
types_1.FunctionType.addParameter(setFunction,
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
hasDeclaredType: true,
|
654
|
-
});
|
655
|
-
types_1.FunctionType.addParameter(setFunction, {
|
656
|
-
category: 0 /* ParameterCategory.Simple */,
|
657
|
-
name: 'obj',
|
658
|
-
type: types_1.AnyType.create(),
|
659
|
-
hasDeclaredType: true,
|
660
|
-
});
|
661
|
-
types_1.FunctionType.addParameter(setFunction, {
|
662
|
-
category: 0 /* ParameterCategory.Simple */,
|
663
|
-
name: 'value',
|
664
|
-
type: setType,
|
665
|
-
hasDeclaredType: true,
|
666
|
-
});
|
667
|
-
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();
|
668
620
|
const setSymbol = symbol_1.Symbol.createWithType(4 /* SymbolFlags.ClassMember */, setFunction);
|
669
621
|
fields.set('__set__', setSymbol);
|
670
622
|
const getFunction = types_1.FunctionType.createSynthesizedInstance('__get__');
|
671
|
-
types_1.FunctionType.addParameter(getFunction,
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
hasDeclaredType: true,
|
676
|
-
});
|
677
|
-
types_1.FunctionType.addParameter(getFunction, {
|
678
|
-
category: 0 /* ParameterCategory.Simple */,
|
679
|
-
name: 'obj',
|
680
|
-
type: types_1.AnyType.create(),
|
681
|
-
hasDeclaredType: true,
|
682
|
-
});
|
683
|
-
types_1.FunctionType.addParameter(getFunction, {
|
684
|
-
category: 0 /* ParameterCategory.Simple */,
|
685
|
-
name: 'objtype',
|
686
|
-
type: types_1.AnyType.create(),
|
687
|
-
hasDeclaredType: true,
|
688
|
-
});
|
689
|
-
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;
|
690
627
|
const getSymbol = symbol_1.Symbol.createWithType(4 /* SymbolFlags.ClassMember */, getFunction);
|
691
628
|
fields.set('__get__', getSymbol);
|
692
629
|
return symbol_1.Symbol.createWithType(4 /* SymbolFlags.ClassMember */, types_1.ClassType.cloneAsInstance(descriptorClass));
|
@@ -751,13 +688,13 @@ exports.addInheritedDataClassEntries = addInheritedDataClassEntries;
|
|
751
688
|
function isDataclassFieldConstructor(type, fieldDescriptorNames) {
|
752
689
|
let callName;
|
753
690
|
if ((0, types_1.isFunction)(type)) {
|
754
|
-
callName = type.
|
691
|
+
callName = type.shared.fullName;
|
755
692
|
}
|
756
693
|
else if ((0, types_1.isOverloadedFunction)(type)) {
|
757
|
-
callName = type.overloads[0].
|
694
|
+
callName = type.priv.overloads[0].shared.fullName;
|
758
695
|
}
|
759
696
|
else if ((0, types_1.isInstantiableClass)(type)) {
|
760
|
-
callName = type.
|
697
|
+
callName = type.shared.fullName;
|
761
698
|
}
|
762
699
|
if (!callName) {
|
763
700
|
return false;
|
@@ -778,43 +715,43 @@ function validateDataClassTransformDecorator(evaluator, node) {
|
|
778
715
|
};
|
779
716
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
780
717
|
// Parse the arguments to the call.
|
781
|
-
node.
|
782
|
-
if (!arg.name || arg.
|
718
|
+
node.d.args.forEach((arg) => {
|
719
|
+
if (!arg.d.name || arg.d.argCategory !== 0 /* ArgumentCategory.Simple */) {
|
783
720
|
evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.dataClassTransformPositionalParam(), arg);
|
784
721
|
return;
|
785
722
|
}
|
786
|
-
switch (arg.name.value) {
|
723
|
+
switch (arg.d.name.d.value) {
|
787
724
|
case 'kw_only_default': {
|
788
|
-
const value = (0, staticExpressions_1.evaluateStaticBoolExpression)(arg.
|
725
|
+
const value = (0, staticExpressions_1.evaluateStaticBoolExpression)(arg.d.valueExpr, fileInfo.executionEnvironment, fileInfo.definedConstants);
|
789
726
|
if (value === undefined) {
|
790
|
-
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);
|
791
728
|
return;
|
792
729
|
}
|
793
730
|
behaviors.keywordOnly = value;
|
794
731
|
break;
|
795
732
|
}
|
796
733
|
case 'eq_default': {
|
797
|
-
const value = (0, staticExpressions_1.evaluateStaticBoolExpression)(arg.
|
734
|
+
const value = (0, staticExpressions_1.evaluateStaticBoolExpression)(arg.d.valueExpr, fileInfo.executionEnvironment, fileInfo.definedConstants);
|
798
735
|
if (value === undefined) {
|
799
|
-
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);
|
800
737
|
return;
|
801
738
|
}
|
802
739
|
behaviors.skipGenerateEq = !value;
|
803
740
|
break;
|
804
741
|
}
|
805
742
|
case 'order_default': {
|
806
|
-
const value = (0, staticExpressions_1.evaluateStaticBoolExpression)(arg.
|
743
|
+
const value = (0, staticExpressions_1.evaluateStaticBoolExpression)(arg.d.valueExpr, fileInfo.executionEnvironment, fileInfo.definedConstants);
|
807
744
|
if (value === undefined) {
|
808
|
-
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);
|
809
746
|
return;
|
810
747
|
}
|
811
748
|
behaviors.generateOrder = value;
|
812
749
|
break;
|
813
750
|
}
|
814
751
|
case 'frozen_default': {
|
815
|
-
const value = (0, staticExpressions_1.evaluateStaticBoolExpression)(arg.
|
752
|
+
const value = (0, staticExpressions_1.evaluateStaticBoolExpression)(arg.d.valueExpr, fileInfo.executionEnvironment, fileInfo.definedConstants);
|
816
753
|
if (value === undefined) {
|
817
|
-
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);
|
818
755
|
return;
|
819
756
|
}
|
820
757
|
behaviors.frozen = value;
|
@@ -830,30 +767,30 @@ function validateDataClassTransformDecorator(evaluator, node) {
|
|
830
767
|
// form that supported this older parameter name.
|
831
768
|
case 'field_descriptors':
|
832
769
|
case 'field_specifiers': {
|
833
|
-
const valueType = evaluator.getTypeOfExpression(arg.
|
770
|
+
const valueType = evaluator.getTypeOfExpression(arg.d.valueExpr).type;
|
834
771
|
if (!(0, types_1.isClassInstance)(valueType) ||
|
835
772
|
!types_1.ClassType.isBuiltIn(valueType, 'tuple') ||
|
836
|
-
!valueType.tupleTypeArguments ||
|
837
|
-
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) &&
|
838
775
|
!(0, types_1.isFunction)(entry.type) &&
|
839
776
|
!(0, types_1.isOverloadedFunction)(entry.type))) {
|
840
777
|
evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.dataClassTransformFieldSpecifier().format({
|
841
778
|
type: evaluator.printType(valueType),
|
842
|
-
}), arg.
|
779
|
+
}), arg.d.valueExpr);
|
843
780
|
return;
|
844
781
|
}
|
845
|
-
valueType.tupleTypeArguments.forEach((arg) => {
|
782
|
+
valueType.priv.tupleTypeArguments.forEach((arg) => {
|
846
783
|
if ((0, types_1.isInstantiableClass)(arg.type) || (0, types_1.isFunction)(arg.type)) {
|
847
|
-
behaviors.fieldDescriptorNames.push(arg.type.
|
784
|
+
behaviors.fieldDescriptorNames.push(arg.type.shared.fullName);
|
848
785
|
}
|
849
786
|
else if ((0, types_1.isOverloadedFunction)(arg.type)) {
|
850
|
-
behaviors.fieldDescriptorNames.push(arg.type.overloads[0].
|
787
|
+
behaviors.fieldDescriptorNames.push(arg.type.priv.overloads[0].shared.fullName);
|
851
788
|
}
|
852
789
|
});
|
853
790
|
break;
|
854
791
|
}
|
855
792
|
default:
|
856
|
-
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);
|
857
794
|
break;
|
858
795
|
}
|
859
796
|
});
|
@@ -871,16 +808,16 @@ function getDataclassDecoratorBehaviors(type) {
|
|
871
808
|
// dataclass_transform decorator. If more than one have such a decorator,
|
872
809
|
// only the first one will be honored, as per PEP 681.
|
873
810
|
functionType =
|
874
|
-
(_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];
|
875
812
|
}
|
876
813
|
if (!functionType) {
|
877
814
|
return undefined;
|
878
815
|
}
|
879
|
-
if (functionType.
|
880
|
-
return functionType.
|
816
|
+
if (functionType.shared.decoratorDataClassBehaviors) {
|
817
|
+
return functionType.shared.decoratorDataClassBehaviors;
|
881
818
|
}
|
882
819
|
// Is this the built-in dataclass? If so, return the default behaviors.
|
883
|
-
if (functionType.
|
820
|
+
if (functionType.shared.fullName === 'dataclasses.dataclass') {
|
884
821
|
return {
|
885
822
|
fieldDescriptorNames: ['dataclasses.field', 'dataclasses.Field'],
|
886
823
|
};
|
@@ -911,15 +848,15 @@ function applyDataClassBehaviorOverrideValue(evaluator, errorNode, classType, ar
|
|
911
848
|
if (argValue !== undefined) {
|
912
849
|
behaviors.frozen = argValue;
|
913
850
|
}
|
914
|
-
classType.
|
851
|
+
classType.shared.baseClasses.forEach((baseClass) => {
|
915
852
|
if ((0, types_1.isInstantiableClass)(baseClass) && types_1.ClassType.isDataClass(baseClass)) {
|
916
853
|
if (types_1.ClassType.isDataClassFrozen(baseClass)) {
|
917
854
|
hasFrozenBaseClass = true;
|
918
855
|
}
|
919
|
-
else if (!baseClass.
|
920
|
-
!(baseClass.
|
921
|
-
(0, types_1.isInstantiableClass)(baseClass.
|
922
|
-
!!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)) {
|
923
860
|
// If this base class is unfrozen and isn't the class that directly
|
924
861
|
// references the metaclass that provides dataclass-like behaviors,
|
925
862
|
// we'll assume we're deriving from an unfrozen dataclass.
|
@@ -954,7 +891,7 @@ function applyDataClassBehaviorOverrideValue(evaluator, errorNode, classType, ar
|
|
954
891
|
case 'slots':
|
955
892
|
if (argValue === true) {
|
956
893
|
behaviors.generateSlots = true;
|
957
|
-
if (classType.
|
894
|
+
if (classType.shared.localSlotsNames) {
|
958
895
|
evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.dataClassSlotsOverwrite(), errorNode);
|
959
896
|
}
|
960
897
|
}
|
@@ -976,11 +913,11 @@ function applyDataClassClassBehaviorOverrides(evaluator, errorNode, classType, a
|
|
976
913
|
// The "frozen" behavior is not inherited from the parent class.
|
977
914
|
// Instead, it comes from the default.
|
978
915
|
behaviors.frozen = behaviors.frozenDefault;
|
979
|
-
classType.
|
916
|
+
classType.shared.dataClassBehaviors = behaviors;
|
980
917
|
args.forEach((arg) => {
|
981
918
|
if (arg.valueExpression && arg.name) {
|
982
|
-
applyDataClassBehaviorOverride(evaluator, arg.name, classType, arg.name.value, arg.valueExpression, behaviors);
|
983
|
-
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') {
|
984
921
|
sawFrozenArg = true;
|
985
922
|
}
|
986
923
|
}
|
@@ -995,7 +932,7 @@ function applyDataClassClassBehaviorOverrides(evaluator, errorNode, classType, a
|
|
995
932
|
exports.applyDataClassClassBehaviorOverrides = applyDataClassClassBehaviorOverrides;
|
996
933
|
function applyDataClassDecorator(evaluator, errorNode, classType, defaultBehaviors, callNode) {
|
997
934
|
var _a;
|
998
|
-
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);
|
999
936
|
}
|
1000
937
|
exports.applyDataClassDecorator = applyDataClassDecorator;
|
1001
938
|
//# sourceMappingURL=dataClasses.js.map
|