@zzzen/pyright-internal 1.2.0-dev.20230430 → 1.2.0-dev.20230507

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.
Files changed (160) hide show
  1. package/dist/analyzer/backgroundAnalysisProgram.d.ts +3 -0
  2. package/dist/analyzer/backgroundAnalysisProgram.js +12 -0
  3. package/dist/analyzer/backgroundAnalysisProgram.js.map +1 -1
  4. package/dist/analyzer/checker.d.ts +1 -0
  5. package/dist/analyzer/checker.js +52 -4
  6. package/dist/analyzer/checker.js.map +1 -1
  7. package/dist/analyzer/constructors.d.ts +6 -0
  8. package/dist/analyzer/constructors.js +456 -0
  9. package/dist/analyzer/constructors.js.map +1 -0
  10. package/dist/analyzer/dataClasses.js +84 -0
  11. package/dist/analyzer/dataClasses.js.map +1 -1
  12. package/dist/analyzer/enums.js +54 -8
  13. package/dist/analyzer/enums.js.map +1 -1
  14. package/dist/analyzer/importStatementUtils.d.ts +2 -2
  15. package/dist/analyzer/importStatementUtils.js.map +1 -1
  16. package/dist/analyzer/namedTuples.js +1 -1
  17. package/dist/analyzer/namedTuples.js.map +1 -1
  18. package/dist/analyzer/operations.d.ts +16 -0
  19. package/dist/analyzer/operations.js +749 -0
  20. package/dist/analyzer/operations.js.map +1 -0
  21. package/dist/analyzer/parseTreeUtils.d.ts +4 -2
  22. package/dist/analyzer/parseTreeUtils.js +32 -1
  23. package/dist/analyzer/parseTreeUtils.js.map +1 -1
  24. package/dist/analyzer/patternMatching.js +16 -0
  25. package/dist/analyzer/patternMatching.js.map +1 -1
  26. package/dist/analyzer/program.d.ts +5 -17
  27. package/dist/analyzer/program.js +46 -493
  28. package/dist/analyzer/program.js.map +1 -1
  29. package/dist/analyzer/service.d.ts +3 -11
  30. package/dist/analyzer/service.js +16 -12
  31. package/dist/analyzer/service.js.map +1 -1
  32. package/dist/analyzer/sourceFile.d.ts +10 -33
  33. package/dist/analyzer/sourceFile.js +225 -181
  34. package/dist/analyzer/sourceFile.js.map +1 -1
  35. package/dist/analyzer/sourceFileInfoUtils.d.ts +3 -9
  36. package/dist/analyzer/sourceFileInfoUtils.js.map +1 -1
  37. package/dist/analyzer/typeEvaluator.js +100 -1285
  38. package/dist/analyzer/typeEvaluator.js.map +1 -1
  39. package/dist/analyzer/typeEvaluatorTypes.d.ts +38 -7
  40. package/dist/analyzer/typeEvaluatorTypes.js +33 -1
  41. package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
  42. package/dist/analyzer/typeGuards.js +2 -8
  43. package/dist/analyzer/typeGuards.js.map +1 -1
  44. package/dist/analyzer/typeUtils.d.ts +2 -0
  45. package/dist/analyzer/typeUtils.js +33 -3
  46. package/dist/analyzer/typeUtils.js.map +1 -1
  47. package/dist/analyzer/typeVarContext.d.ts +5 -5
  48. package/dist/analyzer/typeVarContext.js +7 -0
  49. package/dist/analyzer/typeVarContext.js.map +1 -1
  50. package/dist/analyzer/typedDicts.js +2 -2
  51. package/dist/analyzer/typedDicts.js.map +1 -1
  52. package/dist/analyzer/types.d.ts +4 -2
  53. package/dist/analyzer/types.js +7 -0
  54. package/dist/analyzer/types.js.map +1 -1
  55. package/dist/common/extensibility.d.ts +2 -1
  56. package/dist/common/extensibility.js.map +1 -1
  57. package/dist/common/pathUtils.d.ts +11 -11
  58. package/dist/common/pathUtils.js.map +1 -1
  59. package/dist/common/workspaceEditUtils.d.ts +5 -5
  60. package/dist/common/workspaceEditUtils.js.map +1 -1
  61. package/dist/languageServerBase.d.ts +1 -2
  62. package/dist/languageServerBase.js +8 -13
  63. package/dist/languageServerBase.js.map +1 -1
  64. package/dist/languageService/callHierarchyProvider.d.ts +1 -1
  65. package/dist/languageService/callHierarchyProvider.js +5 -5
  66. package/dist/languageService/callHierarchyProvider.js.map +1 -1
  67. package/dist/languageService/completionProvider.d.ts +10 -13
  68. package/dist/languageService/completionProvider.js +21 -10
  69. package/dist/languageService/completionProvider.js.map +1 -1
  70. package/dist/languageService/documentHighlightProvider.js +1 -1
  71. package/dist/languageService/documentHighlightProvider.js.map +1 -1
  72. package/dist/languageService/documentSymbolCollector.d.ts +6 -7
  73. package/dist/languageService/documentSymbolCollector.js +17 -8
  74. package/dist/languageService/documentSymbolCollector.js.map +1 -1
  75. package/dist/languageService/hoverProvider.d.ts +4 -3
  76. package/dist/languageService/hoverProvider.js +29 -35
  77. package/dist/languageService/hoverProvider.js.map +1 -1
  78. package/dist/languageService/referencesProvider.d.ts +7 -12
  79. package/dist/languageService/referencesProvider.js +25 -17
  80. package/dist/languageService/referencesProvider.js.map +1 -1
  81. package/dist/languageService/renameProvider.d.ts +17 -0
  82. package/dist/languageService/renameProvider.js +143 -0
  83. package/dist/languageService/renameProvider.js.map +1 -0
  84. package/dist/localization/localize.d.ts +17 -14
  85. package/dist/localization/localize.js +4 -6
  86. package/dist/localization/localize.js.map +1 -1
  87. package/dist/localization/package.nls.en-us.json +5 -6
  88. package/dist/tests/documentSymbolCollector.test.js +3 -3
  89. package/dist/tests/documentSymbolCollector.test.js.map +1 -1
  90. package/dist/tests/fourslash/fourslash.d.ts +4 -4
  91. package/dist/tests/fourslash/missingTypeStub.codeAction.fourslash.js +1 -1
  92. package/dist/tests/fourslash/missingTypeStub.codeAction.fourslash.js.map +1 -1
  93. package/dist/tests/harness/fourslash/testState.d.ts +3 -3
  94. package/dist/tests/harness/fourslash/testState.js +14 -14
  95. package/dist/tests/harness/fourslash/testState.js.map +1 -1
  96. package/dist/tests/sourceFile.test.js +1 -1
  97. package/dist/tests/sourceFile.test.js.map +1 -1
  98. package/dist/tests/testStateUtils.d.ts +2 -2
  99. package/dist/tests/testStateUtils.js +38 -8
  100. package/dist/tests/testStateUtils.js.map +1 -1
  101. package/dist/tests/typeEvaluator2.test.js +1 -1
  102. package/dist/tests/typeEvaluator3.test.js +1 -1
  103. package/dist/tests/typeEvaluator4.test.js +9 -1
  104. package/dist/tests/typeEvaluator4.test.js.map +1 -1
  105. package/dist/tests/typeEvaluator5.test.js +4 -0
  106. package/dist/tests/typeEvaluator5.test.js.map +1 -1
  107. package/dist/tests/workspaceEditUtils.test.js +84 -0
  108. package/dist/tests/workspaceEditUtils.test.js.map +1 -1
  109. package/package.json +4 -4
  110. package/dist/languageService/indentationUtils.d.ts +0 -16
  111. package/dist/languageService/indentationUtils.js +0 -727
  112. package/dist/languageService/indentationUtils.js.map +0 -1
  113. package/dist/languageService/insertionPointUtils.d.ts +0 -9
  114. package/dist/languageService/insertionPointUtils.js +0 -132
  115. package/dist/languageService/insertionPointUtils.js.map +0 -1
  116. package/dist/languageService/renameModuleProvider.d.ts +0 -65
  117. package/dist/languageService/renameModuleProvider.js +0 -939
  118. package/dist/languageService/renameModuleProvider.js.map +0 -1
  119. package/dist/tests/indentationUtils.ptvs.test.d.ts +0 -1
  120. package/dist/tests/indentationUtils.ptvs.test.js +0 -324
  121. package/dist/tests/indentationUtils.ptvs.test.js.map +0 -1
  122. package/dist/tests/indentationUtils.reindent.test.d.ts +0 -1
  123. package/dist/tests/indentationUtils.reindent.test.js +0 -372
  124. package/dist/tests/indentationUtils.reindent.test.js.map +0 -1
  125. package/dist/tests/indentationUtils.test.d.ts +0 -1
  126. package/dist/tests/indentationUtils.test.js +0 -502
  127. package/dist/tests/indentationUtils.test.js.map +0 -1
  128. package/dist/tests/insertionPointUtils.test.d.ts +0 -1
  129. package/dist/tests/insertionPointUtils.test.js +0 -154
  130. package/dist/tests/insertionPointUtils.test.js.map +0 -1
  131. package/dist/tests/moveSymbol.importAdder.test.d.ts +0 -1
  132. package/dist/tests/moveSymbol.importAdder.test.js +0 -298
  133. package/dist/tests/moveSymbol.importAdder.test.js.map +0 -1
  134. package/dist/tests/moveSymbol.insertion.test.d.ts +0 -1
  135. package/dist/tests/moveSymbol.insertion.test.js +0 -537
  136. package/dist/tests/moveSymbol.insertion.test.js.map +0 -1
  137. package/dist/tests/moveSymbol.misc.test.d.ts +0 -1
  138. package/dist/tests/moveSymbol.misc.test.js +0 -169
  139. package/dist/tests/moveSymbol.misc.test.js.map +0 -1
  140. package/dist/tests/moveSymbol.updateReference.test.d.ts +0 -1
  141. package/dist/tests/moveSymbol.updateReference.test.js +0 -1071
  142. package/dist/tests/moveSymbol.updateReference.test.js.map +0 -1
  143. package/dist/tests/renameModule.folder.test.d.ts +0 -1
  144. package/dist/tests/renameModule.folder.test.js +0 -229
  145. package/dist/tests/renameModule.folder.test.js.map +0 -1
  146. package/dist/tests/renameModule.fromImports.test.d.ts +0 -1
  147. package/dist/tests/renameModule.fromImports.test.js +0 -790
  148. package/dist/tests/renameModule.fromImports.test.js.map +0 -1
  149. package/dist/tests/renameModule.imports.test.d.ts +0 -1
  150. package/dist/tests/renameModule.imports.test.js +0 -380
  151. package/dist/tests/renameModule.imports.test.js.map +0 -1
  152. package/dist/tests/renameModule.misc.test.d.ts +0 -1
  153. package/dist/tests/renameModule.misc.test.js +0 -615
  154. package/dist/tests/renameModule.misc.test.js.map +0 -1
  155. package/dist/tests/renameModule.relativePath.test.d.ts +0 -1
  156. package/dist/tests/renameModule.relativePath.test.js +0 -231
  157. package/dist/tests/renameModule.relativePath.test.js.map +0 -1
  158. package/dist/tests/renameModuleTestUtils.d.ts +0 -4
  159. package/dist/tests/renameModuleTestUtils.js +0 -76
  160. package/dist/tests/renameModuleTestUtils.js.map +0 -1
