@zzzen/pyright-internal 1.2.0-dev.20240707 → 1.2.0-dev.20240721
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 +672 -655
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.d.ts +5 -3
- package/dist/analyzer/codeFlowEngine.js +112 -103
- 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 +70 -66
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constructorTransform.d.ts +1 -2
- package/dist/analyzer/constructorTransform.js +26 -27
- package/dist/analyzer/constructorTransform.js.map +1 -1
- package/dist/analyzer/constructors.d.ts +2 -2
- package/dist/analyzer/constructors.js +95 -190
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.js +110 -179
- 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 +78 -79
- 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 +194 -145
- 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 +30 -47
- package/dist/analyzer/parameterUtils.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.d.ts +1 -0
- package/dist/analyzer/parseTreeUtils.js +294 -272
- 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 +178 -145
- 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 +82 -147
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/protocols.js +29 -25
- 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 +15 -3
- 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 +2443 -2350
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +13 -9
- package/dist/analyzer/typeEvaluatorTypes.js +7 -1
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +212 -215
- 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 +30 -15
- package/dist/analyzer/typeUtils.js +534 -436
- 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 +97 -199
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +152 -106
- package/dist/analyzer/types.js +695 -496
- package/dist/analyzer/types.js.map +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js +34 -34
- 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 +36 -27
- 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.d.ts +10 -4
- package/dist/languageService/referencesProvider.js +30 -18
- package/dist/languageService/referencesProvider.js.map +1 -1
- package/dist/languageService/renameProvider.js +21 -4
- package/dist/languageService/renameProvider.js.map +1 -1
- package/dist/languageService/signatureHelpProvider.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 +4 -3
- package/dist/localization/localize.js +2 -1
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +0 -1
- package/dist/localization/package.nls.de.json +0 -1
- package/dist/localization/package.nls.en-us.json +2 -1
- package/dist/localization/package.nls.es.json +0 -1
- package/dist/localization/package.nls.fr.json +0 -1
- package/dist/localization/package.nls.it.json +0 -1
- package/dist/localization/package.nls.ja.json +0 -1
- package/dist/localization/package.nls.ko.json +0 -1
- package/dist/localization/package.nls.pl.json +0 -1
- package/dist/localization/package.nls.pt-br.json +0 -1
- package/dist/localization/package.nls.qps-ploc.json +0 -1
- package/dist/localization/package.nls.ru.json +0 -1
- package/dist/localization/package.nls.tr.json +0 -1
- package/dist/localization/package.nls.zh-cn.json +0 -1
- package/dist/localization/package.nls.zh-tw.json +0 -1
- package/dist/parser/parseNodes.d.ts +471 -402
- package/dist/parser/parseNodes.js +629 -356
- package/dist/parser/parseNodes.js.map +1 -1
- package/dist/parser/parser.d.ts +1 -0
- package/dist/parser/parser.js +345 -300
- 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/fourslash/rename.args.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/rename.args.fourslash.js +71 -0
- package/dist/tests/fourslash/rename.args.fourslash.js.map +1 -0
- package/dist/tests/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/typeEvaluator1.test.js +17 -0
- package/dist/tests/typeEvaluator1.test.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +4 -0
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +8 -3
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +10 -6
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator6.test.js +6 -2
- package/dist/tests/typeEvaluator6.test.js.map +1 -1
- package/dist/tests/typeEvaluator7.test.js +7 -3
- 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
@@ -17,10 +17,7 @@ exports.createFunctionFromConstructor = exports.validateConstructorArguments = e
|
|
17
17
|
const collectionUtils_1 = require("../common/collectionUtils");
|
18
18
|
const diagnostic_1 = require("../common/diagnostic");
|
19
19
|
const diagnosticRules_1 = require("../common/diagnosticRules");
|
20
|
-
const localize_1 = require("../localization/localize");
|
21
|
-
const constraintSolver_1 = require("./constraintSolver");
|
22
20
|
const constructorTransform_1 = require("./constructorTransform");
|
23
|
-
const parseTreeUtils_1 = require("./parseTreeUtils");
|
24
21
|
const typeUtils_1 = require("./typeUtils");
|
25
22
|
const typeVarContext_1 = require("./typeVarContext");
|
26
23
|
const types_1 = require("./types");
|
@@ -50,11 +47,18 @@ exports.getBoundCallMethod = getBoundCallMethod;
|
|
50
47
|
// Matches the arguments of a call to the constructor for a class.
|
51
48
|
// If successful, it returns the resulting (specialized) object type that
|
52
49
|
// is allocated by the constructor. If unsuccessful, it reports diagnostics.
|
53
|
-
function validateConstructorArguments(evaluator, errorNode, argList, type, skipUnknownArgCheck, inferenceContext
|
54
|
-
var _a;
|
55
|
-
|
50
|
+
function validateConstructorArguments(evaluator, errorNode, argList, type, skipUnknownArgCheck, inferenceContext) {
|
51
|
+
var _a, _b;
|
52
|
+
// If this is an unspecialized generic type alias, specialize it now
|
53
|
+
// using default type argument values.
|
54
|
+
const aliasInfo = (_a = type.props) === null || _a === void 0 ? void 0 : _a.typeAliasInfo;
|
55
|
+
if ((aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.typeParameters) && !aliasInfo.typeArguments) {
|
56
|
+
const typeAliasTypeVarContext = new typeVarContext_1.TypeVarContext(aliasInfo.typeVarScopeId);
|
57
|
+
type = (0, typeUtils_1.applySolvedTypeVars)(type, typeAliasTypeVarContext, { unknownIfNotFound: true });
|
58
|
+
}
|
59
|
+
const metaclassResult = validateMetaclassCall(evaluator, errorNode, argList, type, skipUnknownArgCheck, inferenceContext);
|
56
60
|
if (metaclassResult) {
|
57
|
-
const metaclassReturnType = (
|
61
|
+
const metaclassReturnType = (_b = metaclassResult.returnType) !== null && _b !== void 0 ? _b : types_1.UnknownType.create();
|
58
62
|
// If there a custom `__call__` method on the metaclass that returns
|
59
63
|
// something other than an instance of the class, assume that it
|
60
64
|
// overrides the normal `type.__call__` logic and don't perform the usual
|
@@ -73,7 +77,7 @@ function validateConstructorArguments(evaluator, errorNode, argList, type, skipU
|
|
73
77
|
// If there is a constructor transform, evaluate all arguments speculatively
|
74
78
|
// so we can later re-evaluate them in the context of the transform.
|
75
79
|
const returnResult = evaluator.useSpeculativeMode(useConstructorTransform ? errorNode : undefined, () => {
|
76
|
-
return validateNewAndInitMethods(evaluator, errorNode, argList, type, skipUnknownArgCheck, inferenceContext,
|
80
|
+
return validateNewAndInitMethods(evaluator, errorNode, argList, type, skipUnknownArgCheck, inferenceContext, newMethodTypeResult);
|
77
81
|
});
|
78
82
|
let validatedArgExpressions = !useConstructorTransform || returnResult.argumentErrors;
|
79
83
|
// Apply a constructor transform if applicable.
|
@@ -82,7 +86,7 @@ function validateConstructorArguments(evaluator, errorNode, argList, type, skipU
|
|
82
86
|
// If there were errors when validating the __new__ and __init__ methods,
|
83
87
|
// we need to re-evaluate the arguments to generate error messages because
|
84
88
|
// we previously evaluated them speculatively.
|
85
|
-
validateNewAndInitMethods(evaluator, errorNode, argList, type, skipUnknownArgCheck, inferenceContext,
|
89
|
+
validateNewAndInitMethods(evaluator, errorNode, argList, type, skipUnknownArgCheck, inferenceContext, newMethodTypeResult);
|
86
90
|
validatedArgExpressions = true;
|
87
91
|
}
|
88
92
|
else if (returnResult.returnType) {
|
@@ -90,7 +94,7 @@ function validateConstructorArguments(evaluator, errorNode, argList, type, skipU
|
|
90
94
|
argumentErrors: !!returnResult.argumentErrors,
|
91
95
|
returnType: returnResult.returnType,
|
92
96
|
isTypeIncomplete: !!returnResult.isTypeIncomplete,
|
93
|
-
}
|
97
|
+
});
|
94
98
|
returnResult.returnType = transformed.returnType;
|
95
99
|
if (transformed.isTypeIncomplete) {
|
96
100
|
returnResult.isTypeIncomplete = true;
|
@@ -113,7 +117,7 @@ function validateConstructorArguments(evaluator, errorNode, argList, type, skipU
|
|
113
117
|
return returnResult;
|
114
118
|
}
|
115
119
|
exports.validateConstructorArguments = validateConstructorArguments;
|
116
|
-
function validateNewAndInitMethods(evaluator, errorNode, argList, type, skipUnknownArgCheck, inferenceContext,
|
120
|
+
function validateNewAndInitMethods(evaluator, errorNode, argList, type, skipUnknownArgCheck, inferenceContext, newMethodTypeResult) {
|
117
121
|
var _a, _b;
|
118
122
|
let returnType;
|
119
123
|
let validatedArgExpressions = false;
|
@@ -125,7 +129,7 @@ function validateNewAndInitMethods(evaluator, errorNode, argList, type, skipUnkn
|
|
125
129
|
if (newMethodTypeResult) {
|
126
130
|
// Use speculative mode for arg expressions because we don't know whether
|
127
131
|
// we'll need to re-evaluate these expressions later for __init__.
|
128
|
-
const newCallResult = validateNewMethod(evaluator, errorNode, argList, type, skipUnknownArgCheck, inferenceContext,
|
132
|
+
const newCallResult = validateNewMethod(evaluator, errorNode, argList, type, skipUnknownArgCheck, inferenceContext, newMethodTypeResult,
|
129
133
|
/* useSpeculativeModeForArgs */ true);
|
130
134
|
if (newCallResult.argumentErrors) {
|
131
135
|
argumentErrors = true;
|
@@ -166,8 +170,8 @@ function validateNewAndInitMethods(evaluator, errorNode, argList, type, skipUnkn
|
|
166
170
|
// but didn't supply solved type arguments, we'll ignore its specialized return
|
167
171
|
// type and rely on the __init__ method to supply the type arguments instead.
|
168
172
|
let initMethodBindToType = newMethodReturnType;
|
169
|
-
if (initMethodBindToType.typeArguments &&
|
170
|
-
initMethodBindToType.typeArguments.some((typeArg) => (0, types_1.isUnknown)(typeArg))) {
|
173
|
+
if (initMethodBindToType.priv.typeArguments &&
|
174
|
+
initMethodBindToType.priv.typeArguments.some((typeArg) => (0, types_1.isUnknown)(typeArg))) {
|
171
175
|
initMethodBindToType = types_1.ClassType.cloneAsInstance(type);
|
172
176
|
}
|
173
177
|
// Determine whether the class overrides the object.__init__ method.
|
@@ -178,7 +182,7 @@ function validateNewAndInitMethods(evaluator, errorNode, argList, type, skipUnkn
|
|
178
182
|
}
|
179
183
|
// Validate __init__ if it's present.
|
180
184
|
if (initMethodTypeResult) {
|
181
|
-
const initCallResult = validateInitMethod(evaluator, errorNode, argList, initMethodBindToType, skipUnknownArgCheck, inferenceContext,
|
185
|
+
const initCallResult = validateInitMethod(evaluator, errorNode, argList, initMethodBindToType, skipUnknownArgCheck, inferenceContext, initMethodTypeResult.type);
|
182
186
|
if (initCallResult.argumentErrors) {
|
183
187
|
argumentErrors = true;
|
184
188
|
}
|
@@ -197,7 +201,7 @@ function validateNewAndInitMethods(evaluator, errorNode, argList, type, skipUnkn
|
|
197
201
|
// If we skipped the __init__ method and the __new__ method was evaluated only
|
198
202
|
// speculatively, evaluate it non-speculatively now so we can report errors.
|
199
203
|
if (!evaluator.isSpeculativeModeInUse(errorNode)) {
|
200
|
-
validateNewMethod(evaluator, errorNode, argList, type, skipUnknownArgCheck, inferenceContext,
|
204
|
+
validateNewMethod(evaluator, errorNode, argList, type, skipUnknownArgCheck, inferenceContext, newMethodTypeResult,
|
201
205
|
/* useSpeculativeModeForArgs */ false);
|
202
206
|
}
|
203
207
|
validatedArgExpressions = true;
|
@@ -223,21 +227,15 @@ function validateNewAndInitMethods(evaluator, errorNode, argList, type, skipUnkn
|
|
223
227
|
// Evaluates the __new__ method for type correctness. If useSpeculativeModeForArgs
|
224
228
|
// is true, use speculative mode to evaluate the arguments (unless an argument
|
225
229
|
// error is produced, in which case it's OK to use speculative mode).
|
226
|
-
function validateNewMethod(evaluator, errorNode, argList, type, skipUnknownArgCheck, inferenceContext,
|
230
|
+
function validateNewMethod(evaluator, errorNode, argList, type, skipUnknownArgCheck, inferenceContext, newMethodTypeResult, useSpeculativeModeForArgs) {
|
227
231
|
let newReturnType;
|
228
232
|
let isTypeIncomplete = false;
|
229
233
|
let argumentErrors = false;
|
230
234
|
const overloadsUsedForCall = [];
|
231
|
-
if (signatureTracker) {
|
232
|
-
newMethodTypeResult.type = (0, typeUtils_1.ensureFunctionSignaturesAreUnique)(newMethodTypeResult.type, signatureTracker, errorNode.start);
|
233
|
-
}
|
234
235
|
const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(type));
|
235
236
|
typeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeId)(newMethodTypeResult.type));
|
236
|
-
if (type.typeAliasInfo) {
|
237
|
-
typeVarContext.addSolveForScope(type.typeAliasInfo.typeVarScopeId);
|
238
|
-
}
|
239
237
|
const callResult = evaluator.useSpeculativeMode(useSpeculativeModeForArgs ? errorNode : undefined, () => {
|
240
|
-
return evaluator.validateCallArguments(errorNode, argList, newMethodTypeResult, typeVarContext, skipUnknownArgCheck, inferenceContext
|
238
|
+
return evaluator.validateCallArguments(errorNode, argList, newMethodTypeResult, typeVarContext, skipUnknownArgCheck, inferenceContext);
|
241
239
|
});
|
242
240
|
if (callResult.isTypeIncomplete) {
|
243
241
|
isTypeIncomplete = true;
|
@@ -246,7 +244,7 @@ function validateNewMethod(evaluator, errorNode, argList, type, skipUnknownArgCh
|
|
246
244
|
argumentErrors = true;
|
247
245
|
// Evaluate the arguments in a non-speculative manner to generate any diagnostics.
|
248
246
|
typeVarContext.unlock();
|
249
|
-
evaluator.validateCallArguments(errorNode, argList, newMethodTypeResult, typeVarContext, skipUnknownArgCheck, inferenceContext
|
247
|
+
evaluator.validateCallArguments(errorNode, argList, newMethodTypeResult, typeVarContext, skipUnknownArgCheck, inferenceContext);
|
250
248
|
}
|
251
249
|
else {
|
252
250
|
newReturnType = callResult.returnType;
|
@@ -257,10 +255,10 @@ function validateNewMethod(evaluator, errorNode, argList, type, skipUnknownArgCh
|
|
257
255
|
if (newReturnType) {
|
258
256
|
// Special-case the 'tuple' type specialization to use the homogenous
|
259
257
|
// arbitrary-length form.
|
260
|
-
if ((0, types_1.isClassInstance)(newReturnType) && (0, typeUtils_1.isTupleClass)(newReturnType) && !newReturnType.tupleTypeArguments) {
|
261
|
-
if (newReturnType.typeArguments && newReturnType.typeArguments.length === 1) {
|
258
|
+
if ((0, types_1.isClassInstance)(newReturnType) && (0, typeUtils_1.isTupleClass)(newReturnType) && !newReturnType.priv.tupleTypeArguments) {
|
259
|
+
if (newReturnType.priv.typeArguments && newReturnType.priv.typeArguments.length === 1) {
|
262
260
|
newReturnType = (0, typeUtils_1.specializeTupleClass)(newReturnType, [
|
263
|
-
{ type: newReturnType.typeArguments[0], isUnbounded: true },
|
261
|
+
{ type: newReturnType.priv.typeArguments[0], isUnbounded: true },
|
264
262
|
]);
|
265
263
|
}
|
266
264
|
newReturnType = applyExpectedTypeForTupleConstructor(newReturnType, inferenceContext);
|
@@ -271,153 +269,60 @@ function validateNewMethod(evaluator, errorNode, argList, type, skipUnknownArgCh
|
|
271
269
|
}
|
272
270
|
return { argumentErrors, returnType: newReturnType, isTypeIncomplete, overloadsUsedForCall };
|
273
271
|
}
|
274
|
-
function validateInitMethod(evaluator, errorNode, argList, type, skipUnknownArgCheck, inferenceContext,
|
275
|
-
let returnType;
|
272
|
+
function validateInitMethod(evaluator, errorNode, argList, type, skipUnknownArgCheck, inferenceContext, initMethodType) {
|
276
273
|
let isTypeIncomplete = false;
|
277
274
|
let argumentErrors = false;
|
278
275
|
const overloadsUsedForCall = [];
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
expectedSubType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(expectedSubType);
|
296
|
-
// If the expected type is the same type as the class and the class
|
297
|
-
// is already explicitly specialized, don't override the explicit
|
298
|
-
// specialization.
|
299
|
-
if ((0, types_1.isClassInstance)(expectedSubType) &&
|
300
|
-
types_1.ClassType.isSameGenericClass(type, expectedSubType) &&
|
301
|
-
type.typeArguments) {
|
302
|
-
return undefined;
|
303
|
-
}
|
304
|
-
const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(type));
|
305
|
-
typeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeId)(initMethodType));
|
306
|
-
if (!(0, constraintSolver_1.addConstraintsForExpectedType)(evaluator, types_1.ClassType.cloneAsInstance(type), expectedSubType, typeVarContext, (0, parseTreeUtils_1.getTypeVarScopesForNode)(errorNode), errorNode.start)) {
|
307
|
-
return undefined;
|
308
|
-
}
|
309
|
-
const specializedConstructor = (0, typeUtils_1.applySolvedTypeVars)(initMethodType, typeVarContext);
|
310
|
-
let callResult;
|
311
|
-
callResult = evaluator.useSpeculativeMode(errorNode, () => {
|
312
|
-
return evaluator.validateCallArguments(errorNode, argList, { type: specializedConstructor }, typeVarContext.clone(), skipUnknownArgCheck,
|
313
|
-
/* inferenceContext */ undefined, signatureTracker);
|
314
|
-
});
|
315
|
-
if (callResult.argumentErrors) {
|
316
|
-
return undefined;
|
317
|
-
}
|
318
|
-
// Call validateCallArguments again, this time without speculative
|
319
|
-
// mode, so any errors are reported.
|
320
|
-
callResult = evaluator.validateCallArguments(errorNode, argList, { type: specializedConstructor }, typeVarContext, skipUnknownArgCheck,
|
321
|
-
/* inferenceContext */ undefined, signatureTracker);
|
322
|
-
if (callResult.isTypeIncomplete) {
|
323
|
-
isTypeIncomplete = true;
|
324
|
-
}
|
325
|
-
if (callResult.argumentErrors) {
|
326
|
-
argumentErrors = true;
|
327
|
-
}
|
328
|
-
if (callResult.overloadsUsedForCall) {
|
329
|
-
(0, collectionUtils_1.appendArray)(overloadsUsedForCall, callResult.overloadsUsedForCall);
|
330
|
-
}
|
331
|
-
// Note that we've found an expected type that works.
|
332
|
-
foundWorkingExpectedType = true;
|
333
|
-
return applyExpectedSubtypeForConstructor(evaluator, type, expectedSubType, typeVarContext);
|
334
|
-
},
|
335
|
-
/* sortSubtypes */ true);
|
336
|
-
if ((0, types_1.isNever)(returnType) || argumentErrors) {
|
337
|
-
returnType = undefined;
|
338
|
-
}
|
276
|
+
const typeVarContext = type.priv.typeArguments
|
277
|
+
? (0, typeUtils_1.buildTypeVarContextFromSpecializedClass)(type)
|
278
|
+
: new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(type));
|
279
|
+
typeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeId)(initMethodType));
|
280
|
+
const returnTypeOverride = (0, typeUtils_1.selfSpecializeClass)(type);
|
281
|
+
const callResult = evaluator.validateCallArguments(errorNode, argList, { type: initMethodType }, typeVarContext, skipUnknownArgCheck, inferenceContext ? { ...inferenceContext, returnTypeOverride } : undefined);
|
282
|
+
let adjustedClassType = type;
|
283
|
+
if (callResult.specializedInitSelfType &&
|
284
|
+
(0, types_1.isClassInstance)(callResult.specializedInitSelfType) &&
|
285
|
+
types_1.ClassType.isSameGenericClass(callResult.specializedInitSelfType, adjustedClassType)) {
|
286
|
+
adjustedClassType = types_1.ClassType.cloneAsInstantiable(callResult.specializedInitSelfType);
|
287
|
+
}
|
288
|
+
const returnType = applyExpectedTypeForConstructor(evaluator, adjustedClassType,
|
289
|
+
/* inferenceContext */ undefined, typeVarContext);
|
290
|
+
if (callResult.isTypeIncomplete) {
|
291
|
+
isTypeIncomplete = true;
|
339
292
|
}
|
340
|
-
if (
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
const callResult = evaluator.validateCallArguments(errorNode, argList, { type: initMethodType }, typeVarContext, skipUnknownArgCheck,
|
346
|
-
/* inferenceContext */ undefined, signatureTracker);
|
347
|
-
let adjustedClassType = type;
|
348
|
-
if (callResult.specializedInitSelfType &&
|
349
|
-
(0, types_1.isClassInstance)(callResult.specializedInitSelfType) &&
|
350
|
-
types_1.ClassType.isSameGenericClass(callResult.specializedInitSelfType, adjustedClassType)) {
|
351
|
-
adjustedClassType = types_1.ClassType.cloneAsInstantiable(callResult.specializedInitSelfType);
|
352
|
-
}
|
353
|
-
returnType = applyExpectedTypeForConstructor(evaluator, adjustedClassType,
|
354
|
-
/* inferenceContext */ undefined, typeVarContext);
|
355
|
-
if (callResult.isTypeIncomplete) {
|
356
|
-
isTypeIncomplete = true;
|
357
|
-
}
|
358
|
-
if (callResult.argumentErrors) {
|
359
|
-
argumentErrors = true;
|
360
|
-
}
|
361
|
-
else if (callResult.overloadsUsedForCall) {
|
362
|
-
overloadsUsedForCall.push(...callResult.overloadsUsedForCall);
|
363
|
-
}
|
293
|
+
if (callResult.argumentErrors) {
|
294
|
+
argumentErrors = true;
|
295
|
+
}
|
296
|
+
else if (callResult.overloadsUsedForCall) {
|
297
|
+
overloadsUsedForCall.push(...callResult.overloadsUsedForCall);
|
364
298
|
}
|
365
299
|
return { argumentErrors, returnType, isTypeIncomplete, overloadsUsedForCall };
|
366
300
|
}
|
367
301
|
function validateFallbackConstructorCall(evaluator, errorNode, argList, type, inferenceContext) {
|
368
|
-
|
369
|
-
//
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
};
|
382
|
-
}
|
383
|
-
// Do our best to specialize the instantiated class based on the expected
|
384
|
-
// type if provided.
|
385
|
-
const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(type));
|
386
|
-
if (inferenceContext) {
|
387
|
-
let expectedType = inferenceContext.expectedType;
|
388
|
-
// If the expectedType is a union, try to pick one that is likely to
|
389
|
-
// be the best choice.
|
390
|
-
if ((0, types_1.isUnion)(expectedType)) {
|
391
|
-
expectedType = (0, types_1.findSubtype)(expectedType, (subtype) => {
|
392
|
-
if ((0, types_1.isAnyOrUnknown)(subtype) || (0, types_1.isNever)(subtype)) {
|
393
|
-
return false;
|
394
|
-
}
|
395
|
-
if ((0, types_1.isClass)(subtype) && evaluator.assignType(subtype, types_1.ClassType.cloneAsInstance(type))) {
|
396
|
-
return true;
|
397
|
-
}
|
398
|
-
return false;
|
399
|
-
});
|
400
|
-
}
|
401
|
-
if (expectedType) {
|
402
|
-
(0, constraintSolver_1.addConstraintsForExpectedType)(evaluator, types_1.ClassType.cloneAsInstance(type), expectedType, typeVarContext, (0, parseTreeUtils_1.getTypeVarScopesForNode)(errorNode), errorNode.start);
|
403
|
-
}
|
404
|
-
}
|
405
|
-
return {
|
406
|
-
argumentErrors: reportedErrors,
|
407
|
-
overloadsUsedForCall: [],
|
408
|
-
returnType: applyExpectedTypeForConstructor(evaluator, type, inferenceContext, typeVarContext),
|
409
|
-
};
|
302
|
+
var _a;
|
303
|
+
// Bind the __new__ method from the object class.
|
304
|
+
const newMethodType = (_a = getBoundNewMethod(evaluator, errorNode, type,
|
305
|
+
/* diag */ undefined, 0 /* MemberAccessFlags.Default */)) === null || _a === void 0 ? void 0 : _a.type;
|
306
|
+
// If there was no object.__new__ or it's not a callable, then something has
|
307
|
+
// gone terribly wrong in the typeshed stubs. To avoid crashing, simply
|
308
|
+
// return the instance.
|
309
|
+
if (!newMethodType || (!(0, types_1.isFunction)(newMethodType) && !(0, types_1.isOverloadedFunction)(newMethodType))) {
|
310
|
+
return { returnType: (0, typeUtils_1.convertToInstance)(type) };
|
311
|
+
}
|
312
|
+
return validateNewMethod(evaluator, errorNode, argList, type,
|
313
|
+
/* skipUnknownArgCheck */ false, inferenceContext, { type: newMethodType },
|
314
|
+
/* useSpeculativeModeForArgs */ false);
|
410
315
|
}
|
411
|
-
function validateMetaclassCall(evaluator, errorNode, argList, type, skipUnknownArgCheck, inferenceContext
|
316
|
+
function validateMetaclassCall(evaluator, errorNode, argList, type, skipUnknownArgCheck, inferenceContext) {
|
412
317
|
const metaclassCallMethodInfo = getBoundCallMethod(evaluator, errorNode, type);
|
413
318
|
if (!metaclassCallMethodInfo) {
|
414
319
|
return undefined;
|
415
320
|
}
|
416
321
|
const callResult = evaluator.validateCallArguments(errorNode, argList, metaclassCallMethodInfo,
|
417
|
-
/* typeVarContext */ undefined, skipUnknownArgCheck, inferenceContext
|
322
|
+
/* typeVarContext */ undefined, skipUnknownArgCheck, inferenceContext);
|
418
323
|
// If the return type is unannotated, don't use the inferred return type.
|
419
324
|
const callType = metaclassCallMethodInfo.type;
|
420
|
-
if ((0, types_1.isFunction)(callType) && !callType.
|
325
|
+
if ((0, types_1.isFunction)(callType) && !callType.shared.declaredReturnType) {
|
421
326
|
return undefined;
|
422
327
|
}
|
423
328
|
// If the return type is unknown, ignore it.
|
@@ -445,7 +350,7 @@ function applyExpectedTypeForConstructor(evaluator, type, inferenceContext, type
|
|
445
350
|
let unsolvedTypeVarsAreUnknown = true;
|
446
351
|
// If this isn't a generic type or it's a type that has already been
|
447
352
|
// explicitly specialized, the expected type isn't applicable.
|
448
|
-
if (type.
|
353
|
+
if (type.shared.typeParameters.length === 0 || type.priv.typeArguments) {
|
449
354
|
return (0, typeUtils_1.applySolvedTypeVars)(types_1.ClassType.cloneAsInstance(type), typeVarContext, { applyInScopePlaceholders: true });
|
450
355
|
}
|
451
356
|
if (inferenceContext) {
|
@@ -458,7 +363,7 @@ function applyExpectedTypeForConstructor(evaluator, type, inferenceContext, type
|
|
458
363
|
// If the expected type didn't provide TypeVar values, remaining
|
459
364
|
// unsolved TypeVars should be considered Unknown unless they were
|
460
365
|
// provided explicitly in the constructor call.
|
461
|
-
if (type.typeArguments) {
|
366
|
+
if (type.priv.typeArguments) {
|
462
367
|
unsolvedTypeVarsAreUnknown = false;
|
463
368
|
}
|
464
369
|
}
|
@@ -475,8 +380,8 @@ function applyExpectedTypeForTupleConstructor(type, inferenceContext) {
|
|
475
380
|
if (inferenceContext &&
|
476
381
|
(0, types_1.isClassInstance)(inferenceContext.expectedType) &&
|
477
382
|
(0, typeUtils_1.isTupleClass)(inferenceContext.expectedType) &&
|
478
|
-
inferenceContext.expectedType.tupleTypeArguments) {
|
479
|
-
specializedType = (0, typeUtils_1.specializeTupleClass)(type, inferenceContext.expectedType.tupleTypeArguments);
|
383
|
+
inferenceContext.expectedType.priv.tupleTypeArguments) {
|
384
|
+
specializedType = (0, typeUtils_1.specializeTupleClass)(type, inferenceContext.expectedType.priv.tupleTypeArguments);
|
480
385
|
}
|
481
386
|
return specializedType;
|
482
387
|
}
|
@@ -513,7 +418,7 @@ function createFunctionFromConstructor(evaluator, classType, selfType = undefine
|
|
513
418
|
}
|
514
419
|
exports.createFunctionFromConstructor = createFunctionFromConstructor;
|
515
420
|
function createFunctionFromMetaclassCall(evaluator, classType, recursionCount) {
|
516
|
-
const metaclass = classType.
|
421
|
+
const metaclass = classType.shared.effectiveMetaclass;
|
517
422
|
if (!metaclass || !(0, types_1.isClass)(metaclass)) {
|
518
423
|
return undefined;
|
519
424
|
}
|
@@ -538,7 +443,7 @@ function createFunctionFromMetaclassCall(evaluator, classType, recursionCount) {
|
|
538
443
|
// any of them returns something other than the instance of the class being
|
539
444
|
// constructed.
|
540
445
|
(0, typeUtils_1.doForEachSignature)(boundCallType, (signature) => {
|
541
|
-
if (signature.
|
446
|
+
if (signature.shared.declaredReturnType) {
|
542
447
|
const returnType = types_1.FunctionType.getEffectiveReturnType(signature);
|
543
448
|
if (returnType && shouldSkipNewAndInitEvaluation(evaluator, classType, returnType)) {
|
544
449
|
useMetaclassCall = true;
|
@@ -559,13 +464,13 @@ function createFunctionFromNewMethod(evaluator, classType, selfType, recursionCo
|
|
559
464
|
// If there are no parameters that include class-scoped type parameters,
|
560
465
|
// self-specialize the class because the type arguments for the class
|
561
466
|
// can't be solved if there are no parameters to supply them.
|
562
|
-
const hasParametersWithTypeVars = newSubtype.
|
467
|
+
const hasParametersWithTypeVars = newSubtype.shared.parameters.some((param, index) => {
|
563
468
|
if (index === 0 || !param.name) {
|
564
469
|
return false;
|
565
470
|
}
|
566
471
|
const paramType = types_1.FunctionType.getEffectiveParameterType(newSubtype, index);
|
567
472
|
const typeVars = (0, typeUtils_1.getTypeVarArgumentsRecursive)(paramType);
|
568
|
-
return typeVars.some((typeVar) => typeVar.scopeId === (0, typeUtils_1.getTypeVarScopeId)(classType));
|
473
|
+
return typeVars.some((typeVar) => typeVar.priv.scopeId === (0, typeUtils_1.getTypeVarScopeId)(classType));
|
569
474
|
});
|
570
475
|
const boundNew = evaluator.bindFunctionToClassOrObject(hasParametersWithTypeVars ? (0, typeUtils_1.selfSpecializeClass)(classType) : classType, newSubtype, newInfo && (0, types_1.isInstantiableClass)(newInfo.classType) ? newInfo.classType : undefined,
|
571
476
|
/* treatConstructorAsClassMethod */ true, selfType,
|
@@ -574,12 +479,12 @@ function createFunctionFromNewMethod(evaluator, classType, selfType, recursionCo
|
|
574
479
|
return undefined;
|
575
480
|
}
|
576
481
|
const convertedNew = types_1.FunctionType.clone(boundNew);
|
577
|
-
convertedNew.
|
578
|
-
if (!convertedNew.
|
579
|
-
convertedNew.
|
482
|
+
convertedNew.shared.typeVarScopeId = newSubtype.shared.typeVarScopeId;
|
483
|
+
if (!convertedNew.shared.docString && classType.shared.docString) {
|
484
|
+
convertedNew.shared.docString = classType.shared.docString;
|
580
485
|
}
|
581
|
-
convertedNew.
|
582
|
-
convertedNew.
|
486
|
+
convertedNew.shared.flags &= ~(4 /* FunctionTypeFlags.StaticMethod */ | 1 /* FunctionTypeFlags.ConstructorMethod */);
|
487
|
+
convertedNew.priv.constructorTypeVarScopeId = (0, typeUtils_1.getTypeVarScopeId)(classType);
|
583
488
|
return convertedNew;
|
584
489
|
};
|
585
490
|
if ((0, types_1.isFunction)(newType)) {
|
@@ -589,7 +494,7 @@ function createFunctionFromNewMethod(evaluator, classType, selfType, recursionCo
|
|
589
494
|
return undefined;
|
590
495
|
}
|
591
496
|
const newOverloads = [];
|
592
|
-
newType.overloads.forEach((overload) => {
|
497
|
+
newType.priv.overloads.forEach((overload) => {
|
593
498
|
const converted = convertNewToConstructor(overload);
|
594
499
|
if (converted) {
|
595
500
|
newOverloads.push(converted);
|
@@ -606,14 +511,14 @@ function createFunctionFromNewMethod(evaluator, classType, selfType, recursionCo
|
|
606
511
|
function createFunctionFromObjectNewMethod(classType) {
|
607
512
|
// Return a fallback constructor based on the object.__new__ method.
|
608
513
|
const constructorFunction = types_1.FunctionType.createSynthesizedInstance('__new__', 0 /* FunctionTypeFlags.None */);
|
609
|
-
constructorFunction.
|
514
|
+
constructorFunction.shared.declaredReturnType = types_1.ClassType.cloneAsInstance(classType);
|
610
515
|
// If this is type[T] or a protocol, we don't know what parameters are accepted
|
611
516
|
// by the constructor, so add the default parameters.
|
612
|
-
if (classType.includeSubclasses || types_1.ClassType.isProtocolClass(classType)) {
|
517
|
+
if (classType.priv.includeSubclasses || types_1.ClassType.isProtocolClass(classType)) {
|
613
518
|
types_1.FunctionType.addDefaultParameters(constructorFunction);
|
614
519
|
}
|
615
|
-
if (!constructorFunction.
|
616
|
-
constructorFunction.
|
520
|
+
if (!constructorFunction.shared.docString && classType.shared.docString) {
|
521
|
+
constructorFunction.shared.docString = classType.shared.docString;
|
617
522
|
}
|
618
523
|
return constructorFunction;
|
619
524
|
}
|
@@ -641,12 +546,12 @@ function createFunctionFromInitMethod(evaluator, classType, selfType, recursionC
|
|
641
546
|
returnType = objectType;
|
642
547
|
// If this is a generic type, self-specialize the class (i.e. fill in
|
643
548
|
// its own type parameters as type arguments).
|
644
|
-
if (objectType.
|
549
|
+
if (objectType.shared.typeParameters.length > 0 && !objectType.priv.typeArguments) {
|
645
550
|
const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeIds)(objectType));
|
646
551
|
// If a TypeVar is not used in any of the parameter types, it should take
|
647
552
|
// on its default value (typically Unknown) in the resulting specialized type.
|
648
553
|
const typeVarsInParams = [];
|
649
|
-
convertedInit.
|
554
|
+
convertedInit.shared.parameters.forEach((param, index) => {
|
650
555
|
const paramType = types_1.FunctionType.getEffectiveParameterType(convertedInit, index);
|
651
556
|
(0, typeUtils_1.addTypeVarsToListIfUnique)(typeVarsInParams, (0, typeUtils_1.getTypeVarArgumentsRecursive)(paramType));
|
652
557
|
});
|
@@ -664,15 +569,15 @@ function createFunctionFromInitMethod(evaluator, classType, selfType, recursionC
|
|
664
569
|
});
|
665
570
|
}
|
666
571
|
}
|
667
|
-
convertedInit.
|
668
|
-
if (convertedInit.specializedTypes) {
|
669
|
-
convertedInit.specializedTypes.returnType = returnType;
|
572
|
+
convertedInit.shared.declaredReturnType = (_a = boundInit.priv.strippedFirstParamType) !== null && _a !== void 0 ? _a : returnType;
|
573
|
+
if (convertedInit.priv.specializedTypes) {
|
574
|
+
convertedInit.priv.specializedTypes.returnType = returnType;
|
670
575
|
}
|
671
|
-
if (!convertedInit.
|
672
|
-
convertedInit.
|
576
|
+
if (!convertedInit.shared.docString && classType.shared.docString) {
|
577
|
+
convertedInit.shared.docString = classType.shared.docString;
|
673
578
|
}
|
674
|
-
convertedInit.
|
675
|
-
convertedInit.
|
579
|
+
convertedInit.shared.flags &= ~4 /* FunctionTypeFlags.StaticMethod */;
|
580
|
+
convertedInit.priv.constructorTypeVarScopeId = (0, typeUtils_1.getTypeVarScopeId)(classType);
|
676
581
|
return convertedInit;
|
677
582
|
}
|
678
583
|
if ((0, types_1.isFunction)(initType)) {
|
@@ -682,7 +587,7 @@ function createFunctionFromInitMethod(evaluator, classType, selfType, recursionC
|
|
682
587
|
return undefined;
|
683
588
|
}
|
684
589
|
const initOverloads = [];
|
685
|
-
initType.overloads.forEach((overload) => {
|
590
|
+
initType.priv.overloads.forEach((overload) => {
|
686
591
|
const converted = convertInitToConstructor(overload);
|
687
592
|
if (converted) {
|
688
593
|
initOverloads.push(converted);
|
@@ -740,15 +645,15 @@ function isDefaultNewMethod(newMethod) {
|
|
740
645
|
if (!newMethod || !(0, types_1.isFunction)(newMethod)) {
|
741
646
|
return false;
|
742
647
|
}
|
743
|
-
const params = newMethod.
|
648
|
+
const params = newMethod.shared.parameters;
|
744
649
|
if (params.length !== 2) {
|
745
650
|
return false;
|
746
651
|
}
|
747
652
|
if (params[0].category !== 1 /* ParameterCategory.ArgsList */ || params[1].category !== 2 /* ParameterCategory.KwargsDict */) {
|
748
653
|
return false;
|
749
654
|
}
|
750
|
-
const returnType = (_a = newMethod.
|
751
|
-
if (!returnType || !(0, types_1.isTypeVar)(returnType) || !returnType.
|
655
|
+
const returnType = (_a = newMethod.shared.declaredReturnType) !== null && _a !== void 0 ? _a : newMethod.priv.inferredReturnType;
|
656
|
+
if (!returnType || !(0, types_1.isTypeVar)(returnType) || !returnType.shared.isSynthesizedSelf) {
|
752
657
|
return false;
|
753
658
|
}
|
754
659
|
return true;
|