@zzzen/pyright-internal 1.2.0-dev.20241027 → 1.2.0-dev.20241110
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.d.ts +2 -3
- package/dist/analyzer/binder.js +36 -21
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.js +11 -7
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.js +2 -2
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/constructorTransform.js +18 -1
- package/dist/analyzer/constructorTransform.js.map +1 -1
- package/dist/analyzer/constructors.js +1 -1
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.js +0 -4
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/declaration.d.ts +1 -1
- package/dist/analyzer/declaration.js.map +1 -1
- package/dist/analyzer/enums.js +3 -1
- package/dist/analyzer/enums.js.map +1 -1
- package/dist/analyzer/importResolver.d.ts +1 -1
- package/dist/analyzer/importResolver.js +5 -5
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/operations.js +6 -0
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/parameterUtils.js +2 -0
- package/dist/analyzer/parameterUtils.js.map +1 -1
- package/dist/analyzer/patternMatching.js +4 -2
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/protocols.js +1 -1
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/service.js +1 -1
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/serviceUtils.d.ts +0 -2
- package/dist/analyzer/serviceUtils.js +3 -5
- package/dist/analyzer/serviceUtils.js.map +1 -1
- package/dist/analyzer/sourceFile.js +1 -1
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/tuples.d.ts +2 -2
- package/dist/analyzer/typeEvaluator.js +153 -43
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +2 -1
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +10 -5
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.js +6 -0
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +0 -1
- package/dist/analyzer/typeUtils.js +51 -30
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typedDicts.d.ts +2 -1
- package/dist/analyzer/typedDicts.js +21 -1
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.js +4 -5
- package/dist/analyzer/types.js.map +1 -1
- package/dist/common/pathConsts.d.ts +3 -0
- package/dist/common/pathConsts.js +4 -1
- package/dist/common/pathConsts.js.map +1 -1
- package/dist/languageService/autoImporter.d.ts +6 -2
- package/dist/languageService/autoImporter.js +15 -15
- package/dist/languageService/autoImporter.js.map +1 -1
- package/dist/languageService/completionProvider.js +4 -2
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/fileWatcherDynamicFeature.js +2 -2
- package/dist/languageService/fileWatcherDynamicFeature.js.map +1 -1
- package/dist/languageService/hoverProvider.d.ts +2 -1
- package/dist/languageService/hoverProvider.js +33 -10
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/signatureHelpProvider.js +21 -13
- package/dist/languageService/signatureHelpProvider.js.map +1 -1
- package/dist/localization/localize.d.ts +5 -4
- package/dist/localization/localize.js +5 -2
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +1 -2
- package/dist/localization/package.nls.de.json +2 -3
- package/dist/localization/package.nls.en-us.json +19 -4
- package/dist/localization/package.nls.es.json +2 -3
- package/dist/localization/package.nls.fr.json +1 -2
- package/dist/localization/package.nls.it.json +2 -3
- package/dist/localization/package.nls.ja.json +1 -2
- package/dist/localization/package.nls.ko.json +1 -2
- package/dist/localization/package.nls.pl.json +1 -2
- package/dist/localization/package.nls.pt-br.json +1 -2
- package/dist/localization/package.nls.qps-ploc.json +1 -2
- package/dist/localization/package.nls.ru.json +1 -2
- package/dist/localization/package.nls.tr.json +1 -2
- package/dist/localization/package.nls.zh-cn.json +1 -2
- package/dist/localization/package.nls.zh-tw.json +1 -2
- package/dist/parser/parseNodes.d.ts +3 -2
- package/dist/parser/parseNodes.js +2 -1
- package/dist/parser/parseNodes.js.map +1 -1
- package/dist/parser/parser.d.ts +2 -1
- package/dist/parser/parser.js +36 -7
- package/dist/parser/parser.js.map +1 -1
- package/dist/tests/fourslash/hover.typedDict.get.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.typedDict.get.fourslash.js +16 -0
- package/dist/tests/fourslash/hover.typedDict.get.fourslash.js.map +1 -0
- package/dist/tests/fourslash/signature.dataclassAlias.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/signature.dataclassAlias.fourslash.js +73 -0
- package/dist/tests/fourslash/signature.dataclassAlias.fourslash.js.map +1 -0
- package/dist/tests/harness/fourslash/testState.js +14 -1
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/harness/fourslash/testStateUtils.js +2 -2
- package/dist/tests/harness/fourslash/testStateUtils.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 +6 -2
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +1 -1
- package/dist/tests/typeEvaluator5.test.js +7 -1
- package/dist/tests/typeEvaluator5.test.js.map +1 -1
- package/dist/tests/typeEvaluator6.test.js +17 -1
- package/dist/tests/typeEvaluator6.test.js.map +1 -1
- package/dist/tests/typeEvaluator7.test.js +13 -3
- 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
@@ -206,6 +206,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
206
206
|
let strClass;
|
207
207
|
let dictClass;
|
208
208
|
let moduleTypeClass;
|
209
|
+
let typedDictClass;
|
209
210
|
let typedDictPrivateClass;
|
210
211
|
let supportsKeysAndGetItemClass;
|
211
212
|
let mappingClass;
|
@@ -500,6 +501,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
500
501
|
strClass = getBuiltInType(node, 'str');
|
501
502
|
dictClass = getBuiltInType(node, 'dict');
|
502
503
|
moduleTypeClass = getTypingType(node, 'ModuleType');
|
504
|
+
typedDictClass = getTypingType(node, 'TypedDict');
|
503
505
|
typedDictPrivateClass = getTypingType(node, '_TypedDict');
|
504
506
|
awaitableClass = getTypingType(node, 'Awaitable');
|
505
507
|
mappingClass = getTypingType(node, 'Mapping');
|
@@ -1210,6 +1212,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
1210
1212
|
if (tupleBaseClass && (0, types_1.isClass)(tupleBaseClass) && tupleBaseClass.priv.tupleTypeArgs) {
|
1211
1213
|
return (0, typeUtils_1.isUnboundedTupleClass)(tupleBaseClass) || tupleBaseClass.priv.tupleTypeArgs.length === 0;
|
1212
1214
|
}
|
1215
|
+
// Handle TypedDicts specially. If one or more entries are required
|
1216
|
+
// or known to exist, we can say for sure that the type is not falsy.
|
1217
|
+
if (types_1.ClassType.isTypedDictClass(type)) {
|
1218
|
+
const tdEntries = (0, typedDicts_1.getTypedDictMembersForClass)(evaluatorInterface, type, /* allowNarrowed */ true);
|
1219
|
+
if (tdEntries) {
|
1220
|
+
for (const tdEntry of tdEntries.knownItems.values()) {
|
1221
|
+
if (tdEntry.isRequired || tdEntry.isProvided) {
|
1222
|
+
return false;
|
1223
|
+
}
|
1224
|
+
}
|
1225
|
+
}
|
1226
|
+
}
|
1213
1227
|
// Check for bool, int, str and bytes literals that are never falsy.
|
1214
1228
|
if (type.priv.literalValue !== undefined) {
|
1215
1229
|
if (types_1.ClassType.isBuiltIn(type, ['bool', 'int', 'str', 'bytes'])) {
|
@@ -2380,7 +2394,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2380
2394
|
if (classTypeResults && (0, types_1.isInstantiableClass)(classTypeResults.classType)) {
|
2381
2395
|
enclosingClass = classTypeResults.classType;
|
2382
2396
|
if ((0, types_1.isClassInstance)(baseType)) {
|
2383
|
-
if (types_1.ClassType.isSameGenericClass(baseType, classTypeResults.classType)) {
|
2397
|
+
if (types_1.ClassType.isSameGenericClass(types_1.ClassType.cloneAsInstantiable(baseType), classTypeResults.classType)) {
|
2384
2398
|
assignTypeToMemberVariable(target, typeResult, /* isInstanceMember */ true, srcExpr);
|
2385
2399
|
}
|
2386
2400
|
}
|
@@ -2455,9 +2469,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2455
2469
|
if (isThisClass && isInstanceMember && memberClass) {
|
2456
2470
|
const inheritedSlotsNames = types_1.ClassType.getInheritedSlotsNames(memberClass);
|
2457
2471
|
if (inheritedSlotsNames && memberClass.shared.localSlotsNames) {
|
2458
|
-
// Skip this check if the local slots is specified but empty
|
2459
|
-
//
|
2460
|
-
|
2472
|
+
// Skip this check if the local slots is specified but empty
|
2473
|
+
// and the class isn't final. This pattern is used in a
|
2474
|
+
// legitimate manner for mix-in classes.
|
2475
|
+
if ((memberClass.shared.localSlotsNames.length > 0 || types_1.ClassType.isFinal(memberClass)) &&
|
2461
2476
|
!inheritedSlotsNames.some((name) => name === memberName)) {
|
2462
2477
|
// Determine whether the assignment corresponds to a descriptor
|
2463
2478
|
// that was assigned as a class variable. If so, then slots will not
|
@@ -2951,7 +2966,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2951
2966
|
}
|
2952
2967
|
}
|
2953
2968
|
}
|
2954
|
-
function verifyRaiseExceptionType(node) {
|
2969
|
+
function verifyRaiseExceptionType(node, allowNone) {
|
2955
2970
|
const baseExceptionType = getBuiltInType(node, 'BaseException');
|
2956
2971
|
const exceptionType = getTypeOfExpression(node).type;
|
2957
2972
|
// Validate that the argument of "raise" is an exception object or class.
|
@@ -2961,7 +2976,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2961
2976
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
2962
2977
|
(0, typeUtils_1.doForEachSubtype)(exceptionType, (subtype) => {
|
2963
2978
|
const concreteSubtype = makeTopLevelTypeVarsConcrete(subtype);
|
2964
|
-
if ((0, types_1.isAnyOrUnknown)(concreteSubtype) || (0, types_1.isNever)(concreteSubtype)
|
2979
|
+
if ((0, types_1.isAnyOrUnknown)(concreteSubtype) || (0, types_1.isNever)(concreteSubtype)) {
|
2980
|
+
return;
|
2981
|
+
}
|
2982
|
+
if (allowNone && (0, typeUtils_1.isNoneInstance)(concreteSubtype)) {
|
2965
2983
|
return;
|
2966
2984
|
}
|
2967
2985
|
if ((0, types_1.isInstantiableClass)(concreteSubtype) && concreteSubtype.priv.literalValue === undefined) {
|
@@ -3828,7 +3846,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3828
3846
|
else {
|
3829
3847
|
// Is this an attempt to delete or overwrite an enum member?
|
3830
3848
|
if ((0, types_1.isClassInstance)(enumMemberResult.type) &&
|
3831
|
-
types_1.ClassType.isSameGenericClass(enumMemberResult.type, baseType) &&
|
3849
|
+
types_1.ClassType.isSameGenericClass(enumMemberResult.type, types_1.ClassType.cloneAsInstance(baseType)) &&
|
3832
3850
|
enumMemberResult.type.priv.literalValue !== undefined) {
|
3833
3851
|
const diagMessage = usage.method === 'set' ? localize_1.LocMessage.enumMemberSet() : localize_1.LocMessage.enumMemberDelete();
|
3834
3852
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportAttributeAccessIssue, diagMessage.format({ name: memberName }) + diag.getString(), node.d.member, (_c = diag.getEffectiveTextRange()) !== null && _c !== void 0 ? _c : node.d.member);
|
@@ -4107,7 +4125,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4107
4125
|
const containingClassType = (_a = getTypeOfClass(containingClass)) === null || _a === void 0 ? void 0 : _a.classType;
|
4108
4126
|
if (containingClassType &&
|
4109
4127
|
(0, types_1.isInstantiableClass)(containingClassType) &&
|
4110
|
-
types_1.ClassType.isSameGenericClass(containingClassType, classType)) {
|
4128
|
+
types_1.ClassType.isSameGenericClass(isAccessedThroughObject ? types_1.ClassType.cloneAsInstance(containingClassType) : containingClassType, classType)) {
|
4111
4129
|
type = (_b = getDeclaredTypeOfSymbol(memberInfo.symbol)) === null || _b === void 0 ? void 0 : _b.type;
|
4112
4130
|
if (type && (0, types_1.isInstantiableClass)(memberInfo.classType)) {
|
4113
4131
|
type = (0, typeUtils_1.partiallySpecializeType)(type, memberInfo.classType,
|
@@ -4165,7 +4183,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4165
4183
|
// Mark the member accessed if it's not coming from a parent class.
|
4166
4184
|
if (errorNode &&
|
4167
4185
|
(0, types_1.isInstantiableClass)(memberInfo.classType) &&
|
4168
|
-
types_1.ClassType.isSameGenericClass(memberInfo.classType, classType)) {
|
4186
|
+
types_1.ClassType.isSameGenericClass(memberInfo.classType, isAccessedThroughObject ? types_1.ClassType.cloneAsInstantiable(classType) : classType)) {
|
4169
4187
|
setSymbolAccessed(AnalyzerNodeInfo.getFileInfo(errorNode), memberInfo.symbol, errorNode);
|
4170
4188
|
}
|
4171
4189
|
// Special-case `__init_subclass` and `__class_getitem__` because
|
@@ -4521,8 +4539,28 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4521
4539
|
isAsymmetric = false;
|
4522
4540
|
}
|
4523
4541
|
else {
|
4524
|
-
|
4542
|
+
let getterType = getEffectiveTypeOfSymbol(getterSymbolResult.symbol);
|
4525
4543
|
const setterType = getEffectiveTypeOfSymbol(setterSymbolResult.symbol);
|
4544
|
+
// If this is an overload, find the appropriate overload.
|
4545
|
+
if ((0, types_1.isOverloaded)(getterType)) {
|
4546
|
+
const getOverloads = types_1.OverloadedType.getOverloads(getterType).filter((overload) => {
|
4547
|
+
if (overload.shared.parameters.length < 2) {
|
4548
|
+
return false;
|
4549
|
+
}
|
4550
|
+
const param1Type = types_1.FunctionType.getParamType(overload, 1);
|
4551
|
+
return !(0, typeUtils_1.isNoneInstance)(param1Type);
|
4552
|
+
});
|
4553
|
+
if (getOverloads.length === 1) {
|
4554
|
+
getterType = getOverloads[0];
|
4555
|
+
}
|
4556
|
+
else {
|
4557
|
+
isAsymmetric = true;
|
4558
|
+
}
|
4559
|
+
}
|
4560
|
+
// If this is an overload, find the appropriate overload.
|
4561
|
+
if ((0, types_1.isOverloaded)(setterType)) {
|
4562
|
+
isAsymmetric = true;
|
4563
|
+
}
|
4526
4564
|
// If either the setter or getter is an overload (or some other non-function type),
|
4527
4565
|
// conservatively assume that it's not asymmetric.
|
4528
4566
|
if ((0, types_1.isFunction)(getterType) && (0, types_1.isFunction)(setterType)) {
|
@@ -5195,11 +5233,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5195
5233
|
types_1.ClassType.isPartiallyEvaluated(concreteSubtype);
|
5196
5234
|
const isFinalAnnotation = (0, types_1.isInstantiableClass)(concreteSubtype) && types_1.ClassType.isBuiltIn(concreteSubtype, 'Final');
|
5197
5235
|
const isClassVarAnnotation = (0, types_1.isInstantiableClass)(concreteSubtype) && types_1.ClassType.isBuiltIn(concreteSubtype, 'ClassVar');
|
5236
|
+
// This feature is currently experimental.
|
5237
|
+
const supportsTypedDictTypeArg = AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.enableExperimentalFeatures &&
|
5238
|
+
types_1.ClassType.isBuiltIn(concreteSubtype, 'TypedDict');
|
5198
5239
|
let typeArgs = getTypeArgs(node, flags, {
|
5199
5240
|
isAnnotatedClass,
|
5200
5241
|
hasCustomClassGetItem: hasCustomClassGetItem || !isGenericClass,
|
5201
5242
|
isFinalAnnotation,
|
5202
5243
|
isClassVarAnnotation,
|
5244
|
+
supportsTypedDictTypeArg,
|
5203
5245
|
});
|
5204
5246
|
if (!isAnnotatedClass) {
|
5205
5247
|
typeArgs = adjustTypeArgsForTypeVarTuple(typeArgs, concreteSubtype.shared.typeParams, node);
|
@@ -5586,7 +5628,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5586
5628
|
};
|
5587
5629
|
}
|
5588
5630
|
else {
|
5589
|
-
typeResult = getTypeArg(expr, adjFlags);
|
5631
|
+
typeResult = getTypeArg(expr, adjFlags, !!(options === null || options === void 0 ? void 0 : options.supportsTypedDictTypeArg) && argIndex === 0);
|
5590
5632
|
}
|
5591
5633
|
return typeResult;
|
5592
5634
|
};
|
@@ -5664,7 +5706,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5664
5706
|
}
|
5665
5707
|
return undefined;
|
5666
5708
|
}
|
5667
|
-
function getTypeArg(node, flags) {
|
5709
|
+
function getTypeArg(node, flags, supportsDictExpression) {
|
5668
5710
|
let typeResult;
|
5669
5711
|
let adjustedFlags = flags | 128 /* EvalFlags.InstantiableType */ | 1 /* EvalFlags.ConvertEllipsisToAny */ | 8 /* EvalFlags.StrLiteralAsType */;
|
5670
5712
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
@@ -5682,6 +5724,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5682
5724
|
// Set the node's type so it isn't reevaluated later.
|
5683
5725
|
setTypeResultForNode(node, { type: types_1.UnknownType.create() });
|
5684
5726
|
}
|
5727
|
+
else if (node.nodeType === 18 /* ParseNodeType.Dictionary */ && supportsDictExpression) {
|
5728
|
+
const inlinedTypeDict = typedDictClass && (0, types_1.isInstantiableClass)(typedDictClass)
|
5729
|
+
? (0, typedDicts_1.createTypedDictTypeInlined)(evaluatorInterface, node, typedDictClass)
|
5730
|
+
: undefined;
|
5731
|
+
const keyTypeFallback = strClass && (0, types_1.isInstantiableClass)(strClass) ? strClass : types_1.UnknownType.create();
|
5732
|
+
typeResult = {
|
5733
|
+
type: keyTypeFallback,
|
5734
|
+
inlinedTypeDict,
|
5735
|
+
node,
|
5736
|
+
};
|
5737
|
+
}
|
5685
5738
|
else {
|
5686
5739
|
typeResult = { ...getTypeOfExpression(node, adjustedFlags), node };
|
5687
5740
|
if (node.nodeType === 18 /* ParseNodeType.Dictionary */) {
|
@@ -6192,7 +6245,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6192
6245
|
if (bindToType &&
|
6193
6246
|
types_1.ClassType.isProtocolClass(bindToType) &&
|
6194
6247
|
effectiveTargetClass &&
|
6195
|
-
!types_1.ClassType.isSameGenericClass(bindToType, effectiveTargetClass)) {
|
6248
|
+
!types_1.ClassType.isSameGenericClass(types_1.TypeBase.isInstance(bindToType) ? types_1.ClassType.cloneAsInstantiable(bindToType) : bindToType, effectiveTargetClass)) {
|
6196
6249
|
isProtocolClass = true;
|
6197
6250
|
effectiveTargetClass = undefined;
|
6198
6251
|
}
|
@@ -6248,7 +6301,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6248
6301
|
// class.
|
6249
6302
|
if (bindToType) {
|
6250
6303
|
let nextBaseClassType;
|
6251
|
-
if (types_1.ClassType.isSameGenericClass(bindToType, concreteTargetClassType)) {
|
6304
|
+
if (types_1.ClassType.isSameGenericClass(types_1.TypeBase.isInstance(bindToType) ? types_1.ClassType.cloneAsInstantiable(bindToType) : bindToType, concreteTargetClassType)) {
|
6252
6305
|
if (bindToType.shared.baseClasses.length > 0) {
|
6253
6306
|
nextBaseClassType = bindToType.shared.baseClasses[0];
|
6254
6307
|
}
|
@@ -8811,7 +8864,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8811
8864
|
return { isCompatible: false, argType, isTypeIncomplete, skippedBareTypeVarExpectedType, condition };
|
8812
8865
|
}
|
8813
8866
|
if (!options.skipUnknownArgCheck) {
|
8814
|
-
const simplifiedType = (0, types_1.removeUnbound)(argType);
|
8867
|
+
const simplifiedType = makeTopLevelTypeVarsConcrete((0, types_1.removeUnbound)(argType));
|
8815
8868
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(argParam.errorNode);
|
8816
8869
|
function getDiagAddendum() {
|
8817
8870
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
@@ -9475,7 +9528,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9475
9528
|
if ((0, typeUtils_1.isNoneInstance)(subtype)) {
|
9476
9529
|
if (objectClass && (0, types_1.isInstantiableClass)(objectClass)) {
|
9477
9530
|
// Use 'object' for 'None'.
|
9478
|
-
return handleSubtype(
|
9531
|
+
return handleSubtype(types_1.ClassType.cloneAsInstance(objectClass));
|
9479
9532
|
}
|
9480
9533
|
}
|
9481
9534
|
if ((0, typeUtils_1.isNoneTypeClass)(subtype)) {
|
@@ -12019,6 +12072,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12019
12072
|
}
|
12020
12073
|
argType = (0, typeUtils_1.stripTypeFormRecursive)(argType);
|
12021
12074
|
if (!(0, types_1.isAnyOrUnknown)(argType) && !(0, types_1.isUnbound)(argType)) {
|
12075
|
+
// If the specified base class is type(T), use the metaclass
|
12076
|
+
// of T if it's known.
|
12077
|
+
if ((0, types_1.isClass)(argType) &&
|
12078
|
+
types_1.TypeBase.getInstantiableDepth(argType) > 0 &&
|
12079
|
+
argType.shared.effectiveMetaclass &&
|
12080
|
+
(0, types_1.isClass)(argType.shared.effectiveMetaclass)) {
|
12081
|
+
argType = argType.shared.effectiveMetaclass;
|
12082
|
+
}
|
12022
12083
|
if ((0, typeUtils_1.isMetaclassInstance)(argType)) {
|
12023
12084
|
(0, debug_1.assert)((0, types_1.isClassInstance)(argType));
|
12024
12085
|
argType =
|
@@ -12125,8 +12186,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12125
12186
|
if (protocolTypeParams) {
|
12126
12187
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.duplicateGenericAndProtocolBase(), arg.d.valueExpr);
|
12127
12188
|
}
|
12128
|
-
genericTypeParams =
|
12129
|
-
(0, typeUtils_1.addTypeVarsToListIfUnique)(genericTypeParams, (0, typeUtils_1.getTypeVarArgsRecursive)(argType));
|
12189
|
+
genericTypeParams = buildTypeParamsFromTypeArgs(argType);
|
12130
12190
|
}
|
12131
12191
|
}
|
12132
12192
|
}
|
@@ -12137,8 +12197,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12137
12197
|
if (genericTypeParams) {
|
12138
12198
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.duplicateGenericAndProtocolBase(), arg.d.valueExpr);
|
12139
12199
|
}
|
12140
|
-
protocolTypeParams =
|
12141
|
-
(0, typeUtils_1.addTypeVarsToListIfUnique)(protocolTypeParams, (0, typeUtils_1.getTypeVarArgsRecursive)(argType));
|
12200
|
+
protocolTypeParams = buildTypeParamsFromTypeArgs(argType);
|
12142
12201
|
if (node.d.typeParams && protocolTypeParams.length > 0) {
|
12143
12202
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.protocolBaseClassWithTypeArgs(), arg.d.valueExpr);
|
12144
12203
|
protocolTypeParams = [];
|
@@ -12336,11 +12395,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12336
12395
|
}
|
12337
12396
|
// Determine the effective metaclass.
|
12338
12397
|
if (metaclassNode) {
|
12339
|
-
|
12398
|
+
let metaclassType = getTypeOfExpression(metaclassNode, exprFlags).type;
|
12340
12399
|
if ((0, types_1.isInstantiableClass)(metaclassType) || (0, types_1.isUnknown)(metaclassType)) {
|
12341
12400
|
if ((0, typeUtils_1.requiresSpecialization)(metaclassType, { ignorePseudoGeneric: true })) {
|
12342
12401
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.metaclassIsGeneric(), metaclassNode);
|
12343
12402
|
}
|
12403
|
+
// If the specified metaclass is type(T), use the metaclass
|
12404
|
+
// of T if it's known.
|
12405
|
+
if (types_1.TypeBase.getInstantiableDepth(metaclassType) > 0 &&
|
12406
|
+
(0, types_1.isClass)(metaclassType) &&
|
12407
|
+
metaclassType.shared.effectiveMetaclass &&
|
12408
|
+
(0, types_1.isClass)(metaclassType.shared.effectiveMetaclass)) {
|
12409
|
+
metaclassType = metaclassType.shared.effectiveMetaclass;
|
12410
|
+
}
|
12344
12411
|
classType.shared.declaredMetaclass = metaclassType;
|
12345
12412
|
if ((0, types_1.isInstantiableClass)(metaclassType)) {
|
12346
12413
|
if ((0, enums_1.isEnumMetaclass)(metaclassType)) {
|
@@ -12487,6 +12554,22 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12487
12554
|
return { classType, decoratedType };
|
12488
12555
|
});
|
12489
12556
|
}
|
12557
|
+
function buildTypeParamsFromTypeArgs(classType) {
|
12558
|
+
var _a;
|
12559
|
+
const typeParams = [];
|
12560
|
+
const typeArgs = (_a = classType.priv.typeArgs) !== null && _a !== void 0 ? _a : [];
|
12561
|
+
typeArgs.forEach((typeArg, index) => {
|
12562
|
+
if ((0, types_1.isTypeVar)(typeArg)) {
|
12563
|
+
typeParams.push(typeArg);
|
12564
|
+
return;
|
12565
|
+
}
|
12566
|
+
// Synthesize a dummy type parameter.
|
12567
|
+
const typeVar = types_1.TypeVarType.createInstance(`__P${index}`);
|
12568
|
+
typeVar.shared.isSynthesized = true;
|
12569
|
+
typeParams.push(typeVar);
|
12570
|
+
});
|
12571
|
+
return typeParams;
|
12572
|
+
}
|
12490
12573
|
// Determines whether the type parameters has a default that refers to another
|
12491
12574
|
// type parameter. If so, validates that it is in the list of "live" type
|
12492
12575
|
// parameters and updates the scope of the type parameter referred to in the
|
@@ -13618,6 +13701,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13618
13701
|
}
|
13619
13702
|
writeTypeCache(node.d.suite, { type: inferredReturnType, isIncomplete }, 0 /* EvalFlags.None */);
|
13620
13703
|
}
|
13704
|
+
catch (err) {
|
13705
|
+
// Attempt to handle a stack overflow without crashing. In rare
|
13706
|
+
// cases, we can get very deep stacks when inferring return types
|
13707
|
+
// within untyped code.
|
13708
|
+
if ((err === null || err === void 0 ? void 0 : err.message) === 'Maximum call stack size exceeded') {
|
13709
|
+
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
13710
|
+
console.error(`Overflowed stack when inferring return type for function: ${node.d.name.d.value} in file ${fileInfo.fileUri.toUserVisibleString()}`);
|
13711
|
+
return;
|
13712
|
+
}
|
13713
|
+
throw err;
|
13714
|
+
}
|
13621
13715
|
finally {
|
13622
13716
|
functionRecursionMap.delete(node.id);
|
13623
13717
|
}
|
@@ -14628,7 +14722,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14628
14722
|
}
|
14629
14723
|
case 'TypedDict': {
|
14630
14724
|
if ((flags & (67108864 /* EvalFlags.NoNonTypeSpecialForms */ | 256 /* EvalFlags.TypeExpression */)) !== 0) {
|
14631
|
-
|
14725
|
+
const isInlinedTypedDict = AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.enableExperimentalFeatures &&
|
14726
|
+
!!typeArgs;
|
14727
|
+
if (!isInlinedTypedDict) {
|
14728
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.typedDictNotAllowed(), errorNode);
|
14729
|
+
}
|
14632
14730
|
}
|
14633
14731
|
isValidTypeForm = false;
|
14634
14732
|
break;
|
@@ -14744,7 +14842,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14744
14842
|
if (firstDefaultParamIndex >= 0) {
|
14745
14843
|
minTypeArgCount = firstDefaultParamIndex;
|
14746
14844
|
}
|
14747
|
-
|
14845
|
+
// Classes that accept inlined type dict type args allow only one.
|
14846
|
+
if (typeArgs.length > 0 && typeArgs[0].inlinedTypeDict) {
|
14847
|
+
if (typeArgs.length > 1) {
|
14848
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeArguments, localize_1.LocMessage.typeArgsTooMany().format({
|
14849
|
+
name: classType.priv.aliasName || classType.shared.name,
|
14850
|
+
expected: 1,
|
14851
|
+
received: typeArgCount,
|
14852
|
+
}), typeArgs[1].node);
|
14853
|
+
}
|
14854
|
+
return { type: typeArgs[0].inlinedTypeDict };
|
14855
|
+
}
|
14856
|
+
else if (typeArgCount > typeParams.length) {
|
14748
14857
|
if (!types_1.ClassType.isPartiallyEvaluated(classType) && !types_1.ClassType.isTupleClass(classType)) {
|
14749
14858
|
if (typeParams.length === 0) {
|
14750
14859
|
isValidTypeForm = false;
|
@@ -15635,12 +15744,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15635
15744
|
((_c = declaration.node.parent) === null || _c === void 0 ? void 0 : _c.nodeType) === 35 /* ParseNodeType.MemberAccess */
|
15636
15745
|
? declaration.node.parent
|
15637
15746
|
: declaration.node;
|
15747
|
+
const allowClassVar = ParseTreeUtils.isClassVarAllowedForAssignmentTarget(declNode);
|
15748
|
+
const allowFinal = ParseTreeUtils.isFinalAllowedForAssignmentTarget(declNode);
|
15749
|
+
const allowRequired = ParseTreeUtils.isRequiredAllowedForAssignmentTarget(declNode) ||
|
15750
|
+
!!declaration.isInInlinedTypedDict;
|
15638
15751
|
declaredType = getTypeOfAnnotation(typeAnnotationNode, {
|
15639
15752
|
varTypeAnnotation: true,
|
15640
|
-
allowClassVar
|
15641
|
-
allowFinal
|
15642
|
-
allowRequired
|
15643
|
-
allowReadOnly:
|
15753
|
+
allowClassVar,
|
15754
|
+
allowFinal,
|
15755
|
+
allowRequired,
|
15756
|
+
allowReadOnly: allowRequired,
|
15644
15757
|
enforceClassTypeVarScope: declaration.isDefinedByMemberAccess,
|
15645
15758
|
});
|
15646
15759
|
}
|
@@ -17098,7 +17211,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17098
17211
|
errorSource = localize_1.LocAddendum.typeVarIsCovariant;
|
17099
17212
|
}
|
17100
17213
|
else if (variance === 4 /* Variance.Contravariant */) {
|
17101
|
-
effectiveFlags =
|
17214
|
+
effectiveFlags = flags | 2 /* AssignTypeFlags.Contravariant */ | 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */;
|
17102
17215
|
errorSource = localize_1.LocAddendum.typeVarIsContravariant;
|
17103
17216
|
}
|
17104
17217
|
else {
|
@@ -17467,7 +17580,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17467
17580
|
// the metaclass of the instantiable dest type.
|
17468
17581
|
const destMetaclass = destType.shared.effectiveMetaclass;
|
17469
17582
|
if (destMetaclass && (0, types_1.isInstantiableClass)(destMetaclass)) {
|
17470
|
-
if (assignClass(types_1.ClassType.
|
17583
|
+
if (assignClass(destMetaclass, types_1.ClassType.cloneAsInstantiable(expandedSrcType), diag, constraints, flags, recursionCount,
|
17471
17584
|
/* reportErrorsUsingObjType */ false)) {
|
17472
17585
|
return true;
|
17473
17586
|
}
|
@@ -17588,9 +17701,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17588
17701
|
if ((0, types_1.isAnyOrUnknown)(metaclass)) {
|
17589
17702
|
return true;
|
17590
17703
|
}
|
17591
|
-
|
17592
|
-
|
17593
|
-
|
17704
|
+
if (assignClass(types_1.ClassType.cloneAsInstantiable(destType), metaclass,
|
17705
|
+
/* diag */ undefined, constraints, flags, recursionCount,
|
17706
|
+
/* reportErrorsUsingObjType */ true)) {
|
17707
|
+
return true;
|
17594
17708
|
}
|
17595
17709
|
}
|
17596
17710
|
}
|
@@ -19151,6 +19265,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
19151
19265
|
var _a, _b;
|
19152
19266
|
const baseParamDetails = (0, parameterUtils_1.getParamListDetails)(baseMethod);
|
19153
19267
|
const overrideParamDetails = (0, parameterUtils_1.getParamListDetails)(overrideMethod);
|
19268
|
+
const constraints = new constraintTracker_1.ConstraintTracker();
|
19154
19269
|
let canOverride = true;
|
19155
19270
|
if (!types_1.FunctionType.isGradualCallableForm(baseMethod) && !types_1.FunctionType.isGradualCallableForm(overrideMethod)) {
|
19156
19271
|
// Verify that we're not overriding a static, class or instance method with
|
@@ -19183,8 +19298,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
19183
19298
|
else {
|
19184
19299
|
const overrideArgsType = overrideParamDetails.params[overrideParamDetails.argsIndex].type;
|
19185
19300
|
for (let i = overrideParamDetails.positionParamCount; i < baseParamDetails.positionParamCount; i++) {
|
19186
|
-
if (!assignType(overrideArgsType, baseParamDetails.params[i].type, diag === null || diag === void 0 ? void 0 : diag.createAddendum(),
|
19187
|
-
/* constraints */ undefined, 0 /* AssignTypeFlags.Default */)) {
|
19301
|
+
if (!assignType(overrideArgsType, baseParamDetails.params[i].type, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), constraints, 2 /* AssignTypeFlags.Contravariant */)) {
|
19188
19302
|
localize_1.LocAddendum.overrideParamType().format({
|
19189
19303
|
index: i + 1,
|
19190
19304
|
baseType: printType(baseParamDetails.params[i].type),
|
@@ -19273,8 +19387,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
19273
19387
|
const overrideIsSynthesizedTypeVar = (0, types_1.isTypeVar)(overrideParamType) && overrideParamType.shared.isSynthesized;
|
19274
19388
|
if (!exemptSelfClsParam || (!baseIsSynthesizedTypeVar && !overrideIsSynthesizedTypeVar)) {
|
19275
19389
|
if (baseParam.category !== overrideParam.category ||
|
19276
|
-
!assignType(overrideParamType, baseParamType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(),
|
19277
|
-
/* constraints */ undefined, 0 /* AssignTypeFlags.Default */)) {
|
19390
|
+
!assignType(overrideParamType, baseParamType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), constraints, 2 /* AssignTypeFlags.Contravariant */)) {
|
19278
19391
|
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideParamType().format({
|
19279
19392
|
index: i + 1,
|
19280
19393
|
baseType: printType(baseParamType),
|
@@ -19316,8 +19429,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
19316
19429
|
else {
|
19317
19430
|
const overrideParamType = overrideParamDetails.params[overrideParamDetails.argsIndex].type;
|
19318
19431
|
const baseParamType = baseParamDetails.params[baseParamDetails.argsIndex].type;
|
19319
|
-
if (!assignType(overrideParamType, baseParamType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(),
|
19320
|
-
/* constraints */ undefined, 0 /* AssignTypeFlags.Default */)) {
|
19432
|
+
if (!assignType(overrideParamType, baseParamType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), constraints, 2 /* AssignTypeFlags.Contravariant */)) {
|
19321
19433
|
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideParamKeywordType().format({
|
19322
19434
|
name: (_b = overrideParamDetails.params[overrideParamDetails.argsIndex].param.name) !== null && _b !== void 0 ? _b : '?',
|
19323
19435
|
baseType: printType(baseParamType),
|
@@ -19344,8 +19456,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
19344
19456
|
if (!targetParamType) {
|
19345
19457
|
targetParamType = overrideParamDetails.params[overrideParamDetails.kwargsIndex].type;
|
19346
19458
|
}
|
19347
|
-
if (!assignType(targetParamType, paramInfo.type, diag === null || diag === void 0 ? void 0 : diag.createAddendum(),
|
19348
|
-
/* constraints */ undefined, 0 /* AssignTypeFlags.Default */)) {
|
19459
|
+
if (!assignType(targetParamType, paramInfo.type, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), constraints, 2 /* AssignTypeFlags.Contravariant */)) {
|
19349
19460
|
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideParamKeywordType().format({
|
19350
19461
|
name: (_b = paramInfo.param.name) !== null && _b !== void 0 ? _b : '?',
|
19351
19462
|
baseType: printType(paramInfo.type),
|
@@ -19402,9 +19513,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
19402
19513
|
}
|
19403
19514
|
// Now check the return type.
|
19404
19515
|
const baseReturnType = getEffectiveReturnType(baseMethod);
|
19405
|
-
const overrideReturnType = getEffectiveReturnType(overrideMethod);
|
19406
|
-
if (!assignType(baseReturnType, overrideReturnType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(),
|
19407
|
-
/* constraints */ undefined, 0 /* AssignTypeFlags.Default */)) {
|
19516
|
+
const overrideReturnType = solveAndApplyConstraints(getEffectiveReturnType(overrideMethod), constraints);
|
19517
|
+
if (!assignType(baseReturnType, overrideReturnType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), constraints, 0 /* AssignTypeFlags.Default */)) {
|
19408
19518
|
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideReturnType().format({
|
19409
19519
|
baseType: printType(baseReturnType),
|
19410
19520
|
overrideType: printType(overrideReturnType),
|