@zzzen/pyright-internal 1.2.0-dev.20241006 → 1.2.0-dev.20241020
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 +1 -2
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.js +3 -16
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +11 -6
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constraintTracker.d.ts +1 -0
- package/dist/analyzer/constraintTracker.js +7 -1
- package/dist/analyzer/constraintTracker.js.map +1 -1
- package/dist/analyzer/constructorTransform.js +3 -6
- package/dist/analyzer/constructorTransform.js.map +1 -1
- package/dist/analyzer/constructors.js +10 -8
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.js +76 -19
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/importResolver.js +2 -10
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/parameterUtils.d.ts +2 -1
- package/dist/analyzer/parameterUtils.js +2 -1
- package/dist/analyzer/parameterUtils.js.map +1 -1
- package/dist/analyzer/patternMatching.js +2 -2
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/protocols.js +68 -26
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/tuples.js +2 -2
- package/dist/analyzer/tuples.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +163 -92
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +5 -3
- package/dist/analyzer/typeEvaluatorTypes.js +5 -3
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +3 -3
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.js +5 -7
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +7 -1
- package/dist/analyzer/typeUtils.js +97 -11
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typedDicts.js +41 -30
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +12 -5
- package/dist/analyzer/types.js +33 -10
- package/dist/analyzer/types.js.map +1 -1
- package/dist/common/pythonVersion.js +1 -1
- package/dist/languageService/completionProvider.d.ts +2 -2
- package/dist/languageService/completionProvider.js +14 -7
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/localization/localize.d.ts +4 -0
- package/dist/localization/localize.js +2 -0
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +2 -1
- package/dist/localization/package.nls.de.json +2 -1
- package/dist/localization/package.nls.en-us.json +7 -2
- package/dist/localization/package.nls.es.json +2 -1
- package/dist/localization/package.nls.fr.json +2 -1
- package/dist/localization/package.nls.it.json +2 -1
- package/dist/localization/package.nls.ja.json +2 -1
- package/dist/localization/package.nls.ko.json +2 -1
- package/dist/localization/package.nls.pl.json +2 -1
- package/dist/localization/package.nls.pt-br.json +2 -1
- package/dist/localization/package.nls.qps-ploc.json +2 -1
- package/dist/localization/package.nls.ru.json +2 -1
- package/dist/localization/package.nls.tr.json +2 -1
- package/dist/localization/package.nls.zh-cn.json +2 -1
- package/dist/localization/package.nls.zh-tw.json +2 -1
- package/dist/parser/tokenizer.d.ts +1 -0
- package/dist/parser/tokenizer.js +8 -0
- package/dist/parser/tokenizer.js.map +1 -1
- package/dist/tests/fourslash/findDefinitions.dataclasses.converter.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.dataclasses.converter.fourslash.js +40 -0
- package/dist/tests/fourslash/findDefinitions.dataclasses.converter.fourslash.js.map +1 -0
- package/dist/tests/typeEvaluator1.test.js +1 -0
- package/dist/tests/typeEvaluator1.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +1 -1
- package/dist/tests/typeEvaluator4.test.js +7 -2
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator5.test.js +8 -2
- package/dist/tests/typeEvaluator5.test.js.map +1 -1
- package/dist/tests/typeEvaluator6.test.js +4 -4
- package/dist/tests/typeEvaluator6.test.js.map +1 -1
- package/dist/tests/typeEvaluator7.test.js +11 -2
- package/dist/tests/typeEvaluator7.test.js.map +1 -1
- package/dist/tests/typeEvaluator8.test.js +12 -0
- package/dist/tests/typeEvaluator8.test.js.map +1 -1
- package/package.json +1 -1
@@ -158,6 +158,11 @@ const maxInferFunctionReturnRecursionCount = 12;
|
|
158
158
|
// it can increase the chance of false negatives for such recursive
|
159
159
|
// type aliases.
|
160
160
|
const maxRecursiveTypeAliasRecursionCount = 10;
|
161
|
+
// Normally a symbol can have only one type declaration, but there are
|
162
|
+
// cases where multiple are possible (e.g. a property with a setter
|
163
|
+
// and a deleter). In extreme cases, we need to limit the number of
|
164
|
+
// type declarations we consider to avoid excessive computation.
|
165
|
+
const maxTypedDeclsPerSymbol = 16;
|
161
166
|
// This switch enables a special debug mode that attempts to catch
|
162
167
|
// bugs due to inconsistent evaluation flags used when reading types
|
163
168
|
// from the type cache.
|
@@ -892,7 +897,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
892
897
|
if ((flags & 64 /* EvalFlags.NoTypeVarTuple */) === 0 && (0, types_1.isTypeVarTuple)(iterType) && !iterType.priv.isUnpacked) {
|
893
898
|
typeResult = { type: types_1.TypeVarType.cloneForUnpacked(iterType) };
|
894
899
|
}
|
895
|
-
else if ((flags &
|
900
|
+
else if ((flags & 4194304 /* EvalFlags.AllowUnpackedTuple */) !== 0 &&
|
896
901
|
(0, types_1.isInstantiableClass)(iterType) &&
|
897
902
|
types_1.ClassType.isBuiltIn(iterType, 'tuple')) {
|
898
903
|
typeResult = { type: types_1.ClassType.cloneForUnpacked(iterType) };
|
@@ -999,7 +1004,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
999
1004
|
let typeResult;
|
1000
1005
|
// In most cases, annotations within a string are not parsed by the interpreter.
|
1001
1006
|
// There are a few exceptions (e.g. the "bound" value for a TypeVar constructor).
|
1002
|
-
if ((flags &
|
1007
|
+
if ((flags & 16777216 /* EvalFlags.ParsesStringLiteral */) === 0) {
|
1003
1008
|
updatedFlags |= 524288 /* EvalFlags.NotParsed */;
|
1004
1009
|
}
|
1005
1010
|
updatedFlags &= ~1073741824 /* EvalFlags.TypeFormArg */;
|
@@ -1109,7 +1114,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
1109
1114
|
}
|
1110
1115
|
}
|
1111
1116
|
return (0, typeUtils_1.mapSubtypes)(type, (subtype) => {
|
1112
|
-
var _a;
|
1113
1117
|
if ((0, types_1.isClass)(subtype)) {
|
1114
1118
|
if (subtype.priv.literalValue !== undefined) {
|
1115
1119
|
subtype = types_1.ClassType.cloneWithLiteral(subtype, /* value */ undefined);
|
@@ -1118,9 +1122,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
1118
1122
|
// Handle "LiteralString" specially.
|
1119
1123
|
if (strClass && (0, types_1.isInstantiableClass)(strClass)) {
|
1120
1124
|
let strInstance = types_1.ClassType.cloneAsInstance(strClass);
|
1121
|
-
|
1122
|
-
strInstance = types_1.TypeBase.cloneForCondition(strInstance, (0, typeUtils_1.getTypeCondition)(subtype));
|
1123
|
-
}
|
1125
|
+
strInstance = types_1.TypeBase.cloneForCondition(strInstance, (0, typeUtils_1.getTypeCondition)(subtype));
|
1124
1126
|
return strInstance;
|
1125
1127
|
}
|
1126
1128
|
}
|
@@ -1554,10 +1556,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
1554
1556
|
return undefined;
|
1555
1557
|
}
|
1556
1558
|
function getBoundMagicMethod(classType, memberName, selfType, diag, recursionCount = 0) {
|
1557
|
-
if (recursionCount > types_1.maxTypeRecursionCount) {
|
1558
|
-
return undefined;
|
1559
|
-
}
|
1560
|
-
recursionCount++;
|
1561
1559
|
const boundMethodResult = getTypeOfBoundMember(
|
1562
1560
|
/* errorNode */ undefined, classType, memberName,
|
1563
1561
|
/* usage */ undefined, diag, 16 /* MemberAccessFlags.SkipInstanceMembers */ | 512 /* MemberAccessFlags.SkipAttributeAccessOverride */, selfType, recursionCount);
|
@@ -1568,6 +1566,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
1568
1566
|
return boundMethodResult.type;
|
1569
1567
|
}
|
1570
1568
|
if ((0, types_1.isClassInstance)(boundMethodResult.type)) {
|
1569
|
+
if (recursionCount > types_1.maxTypeRecursionCount) {
|
1570
|
+
return undefined;
|
1571
|
+
}
|
1572
|
+
recursionCount++;
|
1571
1573
|
return getBoundMagicMethod(boundMethodResult.type, '__call__', selfType !== null && selfType !== void 0 ? selfType : types_1.ClassType.cloneAsInstance(classType), diag, recursionCount);
|
1572
1574
|
}
|
1573
1575
|
if ((0, types_1.isAnyOrUnknown)(boundMethodResult.type)) {
|
@@ -2308,7 +2310,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2308
2310
|
const isTypeAlias = !!declaredType && (0, types_1.isClassInstance)(declaredType) && types_1.ClassType.isBuiltIn(declaredType, 'TypeAlias');
|
2309
2311
|
if (declaredType && !isTypeAlias) {
|
2310
2312
|
let diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
2311
|
-
|
2313
|
+
const liveScopeIds = ParseTreeUtils.getTypeVarScopesForNode(nameNode);
|
2314
|
+
const boundDeclaredType = (0, typeUtils_1.makeTypeVarsBound)(declaredType, liveScopeIds);
|
2315
|
+
const srcType = (0, typeUtils_1.makeTypeVarsBound)(typeResult.type, liveScopeIds);
|
2316
|
+
if (!assignType(boundDeclaredType, srcType, diagAddendum)) {
|
2312
2317
|
// If there was an expected type mismatch, use that diagnostic
|
2313
2318
|
// addendum because it will be more informative.
|
2314
2319
|
if (expectedTypeDiagAddendum) {
|
@@ -2529,7 +2534,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2529
2534
|
// Is this subtype a tuple?
|
2530
2535
|
const tupleType = (0, typeUtils_1.getSpecializedTupleType)(subtype);
|
2531
2536
|
if (tupleType && tupleType.priv.tupleTypeArgs) {
|
2532
|
-
const sourceEntryTypes = tupleType.priv.tupleTypeArgs.map((t) => (0, typeUtils_1.addConditionToType)(t.type, (0, typeUtils_1.getTypeCondition)(subtype),
|
2537
|
+
const sourceEntryTypes = tupleType.priv.tupleTypeArgs.map((t) => (0, typeUtils_1.addConditionToType)(t.type, (0, typeUtils_1.getTypeCondition)(subtype), { skipSelfCondition: true }));
|
2533
2538
|
const unboundedIndex = tupleType.priv.tupleTypeArgs.findIndex((t) => t.isUnbounded);
|
2534
2539
|
if (unboundedIndex >= 0) {
|
2535
2540
|
if (sourceEntryTypes.length < targetTypes.length) {
|
@@ -2714,6 +2719,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2714
2719
|
useBoundTypeVars: types_1.TypeVarType.isBound(subtype),
|
2715
2720
|
});
|
2716
2721
|
}
|
2722
|
+
if (subtype.priv.isUnpacked && (0, types_1.isClass)(boundType)) {
|
2723
|
+
boundType = types_1.ClassType.cloneForUnpacked(boundType);
|
2724
|
+
}
|
2717
2725
|
boundType = types_1.TypeBase.isInstantiable(subtype) ? (0, typeUtils_1.convertToInstantiable)(boundType) : boundType;
|
2718
2726
|
return (0, typeUtils_1.addConditionToType)(boundType, [{ typeVar: subtype, constraintIndex: 0 }]);
|
2719
2727
|
}
|
@@ -2890,11 +2898,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2890
2898
|
break;
|
2891
2899
|
}
|
2892
2900
|
case 54 /* ParseNodeType.TypeAnnotation */: {
|
2893
|
-
|
2901
|
+
let annotationType = getTypeOfAnnotation(target.d.annotation, {
|
2894
2902
|
varTypeAnnotation: true,
|
2895
2903
|
allowFinal: ParseTreeUtils.isFinalAllowedForAssignmentTarget(target.d.valueExpr),
|
2896
2904
|
allowClassVar: ParseTreeUtils.isClassVarAllowedForAssignmentTarget(target.d.valueExpr),
|
2897
2905
|
});
|
2906
|
+
if (annotationType) {
|
2907
|
+
const liveScopeIds = ParseTreeUtils.getTypeVarScopesForNode(target);
|
2908
|
+
annotationType = (0, typeUtils_1.makeTypeVarsBound)(annotationType, liveScopeIds);
|
2909
|
+
}
|
2898
2910
|
// Handle a bare "Final" or "ClassVar" in a special manner.
|
2899
2911
|
const isBareFinalOrClassVar = (0, types_1.isClassInstance)(annotationType) &&
|
2900
2912
|
(types_1.ClassType.isBuiltIn(annotationType, 'Final') || types_1.ClassType.isBuiltIn(annotationType, 'ClassVar'));
|
@@ -3143,6 +3155,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3143
3155
|
if ((flags & 256 /* EvalFlags.TypeExpression */) !== 0) {
|
3144
3156
|
type = validateSymbolIsTypeExpression(node, type, !!effectiveTypeInfo.includesVariableDecl);
|
3145
3157
|
}
|
3158
|
+
if ((0, types_1.isTypeVar)(type) && !type.shared.isSynthesized) {
|
3159
|
+
type = validateTypeVarUsage(node, type, flags);
|
3160
|
+
}
|
3146
3161
|
// Add TypeForm details if appropriate.
|
3147
3162
|
type = addTypeFormForSymbol(node, type, flags, !!effectiveTypeInfo.includesVariableDecl);
|
3148
3163
|
}
|
@@ -3156,7 +3171,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3156
3171
|
type = types_1.UnknownType.create();
|
3157
3172
|
}
|
3158
3173
|
}
|
3159
|
-
if ((0, types_1.isParamSpec)(type)) {
|
3174
|
+
if ((0, types_1.isParamSpec)(type) && type.priv.scopeId) {
|
3160
3175
|
if (flags & 32 /* EvalFlags.NoParamSpec */) {
|
3161
3176
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.paramSpecContext(), node);
|
3162
3177
|
type = types_1.UnknownType.create();
|
@@ -3173,9 +3188,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3173
3188
|
}
|
3174
3189
|
}
|
3175
3190
|
}
|
3176
|
-
if ((0, types_1.isTypeVar)(type) && !type.shared.isSynthesized) {
|
3177
|
-
type = validateTypeVarUsage(node, type, flags);
|
3178
|
-
}
|
3179
3191
|
return { type, isIncomplete };
|
3180
3192
|
}
|
3181
3193
|
function addTypeFormForSymbol(node, type, flags, includesVarDecl) {
|
@@ -3231,7 +3243,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3231
3243
|
if ((0, typeUtils_1.isTypeAliasPlaceholder)(type)) {
|
3232
3244
|
return true;
|
3233
3245
|
}
|
3234
|
-
if ((0, types_1.isTypeVar)(type)
|
3246
|
+
if ((0, types_1.isTypeVar)(type)) {
|
3235
3247
|
return true;
|
3236
3248
|
}
|
3237
3249
|
// Exempts class types that are created by calling NewType, NamedTuple, etc.
|
@@ -3470,7 +3482,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3470
3482
|
if (type.priv.scopeId && !scopedTypeVarInfo.foundInterveningClass) {
|
3471
3483
|
return type;
|
3472
3484
|
}
|
3473
|
-
if (!type.shared.isSynthesized) {
|
3485
|
+
if (!type.shared.isSynthesized && (flags & 128 /* EvalFlags.InstantiableType */) !== 0) {
|
3474
3486
|
const message = (0, types_1.isParamSpec)(type)
|
3475
3487
|
? localize_1.LocMessage.paramSpecNotUsedByOuterScope()
|
3476
3488
|
: localize_1.LocMessage.typeVarNotUsedByOuterScope();
|
@@ -3531,7 +3543,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3531
3543
|
// Walks up the parse tree to find a function, class, or type alias
|
3532
3544
|
// declaration that provides the context for a type variable.
|
3533
3545
|
function findScopedTypeVar(node, type) {
|
3534
|
-
var _a;
|
3546
|
+
var _a, _b;
|
3535
3547
|
let curNode = node;
|
3536
3548
|
let nestedClassCount = 0;
|
3537
3549
|
(0, debug_1.assert)(types_1.TypeBase.isInstantiable(type));
|
@@ -3598,7 +3610,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3598
3610
|
// purposes of resolving type aliases?
|
3599
3611
|
if (leftType && (0, types_1.isTypeVar)(leftType) && leftType.shared.recursiveAlias) {
|
3600
3612
|
// Type alias statements cannot be used with old-style type variables.
|
3601
|
-
if (typeAliasNode && !type.shared.isTypeParamSyntax) {
|
3613
|
+
if (typeAliasNode && !type.shared.isTypeParamSyntax && !((_a = type.props) === null || _a === void 0 ? void 0 : _a.typeAliasInfo)) {
|
3602
3614
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeParameterNotDeclared().format({
|
3603
3615
|
name: type.shared.name,
|
3604
3616
|
container: typeAliasNode.d.name.d.value,
|
@@ -3608,7 +3620,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3608
3620
|
// If this is a TypeAliasType call, the recursive type parameters will already
|
3609
3621
|
// be populated, and we need to verify that the type parameter is in the
|
3610
3622
|
// list of allowed type parameters.
|
3611
|
-
const allowedTypeParams = (
|
3623
|
+
const allowedTypeParams = (_b = leftType.shared.recursiveAlias) === null || _b === void 0 ? void 0 : _b.typeParams;
|
3612
3624
|
if (allowedTypeParams) {
|
3613
3625
|
if (!allowedTypeParams.some((param) => param.shared.name === type.shared.name)) {
|
3614
3626
|
// Return the original type.
|
@@ -3828,8 +3840,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3828
3840
|
}
|
3829
3841
|
if (typeResult) {
|
3830
3842
|
if (!typeResult.typeErrors) {
|
3831
|
-
type = (0, typeUtils_1.addConditionToType)(typeResult.type, (0, typeUtils_1.getTypeCondition)(baseType),
|
3832
|
-
|
3843
|
+
type = (0, typeUtils_1.addConditionToType)(typeResult.type, (0, typeUtils_1.getTypeCondition)(baseType), {
|
3844
|
+
skipSelfCondition: true,
|
3845
|
+
skipBoundTypeVars: true,
|
3846
|
+
});
|
3833
3847
|
}
|
3834
3848
|
else {
|
3835
3849
|
typeErrors = true;
|
@@ -3841,8 +3855,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3841
3855
|
isIncomplete = true;
|
3842
3856
|
}
|
3843
3857
|
if (typeResult.narrowedTypeForSet) {
|
3844
|
-
narrowedTypeForSet = (0, typeUtils_1.addConditionToType)(typeResult.narrowedTypeForSet, (0, typeUtils_1.getTypeCondition)(baseType),
|
3845
|
-
/* skipSelfCondition */ true);
|
3858
|
+
narrowedTypeForSet = (0, typeUtils_1.addConditionToType)(typeResult.narrowedTypeForSet, (0, typeUtils_1.getTypeCondition)(baseType), { skipSelfCondition: true, skipBoundTypeVars: true });
|
3846
3859
|
}
|
3847
3860
|
if (typeResult.memberAccessDeprecationInfo) {
|
3848
3861
|
memberAccessDeprecationInfo = typeResult.memberAccessDeprecationInfo;
|
@@ -3932,7 +3945,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3932
3945
|
(0, debug_1.assert)((0, types_1.isClassInstance)(subtype));
|
3933
3946
|
const typeResult = getTypeOfBoundMember(node.d.member, subtype, memberName, usage, diag);
|
3934
3947
|
if (typeResult && !typeResult.typeErrors) {
|
3935
|
-
type = (0, typeUtils_1.addConditionToType)(typeResult.type, (0, typeUtils_1.getTypeCondition)(baseType)
|
3948
|
+
type = (0, typeUtils_1.addConditionToType)(typeResult.type, (0, typeUtils_1.getTypeCondition)(baseType), {
|
3949
|
+
skipBoundTypeVars: true,
|
3950
|
+
});
|
3936
3951
|
if (typeResult.isIncomplete) {
|
3937
3952
|
isIncomplete = true;
|
3938
3953
|
}
|
@@ -5542,7 +5557,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5542
5557
|
if (!(options === null || options === void 0 ? void 0 : options.isAnnotatedClass)) {
|
5543
5558
|
adjFlags |= 131072 /* EvalFlags.NoClassVar */ | 16 /* EvalFlags.NoFinal */;
|
5544
5559
|
}
|
5545
|
-
adjFlags |=
|
5560
|
+
adjFlags |= 4194304 /* EvalFlags.AllowUnpackedTuple */ | 134217728 /* EvalFlags.AllowConcatenate */;
|
5546
5561
|
}
|
5547
5562
|
// Create a local function that validates a single type argument.
|
5548
5563
|
const getTypeArgTypeResult = (expr, argIndex) => {
|
@@ -5559,7 +5574,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5559
5574
|
}
|
5560
5575
|
else if ((options === null || options === void 0 ? void 0 : options.isAnnotatedClass) && argIndex > 0) {
|
5561
5576
|
// If it's an Annotated[a, b, c], only the first index should be
|
5562
|
-
// treated as a type.The others can be regular(non
|
5577
|
+
// treated as a type. The others can be regular (non-type) objects.
|
5563
5578
|
adjFlags =
|
5564
5579
|
32 /* EvalFlags.NoParamSpec */ | 64 /* EvalFlags.NoTypeVarTuple */ | 2 /* EvalFlags.NoSpecialize */ | 131072 /* EvalFlags.NoClassVar */;
|
5565
5580
|
if ((0, analyzerFileInfo_1.isAnnotationEvaluationPostponed)(AnalyzerNodeInfo.getFileInfo(node))) {
|
@@ -5638,10 +5653,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5638
5653
|
if ((0, types_1.isTypeVar)(type)) {
|
5639
5654
|
const upperBound = type.shared.boundType;
|
5640
5655
|
if (upperBound && (0, types_1.isClassInstance)(upperBound) && (0, typeUtils_1.isTupleClass)(upperBound)) {
|
5641
|
-
|
5642
|
-
if ((0, types_1.isInstantiableClass)(concrete)) {
|
5643
|
-
return types_1.ClassType.cloneForUnpacked(concrete);
|
5644
|
-
}
|
5656
|
+
return types_1.TypeVarType.cloneForUnpacked(type);
|
5645
5657
|
}
|
5646
5658
|
return undefined;
|
5647
5659
|
}
|
@@ -5927,6 +5939,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5927
5939
|
if (!(0, types_1.isTypeSame)(assertedType, arg0Type, {
|
5928
5940
|
treatAnySameAsUnknown: true,
|
5929
5941
|
ignorePseudoGeneric: true,
|
5942
|
+
ignoreConditions: true,
|
5930
5943
|
})) {
|
5931
5944
|
const srcDestTypes = printSrcDestTypes(arg0TypeResult.type, assertedType, { expandTypeAlias: true });
|
5932
5945
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportAssertTypeFailure, localize_1.LocMessage.assertTypeTypeMismatch().format({
|
@@ -7216,7 +7229,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7216
7229
|
function evaluateCastCall(argList, errorNode) {
|
7217
7230
|
var _a;
|
7218
7231
|
// Verify that the cast is necessary.
|
7219
|
-
|
7232
|
+
let castToType = getTypeOfArgExpectingType(argList[0], { typeExpression: true }).type;
|
7233
|
+
const liveScopeIds = ParseTreeUtils.getTypeVarScopesForNode(errorNode);
|
7234
|
+
castToType = (0, typeUtils_1.makeTypeVarsBound)(castToType, liveScopeIds);
|
7220
7235
|
let castFromType = getTypeOfArg(argList[1], /* inferenceContext */ undefined).type;
|
7221
7236
|
if ((_a = castFromType.props) === null || _a === void 0 ? void 0 : _a.specialForm) {
|
7222
7237
|
castFromType = castFromType.props.specialForm;
|
@@ -7449,7 +7464,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7449
7464
|
const paramInfo = paramDetails.params[paramIndex];
|
7450
7465
|
const paramType = paramInfo.type;
|
7451
7466
|
const paramName = paramInfo.param.name;
|
7452
|
-
const isParamVariadic = paramInfo.param.category === 1 /* ParamCategory.ArgsList */ && (0, types_1.
|
7467
|
+
const isParamVariadic = paramInfo.param.category === 1 /* ParamCategory.ArgsList */ && (0, types_1.isUnpacked)(paramType);
|
7453
7468
|
if (argList[argIndex].argCategory === 1 /* ArgCategory.UnpackedList */) {
|
7454
7469
|
let isArgCompatibleWithVariadic = false;
|
7455
7470
|
const argTypeResult = getTypeOfArg(argList[argIndex], /* inferenceContext */ undefined);
|
@@ -7581,7 +7596,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7581
7596
|
paramType.priv.tupleTypeArgs.length > 0) {
|
7582
7597
|
effectiveParamType = paramType.priv.tupleTypeArgs[0].type;
|
7583
7598
|
}
|
7584
|
-
paramCategory = (0, types_1.
|
7599
|
+
paramCategory = (0, types_1.isUnpacked)(effectiveParamType) ? 1 /* ParamCategory.ArgsList */ : 0 /* ParamCategory.Simple */;
|
7585
7600
|
if (remainingArgCount <= remainingParamCount) {
|
7586
7601
|
if (remainingArgCount < remainingParamCount) {
|
7587
7602
|
if (!canSkipDiagnosticForNode(errorNode) && !isTypeIncomplete) {
|
@@ -8060,7 +8075,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8060
8075
|
!isTypeVarTupleFullyMatched) {
|
8061
8076
|
const paramType = paramDetails.params[paramDetails.argsIndex].type;
|
8062
8077
|
const variadicArgs = validateArgTypeParams.filter((argParam) => argParam.mapsToVarArgList);
|
8063
|
-
if ((0, types_1.
|
8078
|
+
if ((0, types_1.isUnpacked)(paramType) && (!(0, types_1.isTypeVarTuple)(paramType) || !paramType.priv.isInUnion)) {
|
8064
8079
|
const tupleTypeArgs = variadicArgs.map((argParam) => {
|
8065
8080
|
var _a;
|
8066
8081
|
const argType = getTypeOfArg(argParam.argument, /* inferenceContext */ undefined).type;
|
@@ -8084,20 +8099,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8084
8099
|
};
|
8085
8100
|
});
|
8086
8101
|
let specializedTuple;
|
8087
|
-
if (tupleTypeArgs.length === 1 &&
|
8088
|
-
|
8089
|
-
|
8090
|
-
|
8091
|
-
|
8092
|
-
// simplify the type.
|
8093
|
-
specializedTuple = tupleTypeArgs[0].type;
|
8102
|
+
if (tupleTypeArgs.length === 1 && !tupleTypeArgs[0].isUnbounded) {
|
8103
|
+
const entryType = tupleTypeArgs[0].type;
|
8104
|
+
if ((0, types_1.isUnpacked)(entryType)) {
|
8105
|
+
specializedTuple = (0, typeUtils_1.makePacked)(entryType);
|
8106
|
+
}
|
8094
8107
|
}
|
8095
|
-
|
8096
|
-
specializedTuple = (0, tuples_1.makeTupleObject)(evaluatorInterface, tupleTypeArgs, /* isUnpacked */
|
8108
|
+
if (!specializedTuple) {
|
8109
|
+
specializedTuple = (0, tuples_1.makeTupleObject)(evaluatorInterface, tupleTypeArgs, /* isUnpacked */ false);
|
8097
8110
|
}
|
8098
8111
|
const combinedArg = {
|
8099
|
-
paramCategory:
|
8100
|
-
paramType,
|
8112
|
+
paramCategory: 0 /* ParamCategory.Simple */,
|
8113
|
+
paramType: (0, typeUtils_1.makePacked)(paramType),
|
8101
8114
|
requiresTypeVarMatching: true,
|
8102
8115
|
argument: {
|
8103
8116
|
argCategory: 0 /* ArgCategory.Simple */,
|
@@ -8407,7 +8420,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8407
8420
|
eliminateUnsolvedInUnions,
|
8408
8421
|
},
|
8409
8422
|
});
|
8410
|
-
specializedReturnType = (0, typeUtils_1.addConditionToType)(specializedReturnType, typeCondition);
|
8423
|
+
specializedReturnType = (0, typeUtils_1.addConditionToType)(specializedReturnType, typeCondition, { skipBoundTypeVars: true });
|
8411
8424
|
// If the function includes a ParamSpec and the captured signature(s) includes
|
8412
8425
|
// generic types, we may need to apply those solved TypeVars.
|
8413
8426
|
if (paramSpecConstraints.length > 0) {
|
@@ -8423,7 +8436,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8423
8436
|
}
|
8424
8437
|
// If the final return type is an unpacked tuple, turn it into a normal (unpacked) tuple.
|
8425
8438
|
if ((0, types_1.isUnpackedClass)(specializedReturnType)) {
|
8426
|
-
specializedReturnType = types_1.ClassType.
|
8439
|
+
specializedReturnType = types_1.ClassType.cloneForPacked(specializedReturnType);
|
8427
8440
|
}
|
8428
8441
|
const liveTypeVarScopes = ParseTreeUtils.getTypeVarScopesForNode(errorNode);
|
8429
8442
|
specializedReturnType = adjustCallableReturnType(errorNode, specializedReturnType, liveTypeVarScopes);
|
@@ -10690,16 +10703,23 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10690
10703
|
// As per the specification, we support None, int, bool, str, bytes literals
|
10691
10704
|
// plus enum values.
|
10692
10705
|
const literalTypes = [];
|
10706
|
+
let isValidTypeForm = true;
|
10693
10707
|
for (const item of node.d.items) {
|
10694
10708
|
let type;
|
10695
10709
|
const itemExpr = item.d.valueExpr;
|
10696
10710
|
if (item.d.argCategory !== 0 /* ArgCategory.Simple */) {
|
10697
|
-
|
10698
|
-
|
10711
|
+
if ((flags & 256 /* EvalFlags.TypeExpression */) !== 0) {
|
10712
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.unpackedArgInTypeArgument(), itemExpr);
|
10713
|
+
type = types_1.UnknownType.create();
|
10714
|
+
isValidTypeForm = false;
|
10715
|
+
}
|
10699
10716
|
}
|
10700
10717
|
else if (item.d.name) {
|
10701
|
-
|
10702
|
-
|
10718
|
+
if ((flags & 256 /* EvalFlags.TypeExpression */) !== 0) {
|
10719
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.keywordArgInTypeArgument(), itemExpr);
|
10720
|
+
type = types_1.UnknownType.create();
|
10721
|
+
isValidTypeForm = false;
|
10722
|
+
}
|
10703
10723
|
}
|
10704
10724
|
else if (itemExpr.nodeType === 48 /* ParseNodeType.StringList */) {
|
10705
10725
|
const isBytes = (itemExpr.d.strings[0].d.token.flags & 32 /* StringTokenFlags.Bytes */) !== 0;
|
@@ -10710,11 +10730,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10710
10730
|
else {
|
10711
10731
|
type = cloneBuiltinClassWithLiteral(node, classType, 'str', value);
|
10712
10732
|
}
|
10713
|
-
|
10714
|
-
|
10715
|
-
|
10716
|
-
|
10717
|
-
|
10733
|
+
if ((flags & 256 /* EvalFlags.TypeExpression */) !== 0) {
|
10734
|
+
itemExpr.d.strings.forEach((stringNode) => {
|
10735
|
+
if ((stringNode.d.token.flags & 512 /* StringTokenFlags.NamedUnicodeEscape */) !== 0) {
|
10736
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.literalNamedUnicodeEscape(), stringNode);
|
10737
|
+
isValidTypeForm = false;
|
10738
|
+
}
|
10739
|
+
});
|
10740
|
+
}
|
10718
10741
|
}
|
10719
10742
|
else if (itemExpr.nodeType === 40 /* ParseNodeType.Number */) {
|
10720
10743
|
if (!itemExpr.d.isImaginary && itemExpr.d.isInteger) {
|
@@ -10770,6 +10793,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10770
10793
|
if ((flags & 256 /* EvalFlags.TypeExpression */) !== 0) {
|
10771
10794
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.literalUnsupportedType(), item);
|
10772
10795
|
type = types_1.UnknownType.create();
|
10796
|
+
isValidTypeForm = false;
|
10773
10797
|
}
|
10774
10798
|
else {
|
10775
10799
|
return types_1.ClassType.cloneAsInstance(classType);
|
@@ -10781,7 +10805,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10781
10805
|
if ((0, types_1.isUnion)(result) && unionTypeClass && (0, types_1.isInstantiableClass)(unionTypeClass)) {
|
10782
10806
|
result = types_1.TypeBase.cloneAsSpecialForm(result, types_1.ClassType.cloneAsInstance(unionTypeClass));
|
10783
10807
|
}
|
10784
|
-
if (isTypeFormSupported(node)) {
|
10808
|
+
if (isTypeFormSupported(node) && isValidTypeForm) {
|
10785
10809
|
result = types_1.TypeBase.cloneWithTypeForm(result, (0, typeUtils_1.convertToInstance)(result));
|
10786
10810
|
}
|
10787
10811
|
return result;
|
@@ -10952,13 +10976,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10952
10976
|
isUsageLegal = true;
|
10953
10977
|
}
|
10954
10978
|
}
|
10955
|
-
if ((flags & 1048576 /* EvalFlags.AllowRequired */) !== 0) {
|
10956
|
-
isUsageLegal = true;
|
10957
|
-
}
|
10958
10979
|
let isReadOnly = typeArgs[0].isReadOnly;
|
10959
10980
|
let isRequired = typeArgs[0].isRequired;
|
10960
10981
|
let isNotRequired = typeArgs[0].isNotRequired;
|
10961
10982
|
if (classType.shared.name === 'ReadOnly') {
|
10983
|
+
if ((flags & 2097152 /* EvalFlags.AllowReadOnly */) !== 0) {
|
10984
|
+
isUsageLegal = true;
|
10985
|
+
}
|
10962
10986
|
// Nested ReadOnly are not allowed.
|
10963
10987
|
if (typeArgs[0].isReadOnly) {
|
10964
10988
|
isUsageLegal = false;
|
@@ -10966,6 +10990,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10966
10990
|
isReadOnly = true;
|
10967
10991
|
}
|
10968
10992
|
else {
|
10993
|
+
if ((flags & 1048576 /* EvalFlags.AllowRequired */) !== 0) {
|
10994
|
+
isUsageLegal = true;
|
10995
|
+
}
|
10969
10996
|
// Nested Required/NotRequired are not allowed.
|
10970
10997
|
if (typeArgs[0].isRequired || typeArgs[0].isNotRequired) {
|
10971
10998
|
isUsageLegal = false;
|
@@ -10993,7 +11020,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10993
11020
|
return classType;
|
10994
11021
|
}
|
10995
11022
|
const typeArgType = typeArgs[0].type;
|
10996
|
-
if ((flags &
|
11023
|
+
if ((flags & 4194304 /* EvalFlags.AllowUnpackedTuple */) !== 0) {
|
10997
11024
|
const unpackedType = applyUnpackToTupleLike(typeArgType);
|
10998
11025
|
if (unpackedType) {
|
10999
11026
|
return unpackedType;
|
@@ -11004,7 +11031,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11004
11031
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.unpackExpectedTypeVarTuple(), errorNode);
|
11005
11032
|
return types_1.UnknownType.create();
|
11006
11033
|
}
|
11007
|
-
if ((flags &
|
11034
|
+
if ((flags & 8388608 /* EvalFlags.AllowUnpackedTypedDict */) !== 0) {
|
11008
11035
|
if ((0, types_1.isInstantiableClass)(typeArgType) && types_1.ClassType.isTypedDictClass(typeArgType)) {
|
11009
11036
|
return types_1.ClassType.cloneForUnpacked(typeArgType);
|
11010
11037
|
}
|
@@ -11641,8 +11668,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11641
11668
|
}
|
11642
11669
|
}
|
11643
11670
|
if (!rightHandType) {
|
11644
|
-
// Determine whether there is a declared type.
|
11645
|
-
const declaredType = getDeclaredTypeForExpression(node.d.leftExpr, { method: 'set' });
|
11646
11671
|
let typeAliasNameNode;
|
11647
11672
|
let typeAliasPlaceholder;
|
11648
11673
|
let isSpeculativeTypeAlias = false;
|
@@ -11686,6 +11711,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11686
11711
|
writeTypeCache(node.d.leftExpr.d.valueExpr, { type: typeAliasPlaceholder }, /* flags */ undefined);
|
11687
11712
|
}
|
11688
11713
|
}
|
11714
|
+
let declaredType = getDeclaredTypeForExpression(node.d.leftExpr, { method: 'set' });
|
11715
|
+
if (declaredType) {
|
11716
|
+
const liveTypeVarScopes = ParseTreeUtils.getTypeVarScopesForNode(node);
|
11717
|
+
declaredType = (0, typeUtils_1.makeTypeVarsBound)(declaredType, liveTypeVarScopes);
|
11718
|
+
}
|
11689
11719
|
const srcTypeResult = getTypeOfExpression(node.d.rightExpr, flags, (0, typeUtils_1.makeInferenceContext)(declaredType));
|
11690
11720
|
rightHandType = srcTypeResult.type;
|
11691
11721
|
expectedTypeDiagAddendum = srcTypeResult.expectedTypeDiagAddendum;
|
@@ -12125,6 +12155,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12125
12155
|
if (AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.enableExperimentalFeatures) {
|
12126
12156
|
classType.shared.flags |=
|
12127
12157
|
8 /* ClassTypeFlags.TypedDictMarkedClosed */ | 16 /* ClassTypeFlags.TypedDictEffectivelyClosed */;
|
12158
|
+
if (classType.shared.typedDictExtraItemsExpr) {
|
12159
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typedDictExtraItemsClosed(), classType.shared.typedDictExtraItemsExpr);
|
12160
|
+
}
|
12161
|
+
}
|
12162
|
+
}
|
12163
|
+
}
|
12164
|
+
else if (arg.d.name.d.value === 'extra_items') {
|
12165
|
+
// This is an experimental feature because PEP 728 hasn't been accepted yet.
|
12166
|
+
if (AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.enableExperimentalFeatures) {
|
12167
|
+
// Record a reference to the expression but don't evaluate it yet.
|
12168
|
+
// It may refer to the class itself.
|
12169
|
+
classType.shared.typedDictExtraItemsExpr = arg.d.valueExpr;
|
12170
|
+
classType.shared.flags |= 16 /* ClassTypeFlags.TypedDictEffectivelyClosed */;
|
12171
|
+
if (types_1.ClassType.isTypedDictMarkedClosed(classType)) {
|
12172
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typedDictExtraItemsClosed(), classType.shared.typedDictExtraItemsExpr);
|
12128
12173
|
}
|
12129
12174
|
}
|
12130
12175
|
}
|
@@ -13328,7 +13373,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13328
13373
|
return type;
|
13329
13374
|
}
|
13330
13375
|
if ((0, types_1.isUnpackedClass)(type)) {
|
13331
|
-
return types_1.ClassType.
|
13376
|
+
return types_1.ClassType.cloneForPacked(type);
|
13332
13377
|
}
|
13333
13378
|
return (0, tuples_1.makeTupleObject)(evaluatorInterface, [{ type, isUnbounded: !(0, types_1.isTypeVarTuple)(type) }]);
|
13334
13379
|
}
|
@@ -13337,9 +13382,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13337
13382
|
if ((0, types_1.isParamSpec)(type) && type.priv.paramSpecAccess) {
|
13338
13383
|
return type;
|
13339
13384
|
}
|
13340
|
-
// Is this an unpacked TypedDict? If so, return
|
13385
|
+
// Is this an unpacked TypedDict? If so, return its packed version.
|
13341
13386
|
if ((0, types_1.isClassInstance)(type) && types_1.ClassType.isTypedDictClass(type) && type.priv.isUnpacked) {
|
13342
|
-
return type;
|
13387
|
+
return types_1.ClassType.cloneForPacked(type);
|
13343
13388
|
}
|
13344
13389
|
// Wrap the type in a dict with str keys.
|
13345
13390
|
const dictType = getBuiltInType(node, 'dict');
|
@@ -14953,7 +14998,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14953
14998
|
flags |= 4 /* EvalFlags.ForwardRefs */;
|
14954
14999
|
}
|
14955
15000
|
else if (options === null || options === void 0 ? void 0 : options.parsesStringLiteral) {
|
14956
|
-
flags |=
|
15001
|
+
flags |= 16777216 /* EvalFlags.ParsesStringLiteral */;
|
14957
15002
|
}
|
14958
15003
|
if (!(options === null || options === void 0 ? void 0 : options.allowFinal)) {
|
14959
15004
|
flags |= 16 /* EvalFlags.NoFinal */;
|
@@ -14961,14 +15006,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14961
15006
|
if (options === null || options === void 0 ? void 0 : options.allowRequired) {
|
14962
15007
|
flags |= 1048576 /* EvalFlags.AllowRequired */ | 256 /* EvalFlags.TypeExpression */;
|
14963
15008
|
}
|
15009
|
+
if (options === null || options === void 0 ? void 0 : options.allowReadOnly) {
|
15010
|
+
flags |= 2097152 /* EvalFlags.AllowReadOnly */ | 256 /* EvalFlags.TypeExpression */;
|
15011
|
+
}
|
14964
15012
|
if (options === null || options === void 0 ? void 0 : options.allowUnpackedTuple) {
|
14965
|
-
flags |=
|
15013
|
+
flags |= 4194304 /* EvalFlags.AllowUnpackedTuple */;
|
14966
15014
|
}
|
14967
15015
|
else {
|
14968
15016
|
flags |= 64 /* EvalFlags.NoTypeVarTuple */;
|
14969
15017
|
}
|
14970
15018
|
if (options === null || options === void 0 ? void 0 : options.allowUnpackedTypedDict) {
|
14971
|
-
flags |=
|
15019
|
+
flags |= 8388608 /* EvalFlags.AllowUnpackedTypedDict */;
|
14972
15020
|
}
|
14973
15021
|
if (!(options === null || options === void 0 ? void 0 : options.allowParamSpec)) {
|
14974
15022
|
flags |= 32 /* EvalFlags.NoParamSpec */;
|
@@ -15419,7 +15467,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15419
15467
|
if (paramDecl) {
|
15420
15468
|
declarations.push(paramDecl);
|
15421
15469
|
}
|
15422
|
-
else if (types_1.ClassType.isDataClass(baseType) ||
|
15470
|
+
else if (types_1.ClassType.isDataClass(baseType) ||
|
15471
|
+
types_1.ClassType.isTypedDictClass(baseType) ||
|
15472
|
+
types_1.ClassType.hasNamedTupleEntry(baseType, paramName)) {
|
15423
15473
|
const lookupResults = (0, typeUtils_1.lookUpClassMember)(baseType, paramName);
|
15424
15474
|
if (lookupResults) {
|
15425
15475
|
(0, collectionUtils_1.appendArray)(declarations, lookupResults.symbol.getDeclarations());
|
@@ -15549,6 +15599,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15549
15599
|
declaredType = (0, typeUtils_1.convertToInstance)(getTypeOfExpressionExpectingType(typeAnnotationNode, {
|
15550
15600
|
allowFinal: true,
|
15551
15601
|
allowRequired: true,
|
15602
|
+
allowReadOnly: true,
|
15552
15603
|
}).type);
|
15553
15604
|
}
|
15554
15605
|
else {
|
@@ -15561,6 +15612,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15561
15612
|
allowClassVar: ParseTreeUtils.isClassVarAllowedForAssignmentTarget(declNode),
|
15562
15613
|
allowFinal: ParseTreeUtils.isFinalAllowedForAssignmentTarget(declNode),
|
15563
15614
|
allowRequired: ParseTreeUtils.isRequiredAllowedForAssignmentTarget(declNode),
|
15615
|
+
allowReadOnly: ParseTreeUtils.isRequiredAllowedForAssignmentTarget(declNode),
|
15564
15616
|
enforceClassTypeVarScope: declaration.isDefinedByMemberAccess,
|
15565
15617
|
});
|
15566
15618
|
}
|
@@ -16240,23 +16292,31 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
16240
16292
|
// cases where a property symbol is redefined to add a setter, deleter,
|
16241
16293
|
// etc.
|
16242
16294
|
if (usageNode && typedDecls.length > 1) {
|
16243
|
-
|
16244
|
-
|
16245
|
-
|
16246
|
-
|
16247
|
-
|
16248
|
-
|
16249
|
-
|
16250
|
-
|
16295
|
+
if (typedDecls.length > maxTypedDeclsPerSymbol) {
|
16296
|
+
// If there are too many typed decls, don't bother filtering them
|
16297
|
+
// because this can be very expensive. Simply use the last one
|
16298
|
+
// in this case.
|
16299
|
+
typedDecls = [typedDecls[typedDecls.length - 1]];
|
16300
|
+
}
|
16301
|
+
else {
|
16302
|
+
const filteredTypedDecls = typedDecls.filter((decl) => {
|
16303
|
+
if (decl.type !== 8 /* DeclarationType.Alias */) {
|
16304
|
+
// Is the declaration in the same execution scope as the "usageNode" node?
|
16305
|
+
const usageScope = ParseTreeUtils.getExecutionScopeNode(usageNode);
|
16306
|
+
const declScope = ParseTreeUtils.getExecutionScopeNode(decl.node);
|
16307
|
+
if (usageScope === declScope) {
|
16308
|
+
if (!isFlowPathBetweenNodes(decl.node, usageNode, /* allowSelf */ false)) {
|
16309
|
+
return false;
|
16310
|
+
}
|
16251
16311
|
}
|
16252
16312
|
}
|
16313
|
+
return true;
|
16314
|
+
});
|
16315
|
+
if (filteredTypedDecls.length === 0) {
|
16316
|
+
return { type: types_1.UnboundType.create() };
|
16253
16317
|
}
|
16254
|
-
|
16255
|
-
});
|
16256
|
-
if (filteredTypedDecls.length === 0) {
|
16257
|
-
return { type: types_1.UnboundType.create() };
|
16318
|
+
typedDecls = filteredTypedDecls;
|
16258
16319
|
}
|
16259
|
-
typedDecls = filteredTypedDecls;
|
16260
16320
|
}
|
16261
16321
|
// Start with the last decl. If that's already being resolved,
|
16262
16322
|
// use the next-to-last decl, etc. This can happen when resolving
|
@@ -17404,6 +17464,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17404
17464
|
}
|
17405
17465
|
let concreteSrcType = makeTopLevelTypeVarsConcrete(srcType);
|
17406
17466
|
if ((0, types_1.isClass)(concreteSrcType) && types_1.TypeBase.isInstance(concreteSrcType)) {
|
17467
|
+
// Handle the case where the source is an unpacked tuple.
|
17468
|
+
if (!destType.priv.isUnpacked &&
|
17469
|
+
concreteSrcType.priv.isUnpacked &&
|
17470
|
+
concreteSrcType.priv.tupleTypeArgs) {
|
17471
|
+
return assignType(destType, (0, typeUtils_1.combineTupleTypeArgs)(concreteSrcType.priv.tupleTypeArgs), diag, constraints, flags, recursionCount);
|
17472
|
+
}
|
17407
17473
|
// Handle enum literals that are assignable to another (non-Enum) literal.
|
17408
17474
|
// This can happen for IntEnum and StrEnum members.
|
17409
17475
|
if (types_1.ClassType.isEnumClass(concreteSrcType) &&
|
@@ -18322,11 +18388,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18322
18388
|
const destParamName = (_c = destParam.param.name) !== null && _c !== void 0 ? _c : '';
|
18323
18389
|
const srcParamName = (_d = srcParam.param.name) !== null && _d !== void 0 ? _d : '';
|
18324
18390
|
if (destParamName) {
|
18325
|
-
const isDestPositionalOnly = destParam.kind === parameterUtils_1.ParamKind.Positional;
|
18391
|
+
const isDestPositionalOnly = destParam.kind === parameterUtils_1.ParamKind.Positional || destParam.kind === parameterUtils_1.ParamKind.ExpandedArgs;
|
18326
18392
|
if (!isDestPositionalOnly &&
|
18327
18393
|
destParam.param.category !== 1 /* ParamCategory.ArgsList */ &&
|
18328
18394
|
srcParam.param.category !== 1 /* ParamCategory.ArgsList */) {
|
18329
|
-
if (srcParam.kind === parameterUtils_1.ParamKind.Positional) {
|
18395
|
+
if (srcParam.kind === parameterUtils_1.ParamKind.Positional || srcParam.kind === parameterUtils_1.ParamKind.ExpandedArgs) {
|
18330
18396
|
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.LocAddendum.functionParamPositionOnly().format({
|
18331
18397
|
name: destParamName,
|
18332
18398
|
}));
|
@@ -18381,6 +18447,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18381
18447
|
}
|
18382
18448
|
}
|
18383
18449
|
else if (destParam.kind !== parameterUtils_1.ParamKind.Positional &&
|
18450
|
+
destParam.kind !== parameterUtils_1.ParamKind.ExpandedArgs &&
|
18384
18451
|
srcParam.kind === parameterUtils_1.ParamKind.Positional &&
|
18385
18452
|
srcParamDetails.kwargsIndex === undefined &&
|
18386
18453
|
!srcParamDetails.params.some((p) => p.kind === parameterUtils_1.ParamKind.Keyword &&
|
@@ -18469,7 +18536,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18469
18536
|
if (!assignParam(destParamType, srcArgsType, paramIndex, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), constraints, flags, recursionCount)) {
|
18470
18537
|
canAssign = false;
|
18471
18538
|
}
|
18472
|
-
|
18539
|
+
const destParamKind = destParamDetails.params[paramIndex].kind;
|
18540
|
+
if (destParamKind !== parameterUtils_1.ParamKind.Positional &&
|
18541
|
+
destParamKind !== parameterUtils_1.ParamKind.ExpandedArgs &&
|
18473
18542
|
srcParamDetails.kwargsIndex === undefined) {
|
18474
18543
|
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.namedParamMissingInSource().format({
|
18475
18544
|
name: (_g = destParamDetails.params[paramIndex].param.name) !== null && _g !== void 0 ? _g : '',
|
@@ -18543,7 +18612,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18543
18612
|
if (index >= destParamDetails.firstKeywordOnlyIndex) {
|
18544
18613
|
if (param.param.name &&
|
18545
18614
|
param.param.category === 0 /* ParamCategory.Simple */ &&
|
18546
|
-
param.kind !== parameterUtils_1.ParamKind.Positional
|
18615
|
+
param.kind !== parameterUtils_1.ParamKind.Positional &&
|
18616
|
+
param.kind !== parameterUtils_1.ParamKind.ExpandedArgs) {
|
18547
18617
|
destParamMap.set(param.param.name, param);
|
18548
18618
|
}
|
18549
18619
|
}
|
@@ -19150,7 +19220,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
19150
19220
|
else if (i < overrideParamDetails.positionOnlyParamCount &&
|
19151
19221
|
i >= baseParamDetails.positionOnlyParamCount) {
|
19152
19222
|
if (!types_1.FunctionParam.isNameSynthesized(baseParam) &&
|
19153
|
-
baseParamDetails.params[i].kind !== parameterUtils_1.ParamKind.Positional
|
19223
|
+
baseParamDetails.params[i].kind !== parameterUtils_1.ParamKind.Positional &&
|
19224
|
+
baseParamDetails.params[i].kind !== parameterUtils_1.ParamKind.ExpandedArgs) {
|
19154
19225
|
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideParamNamePositionOnly().format({
|
19155
19226
|
index: i + 1,
|
19156
19227
|
baseName: baseParam.name || '*',
|