@zzzen/pyright-internal 1.2.0-dev.20240407 → 1.2.0-dev.20240421
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/binder.js +13 -0
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.js +21 -12
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +24 -8
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constructors.d.ts +2 -2
- package/dist/analyzer/constructors.js +174 -109
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.js +15 -1
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/importResolver.js +1 -1
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/importStatementUtils.js +1 -1
- package/dist/analyzer/importStatementUtils.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.d.ts +2 -0
- package/dist/analyzer/parseTreeUtils.js +24 -1
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/properties.js +2 -2
- package/dist/analyzer/protocols.js +5 -5
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/pyTypedUtils.d.ts +4 -0
- package/dist/analyzer/pyTypedUtils.js +17 -3
- package/dist/analyzer/pyTypedUtils.js.map +1 -1
- package/dist/analyzer/service.d.ts +0 -2
- package/dist/analyzer/service.js +1 -4
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/symbolUtils.d.ts +1 -1
- package/dist/analyzer/symbolUtils.js +3 -3
- package/dist/analyzer/symbolUtils.js.map +1 -1
- package/dist/analyzer/typeEvaluator.d.ts +3 -1
- package/dist/analyzer/typeEvaluator.js +167 -76
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +3 -1
- package/dist/analyzer/typeEvaluatorWithTracker.js +4 -2
- package/dist/analyzer/typeEvaluatorWithTracker.js.map +1 -1
- package/dist/analyzer/typeGuards.js +105 -57
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +1 -1
- package/dist/analyzer/typeUtils.js +20 -17
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typeVarContext.js +1 -1
- package/dist/analyzer/typeVarContext.js.map +1 -1
- package/dist/analyzer/typedDicts.js +1 -1
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +2 -2
- package/dist/analyzer/types.js +28 -8
- package/dist/analyzer/types.js.map +1 -1
- package/dist/backgroundAnalysisBase.js +3 -1
- package/dist/backgroundAnalysisBase.js.map +1 -1
- package/dist/backgroundThreadBase.d.ts +5 -5
- package/dist/backgroundThreadBase.js +8 -6
- package/dist/backgroundThreadBase.js.map +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.d.ts +5 -0
- package/dist/commands/dumpFileDebugInfoCommand.js +83 -74
- package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
- package/dist/common/core.d.ts +5 -0
- package/dist/common/core.js +8 -1
- package/dist/common/core.js.map +1 -1
- package/dist/common/fileSystem.d.ts +0 -1
- package/dist/common/fileSystem.js +1 -1
- package/dist/common/fileSystem.js.map +1 -1
- package/dist/common/realFileSystem.d.ts +35 -1
- package/dist/common/realFileSystem.js +4 -1
- package/dist/common/realFileSystem.js.map +1 -1
- package/dist/common/uri/uri.d.ts +2 -0
- package/dist/common/uri/uri.js +9 -4
- package/dist/common/uri/uri.js.map +1 -1
- package/dist/languageService/completionProvider.d.ts +0 -2
- package/dist/languageService/completionProvider.js +7 -28
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/symbolIndexer.js +1 -1
- package/dist/languageService/symbolIndexer.js.map +1 -1
- package/dist/languageService/tooltipUtils.d.ts +1 -1
- package/dist/languageService/tooltipUtils.js +4 -4
- package/dist/localization/localize.d.ts +7 -0
- package/dist/localization/localize.js +5 -0
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +4 -0
- package/dist/localization/package.nls.de.json +5 -1
- package/dist/localization/package.nls.en-us.json +28 -23
- package/dist/localization/package.nls.es.json +8 -4
- package/dist/localization/package.nls.fr.json +8 -4
- package/dist/localization/package.nls.it.json +5 -1
- package/dist/localization/package.nls.ja.json +4 -0
- package/dist/localization/package.nls.ko.json +7 -3
- package/dist/localization/package.nls.pl.json +7 -3
- package/dist/localization/package.nls.pt-br.json +4 -0
- package/dist/localization/package.nls.qps-ploc.json +4 -0
- package/dist/localization/package.nls.ru.json +5 -1
- package/dist/localization/package.nls.tr.json +6 -2
- package/dist/localization/package.nls.zh-cn.json +5 -1
- package/dist/localization/package.nls.zh-tw.json +4 -0
- package/dist/parser/parser.js +3 -2
- package/dist/parser/parser.js.map +1 -1
- package/dist/parser/tokenizer.js +1 -0
- package/dist/parser/tokenizer.js.map +1 -1
- package/dist/parser/tokenizerTypes.d.ts +1 -0
- package/dist/parser/tokenizerTypes.js +1 -0
- package/dist/parser/tokenizerTypes.js.map +1 -1
- package/dist/tests/config.test.js +11 -0
- package/dist/tests/config.test.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.d.ts +1 -1
- package/dist/tests/harness/fourslash/testState.js +2 -2
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/harness/fourslash/workspaceEditTestUtils.d.ts +2 -2
- package/dist/tests/harness/fourslash/workspaceEditTestUtils.js +5 -5
- package/dist/tests/harness/fourslash/workspaceEditTestUtils.js.map +1 -1
- package/dist/tests/importStatementUtils.test.js +1 -1
- package/dist/tests/importStatementUtils.test.js.map +1 -1
- package/dist/tests/tokenizer.test.js +4 -4
- package/dist/tests/tokenizer.test.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +5 -1
- 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 +11 -7
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +2 -2
- package/package.json +2 -2
@@ -170,7 +170,7 @@ const printExpressionTypes = false;
|
|
170
170
|
// complex. Otherwise we risk overflowing the stack or incurring extremely
|
171
171
|
// long analysis times. This number has been tuned empirically.
|
172
172
|
exports.maxCodeComplexity = 768;
|
173
|
-
function createTypeEvaluator(importLookup, evaluatorOptions) {
|
173
|
+
function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
174
174
|
const symbolResolutionStack = [];
|
175
175
|
const asymmetricAccessorAssignmentCache = new Set();
|
176
176
|
const speculativeTypeTracker = new typeCacheUtils_1.SpeculativeTypeTracker();
|
@@ -890,12 +890,27 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
890
890
|
typeResult = getTypeOfExpression(node.typeAnnotation, updatedFlags);
|
891
891
|
}
|
892
892
|
else if (!node.typeAnnotation && node.strings.length === 1) {
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
893
|
+
const tokenFlags = node.strings[0].token.flags;
|
894
|
+
if (tokenFlags & 32 /* StringTokenFlags.Bytes */) {
|
895
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.annotationBytesString(), node);
|
896
|
+
typeResult = { type: types_1.UnknownType.create() };
|
897
|
+
}
|
898
|
+
else if (tokenFlags & 8 /* StringTokenFlags.Raw */) {
|
899
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.annotationRawString(), node);
|
900
|
+
typeResult = { type: types_1.UnknownType.create() };
|
901
|
+
}
|
902
|
+
else if (tokenFlags & 64 /* StringTokenFlags.Format */) {
|
903
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.annotationFormatString(), node);
|
904
|
+
typeResult = { type: types_1.UnknownType.create() };
|
905
|
+
}
|
906
|
+
else {
|
907
|
+
// We didn't know at parse time that this string node was going
|
908
|
+
// to be evaluated as a forward-referenced type. We need
|
909
|
+
// to re-invoke the parser at this stage.
|
910
|
+
const expr = parseStringAsTypeAnnotation(node);
|
911
|
+
if (expr) {
|
912
|
+
typeResult = getTypeOfExpression(expr, updatedFlags);
|
913
|
+
}
|
899
914
|
}
|
900
915
|
}
|
901
916
|
if (!typeResult) {
|
@@ -1430,6 +1445,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1430
1445
|
classType: memberInfo.classType,
|
1431
1446
|
isIncomplete: !!memberInfo.isTypeIncomplete,
|
1432
1447
|
isAsymmetricAccessor: memberInfo.isAsymmetricAccessor,
|
1448
|
+
narrowedTypeForSet: memberInfo.narrowedTypeForSet,
|
1433
1449
|
memberAccessDeprecationInfo: memberInfo.memberAccessDeprecationInfo,
|
1434
1450
|
typeErrors: memberInfo.isDescriptorError,
|
1435
1451
|
};
|
@@ -2258,6 +2274,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2258
2274
|
writeTypeCache(nameNode, { type: destType, isIncomplete: isTypeIncomplete }, 0 /* EvaluatorFlags.None */);
|
2259
2275
|
}
|
2260
2276
|
function assignTypeToMemberAccessNode(target, type, isTypeIncomplete, srcExpr, expectedTypeDiagAddendum) {
|
2277
|
+
var _a;
|
2261
2278
|
const baseTypeResult = getTypeOfExpression(target.leftExpression, 2 /* EvaluatorFlags.MemberAccessBaseDefaults */);
|
2262
2279
|
const baseType = makeTopLevelTypeVarsConcrete(baseTypeResult.type);
|
2263
2280
|
// Handle member accesses (e.g. self.x or cls.y).
|
@@ -2305,7 +2322,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2305
2322
|
setAsymmetricDescriptorAssignment(target);
|
2306
2323
|
}
|
2307
2324
|
const resultToCache = {
|
2308
|
-
type,
|
2325
|
+
type: (_a = setTypeResult.narrowedTypeForSet) !== null && _a !== void 0 ? _a : type,
|
2309
2326
|
isIncomplete: isTypeIncomplete,
|
2310
2327
|
memberAccessDeprecationInfo: setTypeResult.memberAccessDeprecationInfo,
|
2311
2328
|
};
|
@@ -2933,7 +2950,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2933
2950
|
if (typeParamSymbol) {
|
2934
2951
|
symbol = typeParamSymbol;
|
2935
2952
|
(0, debug_1.assert)(symbol.getDeclarations().length === 1);
|
2936
|
-
const decl = (0, symbolUtils_1.
|
2953
|
+
const decl = (0, symbolUtils_1.getLastTypedDeclarationForSymbol)(symbol);
|
2937
2954
|
(0, debug_1.assert)((decl === null || decl === void 0 ? void 0 : decl.type) === 3 /* DeclarationType.TypeParameter */);
|
2938
2955
|
type = getTypeOfTypeParameter(decl.node);
|
2939
2956
|
setSymbolAccessed(fileInfo, symbol, node);
|
@@ -3533,6 +3550,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3533
3550
|
let diag = new diagnostic_1.DiagnosticAddendum();
|
3534
3551
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
3535
3552
|
let type;
|
3553
|
+
let narrowedTypeForSet;
|
3554
|
+
let typeErrors = false;
|
3536
3555
|
let isIncomplete = !!baseTypeResult.isIncomplete;
|
3537
3556
|
let isAsymmetricAccessor;
|
3538
3557
|
const isRequired = false;
|
@@ -3617,15 +3636,24 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3617
3636
|
typeResult = getTypeOfBoundMember(node.memberName, baseType, memberName, usage, diag,
|
3618
3637
|
/* memberAccessFlags */ undefined, baseTypeResult.bindToSelfType);
|
3619
3638
|
}
|
3620
|
-
if (typeResult
|
3621
|
-
|
3622
|
-
|
3623
|
-
|
3624
|
-
|
3639
|
+
if (typeResult) {
|
3640
|
+
if (!typeResult.typeErrors) {
|
3641
|
+
type = (0, typeUtils_1.addConditionToType)(typeResult.type, (0, typeUtils_1.getTypeCondition)(baseType),
|
3642
|
+
/* skipSelfCondition */ true);
|
3643
|
+
}
|
3644
|
+
else {
|
3645
|
+
typeErrors = true;
|
3625
3646
|
}
|
3626
3647
|
if (typeResult.isAsymmetricAccessor) {
|
3627
3648
|
isAsymmetricAccessor = true;
|
3628
3649
|
}
|
3650
|
+
if (typeResult.isIncomplete) {
|
3651
|
+
isIncomplete = true;
|
3652
|
+
}
|
3653
|
+
if (typeResult.narrowedTypeForSet) {
|
3654
|
+
narrowedTypeForSet = (0, typeUtils_1.addConditionToType)(typeResult.narrowedTypeForSet, (0, typeUtils_1.getTypeCondition)(baseType),
|
3655
|
+
/* skipSelfCondition */ true);
|
3656
|
+
}
|
3629
3657
|
if (typeResult.memberAccessDeprecationInfo) {
|
3630
3658
|
memberAccessDeprecationInfo = typeResult.memberAccessDeprecationInfo;
|
3631
3659
|
}
|
@@ -3726,9 +3754,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3726
3754
|
if (typeResult.isIncomplete) {
|
3727
3755
|
isIncomplete = true;
|
3728
3756
|
}
|
3729
|
-
if (typeResult
|
3757
|
+
if (typeResult.memberAccessDeprecationInfo) {
|
3730
3758
|
memberAccessDeprecationInfo = typeResult.memberAccessDeprecationInfo;
|
3731
3759
|
}
|
3760
|
+
if (typeResult.typeErrors) {
|
3761
|
+
typeErrors = true;
|
3762
|
+
}
|
3732
3763
|
return typeResult.type;
|
3733
3764
|
});
|
3734
3765
|
break;
|
@@ -3795,7 +3826,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3795
3826
|
if ((flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) === 0) {
|
3796
3827
|
reportUseOfTypeCheckOnly(type, node.memberName);
|
3797
3828
|
}
|
3798
|
-
return {
|
3829
|
+
return {
|
3830
|
+
type,
|
3831
|
+
isIncomplete,
|
3832
|
+
isAsymmetricAccessor,
|
3833
|
+
narrowedTypeForSet,
|
3834
|
+
isRequired,
|
3835
|
+
isNotRequired,
|
3836
|
+
memberAccessDeprecationInfo,
|
3837
|
+
typeErrors,
|
3838
|
+
};
|
3799
3839
|
}
|
3800
3840
|
function getTypeOfClassMemberName(errorNode, classType, memberName, usage, diag, flags, selfType, recursionCount = 0) {
|
3801
3841
|
var _a, _b, _c;
|
@@ -3831,6 +3871,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3831
3871
|
}
|
3832
3872
|
let type;
|
3833
3873
|
let isTypeIncomplete = false;
|
3874
|
+
let narrowedTypeForSet;
|
3834
3875
|
if (memberInfo.symbol.isInitVar()) {
|
3835
3876
|
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.memberIsInitVar().format({ name: memberName }));
|
3836
3877
|
return undefined;
|
@@ -3985,6 +4026,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3985
4026
|
return resultType;
|
3986
4027
|
});
|
3987
4028
|
if (!isDescriptorError && usage.method === 'set' && usage.setType) {
|
4029
|
+
if (errorNode && memberInfo.symbol.hasTypedDeclarations()) {
|
4030
|
+
// This is an assignment to a member with a declared type. Apply
|
4031
|
+
// narrowing logic based on the assigned type. Skip this for
|
4032
|
+
// descriptor-based accesses.
|
4033
|
+
narrowedTypeForSet = isDescriptorApplied
|
4034
|
+
? usage.setType.type
|
4035
|
+
: narrowTypeBasedOnAssignment(errorNode, type, usage.setType.type);
|
4036
|
+
}
|
3988
4037
|
// Verify that the assigned type is compatible.
|
3989
4038
|
if (!assignType(type, usage.setType.type, diag === null || diag === void 0 ? void 0 : diag.createAddendum())) {
|
3990
4039
|
if (!usage.setType.isIncomplete) {
|
@@ -3994,6 +4043,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3994
4043
|
classType: printObjectTypeForClass(classType),
|
3995
4044
|
}));
|
3996
4045
|
}
|
4046
|
+
// Do not narrow the type in this case. Assume the declared type.
|
4047
|
+
narrowedTypeForSet = type;
|
3997
4048
|
isDescriptorError = true;
|
3998
4049
|
}
|
3999
4050
|
if ((0, types_1.isInstantiableClass)(memberInfo.classType) &&
|
@@ -4014,6 +4065,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4014
4065
|
isClassVar: memberInfo.isClassVar,
|
4015
4066
|
classType: memberInfo.classType,
|
4016
4067
|
isAsymmetricAccessor,
|
4068
|
+
narrowedTypeForSet,
|
4017
4069
|
memberAccessDeprecationInfo,
|
4018
4070
|
};
|
4019
4071
|
}
|
@@ -6644,7 +6696,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6644
6696
|
if (!symbol.isClassMember() && !symbol.isNamedTupleMemberMember()) {
|
6645
6697
|
return undefined;
|
6646
6698
|
}
|
6647
|
-
const lastDecl = (0, symbolUtils_1.
|
6699
|
+
const lastDecl = (0, symbolUtils_1.getLastTypedDeclarationForSymbol)(symbol);
|
6648
6700
|
if (!lastDecl) {
|
6649
6701
|
return undefined;
|
6650
6702
|
}
|
@@ -7010,7 +7062,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7010
7062
|
// validation is left to the caller.
|
7011
7063
|
// This logic is based on PEP 3102: https://www.python.org/dev/peps/pep-3102/
|
7012
7064
|
function matchFunctionArgumentsToParameters(errorNode, argList, typeResult, overloadIndex) {
|
7013
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
7065
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
7014
7066
|
const paramDetails = (0, parameterUtils_1.getParameterListDetails)(typeResult.type);
|
7015
7067
|
let argIndex = 0;
|
7016
7068
|
let matchedUnpackedListOfUnknownLength = false;
|
@@ -7057,8 +7109,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7057
7109
|
// function nested within another function that defines the param
|
7058
7110
|
// spec? We need to handle these two cases differently.
|
7059
7111
|
const paramSpecScopeId = varArgListParam.type.scopeId;
|
7060
|
-
if (
|
7061
|
-
paramSpecScopeId === typeResult.type.details.constructorTypeVarScopeId) {
|
7112
|
+
if ((_b = (0, typeUtils_1.getTypeVarScopeIds)(typeResult.type)) === null || _b === void 0 ? void 0 : _b.some((id) => id === paramSpecScopeId)) {
|
7062
7113
|
paramSpecArgList = [];
|
7063
7114
|
paramSpecTarget = types_1.TypeVarType.cloneForParamSpecAccess(varArgListParam.type, /* access */ undefined);
|
7064
7115
|
}
|
@@ -7069,9 +7120,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7069
7120
|
}
|
7070
7121
|
else if (typeResult.type.details.paramSpec) {
|
7071
7122
|
const paramSpecScopeId = typeResult.type.details.paramSpec.scopeId;
|
7072
|
-
if (typeResult.type
|
7073
|
-
paramSpecScopeId === typeResult.type.details.typeVarScopeId ||
|
7074
|
-
paramSpecScopeId === typeResult.type.details.constructorTypeVarScopeId) {
|
7123
|
+
if ((_c = (0, typeUtils_1.getTypeVarScopeIds)(typeResult.type)) === null || _c === void 0 ? void 0 : _c.some((id) => id === paramSpecScopeId)) {
|
7075
7124
|
hasParamSpecArgsKwargs = true;
|
7076
7125
|
paramSpecArgList = [];
|
7077
7126
|
paramSpecTarget = types_1.TypeVarType.cloneForParamSpecAccess(typeResult.type.details.paramSpec,
|
@@ -7163,7 +7212,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7163
7212
|
? localize_1.LocMessage.argPositionalExpectedOne()
|
7164
7213
|
: localize_1.LocMessage.argPositionalExpectedCount().format({
|
7165
7214
|
expected: positionParamLimitIndex,
|
7166
|
-
}), (
|
7215
|
+
}), (_d = argList[argIndex].valueExpression) !== null && _d !== void 0 ? _d : errorNode);
|
7167
7216
|
}
|
7168
7217
|
reportedArgError = true;
|
7169
7218
|
}
|
@@ -7196,7 +7245,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7196
7245
|
? localize_1.LocMessage.argPositionalExpectedOne()
|
7197
7246
|
: localize_1.LocMessage.argPositionalExpectedCount().format({
|
7198
7247
|
expected: positionParamLimitIndex,
|
7199
|
-
}), (
|
7248
|
+
}), (_e = argList[argIndex].valueExpression) !== null && _e !== void 0 ? _e : errorNode);
|
7200
7249
|
}
|
7201
7250
|
reportedArgError = true;
|
7202
7251
|
}
|
@@ -7238,9 +7287,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7238
7287
|
listElementType = undefined;
|
7239
7288
|
}
|
7240
7289
|
else {
|
7241
|
-
listElementType = (
|
7290
|
+
listElementType = (_f = getTypeOfIterator({ type: argType, isIncomplete: argTypeResult.isIncomplete },
|
7242
7291
|
/* isAsync */ false, errorNode,
|
7243
|
-
/* emitNotIterableError */ false)) === null ||
|
7292
|
+
/* emitNotIterableError */ false)) === null || _f === void 0 ? void 0 : _f.type;
|
7244
7293
|
if (paramDetails.params[paramIndex].param.category !== 1 /* ParameterCategory.ArgsList */) {
|
7245
7294
|
matchedUnpackedListOfUnknownLength = true;
|
7246
7295
|
}
|
@@ -7272,7 +7321,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7272
7321
|
paramType,
|
7273
7322
|
requiresTypeVarMatching: (0, typeUtils_1.requiresSpecialization)(paramType),
|
7274
7323
|
argument: funcArg,
|
7275
|
-
errorNode: (
|
7324
|
+
errorNode: (_g = argList[argIndex].valueExpression) !== null && _g !== void 0 ? _g : errorNode,
|
7276
7325
|
paramName,
|
7277
7326
|
isParamNameSynthesized: paramDetails.params[paramIndex].param.isNameSynthesized,
|
7278
7327
|
mapsToVarArgList: isParamVariadic && remainingArgCount > remainingParamCount,
|
@@ -7576,7 +7625,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7576
7625
|
paramType,
|
7577
7626
|
requiresTypeVarMatching: (0, typeUtils_1.requiresSpecialization)(paramType),
|
7578
7627
|
argument: argList[argIndex],
|
7579
|
-
errorNode: (
|
7628
|
+
errorNode: (_h = argList[argIndex].valueExpression) !== null && _h !== void 0 ? _h : errorNode,
|
7580
7629
|
paramName: paramNameValue,
|
7581
7630
|
});
|
7582
7631
|
trySetActive(argList[argIndex], paramDetails.params[paramInfoIndex].param);
|
@@ -7592,7 +7641,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7592
7641
|
paramType,
|
7593
7642
|
requiresTypeVarMatching: (0, typeUtils_1.requiresSpecialization)(paramType),
|
7594
7643
|
argument: argList[argIndex],
|
7595
|
-
errorNode: (
|
7644
|
+
errorNode: (_j = argList[argIndex].valueExpression) !== null && _j !== void 0 ? _j : errorNode,
|
7596
7645
|
paramName: paramNameValue,
|
7597
7646
|
});
|
7598
7647
|
// Remember that this parameter has already received a value.
|
@@ -7642,7 +7691,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7642
7691
|
requiresTypeVarMatching: false,
|
7643
7692
|
argument: argList[argIndex],
|
7644
7693
|
argType: (0, types_1.isParamSpec)(argType) ? undefined : types_1.AnyType.create(),
|
7645
|
-
errorNode: (
|
7694
|
+
errorNode: (_k = argList[argIndex].valueExpression) !== null && _k !== void 0 ? _k : errorNode,
|
7646
7695
|
});
|
7647
7696
|
}
|
7648
7697
|
}
|
@@ -7954,12 +8003,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7954
8003
|
typeVarContext.addSolveForScope(type.boundTypeVarScopeId);
|
7955
8004
|
}
|
7956
8005
|
}
|
7957
|
-
//
|
7958
|
-
//
|
7959
|
-
// be constructed. Although this isn't part of the official Python spec, other
|
7960
|
-
// type checkers appear to honor it.
|
8006
|
+
// The type annotation for the "self" parameter in an __init__ method to
|
8007
|
+
// can incluence the type being constructed.
|
7961
8008
|
if (type.details.name === '__init__' &&
|
7962
|
-
types_1.FunctionType.isOverloaded(type) &&
|
7963
8009
|
type.strippedFirstParamType &&
|
7964
8010
|
type.boundToType &&
|
7965
8011
|
(0, types_1.isClassInstance)(type.strippedFirstParamType) &&
|
@@ -8126,9 +8172,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8126
8172
|
// If the function is returning a callable, don't eliminate unsolved
|
8127
8173
|
// type vars within a union. There are legit uses for unsolved type vars
|
8128
8174
|
// within a callable.
|
8129
|
-
if ((0, types_1.isFunction)(returnType) ||
|
8130
|
-
(0, types_1.isOverloadedFunction)(returnType) ||
|
8131
|
-
type.details.typeVarScopeId === types_1.WildcardTypeVarScopeId) {
|
8175
|
+
if ((0, types_1.isFunction)(returnType) || (0, types_1.isOverloadedFunction)(returnType)) {
|
8132
8176
|
eliminateUnsolvedInUnions = false;
|
8133
8177
|
}
|
8134
8178
|
// We'll leave TypeVars unsolved if the call is a recursive
|
@@ -8180,7 +8224,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8180
8224
|
specializedReturnType = types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneForTypeGuard(boolClassType, typeGuardType, useTypeIsSemantics));
|
8181
8225
|
}
|
8182
8226
|
}
|
8183
|
-
|
8227
|
+
const liveTypeVarScopes = ParseTreeUtils.getTypeVarScopesForNode(errorNode);
|
8228
|
+
specializedReturnType = adjustCallableReturnType(type, specializedReturnType, liveTypeVarScopes, signatureTracker.getTrackedSignatures());
|
8184
8229
|
if (specializedInitSelfType) {
|
8185
8230
|
specializedInitSelfType = (0, typeUtils_1.applySolvedTypeVars)(specializedInitSelfType, typeVarContext);
|
8186
8231
|
}
|
@@ -8223,23 +8268,24 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8223
8268
|
return [];
|
8224
8269
|
}
|
8225
8270
|
// If the return type includes a generic Callable type, set the type var
|
8226
|
-
// scope to
|
8227
|
-
//
|
8228
|
-
//
|
8229
|
-
// the future.
|
8271
|
+
// scope to the scope of the function it was originally associated with
|
8272
|
+
// to allow these type vars to be solved. This won't work with overloads
|
8273
|
+
// or unions of callables. It's intended for a specific use case. We may
|
8274
|
+
// need to make this more sophisticated in the future.
|
8230
8275
|
// The trackedSignatures parameter supplies a list of function signatures
|
8231
8276
|
// that were used for the function and the arguments passed to it. This is
|
8232
8277
|
// important because the callable return value may be called again with
|
8233
8278
|
// one of these signatures, so we may need to "uniquify" the type parameters
|
8234
8279
|
// to avoid conflicts.
|
8235
|
-
function adjustCallableReturnType(returnType, trackedSignatures) {
|
8236
|
-
if ((0, types_1.isFunction)(returnType) && !returnType.details.name) {
|
8237
|
-
|
8280
|
+
function adjustCallableReturnType(callableType, returnType, liveTypeVarScopes, trackedSignatures) {
|
8281
|
+
if ((0, types_1.isFunction)(returnType) && !returnType.details.name && callableType.details.typeVarScopeId) {
|
8282
|
+
// What type variables are referenced in the callable return type? Do not include any live type variables.
|
8283
|
+
const typeVarsInReturnType = (0, typeUtils_1.getTypeVarArgumentsRecursive)(returnType).filter((t) => !liveTypeVarScopes.some((scopeId) => t.scopeId === scopeId));
|
8238
8284
|
// If there are no unsolved type variables, we're done. If there are
|
8239
|
-
// unsolved type
|
8285
|
+
// unsolved type variables, treat them as though they are rescoped
|
8240
8286
|
// to the callable.
|
8241
8287
|
if (typeVarsInReturnType.length > 0) {
|
8242
|
-
return types_1.FunctionType.cloneWithNewTypeVarScopeId(returnType,
|
8288
|
+
return types_1.FunctionType.cloneWithNewTypeVarScopeId(returnType, callableType.details.typeVarScopeId, typeVarsInReturnType, trackedSignatures);
|
8243
8289
|
}
|
8244
8290
|
}
|
8245
8291
|
return returnType;
|
@@ -8507,7 +8553,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8507
8553
|
if ((0, types_1.isFunction)(concreteParamType) || (0, types_1.isOverloadedFunction)(concreteParamType)) {
|
8508
8554
|
if ((0, types_1.isInstantiableClass)(argType)) {
|
8509
8555
|
const constructor = (0, constructors_1.createFunctionFromConstructor)(evaluatorInterface, argType);
|
8510
|
-
if (constructor
|
8556
|
+
if (constructor) {
|
8511
8557
|
return {
|
8512
8558
|
isCompatible,
|
8513
8559
|
argType,
|
@@ -8754,7 +8800,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8754
8800
|
}
|
8755
8801
|
function verifyTypeVarDefaultIsCompatible(typeVar, defaultValueNode) {
|
8756
8802
|
(0, debug_1.assert)(typeVar.details.isDefaultExplicit);
|
8757
|
-
const typeVarContext = new typeVarContext_1.TypeVarContext(
|
8803
|
+
const typeVarContext = new typeVarContext_1.TypeVarContext(typeVar.scopeId);
|
8758
8804
|
const concreteDefaultType = makeTopLevelTypeVarsConcrete((0, typeUtils_1.applySolvedTypeVars)(typeVar.details.defaultType, typeVarContext, {
|
8759
8805
|
unknownIfNotFound: true,
|
8760
8806
|
}));
|
@@ -8808,7 +8854,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8808
8854
|
if (paramName === 'default') {
|
8809
8855
|
const expr = argList[i].valueExpression;
|
8810
8856
|
if (expr) {
|
8811
|
-
const defaultType = getTypeVarTupleDefaultType(expr);
|
8857
|
+
const defaultType = getTypeVarTupleDefaultType(expr, /* isPep695Syntax */ false);
|
8812
8858
|
if (defaultType) {
|
8813
8859
|
typeVar.details.defaultType = defaultType;
|
8814
8860
|
typeVar.details.isDefaultExplicit = true;
|
@@ -8831,10 +8877,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8831
8877
|
}
|
8832
8878
|
return typeVar;
|
8833
8879
|
}
|
8834
|
-
function getTypeVarTupleDefaultType(node) {
|
8880
|
+
function getTypeVarTupleDefaultType(node, isPep695Syntax) {
|
8835
8881
|
const argType = getTypeOfExpressionExpectingType(node, {
|
8836
8882
|
allowUnpackedTuple: true,
|
8837
8883
|
allowTypeVarsWithoutScopeId: true,
|
8884
|
+
allowForwardReference: isPep695Syntax,
|
8838
8885
|
}).type;
|
8839
8886
|
const isUnpackedTuple = (0, types_1.isClass)(argType) && (0, typeUtils_1.isTupleClass)(argType) && argType.isUnpacked;
|
8840
8887
|
const isUnpackedTypeVarTuple = (0, types_1.isUnpackedVariadicTypeVar)(argType);
|
@@ -8867,7 +8914,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8867
8914
|
if (paramName === 'default') {
|
8868
8915
|
const expr = argList[i].valueExpression;
|
8869
8916
|
if (expr) {
|
8870
|
-
const defaultType = getParamSpecDefaultType(expr);
|
8917
|
+
const defaultType = getParamSpecDefaultType(expr, /* isPep695Syntax */ false);
|
8871
8918
|
if (defaultType) {
|
8872
8919
|
paramSpec.details.defaultType = defaultType;
|
8873
8920
|
paramSpec.details.isDefaultExplicit = true;
|
@@ -8891,7 +8938,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8891
8938
|
}
|
8892
8939
|
return paramSpec;
|
8893
8940
|
}
|
8894
|
-
function getParamSpecDefaultType(node) {
|
8941
|
+
function getParamSpecDefaultType(node, isPep695Syntax) {
|
8895
8942
|
const functionType = types_1.FunctionType.createSynthesizedInstance('', 32768 /* FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck */ | 65536 /* FunctionTypeFlags.ParamSpecValue */);
|
8896
8943
|
if (node.nodeType === 18 /* ParseNodeType.Ellipsis */) {
|
8897
8944
|
types_1.FunctionType.addDefaultParameters(functionType);
|
@@ -8899,7 +8946,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8899
8946
|
}
|
8900
8947
|
if (node.nodeType === 31 /* ParseNodeType.List */) {
|
8901
8948
|
node.entries.forEach((paramExpr, index) => {
|
8902
|
-
const typeResult = getTypeOfExpressionExpectingType(paramExpr, {
|
8949
|
+
const typeResult = getTypeOfExpressionExpectingType(paramExpr, {
|
8950
|
+
allowTypeVarsWithoutScopeId: true,
|
8951
|
+
allowForwardReference: isPep695Syntax,
|
8952
|
+
});
|
8903
8953
|
types_1.FunctionType.addParameter(functionType, {
|
8904
8954
|
category: 0 /* ParameterCategory.Simple */,
|
8905
8955
|
name: `__p${index}`,
|
@@ -10454,6 +10504,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10454
10504
|
else {
|
10455
10505
|
type = cloneBuiltinClassWithLiteral(node, classType, 'str', value);
|
10456
10506
|
}
|
10507
|
+
itemExpr.strings.forEach((stringNode) => {
|
10508
|
+
if ((stringNode.token.flags & 512 /* StringTokenFlags.NamedUnicodeEscape */) !== 0) {
|
10509
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.literalNamedUnicodeEscape(), stringNode);
|
10510
|
+
}
|
10511
|
+
});
|
10457
10512
|
}
|
10458
10513
|
else if (itemExpr.nodeType === 40 /* ParseNodeType.Number */) {
|
10459
10514
|
if (!itemExpr.isImaginary && itemExpr.isInteger) {
|
@@ -13802,6 +13857,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13802
13857
|
break;
|
13803
13858
|
}
|
13804
13859
|
}
|
13860
|
+
else if (parent.nodeType === 75 /* ParseNodeType.TypeParameter */) {
|
13861
|
+
// If this is a bound or default expression in a type parameter list,
|
13862
|
+
// we need to evaluate it in the context of the type parameter.
|
13863
|
+
if (node === parent.boundExpression || node === parent.defaultExpression) {
|
13864
|
+
getTypeOfTypeParameter(parent);
|
13865
|
+
return;
|
13866
|
+
}
|
13867
|
+
break;
|
13868
|
+
}
|
13805
13869
|
else {
|
13806
13870
|
break;
|
13807
13871
|
}
|
@@ -15103,6 +15167,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15103
15167
|
const constraints = node.boundExpression.expressions.map((constraint) => {
|
15104
15168
|
const constraintType = getTypeOfExpressionExpectingType(constraint, {
|
15105
15169
|
disallowProtocolAndTypedDict: true,
|
15170
|
+
allowForwardReference: true,
|
15106
15171
|
}).type;
|
15107
15172
|
if ((0, typeUtils_1.requiresSpecialization)(constraintType, {
|
15108
15173
|
ignorePseudoGeneric: true,
|
@@ -15122,6 +15187,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15122
15187
|
else {
|
15123
15188
|
const boundType = getTypeOfExpressionExpectingType(node.boundExpression, {
|
15124
15189
|
disallowProtocolAndTypedDict: true,
|
15190
|
+
allowForwardReference: true,
|
15125
15191
|
}).type;
|
15126
15192
|
if ((0, typeUtils_1.requiresSpecialization)(boundType, { ignorePseudoGeneric: true })) {
|
15127
15193
|
addError(localize_1.LocMessage.typeVarConstraintGeneric(), node.boundExpression);
|
@@ -15132,7 +15198,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15132
15198
|
}
|
15133
15199
|
}
|
15134
15200
|
if (node.typeParamCategory === parseNodes_1.TypeParameterCategory.ParamSpec) {
|
15135
|
-
const defaultType = node.defaultExpression
|
15201
|
+
const defaultType = node.defaultExpression
|
15202
|
+
? getParamSpecDefaultType(node.defaultExpression, /* isPep695Syntax */ true)
|
15203
|
+
: undefined;
|
15136
15204
|
if (defaultType) {
|
15137
15205
|
typeVar.details.defaultType = defaultType;
|
15138
15206
|
typeVar.details.isDefaultExplicit = true;
|
@@ -15142,7 +15210,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15142
15210
|
}
|
15143
15211
|
}
|
15144
15212
|
else if (node.typeParamCategory === parseNodes_1.TypeParameterCategory.TypeVarTuple) {
|
15145
|
-
const defaultType = node.defaultExpression
|
15213
|
+
const defaultType = node.defaultExpression
|
15214
|
+
? getTypeVarTupleDefaultType(node.defaultExpression, /* isPep695Syntax */ true)
|
15215
|
+
: undefined;
|
15146
15216
|
if (defaultType) {
|
15147
15217
|
typeVar.details.defaultType = defaultType;
|
15148
15218
|
typeVar.details.isDefaultExplicit = true;
|
@@ -15153,7 +15223,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15153
15223
|
}
|
15154
15224
|
else {
|
15155
15225
|
const defaultType = node.defaultExpression
|
15156
|
-
? (0, typeUtils_1.convertToInstance)(getTypeOfExpressionExpectingType(node.defaultExpression).type)
|
15226
|
+
? (0, typeUtils_1.convertToInstance)(getTypeOfExpressionExpectingType(node.defaultExpression, { allowForwardReference: true }).type)
|
15157
15227
|
: undefined;
|
15158
15228
|
if (defaultType) {
|
15159
15229
|
typeVar.details.defaultType = defaultType;
|
@@ -15782,14 +15852,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15782
15852
|
function getFunctionEffectiveReturnType(type, args, inferTypeIfNeeded = true) {
|
15783
15853
|
const specializedReturnType = types_1.FunctionType.getSpecializedReturnType(type, /* includeInferred */ false);
|
15784
15854
|
if (specializedReturnType && !(0, types_1.isUnknown)(specializedReturnType)) {
|
15785
|
-
return adjustCallableReturnType(specializedReturnType, /*
|
15855
|
+
return adjustCallableReturnType(type, specializedReturnType, /* liveTypeVarScopes */ []);
|
15786
15856
|
}
|
15787
15857
|
if (inferTypeIfNeeded) {
|
15788
15858
|
return getFunctionInferredReturnType(type, args);
|
15789
15859
|
}
|
15790
15860
|
return types_1.UnknownType.create();
|
15791
15861
|
}
|
15792
|
-
function
|
15862
|
+
function _getFunctionInferredReturnType(type, args) {
|
15793
15863
|
var _a;
|
15794
15864
|
let returnType;
|
15795
15865
|
let isIncomplete = false;
|
@@ -17148,6 +17218,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17148
17218
|
const constructor = (0, constructors_1.createFunctionFromConstructor)(evaluatorInterface, concreteSrcType, (0, types_1.isTypeVar)(srcType) ? (0, typeUtils_1.convertToInstance)(srcType) : undefined, recursionCount);
|
17149
17219
|
if (constructor) {
|
17150
17220
|
concreteSrcType = constructor;
|
17221
|
+
// The constructor conversion may result in a union of the
|
17222
|
+
// __init__ and __new__ callables.
|
17223
|
+
if ((0, types_1.isUnion)(concreteSrcType)) {
|
17224
|
+
return assignType(destType, concreteSrcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount);
|
17225
|
+
}
|
17151
17226
|
}
|
17152
17227
|
}
|
17153
17228
|
if ((0, types_1.isAnyOrUnknown)(concreteSrcType)) {
|
@@ -17357,12 +17432,23 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17357
17432
|
else if (remainingDestSubtypes.length === remainingSrcSubtypes.length) {
|
17358
17433
|
// If the number of remaining source subtypes is the same as the number
|
17359
17434
|
// of dest TypeVars, try to assign each source subtype to its own dest TypeVar.
|
17360
|
-
|
17361
|
-
|
17362
|
-
|
17435
|
+
const reorderedDestSubtypes = [...remainingDestSubtypes];
|
17436
|
+
for (let srcIndex = 0; srcIndex < remainingSrcSubtypes.length; srcIndex++) {
|
17437
|
+
let foundMatchForSrc = false;
|
17438
|
+
for (let destIndex = 0; destIndex < reorderedDestSubtypes.length; destIndex++) {
|
17439
|
+
if (assignType(reorderedDestSubtypes[destIndex], remainingSrcSubtypes[srcIndex], diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
|
17440
|
+
foundMatchForSrc = true;
|
17441
|
+
// Move the matched dest TypeVar to the end of the list so the other
|
17442
|
+
// dest TypeVars have a better chance of being assigned to.
|
17443
|
+
reorderedDestSubtypes.push(...reorderedDestSubtypes.splice(destIndex, 1));
|
17444
|
+
break;
|
17445
|
+
}
|
17446
|
+
}
|
17447
|
+
if (!foundMatchForSrc) {
|
17363
17448
|
canUseFastPath = false;
|
17449
|
+
break;
|
17364
17450
|
}
|
17365
|
-
}
|
17451
|
+
}
|
17366
17452
|
// We can avoid checking the source subtypes that have already been checked.
|
17367
17453
|
sortedSrcTypes = remainingSrcSubtypes;
|
17368
17454
|
}
|
@@ -18181,10 +18267,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18181
18267
|
remainingFunction.details.typeVarScopeId = effectiveSrcType.details.typeVarScopeId;
|
18182
18268
|
remainingFunction.details.constructorTypeVarScopeId =
|
18183
18269
|
effectiveSrcType.details.constructorTypeVarScopeId;
|
18270
|
+
remainingFunction.details.methodClass = effectiveSrcType.details.methodClass;
|
18184
18271
|
remainingParams.forEach((param) => {
|
18185
18272
|
types_1.FunctionType.addParameter(remainingFunction, param);
|
18186
18273
|
});
|
18187
18274
|
remainingFunction.details.paramSpec = srcParamSpec ? (0, typeUtils_1.convertToInstance)(srcParamSpec) : undefined;
|
18275
|
+
types_1.FunctionType.addHigherOrderTypeVarScopeIds(remainingFunction, effectiveSrcType.details.higherOrderTypeVarScopeIds);
|
18188
18276
|
if (!assignType(destParamSpec, remainingFunction,
|
18189
18277
|
/* diag */ undefined, destTypeVarContext, srcTypeVarContext, flags)) {
|
18190
18278
|
// If we couldn't assign the function to the ParamSpec, see if we can
|
@@ -18215,12 +18303,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18215
18303
|
(0, typeUtils_1.containsLiteralType)(srcType.details.declaredReturnType, /* includeTypeArgs */ true)) {
|
18216
18304
|
effectiveFlags |= 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */;
|
18217
18305
|
}
|
18218
|
-
if ((
|
18219
|
-
// We'll allow any function that returns NoReturn to match any
|
18220
|
-
// function return type, consistent with other type checkers.
|
18221
|
-
isReturnTypeCompatible = true;
|
18222
|
-
}
|
18223
|
-
else if (assignType(destReturnType, srcReturnType, returnDiag === null || returnDiag === void 0 ? void 0 : returnDiag.createAddendum(), destTypeVarContext, srcTypeVarContext, effectiveFlags, recursionCount)) {
|
18306
|
+
if (assignType(destReturnType, srcReturnType, returnDiag === null || returnDiag === void 0 ? void 0 : returnDiag.createAddendum(), destTypeVarContext, srcTypeVarContext, effectiveFlags, recursionCount)) {
|
18224
18307
|
isReturnTypeCompatible = true;
|
18225
18308
|
}
|
18226
18309
|
else {
|
@@ -18893,11 +18976,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18893
18976
|
}
|
18894
18977
|
// If the memberType is an instance or class method, creates a new
|
18895
18978
|
// version of the function that has the "self" or "cls" parameter bound
|
18896
|
-
// to it. If
|
18979
|
+
// to it. If treatConstructorAsClassMethod is true, the function is
|
18897
18980
|
// treated like a class method even if it's not marked as such. That's
|
18898
18981
|
// needed to special-case the __new__ magic method when it's invoked as
|
18899
18982
|
// a constructor (as opposed to by name).
|
18900
|
-
function bindFunctionToClassOrObject(baseType, memberType, memberClass,
|
18983
|
+
function bindFunctionToClassOrObject(baseType, memberType, memberClass, treatConstructorAsClassMethod = false, selfType, diag, recursionCount = 0) {
|
18901
18984
|
return (0, typeUtils_1.mapSignatures)(memberType, (functionType) => {
|
18902
18985
|
// If the caller specified no base type, always strip the
|
18903
18986
|
// first parameter. This is used in cases like constructors.
|
@@ -18912,11 +18995,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18912
18995
|
const baseObj = (0, types_1.isClassInstance)(baseType)
|
18913
18996
|
? baseType
|
18914
18997
|
: types_1.ClassType.cloneAsInstance((0, typeUtils_1.specializeClassType)(baseType));
|
18915
|
-
|
18916
|
-
|
18998
|
+
let stripFirstParam = false;
|
18999
|
+
if ((0, types_1.isClassInstance)(baseType)) {
|
19000
|
+
stripFirstParam = true;
|
19001
|
+
}
|
19002
|
+
else if (memberClass && (0, typeUtils_1.isInstantiableMetaclass)(memberClass)) {
|
19003
|
+
stripFirstParam = true;
|
19004
|
+
}
|
19005
|
+
return partiallySpecializeFunctionForBoundClassOrObject(baseType, functionType, memberClass !== null && memberClass !== void 0 ? memberClass : types_1.ClassType.cloneAsInstantiable(baseObj), diag, recursionCount, selfType !== null && selfType !== void 0 ? selfType : baseObj, stripFirstParam);
|
18917
19006
|
}
|
18918
19007
|
if (types_1.FunctionType.isClassMethod(functionType) ||
|
18919
|
-
(
|
19008
|
+
(treatConstructorAsClassMethod && types_1.FunctionType.isConstructorMethod(functionType))) {
|
18920
19009
|
const baseClass = (0, types_1.isInstantiableClass)(baseType) ? baseType : types_1.ClassType.cloneAsInstantiable(baseType);
|
18921
19010
|
const clsType = selfType ? (0, typeUtils_1.convertToInstantiable)(selfType) : undefined;
|
18922
19011
|
return partiallySpecializeFunctionForBoundClassOrObject(baseClass, functionType, memberClass !== null && memberClass !== void 0 ? memberClass : baseClass, diag, recursionCount, clsType !== null && clsType !== void 0 ? clsType : baseClass,
|
@@ -19175,6 +19264,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
19175
19264
|
});
|
19176
19265
|
});
|
19177
19266
|
}
|
19267
|
+
// Track these apis internal usages when logging is on. otherwise, it should be noop.
|
19268
|
+
const getFunctionInferredReturnType = wrapWithLogger(_getFunctionInferredReturnType);
|
19178
19269
|
const evaluatorInterface = {
|
19179
19270
|
runWithCancellationToken,
|
19180
19271
|
getType,
|