@zzzen/pyright-internal 1.2.0-dev.20241020 → 1.2.0-dev.20241103
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 +1 -3
- package/dist/analyzer/binder.js +62 -46
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.js +9 -5
- 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/constraintSolver.js +11 -1
- package/dist/analyzer/constraintSolver.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 +1 -17
- 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/declarationUtils.js +1 -3
- package/dist/analyzer/declarationUtils.js.map +1 -1
- package/dist/analyzer/enums.js +3 -1
- package/dist/analyzer/enums.js.map +1 -1
- package/dist/analyzer/operations.js +2 -2
- 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/parseTreeUtils.js +4 -0
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/patternMatching.js +1 -1
- 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 +5 -5
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceFile.js +1 -1
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/symbol.d.ts +8 -3
- package/dist/analyzer/symbol.js +4 -4
- package/dist/analyzer/symbol.js.map +1 -1
- package/dist/analyzer/tuples.d.ts +2 -2
- package/dist/analyzer/typeEvaluator.js +209 -95
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +2 -5
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +13 -10
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.d.ts +1 -1
- package/dist/analyzer/typePrinter.js +23 -17
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +2 -2
- package/dist/analyzer/typeUtils.js +59 -29
- 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.d.ts +1 -1
- package/dist/analyzer/types.js +7 -6
- package/dist/analyzer/types.js.map +1 -1
- package/dist/common/configOptions.d.ts +1 -1
- package/dist/common/configOptions.js +4 -3
- package/dist/common/configOptions.js.map +1 -1
- package/dist/languageService/completionProvider.js +3 -3
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/definitionProvider.d.ts +2 -0
- package/dist/languageService/definitionProvider.js +21 -5
- package/dist/languageService/definitionProvider.js.map +1 -1
- package/dist/languageService/hoverProvider.d.ts +2 -1
- package/dist/languageService/hoverProvider.js +36 -12
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/localization/localize.d.ts +4 -0
- package/dist/localization/localize.js +10 -1
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +3 -1
- package/dist/localization/package.nls.de.json +2 -0
- package/dist/localization/package.nls.en-us.json +4 -0
- package/dist/localization/package.nls.es.json +2 -0
- package/dist/localization/package.nls.fr.json +2 -0
- package/dist/localization/package.nls.it.json +3 -1
- package/dist/localization/package.nls.ja.json +2 -0
- package/dist/localization/package.nls.ko.json +2 -0
- package/dist/localization/package.nls.pl.json +2 -0
- package/dist/localization/package.nls.pt-br.json +3 -1
- package/dist/localization/package.nls.qps-ploc.json +3 -1
- package/dist/localization/package.nls.ru.json +3 -1
- package/dist/localization/package.nls.tr.json +2 -0
- package/dist/localization/package.nls.zh-cn.json +2 -0
- package/dist/localization/package.nls.zh-tw.json +3 -1
- package/dist/server.d.ts +1 -2
- 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/import.multipart2.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/import.multipart2.fourslash.js +20 -0
- package/dist/tests/fourslash/import.multipart2.fourslash.js.map +1 -0
- package/dist/tests/typeEvaluator2.test.js +8 -0
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +5 -1
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +3 -3
- package/dist/tests/typeEvaluator5.test.js +7 -1
- package/dist/tests/typeEvaluator5.test.js.map +1 -1
- package/dist/tests/typeEvaluator6.test.js +6 -0
- package/dist/tests/typeEvaluator6.test.js.map +1 -1
- package/dist/tests/typeEvaluator7.test.js +10 -0
- 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 +2 -2
@@ -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');
|
@@ -2022,7 +2024,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2022
2024
|
// Handle the case where the type is synthesized (used for
|
2023
2025
|
// dataclasses).
|
2024
2026
|
if (synthesizedType) {
|
2025
|
-
isObjectHashable = !(0, typeUtils_1.isNoneInstance)(synthesizedType);
|
2027
|
+
isObjectHashable = !(0, typeUtils_1.isNoneInstance)(synthesizedType.type);
|
2026
2028
|
}
|
2027
2029
|
else {
|
2028
2030
|
// Assume that if '__hash__' is declared as a variable, it is
|
@@ -2380,7 +2382,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2380
2382
|
if (classTypeResults && (0, types_1.isInstantiableClass)(classTypeResults.classType)) {
|
2381
2383
|
enclosingClass = classTypeResults.classType;
|
2382
2384
|
if ((0, types_1.isClassInstance)(baseType)) {
|
2383
|
-
if (types_1.ClassType.isSameGenericClass(baseType, classTypeResults.classType)) {
|
2385
|
+
if (types_1.ClassType.isSameGenericClass(types_1.ClassType.cloneAsInstantiable(baseType), classTypeResults.classType)) {
|
2384
2386
|
assignTypeToMemberVariable(target, typeResult, /* isInstanceMember */ true, srcExpr);
|
2385
2387
|
}
|
2386
2388
|
}
|
@@ -3828,7 +3830,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3828
3830
|
else {
|
3829
3831
|
// Is this an attempt to delete or overwrite an enum member?
|
3830
3832
|
if ((0, types_1.isClassInstance)(enumMemberResult.type) &&
|
3831
|
-
types_1.ClassType.isSameGenericClass(enumMemberResult.type, baseType) &&
|
3833
|
+
types_1.ClassType.isSameGenericClass(enumMemberResult.type, types_1.ClassType.cloneAsInstance(baseType)) &&
|
3832
3834
|
enumMemberResult.type.priv.literalValue !== undefined) {
|
3833
3835
|
const diagMessage = usage.method === 'set' ? localize_1.LocMessage.enumMemberSet() : localize_1.LocMessage.enumMemberDelete();
|
3834
3836
|
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 +4109,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4107
4109
|
const containingClassType = (_a = getTypeOfClass(containingClass)) === null || _a === void 0 ? void 0 : _a.classType;
|
4108
4110
|
if (containingClassType &&
|
4109
4111
|
(0, types_1.isInstantiableClass)(containingClassType) &&
|
4110
|
-
types_1.ClassType.isSameGenericClass(containingClassType, classType)) {
|
4112
|
+
types_1.ClassType.isSameGenericClass(isAccessedThroughObject ? types_1.ClassType.cloneAsInstance(containingClassType) : containingClassType, classType)) {
|
4111
4113
|
type = (_b = getDeclaredTypeOfSymbol(memberInfo.symbol)) === null || _b === void 0 ? void 0 : _b.type;
|
4112
4114
|
if (type && (0, types_1.isInstantiableClass)(memberInfo.classType)) {
|
4113
4115
|
type = (0, typeUtils_1.partiallySpecializeType)(type, memberInfo.classType,
|
@@ -4165,7 +4167,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4165
4167
|
// Mark the member accessed if it's not coming from a parent class.
|
4166
4168
|
if (errorNode &&
|
4167
4169
|
(0, types_1.isInstantiableClass)(memberInfo.classType) &&
|
4168
|
-
types_1.ClassType.isSameGenericClass(memberInfo.classType, classType)) {
|
4170
|
+
types_1.ClassType.isSameGenericClass(memberInfo.classType, isAccessedThroughObject ? types_1.ClassType.cloneAsInstantiable(classType) : classType)) {
|
4169
4171
|
setSymbolAccessed(AnalyzerNodeInfo.getFileInfo(errorNode), memberInfo.symbol, errorNode);
|
4170
4172
|
}
|
4171
4173
|
// Special-case `__init_subclass` and `__class_getitem__` because
|
@@ -4521,8 +4523,28 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4521
4523
|
isAsymmetric = false;
|
4522
4524
|
}
|
4523
4525
|
else {
|
4524
|
-
|
4526
|
+
let getterType = getEffectiveTypeOfSymbol(getterSymbolResult.symbol);
|
4525
4527
|
const setterType = getEffectiveTypeOfSymbol(setterSymbolResult.symbol);
|
4528
|
+
// If this is an overload, find the appropriate overload.
|
4529
|
+
if ((0, types_1.isOverloaded)(getterType)) {
|
4530
|
+
const getOverloads = types_1.OverloadedType.getOverloads(getterType).filter((overload) => {
|
4531
|
+
if (overload.shared.parameters.length < 2) {
|
4532
|
+
return false;
|
4533
|
+
}
|
4534
|
+
const param1Type = types_1.FunctionType.getParamType(overload, 1);
|
4535
|
+
return !(0, typeUtils_1.isNoneInstance)(param1Type);
|
4536
|
+
});
|
4537
|
+
if (getOverloads.length === 1) {
|
4538
|
+
getterType = getOverloads[0];
|
4539
|
+
}
|
4540
|
+
else {
|
4541
|
+
isAsymmetric = true;
|
4542
|
+
}
|
4543
|
+
}
|
4544
|
+
// If this is an overload, find the appropriate overload.
|
4545
|
+
if ((0, types_1.isOverloaded)(setterType)) {
|
4546
|
+
isAsymmetric = true;
|
4547
|
+
}
|
4526
4548
|
// If either the setter or getter is an overload (or some other non-function type),
|
4527
4549
|
// conservatively assume that it's not asymmetric.
|
4528
4550
|
if ((0, types_1.isFunction)(getterType) && (0, types_1.isFunction)(setterType)) {
|
@@ -5195,11 +5217,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5195
5217
|
types_1.ClassType.isPartiallyEvaluated(concreteSubtype);
|
5196
5218
|
const isFinalAnnotation = (0, types_1.isInstantiableClass)(concreteSubtype) && types_1.ClassType.isBuiltIn(concreteSubtype, 'Final');
|
5197
5219
|
const isClassVarAnnotation = (0, types_1.isInstantiableClass)(concreteSubtype) && types_1.ClassType.isBuiltIn(concreteSubtype, 'ClassVar');
|
5220
|
+
// This feature is currently experimental.
|
5221
|
+
const supportsTypedDictTypeArg = AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.enableExperimentalFeatures &&
|
5222
|
+
types_1.ClassType.isBuiltIn(concreteSubtype, 'TypedDict');
|
5198
5223
|
let typeArgs = getTypeArgs(node, flags, {
|
5199
5224
|
isAnnotatedClass,
|
5200
5225
|
hasCustomClassGetItem: hasCustomClassGetItem || !isGenericClass,
|
5201
5226
|
isFinalAnnotation,
|
5202
5227
|
isClassVarAnnotation,
|
5228
|
+
supportsTypedDictTypeArg,
|
5203
5229
|
});
|
5204
5230
|
if (!isAnnotatedClass) {
|
5205
5231
|
typeArgs = adjustTypeArgsForTypeVarTuple(typeArgs, concreteSubtype.shared.typeParams, node);
|
@@ -5586,7 +5612,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5586
5612
|
};
|
5587
5613
|
}
|
5588
5614
|
else {
|
5589
|
-
typeResult = getTypeArg(expr, adjFlags);
|
5615
|
+
typeResult = getTypeArg(expr, adjFlags, !!(options === null || options === void 0 ? void 0 : options.supportsTypedDictTypeArg) && argIndex === 0);
|
5590
5616
|
}
|
5591
5617
|
return typeResult;
|
5592
5618
|
};
|
@@ -5664,7 +5690,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5664
5690
|
}
|
5665
5691
|
return undefined;
|
5666
5692
|
}
|
5667
|
-
function getTypeArg(node, flags) {
|
5693
|
+
function getTypeArg(node, flags, supportsDictExpression) {
|
5668
5694
|
let typeResult;
|
5669
5695
|
let adjustedFlags = flags | 128 /* EvalFlags.InstantiableType */ | 1 /* EvalFlags.ConvertEllipsisToAny */ | 8 /* EvalFlags.StrLiteralAsType */;
|
5670
5696
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
@@ -5682,6 +5708,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5682
5708
|
// Set the node's type so it isn't reevaluated later.
|
5683
5709
|
setTypeResultForNode(node, { type: types_1.UnknownType.create() });
|
5684
5710
|
}
|
5711
|
+
else if (node.nodeType === 18 /* ParseNodeType.Dictionary */ && supportsDictExpression) {
|
5712
|
+
const inlinedTypeDict = typedDictClass && (0, types_1.isInstantiableClass)(typedDictClass)
|
5713
|
+
? (0, typedDicts_1.createTypedDictTypeInlined)(evaluatorInterface, node, typedDictClass)
|
5714
|
+
: undefined;
|
5715
|
+
const keyTypeFallback = strClass && (0, types_1.isInstantiableClass)(strClass) ? strClass : types_1.UnknownType.create();
|
5716
|
+
typeResult = {
|
5717
|
+
type: keyTypeFallback,
|
5718
|
+
inlinedTypeDict,
|
5719
|
+
node,
|
5720
|
+
};
|
5721
|
+
}
|
5685
5722
|
else {
|
5686
5723
|
typeResult = { ...getTypeOfExpression(node, adjustedFlags), node };
|
5687
5724
|
if (node.nodeType === 18 /* ParseNodeType.Dictionary */) {
|
@@ -6192,7 +6229,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6192
6229
|
if (bindToType &&
|
6193
6230
|
types_1.ClassType.isProtocolClass(bindToType) &&
|
6194
6231
|
effectiveTargetClass &&
|
6195
|
-
!types_1.ClassType.isSameGenericClass(bindToType, effectiveTargetClass)) {
|
6232
|
+
!types_1.ClassType.isSameGenericClass(types_1.TypeBase.isInstance(bindToType) ? types_1.ClassType.cloneAsInstantiable(bindToType) : bindToType, effectiveTargetClass)) {
|
6196
6233
|
isProtocolClass = true;
|
6197
6234
|
effectiveTargetClass = undefined;
|
6198
6235
|
}
|
@@ -6248,7 +6285,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6248
6285
|
// class.
|
6249
6286
|
if (bindToType) {
|
6250
6287
|
let nextBaseClassType;
|
6251
|
-
if (types_1.ClassType.isSameGenericClass(bindToType, concreteTargetClassType)) {
|
6288
|
+
if (types_1.ClassType.isSameGenericClass(types_1.TypeBase.isInstance(bindToType) ? types_1.ClassType.cloneAsInstantiable(bindToType) : bindToType, concreteTargetClassType)) {
|
6252
6289
|
if (bindToType.shared.baseClasses.length > 0) {
|
6253
6290
|
nextBaseClassType = bindToType.shared.baseClasses[0];
|
6254
6291
|
}
|
@@ -7310,13 +7347,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7310
7347
|
// Build a map of parameters by name.
|
7311
7348
|
const paramMap = new Map();
|
7312
7349
|
paramDetails.params.forEach((paramInfo) => {
|
7350
|
+
var _a, _b;
|
7313
7351
|
(0, debug_1.assert)(paramInfo !== undefined, 'paramInfo is undefined for param name map');
|
7314
7352
|
const param = paramInfo.param;
|
7315
7353
|
if (param.name && param.category === 0 /* ParamCategory.Simple */ && paramInfo.kind !== parameterUtils_1.ParamKind.Positional) {
|
7316
|
-
paramMap.
|
7317
|
-
|
7318
|
-
|
7319
|
-
}
|
7354
|
+
let argsNeeded = (_b = (_a = paramMap.get(param.name)) === null || _a === void 0 ? void 0 : _a.argsNeeded) !== null && _b !== void 0 ? _b : 0;
|
7355
|
+
if (param.category === 0 /* ParamCategory.Simple */ && !paramInfo.defaultType) {
|
7356
|
+
argsNeeded += 1;
|
7357
|
+
}
|
7358
|
+
paramMap.set(param.name, { argsNeeded, argsReceived: 0 });
|
7320
7359
|
}
|
7321
7360
|
});
|
7322
7361
|
let positionalOnlyLimitIndex = paramDetails.positionOnlyParamCount;
|
@@ -8369,11 +8408,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8369
8408
|
if (paramSpec) {
|
8370
8409
|
if (argParam.argument.argCategory === 1 /* ArgCategory.UnpackedList */) {
|
8371
8410
|
if ((0, parameterUtils_1.isParamSpecArgs)(paramSpec, argResult.argType)) {
|
8411
|
+
if (sawParamSpecArgs) {
|
8412
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.paramSpecArgsKwargsDuplicate().format({ type: printType(paramSpec) }), argParam.errorNode);
|
8413
|
+
}
|
8372
8414
|
sawParamSpecArgs = true;
|
8373
8415
|
}
|
8374
8416
|
}
|
8375
8417
|
if (argParam.argument.argCategory === 2 /* ArgCategory.UnpackedDictionary */) {
|
8376
8418
|
if ((0, parameterUtils_1.isParamSpecKwargs)(paramSpec, argResult.argType)) {
|
8419
|
+
if (sawParamSpecKwargs) {
|
8420
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.paramSpecArgsKwargsDuplicate().format({ type: printType(paramSpec) }), argParam.errorNode);
|
8421
|
+
}
|
8377
8422
|
sawParamSpecKwargs = true;
|
8378
8423
|
}
|
8379
8424
|
}
|
@@ -9467,7 +9512,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9467
9512
|
if ((0, typeUtils_1.isNoneInstance)(subtype)) {
|
9468
9513
|
if (objectClass && (0, types_1.isInstantiableClass)(objectClass)) {
|
9469
9514
|
// Use 'object' for 'None'.
|
9470
|
-
return handleSubtype(
|
9515
|
+
return handleSubtype(types_1.ClassType.cloneAsInstance(objectClass));
|
9471
9516
|
}
|
9472
9517
|
}
|
9473
9518
|
if ((0, typeUtils_1.isNoneTypeClass)(subtype)) {
|
@@ -12117,8 +12162,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12117
12162
|
if (protocolTypeParams) {
|
12118
12163
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.duplicateGenericAndProtocolBase(), arg.d.valueExpr);
|
12119
12164
|
}
|
12120
|
-
genericTypeParams =
|
12121
|
-
(0, typeUtils_1.addTypeVarsToListIfUnique)(genericTypeParams, (0, typeUtils_1.getTypeVarArgsRecursive)(argType));
|
12165
|
+
genericTypeParams = buildTypeParamsFromTypeArgs(argType);
|
12122
12166
|
}
|
12123
12167
|
}
|
12124
12168
|
}
|
@@ -12129,8 +12173,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12129
12173
|
if (genericTypeParams) {
|
12130
12174
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.duplicateGenericAndProtocolBase(), arg.d.valueExpr);
|
12131
12175
|
}
|
12132
|
-
protocolTypeParams =
|
12133
|
-
(0, typeUtils_1.addTypeVarsToListIfUnique)(protocolTypeParams, (0, typeUtils_1.getTypeVarArgsRecursive)(argType));
|
12176
|
+
protocolTypeParams = buildTypeParamsFromTypeArgs(argType);
|
12134
12177
|
if (node.d.typeParams && protocolTypeParams.length > 0) {
|
12135
12178
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.protocolBaseClassWithTypeArgs(), arg.d.valueExpr);
|
12136
12179
|
protocolTypeParams = [];
|
@@ -12479,6 +12522,22 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12479
12522
|
return { classType, decoratedType };
|
12480
12523
|
});
|
12481
12524
|
}
|
12525
|
+
function buildTypeParamsFromTypeArgs(classType) {
|
12526
|
+
var _a;
|
12527
|
+
const typeParams = [];
|
12528
|
+
const typeArgs = (_a = classType.priv.typeArgs) !== null && _a !== void 0 ? _a : [];
|
12529
|
+
typeArgs.forEach((typeArg, index) => {
|
12530
|
+
if ((0, types_1.isTypeVar)(typeArg)) {
|
12531
|
+
typeParams.push(typeArg);
|
12532
|
+
return;
|
12533
|
+
}
|
12534
|
+
// Synthesize a dummy type parameter.
|
12535
|
+
const typeVar = types_1.TypeVarType.createInstance(`__P${index}`);
|
12536
|
+
typeVar.shared.isSynthesized = true;
|
12537
|
+
typeParams.push(typeVar);
|
12538
|
+
});
|
12539
|
+
return typeParams;
|
12540
|
+
}
|
12482
12541
|
// Determines whether the type parameters has a default that refers to another
|
12483
12542
|
// type parameter. If so, validates that it is in the list of "live" type
|
12484
12543
|
// parameters and updates the scope of the type parameter referred to in the
|
@@ -13610,6 +13669,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13610
13669
|
}
|
13611
13670
|
writeTypeCache(node.d.suite, { type: inferredReturnType, isIncomplete }, 0 /* EvalFlags.None */);
|
13612
13671
|
}
|
13672
|
+
catch (err) {
|
13673
|
+
// Attempt to handle a stack overflow without crashing. In rare
|
13674
|
+
// cases, we can get very deep stacks when inferring return types
|
13675
|
+
// within untyped code.
|
13676
|
+
if ((err === null || err === void 0 ? void 0 : err.message) === 'Maximum call stack size exceeded') {
|
13677
|
+
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
13678
|
+
console.error(`Overflowed stack when inferring return type for function: ${node.d.name.d.value} in file ${fileInfo.fileUri.toUserVisibleString()}`);
|
13679
|
+
return;
|
13680
|
+
}
|
13681
|
+
throw err;
|
13682
|
+
}
|
13613
13683
|
finally {
|
13614
13684
|
functionRecursionMap.delete(node.id);
|
13615
13685
|
}
|
@@ -14620,7 +14690,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14620
14690
|
}
|
14621
14691
|
case 'TypedDict': {
|
14622
14692
|
if ((flags & (67108864 /* EvalFlags.NoNonTypeSpecialForms */ | 256 /* EvalFlags.TypeExpression */)) !== 0) {
|
14623
|
-
|
14693
|
+
const isInlinedTypedDict = AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.enableExperimentalFeatures &&
|
14694
|
+
!!typeArgs;
|
14695
|
+
if (!isInlinedTypedDict) {
|
14696
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.typedDictNotAllowed(), errorNode);
|
14697
|
+
}
|
14624
14698
|
}
|
14625
14699
|
isValidTypeForm = false;
|
14626
14700
|
break;
|
@@ -14736,7 +14810,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14736
14810
|
if (firstDefaultParamIndex >= 0) {
|
14737
14811
|
minTypeArgCount = firstDefaultParamIndex;
|
14738
14812
|
}
|
14739
|
-
|
14813
|
+
// Classes that accept inlined type dict type args allow only one.
|
14814
|
+
if (typeArgs.length > 0 && typeArgs[0].inlinedTypeDict) {
|
14815
|
+
if (typeArgs.length > 1) {
|
14816
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeArguments, localize_1.LocMessage.typeArgsTooMany().format({
|
14817
|
+
name: classType.priv.aliasName || classType.shared.name,
|
14818
|
+
expected: 1,
|
14819
|
+
received: typeArgCount,
|
14820
|
+
}), typeArgs[1].node);
|
14821
|
+
}
|
14822
|
+
return { type: typeArgs[0].inlinedTypeDict };
|
14823
|
+
}
|
14824
|
+
else if (typeArgCount > typeParams.length) {
|
14740
14825
|
if (!types_1.ClassType.isPartiallyEvaluated(classType) && !types_1.ClassType.isTupleClass(classType)) {
|
14741
14826
|
if (typeParams.length === 0) {
|
14742
14827
|
isValidTypeForm = false;
|
@@ -15088,15 +15173,24 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15088
15173
|
// Filter the declarations based on flow reachability.
|
15089
15174
|
const reachableDecl = symbolWithScope.symbol.getDeclarations().find((decl) => {
|
15090
15175
|
if (decl.type !== 8 /* DeclarationType.Alias */ && decl.type !== 0 /* DeclarationType.Intrinsic */) {
|
15091
|
-
//
|
15092
|
-
|
15176
|
+
// Determine if the declaration is in the same execution scope as the "usageNode" node.
|
15177
|
+
let usageScopeNode = ParseTreeUtils.getExecutionScopeNode(node);
|
15093
15178
|
const declNode = decl.type === 6 /* DeclarationType.Class */ ||
|
15094
15179
|
decl.type === 5 /* DeclarationType.Function */ ||
|
15095
15180
|
decl.type === 4 /* DeclarationType.TypeAlias */
|
15096
15181
|
? decl.node.d.name
|
15097
15182
|
: decl.node;
|
15098
|
-
const
|
15099
|
-
|
15183
|
+
const declScopeNode = ParseTreeUtils.getExecutionScopeNode(declNode);
|
15184
|
+
// If this is a type parameter scope, it will be a proxy for its
|
15185
|
+
// containing scope, so we need to use that instead.
|
15186
|
+
const usageScope = AnalyzerNodeInfo.getScope(usageScopeNode);
|
15187
|
+
if (usageScope === null || usageScope === void 0 ? void 0 : usageScope.proxy) {
|
15188
|
+
const typeParamScope = AnalyzerNodeInfo.getScope(usageScopeNode);
|
15189
|
+
if (!(typeParamScope === null || typeParamScope === void 0 ? void 0 : typeParamScope.symbolTable.has(name)) && usageScopeNode.parent) {
|
15190
|
+
usageScopeNode = ParseTreeUtils.getExecutionScopeNode(usageScopeNode.parent);
|
15191
|
+
}
|
15192
|
+
}
|
15193
|
+
if (usageScopeNode === declScopeNode) {
|
15100
15194
|
if (!isFlowPathBetweenNodes(declNode, node)) {
|
15101
15195
|
// If there was no control flow path from the usage back
|
15102
15196
|
// to the source, see if the usage node is reachable by
|
@@ -15303,7 +15397,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15303
15397
|
// dictionary expression where those keys are associated with a known TypedDict.
|
15304
15398
|
function getDeclInfoForStringNode(node) {
|
15305
15399
|
var _a;
|
15306
|
-
const
|
15400
|
+
const decls = [];
|
15401
|
+
const synthesizedTypes = [];
|
15307
15402
|
const expectedType = (_a = getExpectedType(node)) === null || _a === void 0 ? void 0 : _a.type;
|
15308
15403
|
if (expectedType) {
|
15309
15404
|
(0, typeUtils_1.doForEachSubtype)(expectedType, (subtype) => {
|
@@ -15317,13 +15412,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15317
15412
|
if (entry) {
|
15318
15413
|
const symbol = (_b = (0, typeUtils_1.lookUpObjectMember)(subtype, node.d.value)) === null || _b === void 0 ? void 0 : _b.symbol;
|
15319
15414
|
if (symbol) {
|
15320
|
-
(0, collectionUtils_1.appendArray)(
|
15415
|
+
(0, collectionUtils_1.appendArray)(decls, symbol.getDeclarations());
|
15416
|
+
const synthTypeInfo = symbol.getSynthesizedType();
|
15417
|
+
if (synthTypeInfo) {
|
15418
|
+
synthesizedTypes.push(synthTypeInfo);
|
15419
|
+
}
|
15321
15420
|
}
|
15322
15421
|
}
|
15323
15422
|
}
|
15324
15423
|
});
|
15325
15424
|
}
|
15326
|
-
return
|
15425
|
+
return decls.length === 0 ? undefined : { decls, synthesizedTypes };
|
15327
15426
|
}
|
15328
15427
|
function getAliasFromImport(node) {
|
15329
15428
|
if (node.parent &&
|
@@ -15339,7 +15438,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15339
15438
|
if (skipUnreachableCode && AnalyzerNodeInfo.isCodeUnreachable(node)) {
|
15340
15439
|
return undefined;
|
15341
15440
|
}
|
15342
|
-
const
|
15441
|
+
const decls = [];
|
15343
15442
|
const synthesizedTypes = [];
|
15344
15443
|
// If the node is part of a "from X import Y as Z" statement and the node
|
15345
15444
|
// is the "Y" (non-aliased) name, we need to look up the alias symbol
|
@@ -15356,7 +15455,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15356
15455
|
const declsForThisImport = symbolInScope.symbol.getDeclarations().filter((decl) => {
|
15357
15456
|
return decl.type === 8 /* DeclarationType.Alias */ && decl.node === node.parent;
|
15358
15457
|
});
|
15359
|
-
(0, collectionUtils_1.appendArray)(
|
15458
|
+
(0, collectionUtils_1.appendArray)(decls, (0, declarationUtils_1.getDeclarationsWithUsesLocalNameRemoved)(declsForThisImport));
|
15360
15459
|
}
|
15361
15460
|
}
|
15362
15461
|
}
|
@@ -15407,16 +15506,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15407
15506
|
// which includes every assignment of that symbol.
|
15408
15507
|
const typedDecls = symbol.getTypedDeclarations();
|
15409
15508
|
if (typedDecls.length > 0) {
|
15410
|
-
(0, collectionUtils_1.appendArray)(
|
15509
|
+
(0, collectionUtils_1.appendArray)(decls, typedDecls);
|
15411
15510
|
}
|
15412
15511
|
else {
|
15413
|
-
|
15414
|
-
|
15415
|
-
|
15416
|
-
|
15417
|
-
|
15418
|
-
(0, collectionUtils_1.appendArray)(declarations, symbol.getDeclarations());
|
15419
|
-
}
|
15512
|
+
(0, collectionUtils_1.appendArray)(decls, symbol.getDeclarations());
|
15513
|
+
}
|
15514
|
+
const synthTypeInfo = symbol.getSynthesizedType();
|
15515
|
+
if (synthTypeInfo) {
|
15516
|
+
synthesizedTypes.push(synthTypeInfo);
|
15420
15517
|
}
|
15421
15518
|
}
|
15422
15519
|
});
|
@@ -15434,7 +15531,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15434
15531
|
// Synthesize an alias declaration for this name part. The only
|
15435
15532
|
// time this case is used is for IDE services such as
|
15436
15533
|
// the find all references, hover provider and etc.
|
15437
|
-
|
15534
|
+
decls.push((0, declarationUtils_1.synthesizeAliasDeclaration)(importInfo.resolvedUris[namePartIndex]));
|
15438
15535
|
}
|
15439
15536
|
}
|
15440
15537
|
}
|
@@ -15449,14 +15546,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15449
15546
|
if ((0, types_1.isFunction)(baseType) && baseType.shared.declaration) {
|
15450
15547
|
const paramDecl = getDeclarationFromKeywordParam(baseType, paramName);
|
15451
15548
|
if (paramDecl) {
|
15452
|
-
|
15549
|
+
decls.push(paramDecl);
|
15453
15550
|
}
|
15454
15551
|
}
|
15455
15552
|
else if ((0, types_1.isOverloaded)(baseType)) {
|
15456
15553
|
types_1.OverloadedType.getOverloads(baseType).forEach((f) => {
|
15457
15554
|
const paramDecl = getDeclarationFromKeywordParam(f, paramName);
|
15458
15555
|
if (paramDecl) {
|
15459
|
-
|
15556
|
+
decls.push(paramDecl);
|
15460
15557
|
}
|
15461
15558
|
});
|
15462
15559
|
}
|
@@ -15465,14 +15562,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15465
15562
|
if (initMethodType && (0, types_1.isFunction)(initMethodType)) {
|
15466
15563
|
const paramDecl = getDeclarationFromKeywordParam(initMethodType, paramName);
|
15467
15564
|
if (paramDecl) {
|
15468
|
-
|
15565
|
+
decls.push(paramDecl);
|
15469
15566
|
}
|
15470
15567
|
else if (types_1.ClassType.isDataClass(baseType) ||
|
15471
15568
|
types_1.ClassType.isTypedDictClass(baseType) ||
|
15472
15569
|
types_1.ClassType.hasNamedTupleEntry(baseType, paramName)) {
|
15473
15570
|
const lookupResults = (0, typeUtils_1.lookUpClassMember)(baseType, paramName);
|
15474
15571
|
if (lookupResults) {
|
15475
|
-
(0, collectionUtils_1.appendArray)(
|
15572
|
+
(0, collectionUtils_1.appendArray)(decls, lookupResults.symbol.getDeclarations());
|
15573
|
+
const synthTypeInfo = lookupResults.symbol.getSynthesizedType();
|
15574
|
+
if (synthTypeInfo) {
|
15575
|
+
synthesizedTypes.push(synthTypeInfo);
|
15576
|
+
}
|
15476
15577
|
}
|
15477
15578
|
}
|
15478
15579
|
}
|
@@ -15497,10 +15598,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15497
15598
|
const allowForwardReferences = isWithinTypeAnnotation || isWithinTypeAliasStatement || fileInfo.isStubFile;
|
15498
15599
|
const symbolWithScope = lookUpSymbolRecursive(node, node.d.value, !allowForwardReferences, isWithinTypeAnnotation);
|
15499
15600
|
if (symbolWithScope) {
|
15500
|
-
(0, collectionUtils_1.appendArray)(
|
15601
|
+
(0, collectionUtils_1.appendArray)(decls, symbolWithScope.symbol.getDeclarations());
|
15602
|
+
const synthTypeInfo = symbolWithScope.symbol.getSynthesizedType();
|
15603
|
+
if (synthTypeInfo) {
|
15604
|
+
synthesizedTypes.push(synthTypeInfo);
|
15605
|
+
}
|
15501
15606
|
}
|
15502
15607
|
}
|
15503
|
-
return { decls
|
15608
|
+
return { decls, synthesizedTypes };
|
15504
15609
|
}
|
15505
15610
|
function getTypeForDeclaration(declaration) {
|
15506
15611
|
var _a, _b, _c;
|
@@ -15607,12 +15712,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15607
15712
|
((_c = declaration.node.parent) === null || _c === void 0 ? void 0 : _c.nodeType) === 35 /* ParseNodeType.MemberAccess */
|
15608
15713
|
? declaration.node.parent
|
15609
15714
|
: declaration.node;
|
15715
|
+
const allowClassVar = ParseTreeUtils.isClassVarAllowedForAssignmentTarget(declNode);
|
15716
|
+
const allowFinal = ParseTreeUtils.isFinalAllowedForAssignmentTarget(declNode);
|
15717
|
+
const allowRequired = ParseTreeUtils.isRequiredAllowedForAssignmentTarget(declNode) ||
|
15718
|
+
!!declaration.isInInlinedTypedDict;
|
15610
15719
|
declaredType = getTypeOfAnnotation(typeAnnotationNode, {
|
15611
15720
|
varTypeAnnotation: true,
|
15612
|
-
allowClassVar
|
15613
|
-
allowFinal
|
15614
|
-
allowRequired
|
15615
|
-
allowReadOnly:
|
15721
|
+
allowClassVar,
|
15722
|
+
allowFinal,
|
15723
|
+
allowRequired,
|
15724
|
+
allowReadOnly: allowRequired,
|
15616
15725
|
enforceClassTypeVarScope: declaration.isDefinedByMemberAccess,
|
15617
15726
|
});
|
15618
15727
|
}
|
@@ -16270,7 +16379,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
16270
16379
|
// provided, but type inference is still required. In such cases, the attributes
|
16271
16380
|
// are returned as flags.
|
16272
16381
|
function getDeclaredTypeOfSymbol(symbol, usageNode) {
|
16273
|
-
|
16382
|
+
var _a;
|
16383
|
+
const synthesizedType = (_a = symbol.getSynthesizedType()) === null || _a === void 0 ? void 0 : _a.type;
|
16274
16384
|
if (synthesizedType) {
|
16275
16385
|
return { type: synthesizedType };
|
16276
16386
|
}
|
@@ -16884,41 +16994,49 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
16884
16994
|
}
|
16885
16995
|
// Now handle generic base classes.
|
16886
16996
|
destType.shared.baseClasses.forEach((baseClass) => {
|
16887
|
-
if (
|
16888
|
-
!types_1.
|
16889
|
-
|
16890
|
-
|
16891
|
-
|
16892
|
-
|
16893
|
-
|
16894
|
-
|
16895
|
-
|
16896
|
-
|
16897
|
-
|
16898
|
-
|
16899
|
-
|
16900
|
-
|
16901
|
-
|
16902
|
-
|
16903
|
-
|
16904
|
-
|
16905
|
-
|
16906
|
-
|
16907
|
-
|
16908
|
-
|
16909
|
-
|
16910
|
-
|
16911
|
-
if (paramVariance === 2 /* Variance.Invariant */ || paramVariance === 3 /* Variance.Covariant */) {
|
16912
|
-
isAssignable = false;
|
16913
|
-
}
|
16914
|
-
}
|
16997
|
+
if (!isAssignable ||
|
16998
|
+
!(0, types_1.isInstantiableClass)(baseClass) ||
|
16999
|
+
types_1.ClassType.isBuiltIn(baseClass, ['object', 'Protocol', 'Generic']) ||
|
17000
|
+
baseClass.shared.typeParams.length === 0) {
|
17001
|
+
return;
|
17002
|
+
}
|
17003
|
+
const specializedDestBaseClass = (0, typeUtils_1.specializeForBaseClass)(destType, baseClass);
|
17004
|
+
const specializedSrcBaseClass = (0, typeUtils_1.specializeForBaseClass)(srcType, baseClass);
|
17005
|
+
if (!ignoreBaseClassVariance) {
|
17006
|
+
specializedDestBaseClass.shared.typeParams.forEach((param, index) => {
|
17007
|
+
if ((0, types_1.isParamSpec)(param) || (0, types_1.isTypeVarTuple)(param) || param.shared.isSynthesized) {
|
17008
|
+
return;
|
17009
|
+
}
|
17010
|
+
if (!specializedSrcBaseClass.priv.typeArgs ||
|
17011
|
+
index >= specializedSrcBaseClass.priv.typeArgs.length ||
|
17012
|
+
!specializedDestBaseClass.priv.typeArgs ||
|
17013
|
+
index >= specializedDestBaseClass.priv.typeArgs.length) {
|
17014
|
+
return;
|
17015
|
+
}
|
17016
|
+
const paramVariance = param.shared.declaredVariance;
|
17017
|
+
if ((0, types_1.isTypeVar)(specializedSrcBaseClass.priv.typeArgs[index])) {
|
17018
|
+
if (paramVariance === 2 /* Variance.Invariant */ || paramVariance === 4 /* Variance.Contravariant */) {
|
17019
|
+
isAssignable = false;
|
17020
|
+
return;
|
16915
17021
|
}
|
16916
|
-
}
|
16917
|
-
|
16918
|
-
|
16919
|
-
|
16920
|
-
|
16921
|
-
|
17022
|
+
}
|
17023
|
+
if ((0, types_1.isTypeVar)(specializedDestBaseClass.priv.typeArgs[index])) {
|
17024
|
+
if (paramVariance === 2 /* Variance.Invariant */ || paramVariance === 3 /* Variance.Covariant */) {
|
17025
|
+
isAssignable = false;
|
17026
|
+
return;
|
17027
|
+
}
|
17028
|
+
}
|
17029
|
+
});
|
17030
|
+
}
|
17031
|
+
if (!isAssignable) {
|
17032
|
+
return;
|
17033
|
+
}
|
17034
|
+
// Handle tuples specially since their type arguments are variadic.
|
17035
|
+
if (types_1.ClassType.isTupleClass(specializedDestBaseClass)) {
|
17036
|
+
return;
|
17037
|
+
}
|
17038
|
+
if (!assignClassToSelf(specializedDestBaseClass, specializedSrcBaseClass, assumedVariance, ignoreBaseClassVariance, recursionCount)) {
|
17039
|
+
isAssignable = false;
|
16922
17040
|
}
|
16923
17041
|
});
|
16924
17042
|
return isAssignable;
|
@@ -17430,7 +17548,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17430
17548
|
// the metaclass of the instantiable dest type.
|
17431
17549
|
const destMetaclass = destType.shared.effectiveMetaclass;
|
17432
17550
|
if (destMetaclass && (0, types_1.isInstantiableClass)(destMetaclass)) {
|
17433
|
-
if (assignClass(types_1.ClassType.
|
17551
|
+
if (assignClass(destMetaclass, types_1.ClassType.cloneAsInstantiable(expandedSrcType), diag, constraints, flags, recursionCount,
|
17434
17552
|
/* reportErrorsUsingObjType */ false)) {
|
17435
17553
|
return true;
|
17436
17554
|
}
|
@@ -19114,6 +19232,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
19114
19232
|
var _a, _b;
|
19115
19233
|
const baseParamDetails = (0, parameterUtils_1.getParamListDetails)(baseMethod);
|
19116
19234
|
const overrideParamDetails = (0, parameterUtils_1.getParamListDetails)(overrideMethod);
|
19235
|
+
const constraints = new constraintTracker_1.ConstraintTracker();
|
19117
19236
|
let canOverride = true;
|
19118
19237
|
if (!types_1.FunctionType.isGradualCallableForm(baseMethod) && !types_1.FunctionType.isGradualCallableForm(overrideMethod)) {
|
19119
19238
|
// Verify that we're not overriding a static, class or instance method with
|
@@ -19146,8 +19265,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
19146
19265
|
else {
|
19147
19266
|
const overrideArgsType = overrideParamDetails.params[overrideParamDetails.argsIndex].type;
|
19148
19267
|
for (let i = overrideParamDetails.positionParamCount; i < baseParamDetails.positionParamCount; i++) {
|
19149
|
-
if (!assignType(overrideArgsType, baseParamDetails.params[i].type, diag === null || diag === void 0 ? void 0 : diag.createAddendum(),
|
19150
|
-
/* constraints */ undefined, 0 /* AssignTypeFlags.Default */)) {
|
19268
|
+
if (!assignType(overrideArgsType, baseParamDetails.params[i].type, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), constraints, 2 /* AssignTypeFlags.Contravariant */)) {
|
19151
19269
|
localize_1.LocAddendum.overrideParamType().format({
|
19152
19270
|
index: i + 1,
|
19153
19271
|
baseType: printType(baseParamDetails.params[i].type),
|
@@ -19236,8 +19354,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
19236
19354
|
const overrideIsSynthesizedTypeVar = (0, types_1.isTypeVar)(overrideParamType) && overrideParamType.shared.isSynthesized;
|
19237
19355
|
if (!exemptSelfClsParam || (!baseIsSynthesizedTypeVar && !overrideIsSynthesizedTypeVar)) {
|
19238
19356
|
if (baseParam.category !== overrideParam.category ||
|
19239
|
-
!assignType(overrideParamType, baseParamType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(),
|
19240
|
-
/* constraints */ undefined, 0 /* AssignTypeFlags.Default */)) {
|
19357
|
+
!assignType(overrideParamType, baseParamType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), constraints, 2 /* AssignTypeFlags.Contravariant */)) {
|
19241
19358
|
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideParamType().format({
|
19242
19359
|
index: i + 1,
|
19243
19360
|
baseType: printType(baseParamType),
|
@@ -19279,8 +19396,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
19279
19396
|
else {
|
19280
19397
|
const overrideParamType = overrideParamDetails.params[overrideParamDetails.argsIndex].type;
|
19281
19398
|
const baseParamType = baseParamDetails.params[baseParamDetails.argsIndex].type;
|
19282
|
-
if (!assignType(overrideParamType, baseParamType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(),
|
19283
|
-
/* constraints */ undefined, 0 /* AssignTypeFlags.Default */)) {
|
19399
|
+
if (!assignType(overrideParamType, baseParamType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), constraints, 2 /* AssignTypeFlags.Contravariant */)) {
|
19284
19400
|
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideParamKeywordType().format({
|
19285
19401
|
name: (_b = overrideParamDetails.params[overrideParamDetails.argsIndex].param.name) !== null && _b !== void 0 ? _b : '?',
|
19286
19402
|
baseType: printType(baseParamType),
|
@@ -19307,8 +19423,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
19307
19423
|
if (!targetParamType) {
|
19308
19424
|
targetParamType = overrideParamDetails.params[overrideParamDetails.kwargsIndex].type;
|
19309
19425
|
}
|
19310
|
-
if (!assignType(targetParamType, paramInfo.type, diag === null || diag === void 0 ? void 0 : diag.createAddendum(),
|
19311
|
-
/* constraints */ undefined, 0 /* AssignTypeFlags.Default */)) {
|
19426
|
+
if (!assignType(targetParamType, paramInfo.type, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), constraints, 2 /* AssignTypeFlags.Contravariant */)) {
|
19312
19427
|
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideParamKeywordType().format({
|
19313
19428
|
name: (_b = paramInfo.param.name) !== null && _b !== void 0 ? _b : '?',
|
19314
19429
|
baseType: printType(paramInfo.type),
|
@@ -19366,8 +19481,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
19366
19481
|
// Now check the return type.
|
19367
19482
|
const baseReturnType = getEffectiveReturnType(baseMethod);
|
19368
19483
|
const overrideReturnType = getEffectiveReturnType(overrideMethod);
|
19369
|
-
if (!assignType(baseReturnType, overrideReturnType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(),
|
19370
|
-
/* constraints */ undefined, 0 /* AssignTypeFlags.Default */)) {
|
19484
|
+
if (!assignType(baseReturnType, overrideReturnType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), constraints, 0 /* AssignTypeFlags.Default */)) {
|
19371
19485
|
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideReturnType().format({
|
19372
19486
|
baseType: printType(baseReturnType),
|
19373
19487
|
overrideType: printType(overrideReturnType),
|