@zzzen/pyright-internal 1.2.0-dev.20231008 → 1.2.0-dev.20231022
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/checker.js +33 -37
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.js +2 -2
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +262 -168
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constructors.js +3 -4
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/decorators.js +3 -1
- package/dist/analyzer/decorators.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.d.ts +1 -1
- package/dist/analyzer/patternMatching.js +4 -0
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.js +7 -1
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/properties.d.ts +2 -2
- package/dist/analyzer/properties.js +10 -4
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/protocols.js +119 -174
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/service.js +13 -13
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceFile.d.ts +3 -2
- package/dist/analyzer/sourceFile.js +31 -11
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/sourceFileInfo.d.ts +4 -4
- package/dist/analyzer/sourceFileInfo.js +2 -0
- package/dist/analyzer/sourceFileInfo.js.map +1 -1
- package/dist/analyzer/staticExpressions.js +2 -1
- package/dist/analyzer/staticExpressions.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +138 -123
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +4 -3
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +101 -33
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.js +4 -1
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +13 -2
- package/dist/analyzer/typeUtils.js +130 -51
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typeVarContext.d.ts +4 -1
- package/dist/analyzer/typeVarContext.js +7 -2
- package/dist/analyzer/typeVarContext.js.map +1 -1
- package/dist/analyzer/typedDicts.js +99 -27
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +6 -2
- package/dist/analyzer/types.js +49 -17
- package/dist/analyzer/types.js.map +1 -1
- package/dist/backgroundThreadBase.js +5 -1
- package/dist/backgroundThreadBase.js.map +1 -1
- package/dist/common/configOptions.d.ts +2 -1
- package/dist/common/configOptions.js +9 -5
- package/dist/common/configOptions.js.map +1 -1
- package/dist/common/extensibility.d.ts +0 -2
- package/dist/common/extensibility.js.map +1 -1
- package/dist/common/fileSystem.d.ts +9 -4
- package/dist/common/fileSystem.js +8 -1
- package/dist/common/fileSystem.js.map +1 -1
- package/dist/common/pathUtils.d.ts +8 -5
- package/dist/common/pathUtils.js +90 -33
- package/dist/common/pathUtils.js.map +1 -1
- package/dist/common/realFileSystem.d.ts +7 -1
- package/dist/common/realFileSystem.js +35 -22
- package/dist/common/realFileSystem.js.map +1 -1
- package/dist/common/serviceProviderExtensions.d.ts +3 -4
- package/dist/common/serviceProviderExtensions.js +3 -6
- package/dist/common/serviceProviderExtensions.js.map +1 -1
- package/dist/common/uriParser.d.ts +10 -1
- package/dist/common/uriParser.js.map +1 -1
- package/dist/languageServerBase.d.ts +4 -4
- package/dist/languageServerBase.js +3 -17
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/autoImporter.d.ts +1 -1
- package/dist/languageService/completionProvider.d.ts +2 -2
- package/dist/languageService/completionProvider.js +20 -23
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/hoverProvider.d.ts +6 -2
- package/dist/languageService/hoverProvider.js +33 -65
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/navigationUtils.d.ts +1 -1
- package/dist/languageService/navigationUtils.js +2 -2
- package/dist/languageService/navigationUtils.js.map +1 -1
- package/dist/languageService/referencesProvider.d.ts +9 -2
- package/dist/languageService/referencesProvider.js +19 -12
- package/dist/languageService/referencesProvider.js.map +1 -1
- package/dist/languageService/tooltipUtils.js +1 -3
- package/dist/languageService/tooltipUtils.js.map +1 -1
- package/dist/localization/localize.d.ts +4 -3
- package/dist/localization/localize.js +1 -1
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +7 -1
- package/dist/localization/package.nls.de.json +7 -1
- package/dist/localization/package.nls.en-us.json +1 -1
- package/dist/localization/package.nls.es.json +7 -1
- package/dist/localization/package.nls.fr.json +7 -1
- package/dist/localization/package.nls.it.json +7 -1
- package/dist/localization/package.nls.ja.json +7 -1
- package/dist/localization/package.nls.ko.json +7 -1
- package/dist/localization/package.nls.pl.json +7 -1
- package/dist/localization/package.nls.pt-br.json +7 -1
- package/dist/localization/package.nls.qps-ploc.json +7 -1
- package/dist/localization/package.nls.ru.json +7 -1
- package/dist/localization/package.nls.tr.json +7 -1
- package/dist/localization/package.nls.zh-cn.json +7 -1
- package/dist/localization/package.nls.zh-tw.json +7 -1
- package/dist/pyright.js +2 -1
- package/dist/pyright.js.map +1 -1
- package/dist/pyrightFileSystem.d.ts +1 -16
- package/dist/pyrightFileSystem.js +1 -60
- package/dist/pyrightFileSystem.js.map +1 -1
- package/dist/readonlyAugmentedFileSystem.d.ts +1 -4
- package/dist/readonlyAugmentedFileSystem.js +0 -10
- package/dist/readonlyAugmentedFileSystem.js.map +1 -1
- package/dist/server.js +2 -1
- package/dist/server.js.map +1 -1
- package/dist/tests/config.test.js +5 -3
- package/dist/tests/config.test.js.map +1 -1
- package/dist/tests/fourslash/completions.indexer.keys.getitem.fourslash.js +56 -10
- package/dist/tests/fourslash/completions.indexer.keys.getitem.fourslash.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.d.ts +5 -2
- package/dist/tests/harness/fourslash/testState.js +13 -14
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/harness/vfs/filesystem.d.ts +2 -2
- package/dist/tests/harness/vfs/filesystem.js +4 -0
- package/dist/tests/harness/vfs/filesystem.js.map +1 -1
- package/dist/tests/harness/vfs/pathValidation.js +10 -1
- package/dist/tests/harness/vfs/pathValidation.js.map +1 -1
- package/dist/tests/importResolver.test.js +0 -9
- package/dist/tests/importResolver.test.js.map +1 -1
- package/dist/tests/pathUtils.test.js +2 -2
- package/dist/tests/pathUtils.test.js.map +1 -1
- package/dist/tests/pyrightFileSystem.test.js +0 -20
- package/dist/tests/pyrightFileSystem.test.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +4 -0
- package/dist/tests/typeEvaluator1.test.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +14 -2
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +5 -1
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +10 -2
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator5.test.js +7 -1
- package/dist/tests/typeEvaluator5.test.js.map +1 -1
- package/package.json +1 -1
@@ -1284,7 +1284,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1284
1284
|
128 /* SkipAttributeAccessOverride */, types_1.ClassType.cloneAsInstantiable(objectType));
|
1285
1285
|
}
|
1286
1286
|
}
|
1287
|
-
if (memberInfo) {
|
1287
|
+
if (memberInfo && !memberInfo.isSetTypeError) {
|
1288
1288
|
return {
|
1289
1289
|
type: memberInfo.type,
|
1290
1290
|
classType: memberInfo.classType,
|
@@ -1337,7 +1337,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1337
1337
|
/* isAccessedThroughObject */ true, memberName, usage, metaclassDiag, memberAccessFlags, classType);
|
1338
1338
|
}
|
1339
1339
|
}
|
1340
|
-
if (memberInfo) {
|
1340
|
+
if (memberInfo && !memberInfo.isSetTypeError) {
|
1341
1341
|
return {
|
1342
1342
|
type: memberInfo.type,
|
1343
1343
|
isIncomplete: !!memberInfo.isTypeIncomplete,
|
@@ -1358,8 +1358,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1358
1358
|
const unboundMethodType = getTypeOfMember(memberInfo);
|
1359
1359
|
if ((0, types_1.isFunction)(unboundMethodType) || (0, types_1.isOverloadedFunction)(unboundMethodType)) {
|
1360
1360
|
const boundMethod = bindFunctionToClassOrObject(types_1.ClassType.cloneAsInstance(classType), unboundMethodType,
|
1361
|
-
/* memberClass */ undefined,
|
1362
|
-
/*
|
1361
|
+
/* memberClass */ undefined, treatConstructorAsClassMember,
|
1362
|
+
/* firstParamType */ undefined,
|
1363
|
+
/* diag */ undefined, recursionCount);
|
1363
1364
|
if (boundMethod) {
|
1364
1365
|
return boundMethod;
|
1365
1366
|
}
|
@@ -1574,8 +1575,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1574
1575
|
if (setItemMember) {
|
1575
1576
|
const setItemType = getTypeOfMember(setItemMember);
|
1576
1577
|
if ((0, types_1.isFunction)(setItemType)) {
|
1577
|
-
const boundFunction =
|
1578
|
-
/* recursionCount */ undefined,
|
1578
|
+
const boundFunction = bindFunctionToClassOrObjectWithErrors(baseType, setItemType, (0, types_1.isInstantiableClass)(setItemMember.classType) ? setItemMember.classType : undefined, expression,
|
1579
1579
|
/* treatConstructorAsClassMember */ false);
|
1580
1580
|
if (boundFunction && (0, types_1.isFunction)(boundFunction)) {
|
1581
1581
|
if (boundFunction.details.parameters.length >= 2) {
|
@@ -1621,8 +1621,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1621
1621
|
}
|
1622
1622
|
if ((0, types_1.isFunction)(declaredType) || (0, types_1.isOverloadedFunction)(declaredType)) {
|
1623
1623
|
if (bindFunction) {
|
1624
|
-
declaredType =
|
1625
|
-
/*
|
1624
|
+
declaredType = bindFunctionToClassOrObjectWithErrors(classOrObjectBase, declaredType,
|
1625
|
+
/* memberAccessClass */ undefined, expression);
|
1626
1626
|
}
|
1627
1627
|
}
|
1628
1628
|
}
|
@@ -2449,15 +2449,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2449
2449
|
const boundType = types_1.TypeBase.isInstantiable(subtype)
|
2450
2450
|
? (0, typeUtils_1.convertToInstantiable)(subtype.details.boundType)
|
2451
2451
|
: subtype.details.boundType;
|
2452
|
-
|
2453
|
-
|
2454
|
-
|
2455
|
-
|
2456
|
-
|
2457
|
-
|
2458
|
-
|
2459
|
-
|
2460
|
-
|
2452
|
+
// Handle Self and type[Self] specially.
|
2453
|
+
if (subtype.details.isSynthesizedSelf && (0, types_1.isClass)(boundType)) {
|
2454
|
+
return types_1.ClassType.cloneIncludeSubclasses(boundType);
|
2455
|
+
}
|
2456
|
+
return (0, typeUtils_1.addConditionToType)(boundType, [
|
2457
|
+
{
|
2458
|
+
typeVarName: types_1.TypeVarType.getNameWithScope(subtype),
|
2459
|
+
constraintIndex: 0,
|
2460
|
+
isConstrainedTypeVar: false,
|
2461
|
+
},
|
2462
|
+
]);
|
2461
2463
|
}
|
2462
2464
|
// If this is a recursive type alias placeholder
|
2463
2465
|
// that hasn't yet been resolved, return it as is.
|
@@ -2849,8 +2851,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2849
2851
|
return memberType;
|
2850
2852
|
}
|
2851
2853
|
if ((0, types_1.isFunction)(memberType) || (0, types_1.isOverloadedFunction)(memberType)) {
|
2852
|
-
const methodType =
|
2853
|
-
/* recursionCount */ undefined,
|
2854
|
+
const methodType = bindFunctionToClassOrObjectWithErrors(bindToClass || objType, memberType, classMember && (0, types_1.isInstantiableClass)(classMember.classType) ? classMember.classType : undefined, errorNode,
|
2854
2855
|
/* treatConstructorAsClassMember */ false,
|
2855
2856
|
/* firstParamType */ bindToClass);
|
2856
2857
|
if (methodType) {
|
@@ -3902,6 +3903,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3902
3903
|
return undefined;
|
3903
3904
|
}
|
3904
3905
|
type = descriptorResult.type;
|
3906
|
+
let isSetTypeError = false;
|
3905
3907
|
if (usage.method === 'set' && usage.setType) {
|
3906
3908
|
// Verify that the assigned type is compatible.
|
3907
3909
|
if (!assignType(type, usage.setType.type, diag === null || diag === void 0 ? void 0 : diag.createAddendum())) {
|
@@ -3912,7 +3914,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3912
3914
|
classType: printObjectTypeForClass(classType),
|
3913
3915
|
}));
|
3914
3916
|
}
|
3915
|
-
|
3917
|
+
isSetTypeError = true;
|
3916
3918
|
}
|
3917
3919
|
if ((0, types_1.isInstantiableClass)(memberInfo.classType) &&
|
3918
3920
|
types_1.ClassType.isFrozenDataClass(memberInfo.classType) &&
|
@@ -3920,13 +3922,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3920
3922
|
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.dataClassFrozen().format({
|
3921
3923
|
name: printType(types_1.ClassType.cloneAsInstance(memberInfo.classType)),
|
3922
3924
|
}));
|
3923
|
-
|
3925
|
+
isSetTypeError = true;
|
3924
3926
|
}
|
3925
3927
|
}
|
3926
3928
|
return {
|
3927
3929
|
symbol: memberInfo.symbol,
|
3928
3930
|
type,
|
3929
3931
|
isTypeIncomplete,
|
3932
|
+
isSetTypeError,
|
3930
3933
|
isClassMember: !memberInfo.isInstanceMember,
|
3931
3934
|
isClassVar: memberInfo.isClassVar,
|
3932
3935
|
classType: memberInfo.classType,
|
@@ -3945,6 +3948,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3945
3948
|
symbol: undefined,
|
3946
3949
|
type: generalAttrType.type,
|
3947
3950
|
isTypeIncomplete: false,
|
3951
|
+
isSetTypeError: false,
|
3948
3952
|
isClassMember: false,
|
3949
3953
|
isClassVar: false,
|
3950
3954
|
isAsymmetricAccessor: generalAttrType.isAsymmetricAccessor,
|
@@ -4099,8 +4103,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4099
4103
|
bindToClass = accessMethod.classType;
|
4100
4104
|
}
|
4101
4105
|
}
|
4102
|
-
let boundMethodType =
|
4103
|
-
/* recursionCount */ undefined,
|
4106
|
+
let boundMethodType = bindFunctionToClassOrObjectWithErrors(lookupClass, methodType, bindToClass, errorNode,
|
4104
4107
|
/* treatConstructorAsClassMember */ undefined, isAccessedThroughMetaclass ? concreteSubtype : undefined);
|
4105
4108
|
// The synthesized access method for the property may contain
|
4106
4109
|
// type variables associated with the "bindToClass", so we need
|
@@ -4208,8 +4211,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4208
4211
|
effectiveBindToType = (0, typeUtils_1.convertToInstance)(bindToType);
|
4209
4212
|
}
|
4210
4213
|
}
|
4211
|
-
|
4212
|
-
|
4214
|
+
// If the bind-to type is a specific class, add the "includeSubclasses" flag
|
4215
|
+
// to the type to indicate that it could be a subclass.
|
4216
|
+
if (effectiveBindToType && (0, types_1.isClass)(effectiveBindToType)) {
|
4217
|
+
effectiveBindToType = types_1.ClassType.cloneIncludeSubclasses(effectiveBindToType);
|
4218
|
+
}
|
4219
|
+
return bindFunctionToClassOrObjectWithErrors(isAccessedThroughObject ? types_1.ClassType.cloneAsInstance(baseTypeClass) : baseTypeClass, concreteSubtype, memberInfo && (0, types_1.isInstantiableClass)(memberInfo.classType) ? memberInfo.classType : undefined, errorNode, treatConstructorAsClassMember, effectiveBindToType);
|
4213
4220
|
}
|
4214
4221
|
}
|
4215
4222
|
if (usage.method === 'set') {
|
@@ -4392,7 +4399,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4392
4399
|
});
|
4393
4400
|
}
|
4394
4401
|
if ((0, types_1.isFunction)(accessMemberType) || (0, types_1.isOverloadedFunction)(accessMemberType)) {
|
4395
|
-
const boundMethodType =
|
4402
|
+
const boundMethodType = bindFunctionToClassOrObjectWithErrors(classType, accessMemberType, classType, errorNode);
|
4396
4403
|
if (boundMethodType && ((0, types_1.isFunction)(boundMethodType) || (0, types_1.isOverloadedFunction)(boundMethodType))) {
|
4397
4404
|
const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(boundMethodType));
|
4398
4405
|
const callResult = validateCallArguments(errorNode, argList, { type: boundMethodType }, typeVarContext,
|
@@ -4448,7 +4455,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4448
4455
|
}
|
4449
4456
|
}
|
4450
4457
|
}
|
4451
|
-
const indexTypeResult = getTypeOfIndexWithBaseType(node, baseTypeResult, { method: 'get' }, flags);
|
4458
|
+
const indexTypeResult = getTypeOfIndexWithBaseType(node, baseTypeResult, { method: 'get' }, flags & ~16777216 /* DisallowPep695TypeAlias */);
|
4452
4459
|
if ((0, codeFlowTypes_1.isCodeFlowSupportedForReference)(node)) {
|
4453
4460
|
// We limit type narrowing for index expressions to built-in types that are
|
4454
4461
|
// known to have symmetric __getitem__ and __setitem__ methods (i.e. the value
|
@@ -6197,17 +6204,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6197
6204
|
// intended behavior according to PEP 484.
|
6198
6205
|
const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, { type: overload, isIncomplete: typeResult.isIncomplete }, overloadIndex);
|
6199
6206
|
if (!matchResults.argumentErrors) {
|
6200
|
-
// If there is an expected return type, see if it's potentially compatible
|
6201
|
-
// with this overload's return type. If not, we'll de-emphasize this overload.
|
6202
|
-
if (inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType) {
|
6203
|
-
const returnType = getFunctionEffectiveReturnType(matchResults.overload);
|
6204
|
-
if (!assignType((0, typeUtils_1.replaceTypeVarsWithAny)(inferenceContext.expectedType), (0, typeUtils_1.replaceTypeVarsWithAny)(returnType),
|
6205
|
-
/* diag */ undefined,
|
6206
|
-
/* destTypeVarContext */ undefined,
|
6207
|
-
/* srcTypeVarContext */ undefined, 8 /* SkipSolveTypeVars */)) {
|
6208
|
-
matchResults.relevance += -0.5;
|
6209
|
-
}
|
6210
|
-
}
|
6211
6207
|
filteredMatchResults.push(matchResults);
|
6212
6208
|
}
|
6213
6209
|
overloadIndex++;
|
@@ -6955,7 +6951,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6955
6951
|
const remainingArgCount = positionalArgCount - argIndex;
|
6956
6952
|
const remainingParamCount = positionParamLimitIndex - paramIndex - 1;
|
6957
6953
|
if (paramIndex >= positionParamLimitIndex) {
|
6958
|
-
if (
|
6954
|
+
if (paramSpecArgList) {
|
6955
|
+
// Push the remaining positional args onto the param spec arg list.
|
6956
|
+
while (argIndex < positionalArgCount) {
|
6957
|
+
paramSpecArgList.push(argList[argIndex]);
|
6958
|
+
argIndex++;
|
6959
|
+
}
|
6960
|
+
}
|
6961
|
+
else {
|
6959
6962
|
let tooManyPositionals = false;
|
6960
6963
|
if (foundUnpackedListArg && argList[argIndex].argumentCategory === 1 /* UnpackedList */) {
|
6961
6964
|
// If this is an unpacked iterable, we will conservatively assume that it
|
@@ -7302,14 +7305,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7302
7305
|
else if (typeResult.type.details.paramSpec &&
|
7303
7306
|
(0, parameterUtils_1.isParamSpecKwargsArgument)(typeResult.type.details.paramSpec, argType)) {
|
7304
7307
|
unpackedDictionaryArgType = types_1.AnyType.create();
|
7305
|
-
|
7306
|
-
|
7307
|
-
|
7308
|
-
|
7309
|
-
|
7310
|
-
|
7311
|
-
|
7312
|
-
|
7308
|
+
if (!paramSpecArgList) {
|
7309
|
+
validateArgTypeParams.push({
|
7310
|
+
paramCategory: 2 /* KwargsDict */,
|
7311
|
+
paramType: typeResult.type.details.paramSpec,
|
7312
|
+
requiresTypeVarMatching: false,
|
7313
|
+
argument: argList[argIndex],
|
7314
|
+
argType: (0, types_1.isParamSpec)(argType) ? undefined : types_1.AnyType.create(),
|
7315
|
+
errorNode: argList[argIndex].valueExpression || errorNode,
|
7316
|
+
});
|
7317
|
+
}
|
7313
7318
|
}
|
7314
7319
|
else {
|
7315
7320
|
const strObjType = getBuiltInObject(errorNode, 'str');
|
@@ -8120,13 +8125,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8120
8125
|
return { argumentErrors: paramSpecArgResult.argumentErrors, typeVarContexts };
|
8121
8126
|
}
|
8122
8127
|
function validateFunctionArgumentsForParamSpecSignature(errorNode, argList, paramSpec, typeVarContext, signatureTracker) {
|
8123
|
-
|
8124
|
-
const paramSpecType = typeVarContext.getParamSpecType(paramSpec);
|
8128
|
+
let paramSpecType = typeVarContext.getParamSpecType(paramSpec);
|
8125
8129
|
if (!paramSpecType) {
|
8126
|
-
|
8127
|
-
return { argumentErrors: true, typeVarContexts: [undefined] };
|
8130
|
+
paramSpecType = (0, typeUtils_1.convertTypeToParamSpecValue)(paramSpec);
|
8128
8131
|
}
|
8129
8132
|
const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, { type: paramSpecType }, 0);
|
8133
|
+
const functionType = matchResults.overload;
|
8130
8134
|
const srcTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeIds)(paramSpecType));
|
8131
8135
|
if (matchResults.argumentErrors) {
|
8132
8136
|
// Evaluate types of all args. This will ensure that referenced symbols are
|
@@ -8138,6 +8142,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8138
8142
|
});
|
8139
8143
|
return { argumentErrors: true, typeVarContexts: [srcTypeVarContext] };
|
8140
8144
|
}
|
8145
|
+
// Handle the recursive case where we're passing (*args: P.args, **kwargs: P.args)
|
8146
|
+
// a remaining function of type (*P).
|
8147
|
+
if (functionType.details.paramSpec &&
|
8148
|
+
functionType.details.parameters.length === 0 &&
|
8149
|
+
(0, types_1.isTypeSame)(functionType.details.paramSpec, paramSpec)) {
|
8150
|
+
// TODO - need to perform additional validation here.
|
8151
|
+
return { argumentErrors: false, typeVarContexts: [srcTypeVarContext] };
|
8152
|
+
}
|
8141
8153
|
const result = validateFunctionArgumentTypes(errorNode, matchResults, srcTypeVarContext, signatureTracker);
|
8142
8154
|
return { argumentErrors: !!result.argumentErrors, typeVarContexts: [srcTypeVarContext] };
|
8143
8155
|
}
|
@@ -8459,7 +8471,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8459
8471
|
}
|
8460
8472
|
else {
|
8461
8473
|
const argType = (_b = (_a = argList[i].typeResult) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : getTypeOfExpressionExpectingType(argList[i].valueExpression).type;
|
8462
|
-
if ((0, typeUtils_1.requiresSpecialization)(argType,
|
8474
|
+
if ((0, typeUtils_1.requiresSpecialization)(argType, { ignorePseudoGeneric: true, ignoreImplicitTypeArgs: true })) {
|
8463
8475
|
addError(localize_1.Localizer.Diagnostic.typeVarBoundGeneric(), argList[i].valueExpression || errorNode);
|
8464
8476
|
}
|
8465
8477
|
typeVar.details.boundType = (0, typeUtils_1.convertToInstance)(argType);
|
@@ -8522,7 +8534,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8522
8534
|
}
|
8523
8535
|
else {
|
8524
8536
|
const argType = (_g = (_f = argList[i].typeResult) === null || _f === void 0 ? void 0 : _f.type) !== null && _g !== void 0 ? _g : getTypeOfExpressionExpectingType(argList[i].valueExpression).type;
|
8525
|
-
if ((0, typeUtils_1.requiresSpecialization)(argType,
|
8537
|
+
if ((0, typeUtils_1.requiresSpecialization)(argType, { ignorePseudoGeneric: true })) {
|
8526
8538
|
addError(localize_1.Localizer.Diagnostic.typeVarConstraintGeneric(), argList[i].valueExpression || errorNode);
|
8527
8539
|
}
|
8528
8540
|
types_1.TypeVarType.addConstraint(typeVar, (0, typeUtils_1.convertToInstance)(argType));
|
@@ -9286,9 +9298,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9286
9298
|
}
|
9287
9299
|
else if (mappingType && (0, types_1.isInstantiableClass)(mappingType)) {
|
9288
9300
|
const mappingTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(mappingType));
|
9289
|
-
|
9290
|
-
mappingType = types_1.ClassType.cloneForSpecialization(mappingType, mappingType.details.typeParameters,
|
9291
|
-
/* isTypeArgumentExplicit */ true);
|
9301
|
+
mappingType = (0, typeUtils_1.selfSpecializeClass)(mappingType);
|
9292
9302
|
if (assignType(types_1.ClassType.cloneAsInstance(mappingType), unexpandedType,
|
9293
9303
|
/* diag */ undefined, mappingTypeVarContext,
|
9294
9304
|
/* srcTypeVarContext */ undefined, 128 /* RetainLiteralsForTypeVar */)) {
|
@@ -10231,7 +10241,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10231
10241
|
const type = typeArgs[0].type;
|
10232
10242
|
// A ClassVar should not allow TypeVars or generic types parameterized
|
10233
10243
|
// by TypeVars.
|
10234
|
-
if ((0, typeUtils_1.requiresSpecialization)(type,
|
10244
|
+
if ((0, typeUtils_1.requiresSpecialization)(type, { ignorePseudoGeneric: true, ignoreSelf: true })) {
|
10235
10245
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
|
10236
10246
|
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.classVarWithTypeVar(), (_a = typeArgs[0].node) !== null && _a !== void 0 ? _a : errorNode);
|
10237
10247
|
}
|
@@ -10351,8 +10361,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10351
10361
|
isRequired = classType.details.name === 'Required';
|
10352
10362
|
isNotRequired = classType.details.name === 'NotRequired';
|
10353
10363
|
}
|
10354
|
-
isRequired = classType.details.name === 'Required';
|
10355
|
-
isNotRequired = classType.details.name === 'NotRequired';
|
10356
10364
|
if (!isUsageLegal) {
|
10357
10365
|
addError(classType.details.name === 'ReadOnly'
|
10358
10366
|
? localize_1.Localizer.Diagnostic.readOnlyNotInTypedDict()
|
@@ -10790,12 +10798,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10790
10798
|
['LiteralString', { alias: '', module: 'builtins' }],
|
10791
10799
|
['ReadOnly', { alias: '', module: 'builtins' }],
|
10792
10800
|
]);
|
10793
|
-
|
10794
|
-
// Support ReadOnly only as an experimental feature.
|
10795
|
-
if (assignedName === 'ReadOnly' &&
|
10796
|
-
!AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.enableExperimentalFeatures) {
|
10797
|
-
aliasMapEntry = undefined;
|
10798
|
-
}
|
10801
|
+
const aliasMapEntry = specialTypes.get(assignedName);
|
10799
10802
|
if (aliasMapEntry) {
|
10800
10803
|
const cachedType = readTypeCache(node, 0 /* None */);
|
10801
10804
|
if (cachedType) {
|
@@ -10823,7 +10826,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10823
10826
|
const nameNode = node.leftExpression;
|
10824
10827
|
const assignedName = nameNode.value;
|
10825
10828
|
if (assignedName === 'Any') {
|
10826
|
-
return types_1.AnyType.
|
10829
|
+
return types_1.AnyType.createSpecialForm();
|
10827
10830
|
}
|
10828
10831
|
const specialTypes = new Map([
|
10829
10832
|
['overload', { alias: '', module: 'builtins' }],
|
@@ -11191,6 +11194,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11191
11194
|
if ((0, types_1.isUnion)(argType)) {
|
11192
11195
|
argType = (0, types_1.removeUnbound)(argType);
|
11193
11196
|
}
|
11197
|
+
// Any is allowed as a base class. Remove its "special form" flag to avoid
|
11198
|
+
// false positive errors.
|
11199
|
+
if ((0, types_1.isAny)(argType) && types_1.TypeBase.isSpecialForm(argType)) {
|
11200
|
+
argType = types_1.AnyType.create();
|
11201
|
+
}
|
11194
11202
|
if (!(0, types_1.isAnyOrUnknown)(argType) && !(0, types_1.isUnbound)(argType)) {
|
11195
11203
|
if ((0, typeUtils_1.isMetaclassInstance)(argType)) {
|
11196
11204
|
(0, debug_1.assert)((0, types_1.isClassInstance)(argType));
|
@@ -11469,7 +11477,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11469
11477
|
if (metaclassNode) {
|
11470
11478
|
const metaclassType = getTypeOfExpression(metaclassNode, exprFlags).type;
|
11471
11479
|
if ((0, types_1.isInstantiableClass)(metaclassType) || (0, types_1.isUnknown)(metaclassType)) {
|
11472
|
-
if ((0, typeUtils_1.requiresSpecialization)(metaclassType,
|
11480
|
+
if ((0, typeUtils_1.requiresSpecialization)(metaclassType, { ignorePseudoGeneric: true })) {
|
11473
11481
|
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.metaclassIsGeneric(), metaclassNode);
|
11474
11482
|
}
|
11475
11483
|
classType.details.declaredMetaclass = metaclassType;
|
@@ -11743,7 +11751,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11743
11751
|
}
|
11744
11752
|
else if (!(0, typeUtils_1.derivesFromClassRecursive)(effectiveMetaclass, baseClassMeta, /* ignoreUnknown */ false)) {
|
11745
11753
|
if (!reportedMetaclassConflict) {
|
11746
|
-
|
11754
|
+
const diag = new diagnostic_1.DiagnosticAddendum();
|
11755
|
+
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.metaclassConflict().format({
|
11756
|
+
metaclass1: printType((0, typeUtils_1.convertToInstance)(effectiveMetaclass)),
|
11757
|
+
metaclass2: printType((0, typeUtils_1.convertToInstance)(baseClassMeta)),
|
11758
|
+
}));
|
11759
|
+
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.metaclassConflict() + diag.getString(), errorNode);
|
11747
11760
|
// Don't report more than once.
|
11748
11761
|
reportedMetaclassConflict = true;
|
11749
11762
|
}
|
@@ -14577,7 +14590,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14577
14590
|
if (node.boundExpression.nodeType === 52 /* Tuple */) {
|
14578
14591
|
const constraints = node.boundExpression.expressions.map((constraint) => {
|
14579
14592
|
const constraintType = getTypeOfExpressionExpectingType(constraint).type;
|
14580
|
-
if ((0, typeUtils_1.requiresSpecialization)(constraintType,
|
14593
|
+
if ((0, typeUtils_1.requiresSpecialization)(constraintType, {
|
14594
|
+
ignorePseudoGeneric: true,
|
14595
|
+
ignoreImplicitTypeArgs: true,
|
14596
|
+
})) {
|
14581
14597
|
addError(localize_1.Localizer.Diagnostic.typeVarBoundGeneric(), constraint);
|
14582
14598
|
}
|
14583
14599
|
return (0, typeUtils_1.convertToInstance)(constraintType);
|
@@ -14591,7 +14607,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14591
14607
|
}
|
14592
14608
|
else {
|
14593
14609
|
const boundType = getTypeOfExpressionExpectingType(node.boundExpression).type;
|
14594
|
-
if ((0, typeUtils_1.requiresSpecialization)(boundType,
|
14610
|
+
if ((0, typeUtils_1.requiresSpecialization)(boundType, { ignorePseudoGeneric: true })) {
|
14595
14611
|
addError(localize_1.Localizer.Diagnostic.typeVarConstraintGeneric(), node.boundExpression);
|
14596
14612
|
}
|
14597
14613
|
if (node.typeParamCategory === parseNodes_1.TypeParameterCategory.TypeVar) {
|
@@ -15495,6 +15511,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15495
15511
|
};
|
15496
15512
|
}
|
15497
15513
|
}
|
15514
|
+
else if ((0, types_1.isAnyOrUnknown)(member.classType)) {
|
15515
|
+
return {
|
15516
|
+
type: member.classType,
|
15517
|
+
isIncomplete: false,
|
15518
|
+
};
|
15519
|
+
}
|
15498
15520
|
return undefined;
|
15499
15521
|
}
|
15500
15522
|
function assignClass(destType, srcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount, reportErrorsUsingObjType) {
|
@@ -16167,7 +16189,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16167
16189
|
if ((0, types_1.isAnyOrUnknown)(destType)) {
|
16168
16190
|
return true;
|
16169
16191
|
}
|
16170
|
-
if ((0, types_1.isAnyOrUnknown)(srcType)) {
|
16192
|
+
if ((0, types_1.isAnyOrUnknown)(srcType) && !types_1.TypeBase.isSpecialForm(srcType)) {
|
16171
16193
|
const targetTypeVarContext = (flags & 2 /* ReverseTypeVarMatching */) === 0 ? destTypeVarContext : srcTypeVarContext;
|
16172
16194
|
if (targetTypeVarContext) {
|
16173
16195
|
// If it's an ellipsis type, convert it to a regular "Any"
|
@@ -16393,7 +16415,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16393
16415
|
}
|
16394
16416
|
}
|
16395
16417
|
}
|
16396
|
-
else if ((0, types_1.isAnyOrUnknown)(concreteSrcType)) {
|
16418
|
+
else if ((0, types_1.isAnyOrUnknown)(concreteSrcType) && !types_1.TypeBase.isSpecialForm(concreteSrcType)) {
|
16397
16419
|
return (flags & 16 /* OverloadOverlapCheck */) === 0;
|
16398
16420
|
}
|
16399
16421
|
else if ((0, types_1.isUnion)(concreteSrcType)) {
|
@@ -16916,31 +16938,24 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16916
16938
|
}
|
16917
16939
|
let specializedSrcType = srcType;
|
16918
16940
|
let specializedDestType = destType;
|
16919
|
-
let
|
16941
|
+
let doSpecializationStep = false;
|
16920
16942
|
if ((flags & 2 /* ReverseTypeVarMatching */) === 0) {
|
16921
16943
|
specializedDestType = (0, typeUtils_1.applySolvedTypeVars)(destType, destTypeVarContext, { useNarrowBoundOnly: true });
|
16922
|
-
|
16923
|
-
reverseMatchingFailed = !assignType(specializedSrcType, specializedDestType,
|
16924
|
-
/* diag */ undefined, srcTypeVarContext, destTypeVarContext, (flags ^ 2 /* ReverseTypeVarMatching */) | 128 /* RetainLiteralsForTypeVar */, recursionCount);
|
16925
|
-
specializedDestType = (0, typeUtils_1.applySolvedTypeVars)(destType, destTypeVarContext);
|
16926
|
-
}
|
16944
|
+
doSpecializationStep = (0, typeUtils_1.requiresSpecialization)(specializedDestType);
|
16927
16945
|
}
|
16928
16946
|
else {
|
16929
16947
|
specializedSrcType = (0, typeUtils_1.applySolvedTypeVars)(srcType, srcTypeVarContext, { useNarrowBoundOnly: true });
|
16930
|
-
|
16931
|
-
|
16932
|
-
|
16933
|
-
|
16948
|
+
doSpecializationStep = (0, typeUtils_1.requiresSpecialization)(specializedSrcType);
|
16949
|
+
}
|
16950
|
+
// Is an additional specialization step required?
|
16951
|
+
if (doSpecializationStep) {
|
16952
|
+
assignType(specializedSrcType, specializedDestType,
|
16953
|
+
/* diag */ undefined, srcTypeVarContext, destTypeVarContext, (flags ^ 2 /* ReverseTypeVarMatching */) | 128 /* RetainLiteralsForTypeVar */, recursionCount);
|
16954
|
+
if ((flags & 2 /* ReverseTypeVarMatching */) === 0) {
|
16955
|
+
specializedDestType = (0, typeUtils_1.applySolvedTypeVars)(destType, destTypeVarContext);
|
16934
16956
|
}
|
16935
|
-
|
16936
|
-
|
16937
|
-
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.paramAssignment().format({
|
16938
|
-
index: paramIndex + 1,
|
16939
|
-
sourceType: printType(destType),
|
16940
|
-
destType: printType(srcType),
|
16941
|
-
}));
|
16942
|
-
}
|
16943
|
-
return false;
|
16957
|
+
else {
|
16958
|
+
specializedSrcType = (0, typeUtils_1.applySolvedTypeVars)(srcType, srcTypeVarContext);
|
16944
16959
|
}
|
16945
16960
|
}
|
16946
16961
|
// Handle the special case where the source is a Self type and the
|
@@ -17379,7 +17394,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17379
17394
|
category: p.category,
|
17380
17395
|
name: p.name,
|
17381
17396
|
isNameSynthesized: p.isNameSynthesized,
|
17382
|
-
hasDefault:
|
17397
|
+
hasDefault: p.hasDefault,
|
17398
|
+
hasDeclaredType: p.hasDeclaredType,
|
17383
17399
|
defaultValueExpression: p.defaultValueExpression,
|
17384
17400
|
type: types_1.FunctionType.getEffectiveParameterType(effectiveSrcType, index),
|
17385
17401
|
});
|
@@ -17479,13 +17495,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17479
17495
|
return undefined;
|
17480
17496
|
}
|
17481
17497
|
recursionCount++;
|
17482
|
-
// If this is a tuple with defined tuple type arguments, don't overwrite them.
|
17483
|
-
if (assignedType.tupleTypeArguments) {
|
17484
|
-
return undefined;
|
17485
|
-
}
|
17486
17498
|
if (assignedType.details.typeParameters.length > 0 &&
|
17487
17499
|
assignedType.typeArguments &&
|
17488
|
-
assignedType.typeArguments.length <= assignedType.details.typeParameters.length
|
17500
|
+
assignedType.typeArguments.length <= assignedType.details.typeParameters.length &&
|
17501
|
+
!assignedType.tupleTypeArguments) {
|
17489
17502
|
const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(assignedType));
|
17490
17503
|
(0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, types_1.ClassType.cloneForSpecialization(assignedType,
|
17491
17504
|
/* typeArguments */ undefined,
|
@@ -18102,13 +18115,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18102
18115
|
});
|
18103
18116
|
return methodList;
|
18104
18117
|
}
|
18118
|
+
function bindFunctionToClassOrObjectWithErrors(baseType, memberType, memberClass, errorNode, treatConstructorAsClassMember = false, firstParamType) {
|
18119
|
+
const diag = errorNode ? new diagnostic_1.DiagnosticAddendum() : undefined;
|
18120
|
+
const result = bindFunctionToClassOrObject(baseType, memberType, memberClass, treatConstructorAsClassMember, firstParamType, diag);
|
18121
|
+
if (!result && errorNode && diag) {
|
18122
|
+
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, diag.getString(), errorNode);
|
18123
|
+
}
|
18124
|
+
return result;
|
18125
|
+
}
|
18105
18126
|
// If the memberType is an instance or class method, creates a new
|
18106
18127
|
// version of the function that has the "self" or "cls" parameter bound
|
18107
18128
|
// to it. If treatAsClassMethod is true, the function is treated like a
|
18108
18129
|
// class method even if it's not marked as such. That's needed to
|
18109
18130
|
// special-case the __new__ magic method when it's invoked as a
|
18110
18131
|
// constructor (as opposed to by name).
|
18111
|
-
function bindFunctionToClassOrObject(baseType, memberType, memberClass,
|
18132
|
+
function bindFunctionToClassOrObject(baseType, memberType, memberClass, treatConstructorAsClassMember = false, firstParamType, diag, recursionCount = 0) {
|
18112
18133
|
if ((0, types_1.isFunction)(memberType)) {
|
18113
18134
|
// If the caller specified no base type, always strip the
|
18114
18135
|
// first parameter. This is used in cases like constructors.
|
@@ -18123,7 +18144,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18123
18144
|
const baseObj = (0, types_1.isClassInstance)(baseType)
|
18124
18145
|
? baseType
|
18125
18146
|
: types_1.ClassType.cloneAsInstance((0, typeUtils_1.specializeClassType)(baseType));
|
18126
|
-
return partiallySpecializeFunctionForBoundClassOrObject(baseType, memberType, memberClass || types_1.ClassType.cloneAsInstantiable(baseObj),
|
18147
|
+
return partiallySpecializeFunctionForBoundClassOrObject(baseType, memberType, memberClass || types_1.ClassType.cloneAsInstantiable(baseObj), diag, recursionCount, firstParamType || baseObj,
|
18127
18148
|
/* stripFirstParam */ (0, types_1.isClassInstance)(baseType));
|
18128
18149
|
}
|
18129
18150
|
if (types_1.FunctionType.isClassMethod(memberType) ||
|
@@ -18136,12 +18157,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18136
18157
|
? firstParamType
|
18137
18158
|
: (0, typeUtils_1.convertToInstantiable)(firstParamType)
|
18138
18159
|
: baseClass;
|
18139
|
-
return partiallySpecializeFunctionForBoundClassOrObject(types_1.TypeBase.isInstance(baseType) ? types_1.ClassType.cloneAsInstantiable(baseType) : baseType, memberType, memberClass || baseClass,
|
18160
|
+
return partiallySpecializeFunctionForBoundClassOrObject(types_1.TypeBase.isInstance(baseType) ? types_1.ClassType.cloneAsInstantiable(baseType) : baseType, memberType, memberClass || baseClass, diag, recursionCount, effectiveFirstParamType,
|
18140
18161
|
/* stripFirstParam */ true);
|
18141
18162
|
}
|
18142
18163
|
if (types_1.FunctionType.isStaticMethod(memberType)) {
|
18143
18164
|
const baseClass = (0, types_1.isInstantiableClass)(baseType) ? baseType : types_1.ClassType.cloneAsInstantiable(baseType);
|
18144
|
-
return partiallySpecializeFunctionForBoundClassOrObject(types_1.TypeBase.isInstance(baseType) ? types_1.ClassType.cloneAsInstantiable(baseType) : baseType, memberType, memberClass || baseClass,
|
18165
|
+
return partiallySpecializeFunctionForBoundClassOrObject(types_1.TypeBase.isInstance(baseType) ? types_1.ClassType.cloneAsInstantiable(baseType) : baseType, memberType, memberClass || baseClass, diag, recursionCount,
|
18145
18166
|
/* effectiveFirstParamType */ undefined,
|
18146
18167
|
/* stripFirstParam */ false);
|
18147
18168
|
}
|
@@ -18150,24 +18171,25 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18150
18171
|
const newOverloadType = types_1.OverloadedFunctionType.create([]);
|
18151
18172
|
// Don't bother binding the implementation.
|
18152
18173
|
types_1.OverloadedFunctionType.getOverloads(memberType).forEach((overload) => {
|
18153
|
-
const boundMethod = bindFunctionToClassOrObject(baseType, overload, memberClass,
|
18154
|
-
/*
|
18174
|
+
const boundMethod = bindFunctionToClassOrObject(baseType, overload, memberClass, treatConstructorAsClassMember, firstParamType,
|
18175
|
+
/* diag */ undefined, recursionCount);
|
18155
18176
|
if (boundMethod) {
|
18156
18177
|
types_1.OverloadedFunctionType.addOverload(newOverloadType, boundMethod);
|
18157
18178
|
}
|
18158
18179
|
});
|
18159
|
-
|
18160
|
-
|
18180
|
+
const newOverloads = types_1.OverloadedFunctionType.getOverloads(newOverloadType);
|
18181
|
+
if (newOverloads.length === 0) {
|
18182
|
+
// No overloads matched, so rebind with the diag
|
18161
18183
|
// to report the error(s) to the user.
|
18162
|
-
if (
|
18184
|
+
if (diag) {
|
18163
18185
|
memberType.overloads.forEach((overload) => {
|
18164
|
-
bindFunctionToClassOrObject(baseType, overload, memberClass,
|
18186
|
+
bindFunctionToClassOrObject(baseType, overload, memberClass, treatConstructorAsClassMember, firstParamType, diag, recursionCount);
|
18165
18187
|
});
|
18166
18188
|
}
|
18167
18189
|
return undefined;
|
18168
18190
|
}
|
18169
|
-
|
18170
|
-
return
|
18191
|
+
if (newOverloads.length === 1) {
|
18192
|
+
return newOverloads[0];
|
18171
18193
|
}
|
18172
18194
|
return newOverloadType;
|
18173
18195
|
}
|
@@ -18179,14 +18201,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18179
18201
|
// is the type used to reference the member, and the memberClass
|
18180
18202
|
// is the class that provided the member (could be an ancestor of
|
18181
18203
|
// the baseType's class).
|
18182
|
-
function partiallySpecializeFunctionForBoundClassOrObject(baseType, memberType, memberClass,
|
18204
|
+
function partiallySpecializeFunctionForBoundClassOrObject(baseType, memberType, memberClass, diag, recursionCount, firstParamType, stripFirstParam = true) {
|
18183
18205
|
const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(memberClass));
|
18184
18206
|
if (firstParamType && memberType.details.parameters.length > 0) {
|
18185
18207
|
const memberTypeFirstParam = memberType.details.parameters[0];
|
18186
18208
|
const memberTypeFirstParamType = types_1.FunctionType.getEffectiveParameterType(memberType, 0);
|
18187
18209
|
// Fill out the typeVarContext for the "self" or "cls" parameter.
|
18188
18210
|
typeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeId)(memberType));
|
18189
|
-
const diag = errorNode ? new diagnostic_1.DiagnosticAddendum() : undefined;
|
18190
18211
|
if ((0, types_1.isTypeVar)(memberTypeFirstParamType) &&
|
18191
18212
|
memberTypeFirstParamType.details.boundType &&
|
18192
18213
|
(0, types_1.isClassInstance)(memberTypeFirstParamType.details.boundType) &&
|
@@ -18201,25 +18222,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18201
18222
|
: firstParamType);
|
18202
18223
|
}
|
18203
18224
|
}
|
18204
|
-
else if (!assignType(memberTypeFirstParamType, firstParamType, diag, typeVarContext,
|
18225
|
+
else if (!assignType(memberTypeFirstParamType, firstParamType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), typeVarContext,
|
18205
18226
|
/* srcTypeVarContext */ undefined, 2048 /* AllowUnspecifiedTypeArguments */, recursionCount)) {
|
18206
18227
|
if (memberTypeFirstParam.name &&
|
18207
18228
|
!memberTypeFirstParam.isNameSynthesized &&
|
18208
18229
|
memberTypeFirstParam.hasDeclaredType) {
|
18209
|
-
if (
|
18210
|
-
|
18211
|
-
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.bindTypeMismatch().format({
|
18230
|
+
if (diag) {
|
18231
|
+
diag.addMessage(localize_1.Localizer.Diagnostic.bindTypeMismatch().format({
|
18212
18232
|
type: printType(baseType),
|
18213
|
-
methodName:
|
18233
|
+
methodName: memberType.details.name || '<anonymous>',
|
18214
18234
|
paramName: memberTypeFirstParam.name,
|
18215
|
-
})
|
18216
|
-
}
|
18217
|
-
else {
|
18218
|
-
// If there was no errorNode, we couldn't report the error,
|
18219
|
-
// so we will instead return undefined and let the caller
|
18220
|
-
// deal with the error.
|
18221
|
-
return undefined;
|
18235
|
+
}));
|
18222
18236
|
}
|
18237
|
+
return undefined;
|
18223
18238
|
}
|
18224
18239
|
}
|
18225
18240
|
}
|