@@ -0,0 +1,6 @@
1
+ import { ExpressionNode } from '../parser/parseNodes';
2
+ import { CallResult, FunctionArgument, TypeEvaluator } from './typeEvaluatorTypes';
3
+ import { InferenceContext } from './typeUtils';
4
+ import { ClassType, FunctionType, OverloadedFunctionType } from './types';
5
+ export declare function validateConstructorArguments(evaluator: TypeEvaluator, errorNode: ExpressionNode, argList: FunctionArgument[], type: ClassType, skipUnknownArgCheck: boolean, inferenceContext: InferenceContext | undefined): CallResult;
6
+ export declare function createFunctionFromConstructor(evaluator: TypeEvaluator, classType: ClassType, recursionCount?: number): FunctionType | OverloadedFunctionType | undefined;
@@ -0,0 +1,456 @@
1
+ "use strict";
2
+ /*
3
+ * constructors.ts
4
+ * Copyright (c) Microsoft Corporation.
5
+ * Licensed under the MIT license.
6
+ * Author: Eric Traut
7
+ *
8
+ * Provides type evaluation logic for constructors. A constructor
9
+ * in Python is implemented by a `__call__` method on the metaclass,
10
+ * which is typically the `type` class. The default implementation
11
+ * calls the `__new__` method on the class to allocate the object.
12
+ * If the resulting object is an instance of the class, it then calls
13
+ * the `__init__` method on the resulting object with the same arguments.
14
+ */
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.createFunctionFromConstructor = exports.validateConstructorArguments = void 0;
17
+ const diagnosticRules_1 = require("../common/diagnosticRules");
18
+ const localize_1 = require("../localization/localize");
19
+ const analyzerNodeInfo_1 = require("./analyzerNodeInfo");
20
+ const constraintSolver_1 = require("./constraintSolver");
21
+ const constructorTransform_1 = require("./constructorTransform");
22
+ const parseTreeUtils_1 = require("./parseTreeUtils");
23
+ const typeUtils_1 = require("./typeUtils");
24
+ const typeVarContext_1 = require("./typeVarContext");
25
+ const types_1 = require("./types");
26
+ // Matches the arguments of a call to the constructor for a class.
27
+ // If successful, it returns the resulting (specialized) object type that
28
+ // is allocated by the constructor. If unsuccessful, it reports diagnostics.
29
+ function validateConstructorArguments(evaluator, errorNode, argList, type, skipUnknownArgCheck, inferenceContext) {
30
+ var _a;
31
+ // If there a custom `__call__` method on the metaclass, assume that it
32
+ // overrides the normal `type.__call__` logic and don't perform the usual
33
+ // __new__ and __init__ validation.
34
+ const metaclassResult = validateMetaclassCall(evaluator, errorNode, argList, type, skipUnknownArgCheck, inferenceContext);
35
+ if (metaclassResult) {
36
+ return metaclassResult;
37
+ }
38
+ // Determine whether the class overrides the object.__new__ method.
39
+ const newMethodInfo = evaluator.getTypeOfClassMemberName(errorNode, type,
40
+ /* isAccessedThroughObject */ false, '__new__', { method: 'get' },
41
+ /* diag */ undefined, 1 /* AccessClassMembersOnly */ |
42
+ 4 /* SkipObjectBaseClass */ |
43
+ 16 /* TreatConstructorAsClassMethod */, type);
44
+ // Determine whether the class overrides the object.__init__ method.
45
+ const initMethodInfo = evaluator.getTypeOfObjectMember(errorNode, types_1.ClassType.cloneAsInstance(type), '__init__', { method: 'get' },
46
+ /* diag */ undefined, 4 /* SkipObjectBaseClass */ | 64 /* SkipAttributeAccessOverride */);
47
+ let returnType;
48
+ let validatedTypes = false;
49
+ let argumentErrors = false;
50
+ let isTypeIncomplete = false;
51
+ const overloadsUsedForCall = [];
52
+ // If the class doesn't override object.__new__ or object.__init__, use the
53
+ // fallback constructor type evaluation for the `object` class.
54
+ if (!newMethodInfo && !initMethodInfo) {
55
+ const callResult = validateFallbackConstructorCall(evaluator, errorNode, argList, type, inferenceContext);
56
+ if (callResult.argumentErrors) {
57
+ argumentErrors = true;
58
+ }
59
+ else {
60
+ overloadsUsedForCall.push(...callResult.overloadsUsedForCall);
61
+ }
62
+ returnType = (_a = callResult.returnType) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
63
+ }
64
+ else {
65
+ // Validate __init__
66
+ // We validate __init__ before __new__ because the former typically has
67
+ // more specific type annotations, and we want to evaluate the arguments
68
+ // in the context of these types. The __new__ method often uses generic
69
+ // vargs and kwargs.
70
+ const initMethodType = initMethodInfo === null || initMethodInfo === void 0 ? void 0 : initMethodInfo.type;
71
+ if (initMethodType && !shouldSkipConstructorCheck(initMethodType)) {
72
+ // If there is an expected type, analyze the constructor call
73
+ // for each of the subtypes that comprise the expected type. If
74
+ // one or more analyzes with no errors, use those results.
75
+ if (inferenceContext) {
76
+ const expectedCallResult = validateConstructorMethodWithContext(evaluator, errorNode, argList, type, skipUnknownArgCheck, inferenceContext, initMethodType);
77
+ if (expectedCallResult && !expectedCallResult.argumentErrors) {
78
+ returnType = expectedCallResult.returnType;
79
+ if (expectedCallResult.isTypeIncomplete) {
80
+ isTypeIncomplete = true;
81
+ }
82
+ }
83
+ }
84
+ if (!returnType) {
85
+ const typeVarContext = type.typeArguments
86
+ ? (0, typeUtils_1.buildTypeVarContextFromSpecializedClass)(type, /* makeConcrete */ false)
87
+ : new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(type));
88
+ typeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeId)(initMethodType));
89
+ const callResult = evaluator.validateCallArguments(errorNode, argList, { type: initMethodType }, typeVarContext, skipUnknownArgCheck);
90
+ let adjustedClassType = type;
91
+ if (callResult.specializedInitSelfType &&
92
+ (0, types_1.isClassInstance)(callResult.specializedInitSelfType) &&
93
+ types_1.ClassType.isSameGenericClass(callResult.specializedInitSelfType, type)) {
94
+ adjustedClassType = types_1.ClassType.cloneAsInstantiable(callResult.specializedInitSelfType);
95
+ }
96
+ returnType = applyExpectedTypeForConstructor(evaluator, adjustedClassType,
97
+ /* inferenceContext */ undefined, typeVarContext);
98
+ if (callResult.isTypeIncomplete) {
99
+ isTypeIncomplete = true;
100
+ }
101
+ if (callResult.argumentErrors) {
102
+ argumentErrors = true;
103
+ }
104
+ else {
105
+ overloadsUsedForCall.push(...callResult.overloadsUsedForCall);
106
+ }
107
+ }
108
+ validatedTypes = true;
109
+ skipUnknownArgCheck = true;
110
+ }
111
+ // Validate __new__
112
+ // Don't report errors for __new__ if __init__ already generated errors. They're
113
+ // probably going to be entirely redundant anyway.
114
+ if (!argumentErrors && newMethodInfo && !shouldSkipConstructorCheck(newMethodInfo.type)) {
115
+ const constructorMethodType = newMethodInfo.type;
116
+ let newReturnType;
117
+ // If there is an expected type that was not applied above when
118
+ // handling the __init__ method, try to apply it with the __new__ method.
119
+ if (inferenceContext && !returnType) {
120
+ const expectedCallResult = validateConstructorMethodWithContext(evaluator, errorNode, argList, type, skipUnknownArgCheck, inferenceContext, constructorMethodType);
121
+ if (expectedCallResult && !expectedCallResult.argumentErrors) {
122
+ newReturnType = expectedCallResult.returnType;
123
+ returnType = newReturnType;
124
+ if (expectedCallResult.isTypeIncomplete) {
125
+ isTypeIncomplete = true;
126
+ }
127
+ }
128
+ }
129
+ const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(type));
130
+ if (type.typeAliasInfo) {
131
+ typeVarContext.addSolveForScope(type.typeAliasInfo.typeVarScopeId);
132
+ }
133
+ typeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeId)(constructorMethodType));
134
+ // Use speculative mode if we're going to later apply a constructor transform.
135
+ // This allows us to use bidirectional type inference for arguments in the transform.
136
+ const callResult = evaluator.useSpeculativeMode((0, constructorTransform_1.hasConstructorTransform)(type) ? errorNode : undefined, () => {
137
+ return evaluator.validateCallArguments(errorNode, argList, newMethodInfo, typeVarContext, skipUnknownArgCheck);
138
+ });
139
+ if (callResult.isTypeIncomplete) {
140
+ isTypeIncomplete = true;
141
+ }
142
+ if (callResult.argumentErrors) {
143
+ argumentErrors = true;
144
+ }
145
+ else if (!newReturnType) {
146
+ newReturnType = callResult.returnType;
147
+ if (overloadsUsedForCall.length === 0) {
148
+ overloadsUsedForCall.push(...callResult.overloadsUsedForCall);
149
+ }
150
+ // If the constructor returned an object whose type matches the class of
151
+ // the original type being constructed, use the return type in case it was
152
+ // specialized. If it doesn't match, we'll fall back on the assumption that
153
+ // the constructed type is an instance of the class type. We need to do this
154
+ // in cases where we're inferring the return type based on a call to
155
+ // super().__new__().
156
+ if (newReturnType) {
157
+ if ((0, types_1.isClassInstance)(newReturnType) && types_1.ClassType.isSameGenericClass(newReturnType, type)) {
158
+ // If the specialized return type derived from the __init__
159
+ // method is "better" than the return type provided by the
160
+ // __new__ method (where "better" means that the type arguments
161
+ // are all known), stick with the __init__ result.
162
+ if ((!(0, typeUtils_1.isPartlyUnknown)(newReturnType) && !(0, typeUtils_1.requiresSpecialization)(newReturnType)) ||
163
+ returnType === undefined) {
164
+ // Special-case the 'tuple' type specialization to use
165
+ // the homogenous arbitrary-length form.
166
+ if ((0, types_1.isClassInstance)(newReturnType) &&
167
+ types_1.ClassType.isTupleClass(newReturnType) &&
168
+ !newReturnType.tupleTypeArguments &&
169
+ newReturnType.typeArguments &&
170
+ newReturnType.typeArguments.length === 1) {
171
+ newReturnType = (0, typeUtils_1.specializeTupleClass)(newReturnType, [
172
+ { type: newReturnType.typeArguments[0], isUnbounded: true },
173
+ ]);
174
+ }
175
+ returnType = newReturnType;
176
+ }
177
+ }
178
+ else if (!returnType && !(0, types_1.isUnknown)(newReturnType)) {
179
+ returnType = newReturnType;
180
+ }
181
+ }
182
+ }
183
+ if (!returnType) {
184
+ returnType = applyExpectedTypeForConstructor(evaluator, type, inferenceContext, typeVarContext);
185
+ }
186
+ else if ((0, types_1.isClassInstance)(returnType) && (0, typeUtils_1.isTupleClass)(returnType) && !returnType.tupleTypeArguments) {
187
+ returnType = applyExpectedTypeForTupleConstructor(returnType, inferenceContext);
188
+ }
189
+ validatedTypes = true;
190
+ }
191
+ }
192
+ // If we weren't able to validate the args, analyze the expressions here
193
+ // to mark symbols referenced and report expression evaluation errors.
194
+ if (!validatedTypes) {
195
+ argList.forEach((arg) => {
196
+ if (arg.valueExpression && !evaluator.isSpeculativeModeInUse(arg.valueExpression)) {
197
+ evaluator.getTypeOfExpression(arg.valueExpression);
198
+ }
199
+ });
200
+ }
201
+ // Apply a constructor transform if applicable.
202
+ if (!argumentErrors && returnType) {
203
+ const transformed = (0, constructorTransform_1.applyConstructorTransform)(evaluator, errorNode, argList, type, {
204
+ argumentErrors,
205
+ returnType,
206
+ isTypeIncomplete,
207
+ });
208
+ returnType = transformed.returnType;
209
+ if (transformed.isTypeIncomplete) {
210
+ isTypeIncomplete = true;
211
+ }
212
+ if (transformed.argumentErrors) {
213
+ argumentErrors = true;
214
+ }
215
+ }
216
+ return { argumentErrors, returnType, isTypeIncomplete, overloadsUsedForCall };
217
+ }
218
+ exports.validateConstructorArguments = validateConstructorArguments;
219
+ function validateFallbackConstructorCall(evaluator, errorNode, argList, type, inferenceContext) {
220
+ let reportedErrors = false;
221
+ if (argList.length > 0) {
222
+ const fileInfo = (0, analyzerNodeInfo_1.getFileInfo)(errorNode);
223
+ evaluator.addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.constructorNoArgs().format({ type: type.aliasName || type.details.name }), errorNode);
224
+ reportedErrors = true;
225
+ }
226
+ if (!inferenceContext && type.typeArguments) {
227
+ // If there was no expected type but the type was already specialized,
228
+ // assume that we're constructing an instance of the specialized type.
229
+ return {
230
+ argumentErrors: reportedErrors,
231
+ overloadsUsedForCall: [],
232
+ returnType: (0, typeUtils_1.convertToInstance)(type),
233
+ };
234
+ }
235
+ // Do our best to specialize the instantiated class based on the expected
236
+ // type if provided.
237
+ const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(type));
238
+ if (inferenceContext) {
239
+ (0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluator, types_1.ClassType.cloneAsInstance(type), inferenceContext.expectedType, typeVarContext, (0, parseTreeUtils_1.getTypeVarScopesForNode)(errorNode));
240
+ }
241
+ return {
242
+ argumentErrors: reportedErrors,
243
+ overloadsUsedForCall: [],
244
+ returnType: applyExpectedTypeForConstructor(evaluator, type, inferenceContext, typeVarContext),
245
+ };
246
+ }
247
+ function validateMetaclassCall(evaluator, errorNode, argList, type, skipUnknownArgCheck, inferenceContext) {
248
+ const metaclass = type.details.effectiveMetaclass;
249
+ if (metaclass && (0, types_1.isInstantiableClass)(metaclass) && !types_1.ClassType.isSameGenericClass(metaclass, type)) {
250
+ const metaclassCallMethodInfo = evaluator.getTypeOfClassMemberName(errorNode, metaclass,
251
+ /* isAccessedThroughObject */ true, '__call__', { method: 'get' },
252
+ /* diag */ undefined, 32 /* ConsiderMetaclassOnly */ |
253
+ 256 /* SkipTypeBaseClass */ |
254
+ 64 /* SkipAttributeAccessOverride */, type);
255
+ if (metaclassCallMethodInfo) {
256
+ const callResult = evaluator.validateCallArguments(errorNode, argList, metaclassCallMethodInfo,
257
+ /* typeVarContext */ undefined, skipUnknownArgCheck, inferenceContext);
258
+ if (!callResult.returnType || (0, types_1.isUnknown)(callResult.returnType)) {
259
+ // The return result isn't known. We'll assume in this case that
260
+ // the metaclass __call__ method allocated a new instance of the
261
+ // requested class.
262
+ const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(type));
263
+ callResult.returnType = applyExpectedTypeForConstructor(evaluator, type, inferenceContext, typeVarContext);
264
+ }
265
+ return callResult;
266
+ }
267
+ }
268
+ return undefined;
269
+ }
270
+ // For a constructor call that targets a generic class and an "expected type"
271
+ // (i.e. bidirectional inference), this function attempts to infer the correct
272
+ // specialized return type for the constructor.
273
+ function validateConstructorMethodWithContext(evaluator, errorNode, argList, type, skipUnknownArgCheck, inferenceContext, constructorMethodType) {
274
+ let isTypeIncomplete = false;
275
+ let argumentErrors = false;
276
+ const overloadsUsedForCall = [];
277
+ const returnType = (0, typeUtils_1.mapSubtypes)(inferenceContext.expectedType, (expectedSubType) => {
278
+ expectedSubType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(expectedSubType);
279
+ const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(type));
280
+ typeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeId)(constructorMethodType));
281
+ if ((0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluator, types_1.ClassType.cloneAsInstance(type), expectedSubType, typeVarContext, (0, parseTreeUtils_1.getTypeVarScopesForNode)(errorNode))) {
282
+ const specializedConstructor = (0, typeUtils_1.applySolvedTypeVars)(constructorMethodType, typeVarContext);
283
+ let callResult;
284
+ evaluator.useSpeculativeMode(errorNode, () => {
285
+ callResult = evaluator.validateCallArguments(errorNode, argList, { type: specializedConstructor }, typeVarContext.clone(), skipUnknownArgCheck);
286
+ });
287
+ if (!callResult.argumentErrors) {
288
+ // Call validateCallArguments again, this time without speculative
289
+ // mode, so any errors are reported.
290
+ callResult = evaluator.validateCallArguments(errorNode, argList, { type: specializedConstructor }, typeVarContext, skipUnknownArgCheck);
291
+ if (callResult.isTypeIncomplete) {
292
+ isTypeIncomplete = true;
293
+ }
294
+ if (callResult.argumentErrors) {
295
+ argumentErrors = true;
296
+ }
297
+ overloadsUsedForCall.push(...callResult.overloadsUsedForCall);
298
+ return applyExpectedSubtypeForConstructor(evaluator, type, expectedSubType, inferenceContext, typeVarContext);
299
+ }
300
+ }
301
+ return undefined;
302
+ });
303
+ if ((0, types_1.isNever)(returnType)) {
304
+ return undefined;
305
+ }
306
+ return { returnType, isTypeIncomplete, argumentErrors, overloadsUsedForCall };
307
+ }
308
+ function applyExpectedSubtypeForConstructor(evaluator, type, expectedSubtype, inferenceContext, typeVarContext) {
309
+ var _a;
310
+ const specializedType = (0, typeUtils_1.applySolvedTypeVars)(types_1.ClassType.cloneAsInstance(type), typeVarContext);
311
+ if (!evaluator.assignType(expectedSubtype, specializedType,
312
+ /* diag */ undefined,
313
+ /* destTypeVarContext */ (_a = inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.typeVarContext) === null || _a === void 0 ? void 0 : _a.clone(),
314
+ /* srcTypeVarContext */ undefined)) {
315
+ return undefined;
316
+ }
317
+ // If the expected type is "Any", transform it to an Any.
318
+ if ((0, types_1.isAny)(expectedSubtype)) {
319
+ return expectedSubtype;
320
+ }
321
+ return specializedType;
322
+ }
323
+ // Handles the case where a constructor is a generic type and the type
324
+ // arguments are not specified but can be provided by the expected type.
325
+ function applyExpectedTypeForConstructor(evaluator, type, inferenceContext, typeVarContext) {
326
+ let unsolvedTypeVarsAreUnknown = true;
327
+ if (inferenceContext) {
328
+ const specializedExpectedType = (0, typeUtils_1.mapSubtypes)(inferenceContext.expectedType, (expectedSubtype) => {
329
+ return applyExpectedSubtypeForConstructor(evaluator, type, expectedSubtype, inferenceContext, typeVarContext);
330
+ });
331
+ if (!(0, types_1.isNever)(specializedExpectedType)) {
332
+ return specializedExpectedType;
333
+ }
334
+ // If the expected type didn't provide TypeVar values, remaining
335
+ // unsolved TypeVars should be considered Unknown unless they were
336
+ // provided explicitly in the constructor call.
337
+ if (type.typeArguments) {
338
+ unsolvedTypeVarsAreUnknown = false;
339
+ }
340
+ }
341
+ const specializedType = (0, typeUtils_1.applySolvedTypeVars)(type, typeVarContext, {
342
+ unknownIfNotFound: unsolvedTypeVarsAreUnknown,
343
+ });
344
+ return types_1.ClassType.cloneAsInstance(specializedType);
345
+ }
346
+ // Similar to applyExpectedTypeForConstructor, this function handles the
347
+ // special case of the tuple class.
348
+ function applyExpectedTypeForTupleConstructor(type, inferenceContext) {
349
+ let specializedType = type;
350
+ if (inferenceContext &&
351
+ (0, types_1.isClassInstance)(inferenceContext.expectedType) &&
352
+ (0, typeUtils_1.isTupleClass)(inferenceContext.expectedType) &&
353
+ inferenceContext.expectedType.tupleTypeArguments) {
354
+ specializedType = (0, typeUtils_1.specializeTupleClass)(type, inferenceContext.expectedType.tupleTypeArguments);
355
+ }
356
+ return specializedType;
357
+ }
358
+ // Synthesize a function that represents the constructor for this class
359
+ // taking into consideration the __init__ and __new__ methods.
360
+ function createFunctionFromConstructor(evaluator, classType, recursionCount = 0) {
361
+ // Use the __init__ method if available. It's usually more detailed.
362
+ const initInfo = (0, typeUtils_1.lookUpClassMember)(classType, '__init__', 8 /* SkipInstanceVariables */ | 4 /* SkipObjectBaseClass */);
363
+ if (initInfo) {
364
+ const initType = evaluator.getTypeOfMember(initInfo);
365
+ const objectType = types_1.ClassType.cloneAsInstance(classType);
366
+ const convertInitToConstructor = (initSubtype) => {
367
+ let constructorFunction = evaluator.bindFunctionToClassOrObject(objectType, initSubtype,
368
+ /* memberClass */ undefined,
369
+ /* errorNode */ undefined, recursionCount);
370
+ if (constructorFunction) {
371
+ constructorFunction = types_1.FunctionType.clone(constructorFunction);
372
+ constructorFunction.details.declaredReturnType = objectType;
373
+ if (constructorFunction.specializedTypes) {
374
+ constructorFunction.specializedTypes.returnType = objectType;
375
+ }
376
+ if (!constructorFunction.details.docString && classType.details.docString) {
377
+ constructorFunction.details.docString = classType.details.docString;
378
+ }
379
+ constructorFunction.details.flags &= ~4 /* StaticMethod */;
380
+ }
381
+ return constructorFunction;
382
+ };
383
+ if ((0, types_1.isFunction)(initType)) {
384
+ return convertInitToConstructor(initType);
385
+ }
386
+ else if ((0, types_1.isOverloadedFunction)(initType)) {
387
+ const initOverloads = [];
388
+ initType.overloads.forEach((overload) => {
389
+ const converted = convertInitToConstructor(overload);
390
+ if (converted) {
391
+ initOverloads.push(converted);
392
+ }
393
+ });
394
+ if (initOverloads.length === 0) {
395
+ return undefined;
396
+ }
397
+ else if (initOverloads.length === 1) {
398
+ return initOverloads[0];
399
+ }
400
+ return types_1.OverloadedFunctionType.create(initOverloads);
401
+ }
402
+ }
403
+ // Fall back on the __new__ method if __init__ isn't available.
404
+ const newInfo = (0, typeUtils_1.lookUpClassMember)(classType, '__new__', 8 /* SkipInstanceVariables */ | 4 /* SkipObjectBaseClass */);
405
+ if (newInfo) {
406
+ const newType = evaluator.getTypeOfMember(newInfo);
407
+ const convertNewToConstructor = (newSubtype) => {
408
+ let constructorFunction = evaluator.bindFunctionToClassOrObject(classType, newSubtype,
409
+ /* memberClass */ undefined,
410
+ /* errorNode */ undefined, recursionCount,
411
+ /* treatConstructorAsClassMember */ true);
412
+ if (constructorFunction) {
413
+ constructorFunction = types_1.FunctionType.clone(constructorFunction);
414
+ if (!constructorFunction.details.docString && classType.details.docString) {
415
+ constructorFunction.details.docString = classType.details.docString;
416
+ }
417
+ constructorFunction.details.flags &= ~(4 /* StaticMethod */ | 1 /* ConstructorMethod */);
418
+ }
419
+ return constructorFunction;
420
+ };
421
+ if ((0, types_1.isFunction)(newType)) {
422
+ return convertNewToConstructor(newType);
423
+ }
424
+ else if ((0, types_1.isOverloadedFunction)(newType)) {
425
+ const newOverloads = [];
426
+ newType.overloads.forEach((overload) => {
427
+ const converted = convertNewToConstructor(overload);
428
+ if (converted) {
429
+ newOverloads.push(converted);
430
+ }
431
+ });
432
+ if (newOverloads.length === 0) {
433
+ return undefined;
434
+ }
435
+ else if (newOverloads.length === 1) {
436
+ return newOverloads[0];
437
+ }
438
+ return types_1.OverloadedFunctionType.create(newOverloads);
439
+ }
440
+ }
441
+ // Return a generic constructor.
442
+ const constructorFunction = types_1.FunctionType.createSynthesizedInstance('__new__', 0 /* None */);
443
+ constructorFunction.details.declaredReturnType = types_1.ClassType.cloneAsInstance(classType);
444
+ types_1.FunctionType.addDefaultParameters(constructorFunction);
445
+ if (!constructorFunction.details.docString && classType.details.docString) {
446
+ constructorFunction.details.docString = classType.details.docString;
447
+ }
448
+ return constructorFunction;
449
+ }
450
+ exports.createFunctionFromConstructor = createFunctionFromConstructor;
451
+ // Determines whether we should skip argument validation. This is required
452
+ // for certain synthesized constructor types, namely NamedTuples.
453
+ function shouldSkipConstructorCheck(type) {
454
+ return (0, types_1.isFunction)(type) && types_1.FunctionType.isSkipConstructorCheck(type);
455
+ }
456
+ //# sourceMappingURL=constructors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constructors.js","sourceRoot":"","sources":["../../../src/analyzer/constructors.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;AAEH,+DAA2D;AAC3D,uDAAqD;AAErD,yDAAiD;AACjD,yDAA+E;AAC/E,iEAA4F;AAC5F,qDAA2D;AAE3D,2CAcqB;AACrB,qDAAkD;AAClD,mCAciB;AAEjB,kEAAkE;AAClE,yEAAyE;AACzE,4EAA4E;AAC5E,SAAgB,4BAA4B,CACxC,SAAwB,EACxB,SAAyB,EACzB,OAA2B,EAC3B,IAAe,EACf,mBAA4B,EAC5B,gBAA8C;;IAE9C,uEAAuE;IACvE,yEAAyE;IACzE,mCAAmC;IACnC,MAAM,eAAe,GAAG,qBAAqB,CACzC,SAAS,EACT,SAAS,EACT,OAAO,EACP,IAAI,EACJ,mBAAmB,EACnB,gBAAgB,CACnB,CAAC;IACF,IAAI,eAAe,EAAE;QACjB,OAAO,eAAe,CAAC;KAC1B;IAED,mEAAmE;IACnE,MAAM,aAAa,GAAG,SAAS,CAAC,wBAAwB,CACpD,SAAS,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AC;IAEvD,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC,SAAS,IAAI,SAAS,CAAC,OAAO,CAAC,SAAS,EAAE;QACvE,mBAAmB,CAAC,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC;KACvE;IAED,OAAO,mBAAmB,CAAC;AAC/B,CAAC;AAlID,sEAkIC;AAED,0EAA0E;AAC1E,iEAAiE;AACjE,SAAS,0BAA0B,CAAC,IAAU;IAC1C,OAAO,IAAA,kBAAU,EAAC,IAAI,CAAC,IAAI,oBAAY,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC;AACzE,CAAC"}
@@ -30,9 +30,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
30
30
  Object.defineProperty(exports, "__esModule", { value: true });
