@zzzen/pyright-internal 1.2.0-dev.20240512 → 1.2.0-dev.20240519
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 +4 -4
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.js +23 -2
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +7 -16
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/dataClasses.js +29 -24
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/deprecatedSymbols.js +1 -0
- package/dist/analyzer/deprecatedSymbols.js.map +1 -1
- package/dist/analyzer/enums.d.ts +2 -5
- package/dist/analyzer/enums.js +97 -40
- package/dist/analyzer/enums.js.map +1 -1
- package/dist/analyzer/operations.js +11 -1
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/properties.js +3 -3
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +90 -156
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeGuards.d.ts +1 -1
- package/dist/analyzer/typeGuards.js +28 -17
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +1 -1
- package/dist/analyzer/typeUtils.js +11 -78
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/types.d.ts +0 -1
- package/dist/analyzer/types.js.map +1 -1
- package/dist/localization/localize.d.ts +6 -6
- package/dist/localization/localize.js +2 -2
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +0 -2
- package/dist/localization/package.nls.de.json +0 -2
- package/dist/localization/package.nls.en-us.json +2 -2
- package/dist/localization/package.nls.es.json +0 -2
- package/dist/localization/package.nls.fr.json +0 -2
- package/dist/localization/package.nls.it.json +0 -2
- package/dist/localization/package.nls.ja.json +0 -2
- package/dist/localization/package.nls.ko.json +0 -2
- package/dist/localization/package.nls.pl.json +0 -2
- package/dist/localization/package.nls.pt-br.json +0 -2
- package/dist/localization/package.nls.qps-ploc.json +0 -2
- package/dist/localization/package.nls.ru.json +0 -2
- package/dist/localization/package.nls.tr.json +0 -2
- package/dist/localization/package.nls.zh-cn.json +0 -2
- package/dist/localization/package.nls.zh-tw.json +0 -2
- package/dist/parser/parser.js +4 -3
- package/dist/parser/parser.js.map +1 -1
- package/dist/parser/tokenizerTypes.d.ts +1 -0
- package/dist/parser/tokenizerTypes.js +4 -0
- package/dist/parser/tokenizerTypes.js.map +1 -1
- package/dist/tests/completions.test.js +2 -2
- package/dist/tests/completions.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 +4 -0
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +4 -0
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +6 -2
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator6.test.js +1 -1
- package/dist/tests/typeEvaluator7.test.js +0 -4
- package/dist/tests/typeEvaluator7.test.js.map +1 -1
- package/dist/tests/typeEvaluator8.test.js +4 -0
- package/dist/tests/typeEvaluator8.test.js.map +1 -1
- package/package.json +1 -1
@@ -3230,14 +3230,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3230
3230
|
if (memberName === 'args' || memberName === 'kwargs') {
|
3231
3231
|
const outerFunctionScope = ParseTreeUtils.getEnclosingClassOrFunction(enclosingScope);
|
3232
3232
|
if ((outerFunctionScope === null || outerFunctionScope === void 0 ? void 0 : outerFunctionScope.nodeType) === 28 /* ParseNodeType.Function */) {
|
3233
|
-
|
3234
|
-
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.paramSpecScopedToReturnType().format({
|
3235
|
-
name: type.details.name,
|
3236
|
-
}), node);
|
3237
|
-
}
|
3238
|
-
else {
|
3239
|
-
enclosingScope = outerFunctionScope;
|
3240
|
-
}
|
3233
|
+
enclosingScope = outerFunctionScope;
|
3241
3234
|
}
|
3242
3235
|
else if (!scopedTypeVarInfo.type.scopeId) {
|
3243
3236
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.paramSpecNotUsedByOuterScope().format({
|
@@ -3272,17 +3265,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3272
3265
|
else if ((flags & 4096 /* EvaluatorFlags.AllowTypeVarsWithoutScopeId */) === 0) {
|
3273
3266
|
if ((type.scopeId === undefined || scopedTypeVarInfo.foundInterveningClass) &&
|
3274
3267
|
!type.details.isSynthesized) {
|
3275
|
-
|
3276
|
-
|
3277
|
-
|
3278
|
-
? localize_1.LocMessage.paramSpecScopedToReturnType()
|
3279
|
-
: localize_1.LocMessage.typeVarScopedToReturnType();
|
3280
|
-
}
|
3281
|
-
else {
|
3282
|
-
message = (0, types_1.isParamSpec)(type)
|
3283
|
-
? localize_1.LocMessage.paramSpecNotUsedByOuterScope()
|
3284
|
-
: localize_1.LocMessage.typeVarNotUsedByOuterScope();
|
3285
|
-
}
|
3268
|
+
const message = (0, types_1.isParamSpec)(type)
|
3269
|
+
? localize_1.LocMessage.paramSpecNotUsedByOuterScope()
|
3270
|
+
: localize_1.LocMessage.typeVarNotUsedByOuterScope();
|
3286
3271
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, message.format({ name: type.details.name }), node);
|
3287
3272
|
}
|
3288
3273
|
}
|
@@ -3357,7 +3342,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3357
3342
|
// Walks up the parse tree to find a function, class, or type alias
|
3358
3343
|
// declaration that provides the context for a type variable.
|
3359
3344
|
function findScopedTypeVar(node, type) {
|
3360
|
-
var _a;
|
3361
3345
|
let curNode = node;
|
3362
3346
|
let nestedClassCount = 0;
|
3363
3347
|
(0, debug_1.assert)(types_1.TypeBase.isInstantiable(type));
|
@@ -3381,12 +3365,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3381
3365
|
if (functionType) {
|
3382
3366
|
const functionDetails = functionType.details;
|
3383
3367
|
typeParametersForScope = functionDetails.typeParameters;
|
3384
|
-
// Was this type parameter "rescoped" to a callable found within the
|
3385
|
-
// return type annotation? If so, it is not available for use within
|
3386
|
-
// the function body.
|
3387
|
-
if ((_a = functionDetails.rescopedTypeParameters) === null || _a === void 0 ? void 0 : _a.some((tp) => tp.details.name === type.details.name)) {
|
3388
|
-
return { type, isRescoped: true, foundInterveningClass: false };
|
3389
|
-
}
|
3390
3368
|
}
|
3391
3369
|
scopeUsesTypeParameterSyntax = !!curNode.typeParameters;
|
3392
3370
|
}
|
@@ -3400,7 +3378,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3400
3378
|
type = types_1.TypeVarType.cloneForScopeId(type, match.scopeId, match.scopeName, match.scopeType);
|
3401
3379
|
return {
|
3402
3380
|
type,
|
3403
|
-
isRescoped: false,
|
3404
3381
|
foundInterveningClass: nestedClassCount > 1 && !scopeUsesTypeParameterSyntax,
|
3405
3382
|
};
|
3406
3383
|
}
|
@@ -3441,13 +3418,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3441
3418
|
if (allowedTypeParams) {
|
3442
3419
|
if (!allowedTypeParams.some((param) => param.details.name === type.details.name)) {
|
3443
3420
|
// Return the original type.
|
3444
|
-
return { type,
|
3421
|
+
return { type, foundInterveningClass: false };
|
3445
3422
|
}
|
3446
3423
|
}
|
3447
3424
|
}
|
3448
3425
|
return {
|
3449
3426
|
type: types_1.TypeVarType.cloneForScopeId(type, leftType.details.recursiveTypeAliasScopeId, leftType.details.recursiveTypeAliasName, 2 /* TypeVarScopeType.TypeAlias */),
|
3450
|
-
isRescoped: false,
|
3451
3427
|
foundInterveningClass: false,
|
3452
3428
|
};
|
3453
3429
|
}
|
@@ -3455,7 +3431,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3455
3431
|
curNode = curNode.parent;
|
3456
3432
|
}
|
3457
3433
|
// Return the original type.
|
3458
|
-
return { type,
|
3434
|
+
return { type, foundInterveningClass: false };
|
3459
3435
|
}
|
3460
3436
|
function getTypeOfMemberAccess(node, flags) {
|
3461
3437
|
var _a;
|
@@ -3547,7 +3523,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3547
3523
|
return typeResult;
|
3548
3524
|
}
|
3549
3525
|
function getTypeOfMemberAccessWithBaseType(node, baseTypeResult, usage, flags) {
|
3550
|
-
var _a;
|
3526
|
+
var _a, _b;
|
3551
3527
|
let baseType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(baseTypeResult.type);
|
3552
3528
|
const memberName = node.memberName.value;
|
3553
3529
|
let diag = new diagnostic_1.DiagnosticAddendum();
|
@@ -3632,8 +3608,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3632
3608
|
}
|
3633
3609
|
case 6 /* TypeCategory.Class */: {
|
3634
3610
|
let typeResult;
|
3635
|
-
|
3636
|
-
|
3611
|
+
const enumMemberResult = (0, enums_1.getTypeOfEnumMember)(evaluatorInterface, node, baseType, memberName, isIncomplete);
|
3612
|
+
if (enumMemberResult) {
|
3613
|
+
if (usage.method === 'get') {
|
3614
|
+
typeResult = enumMemberResult;
|
3615
|
+
}
|
3616
|
+
else {
|
3617
|
+
// Is this an attempt to delete or overwrite an enum member?
|
3618
|
+
if ((0, types_1.isClassInstance)(enumMemberResult.type) &&
|
3619
|
+
types_1.ClassType.isSameGenericClass(enumMemberResult.type, baseType) &&
|
3620
|
+
enumMemberResult.type.literalValue !== undefined) {
|
3621
|
+
const diagMessage = usage.method === 'set' ? localize_1.LocMessage.enumMemberSet() : localize_1.LocMessage.enumMemberDelete();
|
3622
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportAttributeAccessIssue, diagMessage.format({ name: memberName }) + diag.getString(), node.memberName, (_a = diag.getEffectiveTextRange()) !== null && _a !== void 0 ? _a : node.memberName);
|
3623
|
+
}
|
3624
|
+
}
|
3637
3625
|
}
|
3638
3626
|
if (!typeResult) {
|
3639
3627
|
typeResult = getTypeOfBoundMember(node.memberName, baseType, memberName, usage, diag,
|
@@ -3819,7 +3807,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3819
3807
|
const rule = isFunctionRule
|
3820
3808
|
? diagnosticRules_1.DiagnosticRule.reportFunctionMemberAccess
|
3821
3809
|
: diagnosticRules_1.DiagnosticRule.reportAttributeAccessIssue;
|
3822
|
-
addDiagnostic(rule, diagMessage.format({ name: memberName, type: printType(baseType) }) + diag.getString(), node.memberName, (
|
3810
|
+
addDiagnostic(rule, diagMessage.format({ name: memberName, type: printType(baseType) }) + diag.getString(), node.memberName, (_b = diag.getEffectiveTextRange()) !== null && _b !== void 0 ? _b : node.memberName);
|
3823
3811
|
}
|
3824
3812
|
// If this is member access on a function, use "Any" so if the
|
3825
3813
|
// reportFunctionMemberAccess rule is disabled, we don't trigger
|
@@ -5279,19 +5267,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5279
5267
|
const unboundedIndex = tupleTypeArgs.findIndex((typeArg) => typeArg.isUnbounded || (0, types_1.isVariadicTypeVar)(typeArg.type));
|
5280
5268
|
if (value < 0) {
|
5281
5269
|
value = tupleTypeArgs.length + value;
|
5282
|
-
if (value
|
5270
|
+
if (unboundedIndex >= 0 && value <= unboundedIndex) {
|
5283
5271
|
return undefined;
|
5284
5272
|
}
|
5285
|
-
else if (
|
5286
|
-
return
|
5273
|
+
else if (value < 0) {
|
5274
|
+
return 0;
|
5287
5275
|
}
|
5288
5276
|
}
|
5289
5277
|
else {
|
5290
|
-
if (value >
|
5278
|
+
if (unboundedIndex >= 0 && value > unboundedIndex) {
|
5291
5279
|
return undefined;
|
5292
5280
|
}
|
5293
|
-
else if (
|
5294
|
-
return
|
5281
|
+
else if (value > tupleTypeArgs.length) {
|
5282
|
+
return tupleTypeArgs.length;
|
5295
5283
|
}
|
5296
5284
|
}
|
5297
5285
|
}
|
@@ -5894,7 +5882,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5894
5882
|
if (node.arguments.length > 0) {
|
5895
5883
|
targetClassType = getTypeOfExpression(node.arguments[0].valueExpression).type;
|
5896
5884
|
const concreteTargetClassType = makeTopLevelTypeVarsConcrete(targetClassType);
|
5897
|
-
if (!(0, types_1.isAnyOrUnknown)(concreteTargetClassType) &&
|
5885
|
+
if (!(0, types_1.isAnyOrUnknown)(concreteTargetClassType) &&
|
5886
|
+
!(0, types_1.isInstantiableClass)(concreteTargetClassType) &&
|
5887
|
+
!(0, typeUtils_1.isMetaclassInstance)(concreteTargetClassType)) {
|
5898
5888
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportArgumentType, localize_1.LocMessage.superCallFirstArg().format({ type: printType(targetClassType) }), node.arguments[0].valueExpression);
|
5899
5889
|
}
|
5900
5890
|
}
|
@@ -6814,19 +6804,22 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6814
6804
|
if (expandedCallType.details.name === 'type' && argList.length === 1) {
|
6815
6805
|
const argType = getTypeOfArgument(argList[0]).type;
|
6816
6806
|
const returnType = (0, typeUtils_1.mapSubtypes)(argType, (subtype) => {
|
6817
|
-
|
6818
|
-
|
6819
|
-
return (_a = subtype.details.effectiveMetaclass) !== null && _a !== void 0 ? _a : types_1.AnyType.create();
|
6807
|
+
if ((0, types_1.isInstantiableClass)(subtype) && subtype.details.effectiveMetaclass) {
|
6808
|
+
return subtype.details.effectiveMetaclass;
|
6820
6809
|
}
|
6821
|
-
if ((0, types_1.
|
6822
|
-
|
6823
|
-
(0, typeUtils_1.isNoneInstance)(subtype)) {
|
6824
|
-
return (0, typeUtils_1.convertToInstantiable)(stripLiteralValue(subtype));
|
6810
|
+
if ((0, types_1.isNever)(subtype)) {
|
6811
|
+
return subtype;
|
6825
6812
|
}
|
6826
|
-
if (
|
6827
|
-
|
6813
|
+
if (types_1.TypeBase.isInstance(subtype)) {
|
6814
|
+
if ((0, types_1.isClass)(subtype) || (0, types_1.isTypeVar)(subtype)) {
|
6815
|
+
return (0, typeUtils_1.convertToInstantiable)(stripLiteralValue(subtype));
|
6816
|
+
}
|
6817
|
+
if ((0, types_1.isFunction)(subtype)) {
|
6818
|
+
return types_1.FunctionType.cloneAsInstantiable(subtype);
|
6819
|
+
}
|
6828
6820
|
}
|
6829
|
-
return types_1.
|
6821
|
+
return types_1.ClassType.cloneForSpecialization(types_1.ClassType.cloneAsInstance(expandedCallType), [types_1.UnknownType.create()],
|
6822
|
+
/* isTypeArgumentExplicit */ true);
|
6830
6823
|
});
|
6831
6824
|
return { returnType };
|
6832
6825
|
}
|
@@ -8182,7 +8175,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8182
8175
|
// call to a generic function or if this isn't a callable
|
8183
8176
|
// return with type parameters that are rescoped from the original
|
8184
8177
|
// function to the returned callable.
|
8185
|
-
const unknownIfNotFound = !ParseTreeUtils.getTypeVarScopesForNode(errorNode).some((typeVarScope) => typeVarContext.hasSolveForScope(typeVarScope))
|
8178
|
+
const unknownIfNotFound = !ParseTreeUtils.getTypeVarScopesForNode(errorNode).some((typeVarScope) => typeVarContext.hasSolveForScope(typeVarScope));
|
8186
8179
|
let specializedReturnType = (0, typeUtils_1.applySolvedTypeVars)(returnType, typeVarContext, {
|
8187
8180
|
unknownIfNotFound,
|
8188
8181
|
unknownExemptTypeVars: getUnknownExemptTypeVarsForReturnType(type, returnType),
|
@@ -8461,7 +8454,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8461
8454
|
8 /* EvaluatorFlags.EvaluateStringLiteralAsType */ |
|
8462
8455
|
32 /* EvaluatorFlags.DisallowParamSpec */ |
|
8463
8456
|
64 /* EvaluatorFlags.DisallowTypeVarTuple */ |
|
8464
|
-
16 /* EvaluatorFlags.DisallowFinal */
|
8457
|
+
16 /* EvaluatorFlags.DisallowFinal */ |
|
8458
|
+
2 /* EvaluatorFlags.DoNotSpecialize */
|
8465
8459
|
: 2 /* EvaluatorFlags.DoNotSpecialize */ | 16 /* EvaluatorFlags.DisallowFinal */;
|
8466
8460
|
const exprTypeResult = getTypeOfExpression(argParam.argument.valueExpression, flags, (0, typeUtils_1.makeInferenceContext)(expectedType, !!(typeResult === null || typeResult === void 0 ? void 0 : typeResult.isIncomplete), signatureTracker));
|
8467
8461
|
argType = exprTypeResult.type;
|
@@ -8942,9 +8936,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8942
8936
|
return paramSpec;
|
8943
8937
|
}
|
8944
8938
|
function getParamSpecDefaultType(node, isPep695Syntax) {
|
8945
|
-
const functionType = types_1.FunctionType.createSynthesizedInstance('',
|
8939
|
+
const functionType = types_1.FunctionType.createSynthesizedInstance('', 65536 /* FunctionTypeFlags.ParamSpecValue */);
|
8946
8940
|
if (node.nodeType === 18 /* ParseNodeType.Ellipsis */) {
|
8947
8941
|
types_1.FunctionType.addDefaultParameters(functionType);
|
8942
|
+
functionType.details.flags |= 32768 /* FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck */;
|
8948
8943
|
return functionType;
|
8949
8944
|
}
|
8950
8945
|
if (node.nodeType === 31 /* ParseNodeType.List */) {
|
@@ -11310,7 +11305,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11310
11305
|
return undefined;
|
11311
11306
|
}
|
11312
11307
|
function evaluateTypesForAssignmentStatement(node) {
|
11313
|
-
var _a
|
11308
|
+
var _a;
|
11314
11309
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
11315
11310
|
// If the entire statement has already been evaluated, don't
|
11316
11311
|
// re-evaluate it.
|
@@ -11411,20 +11406,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11411
11406
|
}
|
11412
11407
|
// If this is an enum, transform the type as required.
|
11413
11408
|
rightHandType = srcType;
|
11414
|
-
let targetName;
|
11415
|
-
if (node.leftExpression.nodeType === 38 /* ParseNodeType.Name */) {
|
11416
|
-
targetName = node.leftExpression;
|
11417
|
-
}
|
11418
|
-
else if (node.leftExpression.nodeType === 54 /* ParseNodeType.TypeAnnotation */ &&
|
11419
|
-
node.leftExpression.valueExpression.nodeType === 38 /* ParseNodeType.Name */) {
|
11420
|
-
targetName = node.leftExpression.valueExpression;
|
11421
|
-
}
|
11422
|
-
if (targetName) {
|
11423
|
-
rightHandType =
|
11424
|
-
(_a = (0, enums_1.transformTypeForPossibleEnumClass)(evaluatorInterface, node, targetName, () => {
|
11425
|
-
return { assignedType: rightHandType };
|
11426
|
-
})) !== null && _a !== void 0 ? _a : rightHandType;
|
11427
|
-
}
|
11428
11409
|
if (typeAliasNameNode) {
|
11429
11410
|
// If this was a speculative type alias, it becomes a real type alias
|
11430
11411
|
// only if the evaluated type is an instantiable type.
|
@@ -11445,7 +11426,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11445
11426
|
typeAliasTypeVar.details.boundType = rightHandType;
|
11446
11427
|
// Record the type parameters within the recursive type alias so it
|
11447
11428
|
// can be specialized.
|
11448
|
-
typeAliasTypeVar.details.recursiveTypeParameters = (
|
11429
|
+
typeAliasTypeVar.details.recursiveTypeParameters = (_a = rightHandType.typeAliasInfo) === null || _a === void 0 ? void 0 : _a.typeParameters;
|
11449
11430
|
}
|
11450
11431
|
}
|
11451
11432
|
}
|
@@ -12493,7 +12474,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12493
12474
|
});
|
12494
12475
|
}
|
12495
12476
|
function getTypeOfFunction(node) {
|
12496
|
-
var _a;
|
12497
12477
|
initializedBasicTypes(node);
|
12498
12478
|
// Is this predecorated function type cached?
|
12499
12479
|
let functionType = readTypeCache(node.name, 0 /* EvaluatorFlags.None */);
|
@@ -12541,11 +12521,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12541
12521
|
decoratedType = newDecoratedType;
|
12542
12522
|
}
|
12543
12523
|
}
|
12544
|
-
// In case this is an enum class and a method wrapped in an enum.member.
|
12545
|
-
decoratedType =
|
12546
|
-
(_a = (0, enums_1.transformTypeForPossibleEnumClass)(evaluatorInterface, node, node.name, () => {
|
12547
|
-
return { assignedType: decoratedType };
|
12548
|
-
})) !== null && _a !== void 0 ? _a : decoratedType;
|
12549
12524
|
// See if there are any overloads provided by previous function declarations.
|
12550
12525
|
if ((0, types_1.isFunction)(decoratedType)) {
|
12551
12526
|
decoratedType.details.deprecatedMessage = functionType.details.deprecatedMessage;
|
@@ -12879,7 +12854,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12879
12854
|
}
|
12880
12855
|
// Accumulate any type parameters used in the return type.
|
12881
12856
|
if (functionType.details.declaredReturnType && returnTypeAnnotationNode) {
|
12882
|
-
|
12857
|
+
(0, typeUtils_1.addTypeVarsToListIfUnique)(typeParametersSeen, (0, typeUtils_1.getTypeVarArgumentsRecursive)(functionType.details.declaredReturnType), functionType.details.typeVarScopeId);
|
12883
12858
|
}
|
12884
12859
|
// If the return type is explicitly annotated as a generator, mark the
|
12885
12860
|
// function as a generator even though it may not contain a "yield" statement.
|
@@ -12920,34 +12895,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12920
12895
|
}
|
12921
12896
|
}
|
12922
12897
|
}
|
12923
|
-
// If the declared return type of a function contains type variables that
|
12924
|
-
// are found nowhere else in the signature and are contained within a
|
12925
|
-
// Callable, these type variables are "rescoped" from the function to
|
12926
|
-
// the Callable.
|
12927
|
-
function rescopeTypeVarsForCallableReturnType(returnType, functionType, typeParametersSeen) {
|
12928
|
-
const typeVarsInReturnType = (0, typeUtils_1.getTypeVarArgumentsRecursive)(returnType).filter((t) => t.scopeId === functionType.details.typeVarScopeId);
|
12929
|
-
const rescopedTypeVars = [];
|
12930
|
-
typeVarsInReturnType.forEach((typeVar) => {
|
12931
|
-
if (types_1.TypeBase.isInstantiable(typeVar)) {
|
12932
|
-
typeVar = types_1.TypeVarType.cloneAsInstance(typeVar);
|
12933
|
-
}
|
12934
|
-
// If this type variable was already seen in one or more input parameters,
|
12935
|
-
// don't attempt to rescope it.
|
12936
|
-
if (typeParametersSeen.some((tp) => (0, types_1.isTypeSame)((0, typeUtils_1.convertToInstance)(tp), typeVar))) {
|
12937
|
-
return;
|
12938
|
-
}
|
12939
|
-
// Is this type variable seen outside of a single callable?
|
12940
|
-
if ((0, typeUtils_1.isTypeVarLimitedToCallable)(returnType, typeVar)) {
|
12941
|
-
rescopedTypeVars.push(typeVar);
|
12942
|
-
}
|
12943
|
-
});
|
12944
|
-
(0, typeUtils_1.addTypeVarsToListIfUnique)(typeParametersSeen, typeVarsInReturnType);
|
12945
|
-
// Note that the type parameters have been rescoped so they are not
|
12946
|
-
// considered valid for the body of this function.
|
12947
|
-
if (rescopedTypeVars.length > 0) {
|
12948
|
-
functionType.details.rescopedTypeParameters = rescopedTypeVars;
|
12949
|
-
}
|
12950
|
-
}
|
12951
12898
|
function adjustParameterAnnotatedType(param, type) {
|
12952
12899
|
var _a;
|
12953
12900
|
// PEP 484 indicates that if a parameter has a default value of 'None'
|
@@ -15065,7 +15012,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15065
15012
|
return declarations;
|
15066
15013
|
}
|
15067
15014
|
function getTypeForDeclaration(declaration) {
|
15068
|
-
var _a, _b
|
15015
|
+
var _a, _b;
|
15069
15016
|
switch (declaration.type) {
|
15070
15017
|
case 0 /* DeclarationType.Intrinsic */: {
|
15071
15018
|
if (declaration.intrinsicType === 'Any') {
|
@@ -15172,16 +15119,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15172
15119
|
});
|
15173
15120
|
}
|
15174
15121
|
if (declaredType) {
|
15175
|
-
// Apply enum transform if appropriate.
|
15176
|
-
if (declaration.node.nodeType === 38 /* ParseNodeType.Name */) {
|
15177
|
-
const variableNode = (_c = ParseTreeUtils.getParentNodeOfType(declaration.node, 3 /* ParseNodeType.Assignment */)) !== null && _c !== void 0 ? _c : ParseTreeUtils.getParentNodeOfType(declaration.node, 54 /* ParseNodeType.TypeAnnotation */);
|
15178
|
-
if (variableNode) {
|
15179
|
-
declaredType =
|
15180
|
-
(_d = (0, enums_1.transformTypeForPossibleEnumClass)(evaluatorInterface, variableNode, declaration.node, () => {
|
15181
|
-
return { declaredType };
|
15182
|
-
})) !== null && _d !== void 0 ? _d : declaredType;
|
15183
|
-
}
|
15184
|
-
}
|
15185
15122
|
if ((0, types_1.isClassInstance)(declaredType) && types_1.ClassType.isBuiltIn(declaredType, 'TypeAlias')) {
|
15186
15123
|
return { type: undefined, isTypeAlias: true };
|
15187
15124
|
}
|
@@ -15321,7 +15258,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15321
15258
|
return typeVar;
|
15322
15259
|
}
|
15323
15260
|
function getInferredTypeOfDeclaration(symbol, decl) {
|
15324
|
-
var _a, _b, _c
|
15261
|
+
var _a, _b, _c;
|
15325
15262
|
const resolvedDecl = resolveAliasDeclaration(decl, /* resolveLocalNames */ true, {
|
15326
15263
|
allowExternallyHiddenAccess: AnalyzerNodeInfo.getFileInfo(decl.node).isStubFile,
|
15327
15264
|
});
|
@@ -15444,25 +15381,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15444
15381
|
let inferredType = (_c = evaluateTypeForSubnode(resolvedDecl.node, () => {
|
15445
15382
|
evaluateTypesForStatement(typeSource);
|
15446
15383
|
})) === null || _c === void 0 ? void 0 : _c.type;
|
15447
|
-
if (inferredType && resolvedDecl.node.nodeType === 38 /* ParseNodeType.Name */) {
|
15448
|
-
const variableNode = (_d = ParseTreeUtils.getParentNodeOfType(resolvedDecl.node, 3 /* ParseNodeType.Assignment */)) !== null && _d !== void 0 ? _d : ParseTreeUtils.getParentNodeOfType(resolvedDecl.node, 54 /* ParseNodeType.TypeAnnotation */);
|
15449
|
-
if (variableNode) {
|
15450
|
-
// See if this is an enum member. If so, we need to handle it as a special case.
|
15451
|
-
const enumMemberType = (0, enums_1.transformTypeForPossibleEnumClass)(evaluatorInterface, variableNode, resolvedDecl.node, () => {
|
15452
|
-
var _a, _b;
|
15453
|
-
(0, debug_1.assert)(resolvedDecl.inferredTypeSource !== undefined);
|
15454
|
-
const inferredTypeSource = resolvedDecl.inferredTypeSource;
|
15455
|
-
return {
|
15456
|
-
assignedType: (_b = (_a = evaluateTypeForSubnode(inferredTypeSource, () => {
|
15457
|
-
evaluateTypesForStatement(inferredTypeSource);
|
15458
|
-
})) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : types_1.UnknownType.create(),
|
15459
|
-
};
|
15460
|
-
});
|
15461
|
-
if (enumMemberType) {
|
15462
|
-
inferredType = enumMemberType;
|
15463
|
-
}
|
15464
|
-
}
|
15465
|
-
}
|
15466
15384
|
if (inferredType && isTypeAlias && resolvedDecl.typeAliasName) {
|
15467
15385
|
// If this was a speculative type alias, it becomes a real type alias only
|
15468
15386
|
// in the event that its inferred type is instantiable or explicitly Any
|
@@ -16808,7 +16726,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
16808
16726
|
// in the dest type is not in the type map already, it is assigned a type
|
16809
16727
|
// and added to the map.
|
16810
16728
|
function assignType(destType, srcType, diag, destTypeVarContext, srcTypeVarContext, flags = 0 /* AssignTypeFlags.Default */, recursionCount = 0) {
|
16811
|
-
var _a, _b;
|
16729
|
+
var _a, _b, _c;
|
16812
16730
|
// Handle the case where the dest and src types are the same object.
|
16813
16731
|
// We can normally shortcut this and say that they are compatible,
|
16814
16732
|
// but if the type includes TypeVars, we need to go through
|
@@ -17137,6 +17055,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17137
17055
|
return false;
|
17138
17056
|
}
|
17139
17057
|
}
|
17058
|
+
if (types_1.ClassType.isBuiltIn(destType, 'type') && ((_c = srcType.instantiableNestingLevel) !== null && _c !== void 0 ? _c : 0) > 0) {
|
17059
|
+
return true;
|
17060
|
+
}
|
17140
17061
|
if (!isSpecialFormClass(expandedSrcType, flags) &&
|
17141
17062
|
assignClass(destType, expandedSrcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount,
|
17142
17063
|
/* reportErrorsUsingObjType */ false)) {
|
@@ -17867,21 +17788,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17867
17788
|
}
|
17868
17789
|
}
|
17869
17790
|
if (!assignType(specializedSrcType, specializedDestType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), srcTypeVarContext, destTypeVarContext, flags, recursionCount)) {
|
17870
|
-
|
17871
|
-
|
17872
|
-
|
17873
|
-
|
17874
|
-
|
17875
|
-
|
17876
|
-
if (diag && paramIndex !== undefined) {
|
17877
|
-
diag.addMessage(localize_1.LocAddendum.paramAssignment().format({
|
17878
|
-
index: paramIndex + 1,
|
17879
|
-
sourceType: printType(destType),
|
17880
|
-
destType: printType(srcType),
|
17881
|
-
}));
|
17882
|
-
}
|
17883
|
-
return false;
|
17791
|
+
if (diag && paramIndex !== undefined) {
|
17792
|
+
diag.addMessage(localize_1.LocAddendum.paramAssignment().format({
|
17793
|
+
index: paramIndex + 1,
|
17794
|
+
sourceType: printType(destType),
|
17795
|
+
destType: printType(srcType),
|
17796
|
+
}));
|
17884
17797
|
}
|
17798
|
+
return false;
|
17885
17799
|
}
|
17886
17800
|
return true;
|
17887
17801
|
}
|
@@ -17909,6 +17823,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17909
17823
|
if (srcLastToPackIndex < 0) {
|
17910
17824
|
srcLastToPackIndex = srcDetails.params.length;
|
17911
17825
|
}
|
17826
|
+
// If both the source and dest have an *args parameter but the dest's is
|
17827
|
+
// in a later position, then we can't assign the source's *args to the dest.
|
17828
|
+
// Don't make any adjustment in this case.
|
17829
|
+
if (srcDetails.argsIndex !== undefined && destDetails.argsIndex > srcDetails.argsIndex) {
|
17830
|
+
return;
|
17831
|
+
}
|
17912
17832
|
const destFirstNonPositional = (_a = destDetails.firstKeywordOnlyIndex) !== null && _a !== void 0 ? _a : destDetails.params.length;
|
17913
17833
|
const suffixLength = destFirstNonPositional - destDetails.argsIndex - 1;
|
17914
17834
|
const srcPositionalsToPack = srcDetails.params.slice(destDetails.argsIndex, srcLastToPackIndex - suffixLength);
|
@@ -17962,7 +17882,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17962
17882
|
}
|
17963
17883
|
}
|
17964
17884
|
function assignFunction(destType, srcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount) {
|
17965
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
17885
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
17966
17886
|
let canAssign = true;
|
17967
17887
|
const checkReturnType = (flags & 64 /* AssignTypeFlags.SkipFunctionReturnTypeCheck */) === 0;
|
17968
17888
|
const reverseMatching = (flags & 2 /* AssignTypeFlags.ReverseTypeVarMatching */) !== 0;
|
@@ -18036,7 +17956,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18036
17956
|
destParam.param.hasDeclaredType) {
|
18037
17957
|
continue;
|
18038
17958
|
}
|
18039
|
-
if (
|
17959
|
+
if ((0, types_1.isUnpacked)(srcParamType)) {
|
17960
|
+
canAssign = false;
|
17961
|
+
}
|
17962
|
+
else if (!assignFunctionParameter(destParamType, srcParamType, paramIndex, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
|
18040
17963
|
// Handle the special case where the source parameter is a synthesized
|
18041
17964
|
// TypeVar for "self" or "cls".
|
18042
17965
|
if ((flags & 512 /* AssignTypeFlags.SkipSelfClsTypeCheck */) === 0 ||
|
@@ -18045,6 +17968,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18045
17968
|
canAssign = false;
|
18046
17969
|
}
|
18047
17970
|
}
|
17971
|
+
else if (destParam.source !== parameterUtils_1.ParameterSource.PositionOnly &&
|
17972
|
+
srcParam.source === parameterUtils_1.ParameterSource.PositionOnly &&
|
17973
|
+
srcParamDetails.kwargsIndex === undefined &&
|
17974
|
+
!srcParamDetails.params.some((p) => p.source === parameterUtils_1.ParameterSource.KeywordOnly &&
|
17975
|
+
p.param.category === 0 /* ParameterCategory.Simple */ &&
|
17976
|
+
p.param.name === destParam.param.name)) {
|
17977
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.namedParamMissingInSource().format({
|
17978
|
+
name: (_e = destParam.param.name) !== null && _e !== void 0 ? _e : '',
|
17979
|
+
}));
|
17980
|
+
canAssign = false;
|
17981
|
+
}
|
18048
17982
|
}
|
18049
17983
|
if (!types_1.FunctionType.shouldSkipArgsKwargsCompatibilityCheck(destType) &&
|
18050
17984
|
destParamDetails.firstPositionOrKeywordIndex < srcParamDetails.positionOnlyParamCount &&
|
@@ -18108,7 +18042,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18108
18042
|
if (destParamDetails.params[paramIndex].source !== parameterUtils_1.ParameterSource.PositionOnly &&
|
18109
18043
|
srcParamDetails.kwargsIndex === undefined) {
|
18110
18044
|
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.namedParamMissingInSource().format({
|
18111
|
-
name: (
|
18045
|
+
name: (_f = destParamDetails.params[paramIndex].param.name) !== null && _f !== void 0 ? _f : '',
|
18112
18046
|
}));
|
18113
18047
|
canAssign = false;
|
18114
18048
|
}
|
@@ -18156,7 +18090,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18156
18090
|
destParamDetails.argsIndex !== undefined &&
|
18157
18091
|
!destParamDetails.hasUnpackedVariadicTypeVar) {
|
18158
18092
|
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.LocAddendum.argsParamMissing().format({
|
18159
|
-
paramName: (
|
18093
|
+
paramName: (_g = destParamDetails.params[destParamDetails.argsIndex].param.name) !== null && _g !== void 0 ? _g : '',
|
18160
18094
|
}));
|
18161
18095
|
canAssign = false;
|
18162
18096
|
}
|
@@ -18269,7 +18203,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18269
18203
|
// If the source and the dest are using the same ParamSpec, any additional
|
18270
18204
|
// concatenated parameters must match.
|
18271
18205
|
if (targetIncludesParamSpec &&
|
18272
|
-
((
|
18206
|
+
((_h = srcType.details.paramSpec) === null || _h === void 0 ? void 0 : _h.nameWithScope) === ((_j = destType.details.paramSpec) === null || _j === void 0 ? void 0 : _j.nameWithScope)) {
|
18273
18207
|
if (srcParamDetails.params.length !== destParamDetails.params.length) {
|
18274
18208
|
canAssign = false;
|
18275
18209
|
}
|