@zzzen/pyright-internal 1.2.0-dev.20231015 → 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 +6 -13
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +65 -28
- 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/patternMatching.js +4 -0
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/properties.js +6 -2
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/protocols.js +28 -30
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/sourceFile.js +10 -4
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +114 -101
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +1 -1
- package/dist/analyzer/typeGuards.js +28 -20
- 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 +9 -1
- package/dist/analyzer/typeUtils.js +51 -46
- package/dist/analyzer/typeUtils.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 +2 -0
- package/dist/analyzer/types.js +27 -3
- package/dist/analyzer/types.js.map +1 -1
- package/dist/common/pathUtils.d.ts +3 -1
- package/dist/common/pathUtils.js +78 -27
- package/dist/common/pathUtils.js.map +1 -1
- package/dist/common/realFileSystem.js +11 -1
- package/dist/common/realFileSystem.js.map +1 -1
- package/dist/common/serviceProviderExtensions.d.ts +1 -3
- package/dist/common/serviceProviderExtensions.js +0 -7
- 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 +0 -2
- package/dist/languageServerBase.js +0 -14
- package/dist/languageServerBase.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/referencesProvider.js +1 -0
- 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 +6 -1
- package/dist/localization/package.nls.de.json +6 -1
- package/dist/localization/package.nls.en-us.json +1 -1
- package/dist/localization/package.nls.es.json +6 -1
- package/dist/localization/package.nls.fr.json +6 -1
- package/dist/localization/package.nls.it.json +6 -1
- package/dist/localization/package.nls.ja.json +6 -1
- package/dist/localization/package.nls.ko.json +6 -1
- package/dist/localization/package.nls.pl.json +6 -1
- package/dist/localization/package.nls.pt-br.json +6 -1
- package/dist/localization/package.nls.qps-ploc.json +6 -1
- package/dist/localization/package.nls.ru.json +6 -1
- package/dist/localization/package.nls.tr.json +6 -1
- package/dist/localization/package.nls.zh-cn.json +6 -1
- package/dist/localization/package.nls.zh-tw.json +6 -1
- package/dist/pyrightFileSystem.d.ts +1 -15
- package/dist/pyrightFileSystem.js +1 -57
- package/dist/pyrightFileSystem.js.map +1 -1
- 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/pyrightFileSystem.test.js +0 -20
- package/dist/tests/pyrightFileSystem.test.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +10 -2
- package/dist/tests/typeEvaluator2.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
@@ -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) {
|
@@ -4102,8 +4103,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4102
4103
|
bindToClass = accessMethod.classType;
|
4103
4104
|
}
|
4104
4105
|
}
|
4105
|
-
let boundMethodType =
|
4106
|
-
/* recursionCount */ undefined,
|
4106
|
+
let boundMethodType = bindFunctionToClassOrObjectWithErrors(lookupClass, methodType, bindToClass, errorNode,
|
4107
4107
|
/* treatConstructorAsClassMember */ undefined, isAccessedThroughMetaclass ? concreteSubtype : undefined);
|
4108
4108
|
// The synthesized access method for the property may contain
|
4109
4109
|
// type variables associated with the "bindToClass", so we need
|
@@ -4211,8 +4211,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4211
4211
|
effectiveBindToType = (0, typeUtils_1.convertToInstance)(bindToType);
|
4212
4212
|
}
|
4213
4213
|
}
|
4214
|
-
|
4215
|
-
|
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);
|
4216
4220
|
}
|
4217
4221
|
}
|
4218
4222
|
if (usage.method === 'set') {
|
@@ -4395,7 +4399,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4395
4399
|
});
|
4396
4400
|
}
|
4397
4401
|
if ((0, types_1.isFunction)(accessMemberType) || (0, types_1.isOverloadedFunction)(accessMemberType)) {
|
4398
|
-
const boundMethodType =
|
4402
|
+
const boundMethodType = bindFunctionToClassOrObjectWithErrors(classType, accessMemberType, classType, errorNode);
|
4399
4403
|
if (boundMethodType && ((0, types_1.isFunction)(boundMethodType) || (0, types_1.isOverloadedFunction)(boundMethodType))) {
|
4400
4404
|
const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(boundMethodType));
|
4401
4405
|
const callResult = validateCallArguments(errorNode, argList, { type: boundMethodType }, typeVarContext,
|
@@ -4451,7 +4455,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4451
4455
|
}
|
4452
4456
|
}
|
4453
4457
|
}
|
4454
|
-
const indexTypeResult = getTypeOfIndexWithBaseType(node, baseTypeResult, { method: 'get' }, flags);
|
4458
|
+
const indexTypeResult = getTypeOfIndexWithBaseType(node, baseTypeResult, { method: 'get' }, flags & ~16777216 /* DisallowPep695TypeAlias */);
|
4455
4459
|
if ((0, codeFlowTypes_1.isCodeFlowSupportedForReference)(node)) {
|
4456
4460
|
// We limit type narrowing for index expressions to built-in types that are
|
4457
4461
|
// known to have symmetric __getitem__ and __setitem__ methods (i.e. the value
|
@@ -6947,7 +6951,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6947
6951
|
const remainingArgCount = positionalArgCount - argIndex;
|
6948
6952
|
const remainingParamCount = positionParamLimitIndex - paramIndex - 1;
|
6949
6953
|
if (paramIndex >= positionParamLimitIndex) {
|
6950
|
-
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 {
|
6951
6962
|
let tooManyPositionals = false;
|
6952
6963
|
if (foundUnpackedListArg && argList[argIndex].argumentCategory === 1 /* UnpackedList */) {
|
6953
6964
|
// If this is an unpacked iterable, we will conservatively assume that it
|
@@ -7294,14 +7305,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7294
7305
|
else if (typeResult.type.details.paramSpec &&
|
7295
7306
|
(0, parameterUtils_1.isParamSpecKwargsArgument)(typeResult.type.details.paramSpec, argType)) {
|
7296
7307
|
unpackedDictionaryArgType = types_1.AnyType.create();
|
7297
|
-
|
7298
|
-
|
7299
|
-
|
7300
|
-
|
7301
|
-
|
7302
|
-
|
7303
|
-
|
7304
|
-
|
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
|
+
}
|
7305
7318
|
}
|
7306
7319
|
else {
|
7307
7320
|
const strObjType = getBuiltInObject(errorNode, 'str');
|
@@ -8112,13 +8125,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8112
8125
|
return { argumentErrors: paramSpecArgResult.argumentErrors, typeVarContexts };
|
8113
8126
|
}
|
8114
8127
|
function validateFunctionArgumentsForParamSpecSignature(errorNode, argList, paramSpec, typeVarContext, signatureTracker) {
|
8115
|
-
|
8116
|
-
const paramSpecType = typeVarContext.getParamSpecType(paramSpec);
|
8128
|
+
let paramSpecType = typeVarContext.getParamSpecType(paramSpec);
|
8117
8129
|
if (!paramSpecType) {
|
8118
|
-
|
8119
|
-
return { argumentErrors: true, typeVarContexts: [undefined] };
|
8130
|
+
paramSpecType = (0, typeUtils_1.convertTypeToParamSpecValue)(paramSpec);
|
8120
8131
|
}
|
8121
8132
|
const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, { type: paramSpecType }, 0);
|
8133
|
+
const functionType = matchResults.overload;
|
8122
8134
|
const srcTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeIds)(paramSpecType));
|
8123
8135
|
if (matchResults.argumentErrors) {
|
8124
8136
|
// Evaluate types of all args. This will ensure that referenced symbols are
|
@@ -8130,6 +8142,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8130
8142
|
});
|
8131
8143
|
return { argumentErrors: true, typeVarContexts: [srcTypeVarContext] };
|
8132
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
|
+
}
|
8133
8153
|
const result = validateFunctionArgumentTypes(errorNode, matchResults, srcTypeVarContext, signatureTracker);
|
8134
8154
|
return { argumentErrors: !!result.argumentErrors, typeVarContexts: [srcTypeVarContext] };
|
8135
8155
|
}
|
@@ -8451,7 +8471,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8451
8471
|
}
|
8452
8472
|
else {
|
8453
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;
|
8454
|
-
if ((0, typeUtils_1.requiresSpecialization)(argType,
|
8474
|
+
if ((0, typeUtils_1.requiresSpecialization)(argType, { ignorePseudoGeneric: true, ignoreImplicitTypeArgs: true })) {
|
8455
8475
|
addError(localize_1.Localizer.Diagnostic.typeVarBoundGeneric(), argList[i].valueExpression || errorNode);
|
8456
8476
|
}
|
8457
8477
|
typeVar.details.boundType = (0, typeUtils_1.convertToInstance)(argType);
|
@@ -8514,7 +8534,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8514
8534
|
}
|
8515
8535
|
else {
|
8516
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;
|
8517
|
-
if ((0, typeUtils_1.requiresSpecialization)(argType,
|
8537
|
+
if ((0, typeUtils_1.requiresSpecialization)(argType, { ignorePseudoGeneric: true })) {
|
8518
8538
|
addError(localize_1.Localizer.Diagnostic.typeVarConstraintGeneric(), argList[i].valueExpression || errorNode);
|
8519
8539
|
}
|
8520
8540
|
types_1.TypeVarType.addConstraint(typeVar, (0, typeUtils_1.convertToInstance)(argType));
|
@@ -10221,7 +10241,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10221
10241
|
const type = typeArgs[0].type;
|
10222
10242
|
// A ClassVar should not allow TypeVars or generic types parameterized
|
10223
10243
|
// by TypeVars.
|
10224
|
-
if ((0, typeUtils_1.requiresSpecialization)(type,
|
10244
|
+
if ((0, typeUtils_1.requiresSpecialization)(type, { ignorePseudoGeneric: true, ignoreSelf: true })) {
|
10225
10245
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
|
10226
10246
|
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.classVarWithTypeVar(), (_a = typeArgs[0].node) !== null && _a !== void 0 ? _a : errorNode);
|
10227
10247
|
}
|
@@ -10341,8 +10361,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10341
10361
|
isRequired = classType.details.name === 'Required';
|
10342
10362
|
isNotRequired = classType.details.name === 'NotRequired';
|
10343
10363
|
}
|
10344
|
-
isRequired = classType.details.name === 'Required';
|
10345
|
-
isNotRequired = classType.details.name === 'NotRequired';
|
10346
10364
|
if (!isUsageLegal) {
|
10347
10365
|
addError(classType.details.name === 'ReadOnly'
|
10348
10366
|
? localize_1.Localizer.Diagnostic.readOnlyNotInTypedDict()
|
@@ -10780,12 +10798,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10780
10798
|
['LiteralString', { alias: '', module: 'builtins' }],
|
10781
10799
|
['ReadOnly', { alias: '', module: 'builtins' }],
|
10782
10800
|
]);
|
10783
|
-
|
10784
|
-
// Support ReadOnly only as an experimental feature.
|
10785
|
-
if (assignedName === 'ReadOnly' &&
|
10786
|
-
!AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.enableExperimentalFeatures) {
|
10787
|
-
aliasMapEntry = undefined;
|
10788
|
-
}
|
10801
|
+
const aliasMapEntry = specialTypes.get(assignedName);
|
10789
10802
|
if (aliasMapEntry) {
|
10790
10803
|
const cachedType = readTypeCache(node, 0 /* None */);
|
10791
10804
|
if (cachedType) {
|
@@ -11464,7 +11477,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11464
11477
|
if (metaclassNode) {
|
11465
11478
|
const metaclassType = getTypeOfExpression(metaclassNode, exprFlags).type;
|
11466
11479
|
if ((0, types_1.isInstantiableClass)(metaclassType) || (0, types_1.isUnknown)(metaclassType)) {
|
11467
|
-
if ((0, typeUtils_1.requiresSpecialization)(metaclassType,
|
11480
|
+
if ((0, typeUtils_1.requiresSpecialization)(metaclassType, { ignorePseudoGeneric: true })) {
|
11468
11481
|
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.metaclassIsGeneric(), metaclassNode);
|
11469
11482
|
}
|
11470
11483
|
classType.details.declaredMetaclass = metaclassType;
|
@@ -11738,7 +11751,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11738
11751
|
}
|
11739
11752
|
else if (!(0, typeUtils_1.derivesFromClassRecursive)(effectiveMetaclass, baseClassMeta, /* ignoreUnknown */ false)) {
|
11740
11753
|
if (!reportedMetaclassConflict) {
|
11741
|
-
|
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);
|
11742
11760
|
// Don't report more than once.
|
11743
11761
|
reportedMetaclassConflict = true;
|
11744
11762
|
}
|
@@ -14572,7 +14590,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14572
14590
|
if (node.boundExpression.nodeType === 52 /* Tuple */) {
|
14573
14591
|
const constraints = node.boundExpression.expressions.map((constraint) => {
|
14574
14592
|
const constraintType = getTypeOfExpressionExpectingType(constraint).type;
|
14575
|
-
if ((0, typeUtils_1.requiresSpecialization)(constraintType,
|
14593
|
+
if ((0, typeUtils_1.requiresSpecialization)(constraintType, {
|
14594
|
+
ignorePseudoGeneric: true,
|
14595
|
+
ignoreImplicitTypeArgs: true,
|
14596
|
+
})) {
|
14576
14597
|
addError(localize_1.Localizer.Diagnostic.typeVarBoundGeneric(), constraint);
|
14577
14598
|
}
|
14578
14599
|
return (0, typeUtils_1.convertToInstance)(constraintType);
|
@@ -14586,7 +14607,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14586
14607
|
}
|
14587
14608
|
else {
|
14588
14609
|
const boundType = getTypeOfExpressionExpectingType(node.boundExpression).type;
|
14589
|
-
if ((0, typeUtils_1.requiresSpecialization)(boundType,
|
14610
|
+
if ((0, typeUtils_1.requiresSpecialization)(boundType, { ignorePseudoGeneric: true })) {
|
14590
14611
|
addError(localize_1.Localizer.Diagnostic.typeVarConstraintGeneric(), node.boundExpression);
|
14591
14612
|
}
|
14592
14613
|
if (node.typeParamCategory === parseNodes_1.TypeParameterCategory.TypeVar) {
|
@@ -16917,31 +16938,24 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16917
16938
|
}
|
16918
16939
|
let specializedSrcType = srcType;
|
16919
16940
|
let specializedDestType = destType;
|
16920
|
-
let
|
16941
|
+
let doSpecializationStep = false;
|
16921
16942
|
if ((flags & 2 /* ReverseTypeVarMatching */) === 0) {
|
16922
16943
|
specializedDestType = (0, typeUtils_1.applySolvedTypeVars)(destType, destTypeVarContext, { useNarrowBoundOnly: true });
|
16923
|
-
|
16924
|
-
reverseMatchingFailed = !assignType(specializedSrcType, specializedDestType,
|
16925
|
-
/* diag */ undefined, srcTypeVarContext, destTypeVarContext, (flags ^ 2 /* ReverseTypeVarMatching */) | 128 /* RetainLiteralsForTypeVar */, recursionCount);
|
16926
|
-
specializedDestType = (0, typeUtils_1.applySolvedTypeVars)(destType, destTypeVarContext);
|
16927
|
-
}
|
16944
|
+
doSpecializationStep = (0, typeUtils_1.requiresSpecialization)(specializedDestType);
|
16928
16945
|
}
|
16929
16946
|
else {
|
16930
16947
|
specializedSrcType = (0, typeUtils_1.applySolvedTypeVars)(srcType, srcTypeVarContext, { useNarrowBoundOnly: true });
|
16931
|
-
|
16932
|
-
|
16933
|
-
|
16934
|
-
|
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);
|
16935
16956
|
}
|
16936
|
-
|
16937
|
-
|
16938
|
-
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.paramAssignment().format({
|
16939
|
-
index: paramIndex + 1,
|
16940
|
-
sourceType: printType(destType),
|
16941
|
-
destType: printType(srcType),
|
16942
|
-
}));
|
16943
|
-
}
|
16944
|
-
return false;
|
16957
|
+
else {
|
16958
|
+
specializedSrcType = (0, typeUtils_1.applySolvedTypeVars)(srcType, srcTypeVarContext);
|
16945
16959
|
}
|
16946
16960
|
}
|
16947
16961
|
// Handle the special case where the source is a Self type and the
|
@@ -17481,13 +17495,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17481
17495
|
return undefined;
|
17482
17496
|
}
|
17483
17497
|
recursionCount++;
|
17484
|
-
// If this is a tuple with defined tuple type arguments, don't overwrite them.
|
17485
|
-
if (assignedType.tupleTypeArguments) {
|
17486
|
-
return undefined;
|
17487
|
-
}
|
17488
17498
|
if (assignedType.details.typeParameters.length > 0 &&
|
17489
17499
|
assignedType.typeArguments &&
|
17490
|
-
assignedType.typeArguments.length <= assignedType.details.typeParameters.length
|
17500
|
+
assignedType.typeArguments.length <= assignedType.details.typeParameters.length &&
|
17501
|
+
!assignedType.tupleTypeArguments) {
|
17491
17502
|
const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(assignedType));
|
17492
17503
|
(0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, types_1.ClassType.cloneForSpecialization(assignedType,
|
17493
17504
|
/* typeArguments */ undefined,
|
@@ -18104,13 +18115,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18104
18115
|
});
|
18105
18116
|
return methodList;
|
18106
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
|
+
}
|
18107
18126
|
// If the memberType is an instance or class method, creates a new
|
18108
18127
|
// version of the function that has the "self" or "cls" parameter bound
|
18109
18128
|
// to it. If treatAsClassMethod is true, the function is treated like a
|
18110
18129
|
// class method even if it's not marked as such. That's needed to
|
18111
18130
|
// special-case the __new__ magic method when it's invoked as a
|
18112
18131
|
// constructor (as opposed to by name).
|
18113
|
-
function bindFunctionToClassOrObject(baseType, memberType, memberClass,
|
18132
|
+
function bindFunctionToClassOrObject(baseType, memberType, memberClass, treatConstructorAsClassMember = false, firstParamType, diag, recursionCount = 0) {
|
18114
18133
|
if ((0, types_1.isFunction)(memberType)) {
|
18115
18134
|
// If the caller specified no base type, always strip the
|
18116
18135
|
// first parameter. This is used in cases like constructors.
|
@@ -18125,7 +18144,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18125
18144
|
const baseObj = (0, types_1.isClassInstance)(baseType)
|
18126
18145
|
? baseType
|
18127
18146
|
: types_1.ClassType.cloneAsInstance((0, typeUtils_1.specializeClassType)(baseType));
|
18128
|
-
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,
|
18129
18148
|
/* stripFirstParam */ (0, types_1.isClassInstance)(baseType));
|
18130
18149
|
}
|
18131
18150
|
if (types_1.FunctionType.isClassMethod(memberType) ||
|
@@ -18138,12 +18157,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18138
18157
|
? firstParamType
|
18139
18158
|
: (0, typeUtils_1.convertToInstantiable)(firstParamType)
|
18140
18159
|
: baseClass;
|
18141
|
-
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,
|
18142
18161
|
/* stripFirstParam */ true);
|
18143
18162
|
}
|
18144
18163
|
if (types_1.FunctionType.isStaticMethod(memberType)) {
|
18145
18164
|
const baseClass = (0, types_1.isInstantiableClass)(baseType) ? baseType : types_1.ClassType.cloneAsInstantiable(baseType);
|
18146
|
-
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,
|
18147
18166
|
/* effectiveFirstParamType */ undefined,
|
18148
18167
|
/* stripFirstParam */ false);
|
18149
18168
|
}
|
@@ -18152,24 +18171,25 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18152
18171
|
const newOverloadType = types_1.OverloadedFunctionType.create([]);
|
18153
18172
|
// Don't bother binding the implementation.
|
18154
18173
|
types_1.OverloadedFunctionType.getOverloads(memberType).forEach((overload) => {
|
18155
|
-
const boundMethod = bindFunctionToClassOrObject(baseType, overload, memberClass,
|
18156
|
-
/*
|
18174
|
+
const boundMethod = bindFunctionToClassOrObject(baseType, overload, memberClass, treatConstructorAsClassMember, firstParamType,
|
18175
|
+
/* diag */ undefined, recursionCount);
|
18157
18176
|
if (boundMethod) {
|
18158
18177
|
types_1.OverloadedFunctionType.addOverload(newOverloadType, boundMethod);
|
18159
18178
|
}
|
18160
18179
|
});
|
18161
|
-
|
18162
|
-
|
18180
|
+
const newOverloads = types_1.OverloadedFunctionType.getOverloads(newOverloadType);
|
18181
|
+
if (newOverloads.length === 0) {
|
18182
|
+
// No overloads matched, so rebind with the diag
|
18163
18183
|
// to report the error(s) to the user.
|
18164
|
-
if (
|
18184
|
+
if (diag) {
|
18165
18185
|
memberType.overloads.forEach((overload) => {
|
18166
|
-
bindFunctionToClassOrObject(baseType, overload, memberClass,
|
18186
|
+
bindFunctionToClassOrObject(baseType, overload, memberClass, treatConstructorAsClassMember, firstParamType, diag, recursionCount);
|
18167
18187
|
});
|
18168
18188
|
}
|
18169
18189
|
return undefined;
|
18170
18190
|
}
|
18171
|
-
|
18172
|
-
return
|
18191
|
+
if (newOverloads.length === 1) {
|
18192
|
+
return newOverloads[0];
|
18173
18193
|
}
|
18174
18194
|
return newOverloadType;
|
18175
18195
|
}
|
@@ -18181,14 +18201,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18181
18201
|
// is the type used to reference the member, and the memberClass
|
18182
18202
|
// is the class that provided the member (could be an ancestor of
|
18183
18203
|
// the baseType's class).
|
18184
|
-
function partiallySpecializeFunctionForBoundClassOrObject(baseType, memberType, memberClass,
|
18204
|
+
function partiallySpecializeFunctionForBoundClassOrObject(baseType, memberType, memberClass, diag, recursionCount, firstParamType, stripFirstParam = true) {
|
18185
18205
|
const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(memberClass));
|
18186
18206
|
if (firstParamType && memberType.details.parameters.length > 0) {
|
18187
18207
|
const memberTypeFirstParam = memberType.details.parameters[0];
|
18188
18208
|
const memberTypeFirstParamType = types_1.FunctionType.getEffectiveParameterType(memberType, 0);
|
18189
18209
|
// Fill out the typeVarContext for the "self" or "cls" parameter.
|
18190
18210
|
typeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeId)(memberType));
|
18191
|
-
const diag = errorNode ? new diagnostic_1.DiagnosticAddendum() : undefined;
|
18192
18211
|
if ((0, types_1.isTypeVar)(memberTypeFirstParamType) &&
|
18193
18212
|
memberTypeFirstParamType.details.boundType &&
|
18194
18213
|
(0, types_1.isClassInstance)(memberTypeFirstParamType.details.boundType) &&
|
@@ -18203,25 +18222,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18203
18222
|
: firstParamType);
|
18204
18223
|
}
|
18205
18224
|
}
|
18206
|
-
else if (!assignType(memberTypeFirstParamType, firstParamType, diag, typeVarContext,
|
18225
|
+
else if (!assignType(memberTypeFirstParamType, firstParamType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), typeVarContext,
|
18207
18226
|
/* srcTypeVarContext */ undefined, 2048 /* AllowUnspecifiedTypeArguments */, recursionCount)) {
|
18208
18227
|
if (memberTypeFirstParam.name &&
|
18209
18228
|
!memberTypeFirstParam.isNameSynthesized &&
|
18210
18229
|
memberTypeFirstParam.hasDeclaredType) {
|
18211
|
-
if (
|
18212
|
-
|
18213
|
-
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({
|
18214
18232
|
type: printType(baseType),
|
18215
|
-
methodName:
|
18233
|
+
methodName: memberType.details.name || '<anonymous>',
|
18216
18234
|
paramName: memberTypeFirstParam.name,
|
18217
|
-
})
|
18218
|
-
}
|
18219
|
-
else {
|
18220
|
-
// If there was no errorNode, we couldn't report the error,
|
18221
|
-
// so we will instead return undefined and let the caller
|
18222
|
-
// deal with the error.
|
18223
|
-
return undefined;
|
18235
|
+
}));
|
18224
18236
|
}
|
18237
|
+
return undefined;
|
18225
18238
|
}
|
18226
18239
|
}
|
18227
18240
|
}
|