31
31
  exports.applyDataClassDecorator = exports.applyDataClassDefaultBehaviors = exports.applyDataClassClassBehaviorOverrides = exports.getDataclassDecoratorBehaviors = exports.validateDataClassTransformDecorator = exports.synthesizeDataClassMethods = void 0;
32
32
  const debug_1 = require("../common/debug");
33
+ const diagnostic_1 = require("../common/diagnostic");
33
34
  const diagnosticRules_1 = require("../common/diagnosticRules");
34
35
  const localize_1 = require("../localization/localize");
35
36
  const AnalyzerNodeInfo = __importStar(require("./analyzerNodeInfo"));
37
+ const constructors_1 = require("./constructors");
36
38
  const namedTuples_1 = require("./namedTuples");
37
39
  const parseTreeUtils_1 = require("./parseTreeUtils");
38
40
  const staticExpressions_1 = require("./staticExpressions");
@@ -118,6 +120,7 @@ function synthesizeDataClassMethods(evaluator, node, classType, skipSynthesizeIn
118
120
  let isKeywordOnly = types_1.ClassType.isDataClassKeywordOnlyParams(classType) || sawKeywordOnlySeparator;
119
121
  let defaultValueExpression;
120
122
  let includeInInit = true;
123
+ let converter;
121
124
  if (statement.nodeType === 3 /* Assignment */) {
122
125
  if (statement.leftExpression.nodeType === 54 /* TypeAnnotation */ &&
123
126
  statement.leftExpression.valueExpression.nodeType === 38 /* Name */) {
@@ -209,6 +212,10 @@ function synthesizeDataClassMethods(evaluator, node, classType, skipSynthesizeIn
209
212
  aliasName = valueType.literalValue;
210
213
  }
211
214
  }
215
+ const converterArg = statement.rightExpression.arguments.find((arg) => { var _a; return ((_a = arg.name) === null || _a === void 0 ? void 0 : _a.value) === 'converter'; });
216
+ if (converterArg && converterArg.valueExpression) {
217
+ converter = converterArg;
218
+ }
212
219
  }
213
220
  }
214
221
  }
@@ -258,6 +265,7 @@ function synthesizeDataClassMethods(evaluator, node, classType, skipSynthesizeIn
258
265
  nameNode: variableNameNode,
259
266
  type: types_1.UnknownType.create(),
260
267
  isClassVar: true,
268
+ converter,
261
269
  };
262
270
  localDataClassEntries.push(dataClassEntry);
263
271
  }
@@ -276,6 +284,7 @@ function synthesizeDataClassMethods(evaluator, node, classType, skipSynthesizeIn
276
284
  nameNode: variableNameNode,
277
285
  type: types_1.UnknownType.create(),
278
286
  isClassVar: false,
287
+ converter,
279
288
  };
280
289
  localEntryTypeEvaluator.push({ entry: dataClassEntry, evaluator: variableTypeEvaluator });
281
290
  // Add the new entry to the local entry list.
@@ -367,6 +376,9 @@ function synthesizeDataClassMethods(evaluator, node, classType, skipSynthesizeIn
367
376
  // Is the field type a descriptor object? If so, we need to extract the corresponding
368
377
  // type of the __init__ method parameter from the __set__ method.
369
378
  effectiveType = transformDescriptorType(evaluator, effectiveType);
379
+ if (entry.converter) {
380
+ effectiveType = getConverterInputType(evaluator, entry.converter, effectiveType, entry.name);
381
+ }
370
382
  const effectiveName = entry.alias || entry.name;
371
383
  if (!entry.alias && entry.nameNode && (0, symbolNameUtils_1.isPrivateName)(entry.nameNode.value)) {
372
384
  evaluator.addError(localize_1.Localizer.Diagnostic.dataClassFieldWithPrivateName(), entry.nameNode);
@@ -492,6 +504,78 @@ function synthesizeDataClassMethods(evaluator, node, classType, skipSynthesizeIn
492
504
  }
493
505
  }
494
506
  exports.synthesizeDataClassMethods = synthesizeDataClassMethods;
507
+ // Validates converter and, if valid, returns its input type. If invalid,
508
+ // fieldType is returned.
509
+ function getConverterInputType(evaluator, converterNode, fieldType, fieldName) {
510
+ var _a;
511
+ const converterType = getConverterAsFunction(evaluator, evaluator.getTypeOfExpression(converterNode.valueExpression).type);
512
+ if (!converterType) {
513
+ return fieldType;
514
+ }
515
+ // Create synthesized function of the form Callable[[T], fieldType] which
516
+ // will be used to check compatibility of the provided converter.
517
+ const typeVar = types_1.TypeVarType.createInstance('__converterInput');
518
+ typeVar.scopeId = (0, parseTreeUtils_1.getScopeIdForNode)(converterNode);
519
+ const targetFunction = types_1.FunctionType.createSynthesizedInstance('');
520
+ targetFunction.details.typeVarScopeId = typeVar.scopeId;
521
+ targetFunction.details.declaredReturnType = fieldType;
522
+ types_1.FunctionType.addParameter(targetFunction, {
523
+ category: 0 /* Simple */,
524
+ name: '__input',
525
+ type: typeVar,
526
+ hasDeclaredType: true,
527
+ });
528
+ types_1.FunctionType.addParameter(targetFunction, {
529
+ category: 0 /* Simple */,
530
+ name: '',
531
+ type: types_1.UnknownType.create(),
532
+ });
533
+ if ((0, types_1.isFunction)(converterType)) {
534
+ const typeVarContext = new typeVarContext_1.TypeVarContext(typeVar.scopeId);
535
+ const diagAddendum = new diagnostic_1.DiagnosticAddendum();
536
+ if (evaluator.assignType(targetFunction, converterType, diagAddendum, typeVarContext)) {
537
+ const solution = (0, typeUtils_1.applySolvedTypeVars)(typeVar, typeVarContext, { unknownIfNotFound: true });
538
+ return solution;
539
+ }
540
+ evaluator.addDiagnostic(AnalyzerNodeInfo.getFileInfo(converterNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.dataClassConverterFunction().format({
541
+ argType: evaluator.printType(converterType),
542
+ fieldType: evaluator.printType(fieldType),
543
+ fieldName: fieldName,
544
+ }) + diagAddendum.getString(), converterNode, (_a = diagAddendum.getEffectiveTextRange()) !== null && _a !== void 0 ? _a : converterNode);
545
+ }
546
+ else {
547
+ const acceptedTypes = [];
548
+ const diagAddendum = new diagnostic_1.DiagnosticAddendum();
549
+ types_1.OverloadedFunctionType.getOverloads(converterType).forEach((overload) => {
550
+ const typeVarContext = new typeVarContext_1.TypeVarContext(typeVar.scopeId);
551
+ if (evaluator.assignType(targetFunction, overload, diagAddendum, typeVarContext)) {
552
+ const overloadSolution = (0, typeUtils_1.applySolvedTypeVars)(typeVar, typeVarContext, { unknownIfNotFound: true });
553
+ acceptedTypes.push(overloadSolution);
554
+ }
555
+ });
556
+ if (acceptedTypes.length > 0) {
557
+ return (0, types_1.combineTypes)(acceptedTypes);
558
+ }
559
+ evaluator.addDiagnostic(AnalyzerNodeInfo.getFileInfo(converterNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.dataClassConverterOverloads().format({
560
+ funcName: converterType.overloads[0].details.name || '<anonymous function>',
561
+ fieldType: evaluator.printType(fieldType),
562
+ fieldName: fieldName,
563
+ }) + diagAddendum.getString(), converterNode);
564
+ }
565
+ return fieldType;
566
+ }
567
+ function getConverterAsFunction(evaluator, converterType) {
568
+ if ((0, types_1.isFunction)(converterType) || (0, types_1.isOverloadedFunction)(converterType)) {
569
+ return converterType;
570
+ }
571
+ if ((0, types_1.isClassInstance)(converterType)) {
572
+ return evaluator.getBoundMethod(converterType, '__call__');
573
+ }
574
+ if ((0, types_1.isInstantiableClass)(converterType)) {
575
+ return (0, constructors_1.createFunctionFromConstructor)(evaluator, converterType);
576
+ }
577
+ return undefined;
578
+ }
495
579
  // If the specified type is a descriptor — in particular, if it implements a
496
580
  // __set__ method, this method transforms the type into the input parameter
497
581
  // for the set method.