@zzzen/pyright-internal 1.2.0-dev.20231001 → 1.2.0-dev.20231008
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyzer/checker.d.ts +3 -1
- package/dist/analyzer/checker.js +55 -17
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.js +10 -3
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/decorators.d.ts +6 -1
- package/dist/analyzer/decorators.js +31 -24
- package/dist/analyzer/decorators.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.d.ts +1 -0
- package/dist/analyzer/parseTreeUtils.js +21 -2
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/properties.js +4 -0
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/protocols.js +7 -1
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/scopeUtils.js +3 -2
- package/dist/analyzer/scopeUtils.js.map +1 -1
- package/dist/analyzer/typeEvaluator.d.ts +2 -1
- package/dist/analyzer/typeEvaluator.js +147 -222
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +7 -0
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.d.ts +1 -1
- package/dist/analyzer/typeGuards.js +55 -43
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typeUtils.js +1 -1
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/types.d.ts +1 -0
- package/dist/analyzer/types.js +3 -0
- package/dist/analyzer/types.js.map +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
- package/dist/common/extensibility.d.ts +19 -6
- package/dist/common/extensibility.js +6 -7
- package/dist/common/extensibility.js.map +1 -1
- package/dist/common/pythonVersion.d.ts +1 -1
- package/dist/common/pythonVersion.js +1 -1
- package/dist/common/realFileSystem.js +9 -16
- package/dist/common/realFileSystem.js.map +1 -1
- package/dist/common/serviceProvider.d.ts +1 -1
- package/dist/common/serviceProvider.js.map +1 -1
- package/dist/common/serviceProviderExtensions.d.ts +3 -2
- package/dist/common/serviceProviderExtensions.js +2 -1
- package/dist/common/serviceProviderExtensions.js.map +1 -1
- package/dist/languageServerBase.d.ts +2 -0
- package/dist/languageServerBase.js +28 -1
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/callHierarchyProvider.d.ts +0 -1
- package/dist/languageService/callHierarchyProvider.js +33 -16
- package/dist/languageService/callHierarchyProvider.js.map +1 -1
- package/dist/languageService/definitionProvider.js +4 -5
- package/dist/languageService/definitionProvider.js.map +1 -1
- package/dist/languageService/documentHighlightProvider.js +5 -2
- package/dist/languageService/documentHighlightProvider.js.map +1 -1
- package/dist/languageService/documentSymbolCollector.d.ts +32 -23
- package/dist/languageService/documentSymbolCollector.js +170 -267
- package/dist/languageService/documentSymbolCollector.js.map +1 -1
- package/dist/languageService/hoverProvider.js +1 -5
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/referencesProvider.d.ts +6 -6
- package/dist/languageService/referencesProvider.js +23 -8
- package/dist/languageService/referencesProvider.js.map +1 -1
- package/dist/languageService/renameProvider.js +3 -3
- package/dist/languageService/renameProvider.js.map +1 -1
- package/dist/localization/localize.d.ts +21 -0
- package/dist/localization/localize.js +7 -0
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +4 -0
- package/dist/localization/package.nls.de.json +4 -0
- package/dist/localization/package.nls.en-us.json +7 -0
- package/dist/localization/package.nls.es.json +4 -0
- package/dist/localization/package.nls.fr.json +4 -0
- package/dist/localization/package.nls.it.json +4 -0
- package/dist/localization/package.nls.ja.json +4 -0
- package/dist/localization/package.nls.ko.json +4 -0
- package/dist/localization/package.nls.pl.json +4 -0
- package/dist/localization/package.nls.pt-br.json +4 -0
- package/dist/localization/package.nls.qps-ploc.json +4 -0
- package/dist/localization/package.nls.ru.json +4 -0
- package/dist/localization/package.nls.tr.json +4 -0
- package/dist/localization/package.nls.zh-cn.json +4 -0
- package/dist/localization/package.nls.zh-tw.json +4 -0
- package/dist/parser/stringTokenUtils.js +9 -5
- package/dist/parser/stringTokenUtils.js.map +1 -1
- package/dist/parser/tokenizer.d.ts +1 -0
- package/dist/parser/tokenizer.js +5 -5
- package/dist/parser/tokenizer.js.map +1 -1
- package/dist/tests/checker.test.js +8 -0
- package/dist/tests/checker.test.js.map +1 -1
- package/dist/tests/documentSymbolCollector.test.js +8 -363
- package/dist/tests/documentSymbolCollector.test.js.map +1 -1
- package/dist/tests/testStateUtils.d.ts +3 -0
- package/dist/tests/testStateUtils.js +25 -1
- package/dist/tests/testStateUtils.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +1 -1
- package/dist/tests/typeEvaluator2.test.js +9 -5
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +7 -3
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +8 -8
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator5.test.js +4 -2
- package/dist/tests/typeEvaluator5.test.js.map +1 -1
- package/dist/workspaceFactory.d.ts +2 -1
- package/dist/workspaceFactory.js +3 -1
- package/dist/workspaceFactory.js.map +1 -1
- package/package.json +1 -1
- package/dist/tests/fourslash/showcallhierarchy.incomingCalls.overriddenFunction.fourslash.d.ts +0 -1
- package/dist/tests/fourslash/showcallhierarchy.incomingCalls.overriddenFunction.fourslash.js +0 -40
- package/dist/tests/fourslash/showcallhierarchy.incomingCalls.overriddenFunction.fourslash.js.map +0 -1
@@ -181,6 +181,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
181
181
|
let noneType;
|
182
182
|
let objectType;
|
183
183
|
let typeClassType;
|
184
|
+
let awaitableProtocolType;
|
184
185
|
let functionObj;
|
185
186
|
let tupleClassType;
|
186
187
|
let boolClassType;
|
@@ -464,6 +465,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
464
465
|
dictClassType = getBuiltInType(node, 'dict');
|
465
466
|
typedDictClassType = getTypingType(node, 'TypedDict');
|
466
467
|
typedDictPrivateClassType = getTypingType(node, '_TypedDict');
|
468
|
+
awaitableProtocolType = getTypingType(node, 'Awaitable');
|
467
469
|
mappingType = getTypeshedType(node, 'SupportsKeysAndGetItem');
|
468
470
|
if (!mappingType) {
|
469
471
|
// Fall back on 'Mapping' if 'SupportsKeysAndGetItem' is not available.
|
@@ -1277,7 +1279,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1277
1279
|
!types_1.ClassType.isSameGenericClass(metaclass, objectType)) {
|
1278
1280
|
memberInfo = getTypeOfClassMemberName(errorNode, metaclass,
|
1279
1281
|
/* isAccessedThroughObject */ false, memberName, usage,
|
1280
|
-
/* diag */ undefined, memberAccessFlags |
|
1282
|
+
/* diag */ undefined, memberAccessFlags |
|
1283
|
+
2 /* AccessInstanceMembersOnly */ |
|
1284
|
+
128 /* SkipAttributeAccessOverride */, types_1.ClassType.cloneAsInstantiable(objectType));
|
1281
1285
|
}
|
1282
1286
|
}
|
1283
1287
|
if (memberInfo) {
|
@@ -1286,6 +1290,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1286
1290
|
classType: memberInfo.classType,
|
1287
1291
|
isIncomplete: !!memberInfo.isTypeIncomplete,
|
1288
1292
|
isAsymmetricAccessor: memberInfo.isAsymmetricAccessor,
|
1293
|
+
memberAccessDeprecationInfo: memberInfo.memberAccessDeprecationInfo,
|
1289
1294
|
};
|
1290
1295
|
}
|
1291
1296
|
return undefined;
|
@@ -1337,6 +1342,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1337
1342
|
type: memberInfo.type,
|
1338
1343
|
isIncomplete: !!memberInfo.isTypeIncomplete,
|
1339
1344
|
isAsymmetricAccessor: memberInfo.isAsymmetricAccessor,
|
1345
|
+
memberAccessDeprecationInfo: memberInfo.memberAccessDeprecationInfo,
|
1340
1346
|
};
|
1341
1347
|
}
|
1342
1348
|
// Determine whether to use the class or metaclass diagnostic addendum.
|
@@ -1630,31 +1636,32 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1630
1636
|
// (object that provides an __await__ that returns a generator object).
|
1631
1637
|
// If errorNode is undefined, no errors are reported.
|
1632
1638
|
function getTypeOfAwaitable(type, errorNode) {
|
1639
|
+
if (!awaitableProtocolType ||
|
1640
|
+
!(0, types_1.isInstantiableClass)(awaitableProtocolType) ||
|
1641
|
+
awaitableProtocolType.details.typeParameters.length !== 1) {
|
1642
|
+
return types_1.UnknownType.create();
|
1643
|
+
}
|
1644
|
+
const awaitableProtocolObj = types_1.ClassType.cloneAsInstance(awaitableProtocolType);
|
1633
1645
|
return (0, typeUtils_1.mapSubtypes)(type, (subtype) => {
|
1634
1646
|
subtype = makeTopLevelTypeVarsConcrete(subtype);
|
1635
1647
|
if ((0, types_1.isAnyOrUnknown)(subtype)) {
|
1636
1648
|
return subtype;
|
1637
1649
|
}
|
1650
|
+
const diag = errorNode ? new diagnostic_1.DiagnosticAddendum() : undefined;
|
1638
1651
|
if ((0, types_1.isClassInstance)(subtype)) {
|
1639
|
-
const
|
1640
|
-
if (
|
1641
|
-
|
1642
|
-
|
1643
|
-
|
1644
|
-
|
1645
|
-
|
1646
|
-
if (iterReturnType) {
|
1647
|
-
const generatorReturnType = getReturnTypeFromGenerator(awaitReturnType);
|
1648
|
-
if (generatorReturnType) {
|
1649
|
-
return generatorReturnType;
|
1650
|
-
}
|
1651
|
-
}
|
1652
|
+
const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(awaitableProtocolObj));
|
1653
|
+
if (assignType(awaitableProtocolObj, subtype, diag, typeVarContext)) {
|
1654
|
+
const specializedType = (0, typeUtils_1.applySolvedTypeVars)(awaitableProtocolObj, typeVarContext);
|
1655
|
+
if ((0, types_1.isClass)(specializedType) &&
|
1656
|
+
specializedType.typeArguments &&
|
1657
|
+
specializedType.typeArguments.length > 0) {
|
1658
|
+
return specializedType.typeArguments[0];
|
1652
1659
|
}
|
1653
1660
|
}
|
1654
1661
|
}
|
1655
1662
|
if (errorNode) {
|
1656
1663
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
|
1657
|
-
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeNotAwaitable().format({ type: printType(subtype) }), errorNode);
|
1664
|
+
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeNotAwaitable().format({ type: printType(subtype) }) + (diag === null || diag === void 0 ? void 0 : diag.getString()), errorNode);
|
1658
1665
|
}
|
1659
1666
|
return types_1.UnknownType.create();
|
1660
1667
|
});
|
@@ -2169,8 +2176,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2169
2176
|
if (setTypeResult.isAsymmetricAccessor) {
|
2170
2177
|
setAsymmetricDescriptorAssignment(target);
|
2171
2178
|
}
|
2172
|
-
|
2173
|
-
|
2179
|
+
const resultToCache = {
|
2180
|
+
type,
|
2181
|
+
isIncomplete: isTypeIncomplete,
|
2182
|
+
memberAccessDeprecationInfo: setTypeResult.memberAccessDeprecationInfo,
|
2183
|
+
};
|
2184
|
+
writeTypeCache(target.memberName, resultToCache, 0 /* None */);
|
2185
|
+
writeTypeCache(target, resultToCache, 0 /* None */);
|
2174
2186
|
}
|
2175
2187
|
function assignTypeToMemberVariable(node, srcType, isTypeIncomplete, isInstanceMember, srcExprNode) {
|
2176
2188
|
var _a;
|
@@ -2780,9 +2792,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2780
2792
|
}
|
2781
2793
|
case 35 /* MemberAccess */: {
|
2782
2794
|
const baseTypeResult = getTypeOfExpression(node.leftExpression, 16777218 /* MemberAccessBaseDefaults */);
|
2783
|
-
const
|
2784
|
-
|
2785
|
-
|
2795
|
+
const delAccessResult = getTypeOfMemberAccessWithBaseType(node, baseTypeResult, { method: 'del' }, 0 /* None */);
|
2796
|
+
const resultToCache = {
|
2797
|
+
type: delAccessResult.type,
|
2798
|
+
memberAccessDeprecationInfo: delAccessResult.memberAccessDeprecationInfo,
|
2799
|
+
};
|
2800
|
+
writeTypeCache(node.memberName, resultToCache, 0 /* None */);
|
2801
|
+
writeTypeCache(node, resultToCache, 0 /* None */);
|
2786
2802
|
break;
|
2787
2803
|
}
|
2788
2804
|
case 24 /* Index */: {
|
@@ -2819,22 +2835,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2819
2835
|
fileInfo.accessedSymbolSet.add(symbol.id);
|
2820
2836
|
}
|
2821
2837
|
}
|
2822
|
-
function getReturnTypeFromGenerator(type) {
|
2823
|
-
if ((0, types_1.isAnyOrUnknown)(type)) {
|
2824
|
-
return type;
|
2825
|
-
}
|
2826
|
-
if ((0, types_1.isClassInstance)(type)) {
|
2827
|
-
// Is this a Generator? If so, return the third
|
2828
|
-
// type argument, which is the await response type.
|
2829
|
-
if (types_1.ClassType.isBuiltIn(type, 'Generator')) {
|
2830
|
-
const typeArgs = type.typeArguments;
|
2831
|
-
if (typeArgs && typeArgs.length >= 3) {
|
2832
|
-
return typeArgs[2];
|
2833
|
-
}
|
2834
|
-
}
|
2835
|
-
}
|
2836
|
-
return undefined;
|
2837
|
-
}
|
2838
2838
|
function getSpecializedReturnType(objType, memberName, argList, errorNode, bindToClass) {
|
2839
2839
|
const classMember = (0, typeUtils_1.lookUpObjectMember)(objType, memberName, 8 /* SkipInstanceVariables */);
|
2840
2840
|
if (!classMember) {
|
@@ -3457,6 +3457,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3457
3457
|
let isAsymmetricAccessor;
|
3458
3458
|
const isRequired = false;
|
3459
3459
|
const isNotRequired = false;
|
3460
|
+
let memberAccessDeprecationInfo;
|
3460
3461
|
// If the base type was incomplete and unbound, don't proceed
|
3461
3462
|
// because false positive errors will be generated.
|
3462
3463
|
if (baseTypeResult.isIncomplete && (0, types_1.isUnbound)(baseType)) {
|
@@ -3544,6 +3545,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3544
3545
|
if (typeResult === null || typeResult === void 0 ? void 0 : typeResult.isAsymmetricAccessor) {
|
3545
3546
|
isAsymmetricAccessor = true;
|
3546
3547
|
}
|
3548
|
+
if (typeResult === null || typeResult === void 0 ? void 0 : typeResult.memberAccessDeprecationInfo) {
|
3549
|
+
memberAccessDeprecationInfo = typeResult.memberAccessDeprecationInfo;
|
3550
|
+
}
|
3547
3551
|
}
|
3548
3552
|
else {
|
3549
3553
|
// Handle the special case of 'name' and 'value' members within an enum.
|
@@ -3562,6 +3566,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3562
3566
|
if (typeResult === null || typeResult === void 0 ? void 0 : typeResult.isAsymmetricAccessor) {
|
3563
3567
|
isAsymmetricAccessor = true;
|
3564
3568
|
}
|
3569
|
+
if (typeResult === null || typeResult === void 0 ? void 0 : typeResult.memberAccessDeprecationInfo) {
|
3570
|
+
memberAccessDeprecationInfo = typeResult.memberAccessDeprecationInfo;
|
3571
|
+
}
|
3565
3572
|
}
|
3566
3573
|
break;
|
3567
3574
|
}
|
@@ -3664,6 +3671,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3664
3671
|
if (typeResult.isIncomplete) {
|
3665
3672
|
isIncomplete = true;
|
3666
3673
|
}
|
3674
|
+
if (typeResult === null || typeResult === void 0 ? void 0 : typeResult.memberAccessDeprecationInfo) {
|
3675
|
+
memberAccessDeprecationInfo = typeResult.memberAccessDeprecationInfo;
|
3676
|
+
}
|
3667
3677
|
return typeResult.type;
|
3668
3678
|
}
|
3669
3679
|
});
|
@@ -3763,7 +3773,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3763
3773
|
/* ignoreEmptyContainers */ false);
|
3764
3774
|
}
|
3765
3775
|
}
|
3766
|
-
return { type, isIncomplete, isAsymmetricAccessor, isRequired, isNotRequired };
|
3776
|
+
return { type, isIncomplete, isAsymmetricAccessor, isRequired, isNotRequired, memberAccessDeprecationInfo };
|
3767
3777
|
}
|
3768
3778
|
function getTypeOfClassMemberName(errorNode, classType, isAccessedThroughObject, memberName, usage, diag, flags, bindToType) {
|
3769
3779
|
var _a, _b;
|
@@ -3921,6 +3931,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3921
3931
|
isClassVar: memberInfo.isClassVar,
|
3922
3932
|
classType: memberInfo.classType,
|
3923
3933
|
isAsymmetricAccessor: descriptorResult.isAsymmetricAccessor,
|
3934
|
+
memberAccessDeprecationInfo: descriptorResult === null || descriptorResult === void 0 ? void 0 : descriptorResult.memberAccessDeprecationInfo,
|
3924
3935
|
};
|
3925
3936
|
}
|
3926
3937
|
// No attribute of that name was found. If this is a member access
|
@@ -3950,6 +3961,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3950
3961
|
const treatConstructorAsClassMember = (flags & 32 /* TreatConstructorAsClassMethod */) !== 0;
|
3951
3962
|
let isTypeValid = true;
|
3952
3963
|
let isAsymmetricAccessor = false;
|
3964
|
+
let memberAccessDeprecationInfo;
|
3953
3965
|
type = (0, typeUtils_1.mapSubtypes)(type, (subtype) => {
|
3954
3966
|
var _a, _b, _c;
|
3955
3967
|
const concreteSubtype = makeTopLevelTypeVarsConcrete(subtype);
|
@@ -4107,6 +4119,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4107
4119
|
}
|
4108
4120
|
const callResult = validateCallArguments(errorNode, argList, { type: boundMethodType }, typeVarContext,
|
4109
4121
|
/* skipUnknownArgCheck */ true);
|
4122
|
+
if (callResult.overloadsUsedForCall &&
|
4123
|
+
callResult.overloadsUsedForCall.length >= 1) {
|
4124
|
+
const overloadUsed = callResult.overloadsUsedForCall[0];
|
4125
|
+
if (overloadUsed.details.deprecatedMessage) {
|
4126
|
+
memberAccessDeprecationInfo = {
|
4127
|
+
deprecationMessage: overloadUsed.details.deprecatedMessage,
|
4128
|
+
accessType: lookupClass && types_1.ClassType.isPropertyClass(lookupClass)
|
4129
|
+
? 'property'
|
4130
|
+
: 'descriptor',
|
4131
|
+
accessMethod: usage.method,
|
4132
|
+
};
|
4133
|
+
}
|
4134
|
+
}
|
4110
4135
|
if (callResult.argumentErrors) {
|
4111
4136
|
if (usage.method === 'set') {
|
4112
4137
|
if (usage.setType &&
|
@@ -4252,7 +4277,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4252
4277
|
if (!isTypeValid) {
|
4253
4278
|
return undefined;
|
4254
4279
|
}
|
4255
|
-
return { type, isAsymmetricAccessor };
|
4280
|
+
return { type, isAsymmetricAccessor, memberAccessDeprecationInfo };
|
4256
4281
|
}
|
4257
4282
|
function isAsymmetricDescriptorClass(classType) {
|
4258
4283
|
var _a;
|
@@ -5767,7 +5792,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5767
5792
|
if (node.arguments.length > 2) {
|
5768
5793
|
addError(localize_1.Localizer.Diagnostic.superCallArgCount(), node.arguments[2]);
|
5769
5794
|
}
|
5770
|
-
const enclosingFunction = ParseTreeUtils.
|
5795
|
+
const enclosingFunction = ParseTreeUtils.getEnclosingFunctionEvaluationScope(node);
|
5771
5796
|
const enclosingClass = enclosingFunction
|
5772
5797
|
? ParseTreeUtils.getEnclosingClass(enclosingFunction, /* stopAtFunction */ true)
|
5773
5798
|
: undefined;
|
@@ -6214,7 +6239,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6214
6239
|
}
|
6215
6240
|
// Create a helper function that evaluates the overload that best
|
6216
6241
|
// matches the arg/param lists.
|
6217
|
-
function evaluateUsingBestMatchingOverload(skipUnknownArgCheck) {
|
6242
|
+
function evaluateUsingBestMatchingOverload(skipUnknownArgCheck, emitNoOverloadFoundError) {
|
6218
6243
|
// Find the match with the smallest argument match score. If there
|
6219
6244
|
// are more than one with the same score, use the one with the
|
6220
6245
|
// largest index. Later overloads tend to be more general.
|
@@ -6224,6 +6249,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6224
6249
|
}
|
6225
6250
|
return current.argumentMatchScore < previous.argumentMatchScore ? current : previous;
|
6226
6251
|
});
|
6252
|
+
// If there is more than one filtered match, report that no match
|
6253
|
+
// was possible and emit a diagnostic that provides the most likely.
|
6254
|
+
if (emitNoOverloadFoundError) {
|
6255
|
+
const functionName = bestMatch.overload.details.name || '<anonymous function>';
|
6256
|
+
const diagnostic = addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.noOverload().format({ name: functionName }), errorNode);
|
6257
|
+
const overrideDecl = bestMatch.overload.details.declaration;
|
6258
|
+
if (diagnostic && overrideDecl) {
|
6259
|
+
diagnostic.addRelatedInfo(localize_1.Localizer.DiagnosticAddendum.overloadIndex().format({ index: bestMatch.overloadIndex + 1 }), overrideDecl.path, overrideDecl.range);
|
6260
|
+
}
|
6261
|
+
}
|
6227
6262
|
const effectiveTypeVarContext = typeVarContext !== null && typeVarContext !== void 0 ? typeVarContext : new typeVarContext_1.TypeVarContext();
|
6228
6263
|
effectiveTypeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeIds)(bestMatch.overload));
|
6229
6264
|
effectiveTypeVarContext.unlock();
|
@@ -6233,7 +6268,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6233
6268
|
// use the normal type matching mechanism because it is faster and
|
6234
6269
|
// will provide a clearer error message.
|
6235
6270
|
if (filteredMatchResults.length === 1) {
|
6236
|
-
return evaluateUsingBestMatchingOverload(
|
6271
|
+
return evaluateUsingBestMatchingOverload(
|
6272
|
+
/* skipUnknownArgCheck */ false,
|
6273
|
+
/* emitNoOverloadFoundError */ false);
|
6237
6274
|
}
|
6238
6275
|
let expandedArgTypes = [argList.map((arg) => undefined)];
|
6239
6276
|
while (true) {
|
@@ -6275,7 +6312,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6275
6312
|
// in speculative mode because it's very expensive, and we're going to
|
6276
6313
|
// suppress the diagnostic anyway.
|
6277
6314
|
if (!isDiagnosticSuppressedForNode(errorNode) && !isTypeIncomplete) {
|
6278
|
-
const result = evaluateUsingBestMatchingOverload(
|
6315
|
+
const result = evaluateUsingBestMatchingOverload(
|
6316
|
+
/* skipUnknownArgCheck */ true,
|
6317
|
+
/* emitNoOverloadFoundError */ true);
|
6279
6318
|
// Replace the result with an unknown type since we don't know
|
6280
6319
|
// what overload should have been used.
|
6281
6320
|
result.returnType = types_1.UnknownType.create();
|
@@ -7846,7 +7885,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7846
7885
|
let paramSpecTypeVarContext = [];
|
7847
7886
|
// Handle the assignment of additional arguments that map to a param spec.
|
7848
7887
|
if (matchResults.paramSpecArgList && matchResults.paramSpecTarget) {
|
7849
|
-
const paramSpecArgResult = validateFunctionArgumentsForParamSpec(errorNode, matchResults.paramSpecArgList, matchResults.paramSpecTarget, typeVarContext,
|
7888
|
+
const paramSpecArgResult = validateFunctionArgumentsForParamSpec(errorNode, matchResults.paramSpecArgList, matchResults.paramSpecTarget, typeVarContext, signatureTracker);
|
7850
7889
|
if (paramSpecArgResult.argumentErrors) {
|
7851
7890
|
argumentErrors = true;
|
7852
7891
|
argumentMatchScore += 1;
|
@@ -8054,18 +8093,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8054
8093
|
}
|
8055
8094
|
// Determines whether the specified argument list satisfies the function
|
8056
8095
|
// signature bound to the specified ParamSpec. Return value indicates success.
|
8057
|
-
function validateFunctionArgumentsForParamSpec(errorNode, argList, paramSpec, destTypeVarContext,
|
8096
|
+
function validateFunctionArgumentsForParamSpec(errorNode, argList, paramSpec, destTypeVarContext, signatureTracker) {
|
8058
8097
|
const signatureContexts = destTypeVarContext.getSignatureContexts();
|
8059
8098
|
// Handle the common case where there is only one signature context.
|
8060
8099
|
if (signatureContexts.length === 1) {
|
8061
|
-
return validateFunctionArgumentsForParamSpecSignature(errorNode, argList, paramSpec, signatureContexts[0],
|
8100
|
+
return validateFunctionArgumentsForParamSpecSignature(errorNode, argList, paramSpec, signatureContexts[0], signatureTracker);
|
8062
8101
|
}
|
8063
8102
|
const filteredSignatureContexts = [];
|
8064
8103
|
const typeVarContexts = [];
|
8065
8104
|
signatureContexts.forEach((context) => {
|
8066
8105
|
// Use speculative mode to avoid emitting errors or caching types.
|
8067
8106
|
useSpeculativeMode(errorNode, () => {
|
8068
|
-
const paramSpecArgResult = validateFunctionArgumentsForParamSpecSignature(errorNode, argList, paramSpec, context,
|
8107
|
+
const paramSpecArgResult = validateFunctionArgumentsForParamSpecSignature(errorNode, argList, paramSpec, context, signatureTracker);
|
8069
8108
|
if (!paramSpecArgResult.argumentErrors) {
|
8070
8109
|
filteredSignatureContexts.push(context);
|
8071
8110
|
}
|
@@ -8077,163 +8116,30 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8077
8116
|
destTypeVarContext.copySignatureContexts(filteredSignatureContexts);
|
8078
8117
|
}
|
8079
8118
|
// Evaluate non-speculatively to produce a final result and cache types.
|
8080
|
-
const paramSpecArgResult = validateFunctionArgumentsForParamSpecSignature(errorNode, argList, paramSpec, filteredSignatureContexts.length > 0 ? filteredSignatureContexts[0] : signatureContexts[0],
|
8119
|
+
const paramSpecArgResult = validateFunctionArgumentsForParamSpecSignature(errorNode, argList, paramSpec, filteredSignatureContexts.length > 0 ? filteredSignatureContexts[0] : signatureContexts[0], signatureTracker);
|
8081
8120
|
return { argumentErrors: paramSpecArgResult.argumentErrors, typeVarContexts };
|
8082
8121
|
}
|
8083
|
-
function validateFunctionArgumentsForParamSpecSignature(errorNode, argList, paramSpec, typeVarContext,
|
8122
|
+
function validateFunctionArgumentsForParamSpecSignature(errorNode, argList, paramSpec, typeVarContext, signatureTracker) {
|
8084
8123
|
var _a;
|
8085
8124
|
const paramSpecType = typeVarContext.getParamSpecType(paramSpec);
|
8086
8125
|
if (!paramSpecType) {
|
8087
8126
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.paramSpecNotBound().format({ type: printType(paramSpec) }), ((_a = argList[0]) === null || _a === void 0 ? void 0 : _a.valueExpression) || errorNode);
|
8088
8127
|
return { argumentErrors: true, typeVarContexts: [undefined] };
|
8089
8128
|
}
|
8090
|
-
const
|
8129
|
+
const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, { type: paramSpecType }, 0);
|
8091
8130
|
const srcTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeIds)(paramSpecType));
|
8092
|
-
|
8093
|
-
|
8094
|
-
|
8095
|
-
|
8096
|
-
|
8097
|
-
|
8098
|
-
const passCount = 2;
|
8099
|
-
for (let i = 0; i < passCount; i++) {
|
8100
|
-
// Unless we're on the last pass, use speculative mode to suppress
|
8101
|
-
// any diagnostics.
|
8102
|
-
useSpeculativeMode(i < passCount - 1 ? errorNode : undefined, () => {
|
8103
|
-
// Build a map of all named parameters.
|
8104
|
-
paramMap = new Map();
|
8105
|
-
const paramSpecParams = paramSpecType.details.parameters;
|
8106
|
-
paramSpecParams.forEach((param) => {
|
8107
|
-
if (param.name) {
|
8108
|
-
paramMap.set(param.name, param);
|
8109
|
-
}
|
8110
|
-
});
|
8111
|
-
let positionalIndex = 0;
|
8112
|
-
let positionalIndexLimit = paramSpecParams.findIndex((paramInfo) => paramInfo.category !== 0 /* Simple */);
|
8113
|
-
if (positionalIndexLimit < 0) {
|
8114
|
-
positionalIndexLimit = paramSpecParams.length;
|
8115
|
-
}
|
8116
|
-
const argsParam = paramSpecParams.find((paramInfo) => paramInfo.category === 1 /* ArgsList */);
|
8117
|
-
const kwargsParam = paramSpecParams.find((paramInfo) => paramInfo.category === 2 /* KwargsDict */);
|
8118
|
-
const signatureTracker = new typeUtils_1.UniqueSignatureTracker();
|
8119
|
-
const nestedArgList = [];
|
8120
|
-
argList.forEach((arg) => {
|
8121
|
-
var _a;
|
8122
|
-
if (arg.argumentCategory === 0 /* Simple */) {
|
8123
|
-
let paramType;
|
8124
|
-
if (arg.name) {
|
8125
|
-
const paramInfo = paramMap.get(arg.name.value);
|
8126
|
-
if (paramInfo) {
|
8127
|
-
paramType = paramInfo.type;
|
8128
|
-
paramMap.delete(arg.name.value);
|
8129
|
-
}
|
8130
|
-
else if (kwargsParam) {
|
8131
|
-
paramType = kwargsParam.type;
|
8132
|
-
}
|
8133
|
-
else {
|
8134
|
-
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.paramNameMissing().format({ name: arg.name.value }), arg.name || errorNode);
|
8135
|
-
reportedArgError = true;
|
8136
|
-
}
|
8137
|
-
}
|
8138
|
-
else {
|
8139
|
-
if (positionalIndex < positionalIndexLimit) {
|
8140
|
-
const paramInfo = paramSpecParams[positionalIndex];
|
8141
|
-
paramType = paramInfo.type;
|
8142
|
-
if (paramInfo.name) {
|
8143
|
-
paramMap.delete(paramInfo.name);
|
8144
|
-
}
|
8145
|
-
}
|
8146
|
-
else if (argsParam) {
|
8147
|
-
paramType = argsParam.type;
|
8148
|
-
}
|
8149
|
-
else if (paramSpecType.details.paramSpec) {
|
8150
|
-
nestedArgList.push(arg);
|
8151
|
-
}
|
8152
|
-
else {
|
8153
|
-
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, paramSpecParams.length === 1
|
8154
|
-
? localize_1.Localizer.Diagnostic.argPositionalExpectedOne()
|
8155
|
-
: localize_1.Localizer.Diagnostic.argPositionalExpectedCount().format({
|
8156
|
-
expected: paramSpecParams.length,
|
8157
|
-
}), (_a = arg.valueExpression) !== null && _a !== void 0 ? _a : errorNode);
|
8158
|
-
reportedArgError = true;
|
8159
|
-
}
|
8160
|
-
positionalIndex++;
|
8161
|
-
}
|
8162
|
-
if (paramType) {
|
8163
|
-
const argResult = validateArgType({
|
8164
|
-
paramCategory: 0 /* Simple */,
|
8165
|
-
paramType: (0, typeUtils_1.transformExpectedType)(paramType, liveTypeVarScopes,
|
8166
|
-
/* usageOffset */ undefined),
|
8167
|
-
requiresTypeVarMatching: false,
|
8168
|
-
argument: arg,
|
8169
|
-
errorNode: arg.valueExpression || errorNode,
|
8170
|
-
}, srcTypeVarContext, signatureTracker,
|
8171
|
-
/* functionType */ undefined, { conditionFilter });
|
8172
|
-
if (!argResult.isCompatible) {
|
8173
|
-
reportedArgError = true;
|
8174
|
-
}
|
8175
|
-
}
|
8176
|
-
}
|
8177
|
-
else if (arg.argumentCategory === 1 /* UnpackedList */) {
|
8178
|
-
sawUnpackedListArgument = true;
|
8179
|
-
// See if there is an *args parameter.
|
8180
|
-
const argsParam = paramSpecParams.find((param) => param.category === 1 /* ArgsList */ && param.name);
|
8181
|
-
if (argsParam && paramMap.has(argsParam.name)) {
|
8182
|
-
// TODO - validate args type
|
8183
|
-
paramMap.delete(argsParam.name);
|
8184
|
-
}
|
8185
|
-
}
|
8186
|
-
else {
|
8187
|
-
sawUnpackedDictArgument = true;
|
8188
|
-
(0, debug_1.assert)(arg.argumentCategory === 2 /* UnpackedDictionary */);
|
8189
|
-
// See if there is an *kwargs parameter.
|
8190
|
-
const kwargsParam = paramSpecParams.find((param) => param.category === 2 /* KwargsDict */);
|
8191
|
-
if (kwargsParam && paramMap.has(kwargsParam.name)) {
|
8192
|
-
// TODO - validate kwargs type
|
8193
|
-
paramMap.delete(kwargsParam.name);
|
8194
|
-
}
|
8195
|
-
}
|
8196
|
-
});
|
8197
|
-
// Handle recursive ParamSpecs.
|
8198
|
-
if (paramSpecType.details.paramSpec) {
|
8199
|
-
const boundTypeForParamSpec = srcTypeVarContext
|
8200
|
-
.getPrimarySignature()
|
8201
|
-
.getParamSpecType(paramSpecType.details.paramSpec);
|
8202
|
-
if (boundTypeForParamSpec) {
|
8203
|
-
const paramSpecArgResult = validateFunctionArgumentsForParamSpec(errorNode, nestedArgList, paramSpecType.details.paramSpec, srcTypeVarContext, conditionFilter);
|
8204
|
-
if (paramSpecArgResult.argumentErrors) {
|
8205
|
-
reportedArgError = true;
|
8206
|
-
}
|
8207
|
-
}
|
8131
|
+
if (matchResults.argumentErrors) {
|
8132
|
+
// Evaluate types of all args. This will ensure that referenced symbols are
|
8133
|
+
// not reported as unaccessed.
|
8134
|
+
argList.forEach((arg) => {
|
8135
|
+
if (arg.valueExpression && !isSpeculativeModeInUse(arg.valueExpression)) {
|
8136
|
+
getTypeOfExpression(arg.valueExpression);
|
8208
8137
|
}
|
8209
8138
|
});
|
8139
|
+
return { argumentErrors: true, typeVarContexts: [srcTypeVarContext] };
|
8210
8140
|
}
|
8211
|
-
|
8212
|
-
|
8213
|
-
let unassignedParams = Array.from(paramMap.keys());
|
8214
|
-
// Parameters that have defaults can be left unspecified.
|
8215
|
-
unassignedParams = unassignedParams.filter((name) => {
|
8216
|
-
const paramInfo = paramMap.get(name);
|
8217
|
-
return paramInfo.category === 0 /* Simple */ && !paramInfo.hasDefault;
|
8218
|
-
});
|
8219
|
-
if (unassignedParams.length > 0 &&
|
8220
|
-
!paramSpecType.details.paramSpec &&
|
8221
|
-
!sawUnpackedListArgument &&
|
8222
|
-
!sawUnpackedDictArgument) {
|
8223
|
-
const missingParamNames = unassignedParams.map((p) => `"${p}"`).join(', ');
|
8224
|
-
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, unassignedParams.length === 1
|
8225
|
-
? localize_1.Localizer.Diagnostic.argMissingForParam().format({ name: missingParamNames })
|
8226
|
-
: localize_1.Localizer.Diagnostic.argMissingForParams().format({ names: missingParamNames }), errorNode);
|
8227
|
-
reportedArgError = true;
|
8228
|
-
}
|
8229
|
-
}
|
8230
|
-
if (!reportedArgError) {
|
8231
|
-
(0, typeUtils_1.applySourceContextTypeVarsToSignature)(typeVarContext, srcTypeVarContext);
|
8232
|
-
}
|
8233
|
-
return {
|
8234
|
-
argumentErrors: reportedArgError,
|
8235
|
-
typeVarContexts: [reportedArgError ? srcTypeVarContext : undefined],
|
8236
|
-
};
|
8141
|
+
const result = validateFunctionArgumentTypes(errorNode, matchResults, srcTypeVarContext, signatureTracker);
|
8142
|
+
return { argumentErrors: !!result.argumentErrors, typeVarContexts: [srcTypeVarContext] };
|
8237
8143
|
}
|
8238
8144
|
function validateArgType(argParam, typeVarContext, signatureTracker, typeResult, options) {
|
8239
8145
|
var _a;
|
@@ -9184,20 +9090,28 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9184
9090
|
}
|
9185
9091
|
return undefined;
|
9186
9092
|
}
|
9187
|
-
|
9188
|
-
|
9189
|
-
|
9190
|
-
|
9191
|
-
|
9192
|
-
if (!(0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, builtInDict, inferenceContext.expectedType, dictTypeVarContext, ParseTreeUtils.getTypeVarScopesForNode(node), node.start)) {
|
9193
|
-
return undefined;
|
9093
|
+
let expectedKeyType;
|
9094
|
+
let expectedValueType;
|
9095
|
+
if ((0, types_1.isAnyOrUnknown)(inferenceContext.expectedType)) {
|
9096
|
+
expectedKeyType = inferenceContext.expectedType;
|
9097
|
+
expectedValueType = inferenceContext.expectedType;
|
9194
9098
|
}
|
9195
|
-
|
9196
|
-
|
9197
|
-
|
9099
|
+
else {
|
9100
|
+
const builtInDict = getBuiltInObject(node, 'dict');
|
9101
|
+
if (!(0, types_1.isClassInstance)(builtInDict)) {
|
9102
|
+
return undefined;
|
9103
|
+
}
|
9104
|
+
const dictTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(builtInDict));
|
9105
|
+
if (!(0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, builtInDict, inferenceContext.expectedType, dictTypeVarContext, ParseTreeUtils.getTypeVarScopesForNode(node), node.start)) {
|
9106
|
+
return undefined;
|
9107
|
+
}
|
9108
|
+
const specializedDict = (0, typeUtils_1.applySolvedTypeVars)(types_1.ClassType.cloneAsInstantiable(builtInDict), dictTypeVarContext);
|
9109
|
+
if (!specializedDict.typeArguments || specializedDict.typeArguments.length !== 2) {
|
9110
|
+
return undefined;
|
9111
|
+
}
|
9112
|
+
expectedKeyType = specializedDict.typeArguments[0];
|
9113
|
+
expectedValueType = specializedDict.typeArguments[1];
|
9198
9114
|
}
|
9199
|
-
const expectedKeyType = specializedDict.typeArguments[0];
|
9200
|
-
const expectedValueType = specializedDict.typeArguments[1];
|
9201
9115
|
// Dict and MutableMapping types have invariant value types, so they
|
9202
9116
|
// cannot be narrowed further. Other super-types like Mapping, Collection,
|
9203
9117
|
// and Iterable use covariant value types, so they can be narrowed.
|
@@ -9475,22 +9389,28 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9475
9389
|
let isIncomplete = false;
|
9476
9390
|
let typeErrors = false;
|
9477
9391
|
const verifyHashable = node.nodeType === 45 /* Set */;
|
9478
|
-
|
9479
|
-
|
9480
|
-
|
9481
|
-
const builtInListOrSet = getBuiltInObject(node, builtInClassName);
|
9482
|
-
if (!(0, types_1.isClassInstance)(builtInListOrSet)) {
|
9483
|
-
return undefined;
|
9484
|
-
}
|
9485
|
-
const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(builtInListOrSet));
|
9486
|
-
if (!(0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, builtInListOrSet, inferenceContext.expectedType, typeVarContext, ParseTreeUtils.getTypeVarScopesForNode(node), node.start)) {
|
9487
|
-
return undefined;
|
9392
|
+
let expectedEntryType;
|
9393
|
+
if ((0, types_1.isAnyOrUnknown)(inferenceContext.expectedType)) {
|
9394
|
+
expectedEntryType = inferenceContext.expectedType;
|
9488
9395
|
}
|
9489
|
-
|
9490
|
-
|
9491
|
-
|
9396
|
+
else {
|
9397
|
+
if (!(0, types_1.isClassInstance)(inferenceContext.expectedType)) {
|
9398
|
+
return undefined;
|
9399
|
+
}
|
9400
|
+
const builtInListOrSet = getBuiltInObject(node, builtInClassName);
|
9401
|
+
if (!(0, types_1.isClassInstance)(builtInListOrSet)) {
|
9402
|
+
return undefined;
|
9403
|
+
}
|
9404
|
+
const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(builtInListOrSet));
|
9405
|
+
if (!(0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, builtInListOrSet, inferenceContext.expectedType, typeVarContext, ParseTreeUtils.getTypeVarScopesForNode(node), node.start)) {
|
9406
|
+
return undefined;
|
9407
|
+
}
|
9408
|
+
const specializedListOrSet = (0, typeUtils_1.applySolvedTypeVars)(types_1.ClassType.cloneAsInstantiable(builtInListOrSet), typeVarContext);
|
9409
|
+
if (!specializedListOrSet.typeArguments || specializedListOrSet.typeArguments.length !== 1) {
|
9410
|
+
return undefined;
|
9411
|
+
}
|
9412
|
+
expectedEntryType = specializedListOrSet.typeArguments[0];
|
9492
9413
|
}
|
9493
|
-
const expectedEntryType = specializedListOrSet.typeArguments[0];
|
9494
9414
|
const entryTypes = [];
|
9495
9415
|
const expectedTypeDiagAddendum = new diagnostic_1.DiagnosticAddendum();
|
9496
9416
|
node.entries.forEach((entry) => {
|
@@ -10046,6 +9966,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10046
9966
|
functionType.details.declaredReturnType = types_1.UnknownType.create();
|
10047
9967
|
functionType.details.typeVarScopeId = ParseTreeUtils.getScopeIdForNode(errorNode);
|
10048
9968
|
if (typeArgs && typeArgs.length > 0) {
|
9969
|
+
functionType.isCallableWithTypeArgs = true;
|
10049
9970
|
if (typeArgs[0].typeList) {
|
10050
9971
|
const typeList = typeArgs[0].typeList;
|
10051
9972
|
let sawUnpacked = false;
|
@@ -10356,12 +10277,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10356
10277
|
}
|
10357
10278
|
const enclosingFunction = ParseTreeUtils.getEnclosingFunction(errorNode);
|
10358
10279
|
if (enclosingFunction) {
|
10359
|
-
const
|
10280
|
+
const functionInfo = (0, decorators_1.getFunctionInfoFromDecorators)(evaluatorInterface, enclosingFunction,
|
10360
10281
|
/* isInClass */ true);
|
10361
10282
|
const isInnerFunction = !!ParseTreeUtils.getEnclosingFunction(enclosingFunction);
|
10362
10283
|
if (!isInnerFunction) {
|
10363
10284
|
// Check for static methods.
|
10364
|
-
if (
|
10285
|
+
if (functionInfo.flags & 4 /* StaticMethod */) {
|
10365
10286
|
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.selfTypeContext(), errorNode);
|
10366
10287
|
return types_1.UnknownType.create();
|
10367
10288
|
}
|
@@ -12057,6 +11978,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12057
11978
|
}
|
12058
11979
|
// See if there are any overloads provided by previous function declarations.
|
12059
11980
|
if ((0, types_1.isFunction)(decoratedType)) {
|
11981
|
+
decoratedType.details.deprecatedMessage = functionType.details.deprecatedMessage;
|
12060
11982
|
if (types_1.FunctionType.isOverloaded(decoratedType)) {
|
12061
11983
|
// Mark all the parameters as accessed.
|
12062
11984
|
node.parameters.forEach((param) => {
|
@@ -12090,7 +12012,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12090
12012
|
if (containingClassNode) {
|
12091
12013
|
containingClassType = (_a = getTypeOfClass(containingClassNode)) === null || _a === void 0 ? void 0 : _a.classType;
|
12092
12014
|
}
|
12093
|
-
|
12015
|
+
const functionInfo = (0, decorators_1.getFunctionInfoFromDecorators)(evaluatorInterface, node, !!containingClassNode);
|
12016
|
+
let functionFlags = functionInfo.flags;
|
12094
12017
|
if (functionDecl === null || functionDecl === void 0 ? void 0 : functionDecl.isGenerator) {
|
12095
12018
|
functionFlags |= 16 /* Generator */;
|
12096
12019
|
}
|
@@ -12105,6 +12028,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12105
12028
|
}
|
12106
12029
|
const functionType = types_1.FunctionType.createInstance(node.name.value, getFunctionFullName(node, fileInfo.moduleName, node.name.value), fileInfo.moduleName, functionFlags | 131072 /* PartiallyEvaluated */, ParseTreeUtils.getDocString(node.suite.statements));
|
12107
12030
|
functionType.details.typeVarScopeId = ParseTreeUtils.getScopeIdForNode(node);
|
12031
|
+
functionType.details.deprecatedMessage = functionInfo.deprecationMessage;
|
12108
12032
|
if (node.name.value === '__init__' || node.name.value === '__new__') {
|
12109
12033
|
if (containingClassNode) {
|
12110
12034
|
functionType.details.constructorTypeVarScopeId = ParseTreeUtils.getScopeIdForNode(containingClassNode);
|
@@ -13535,7 +13459,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13535
13459
|
// See if the function is a method in a child class. We may be able to
|
13536
13460
|
// infer the type of the parameter from a method of the same name in
|
13537
13461
|
// a parent class if it has an annotated type.
|
13538
|
-
const functionFlags = (0, decorators_1.
|
13462
|
+
const functionFlags = (0, decorators_1.getFunctionInfoFromDecorators)(evaluatorInterface, functionNode,
|
13463
|
+
/* isInClass */ true).flags;
|
13539
13464
|
const inferredParamType = inferParameterType(functionNode, functionFlags, paramIndex, classInfo === null || classInfo === void 0 ? void 0 : classInfo.classType);
|
13540
13465
|
writeTypeCache(node.name, { type: transformVariadicParamType(node, node.category, inferredParamType !== null && inferredParamType !== void 0 ? inferredParamType : types_1.UnknownType.create()) }, 0 /* None */);
|
13541
13466
|
}
|
@@ -18146,7 +18071,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18146
18071
|
let isAbstract;
|
18147
18072
|
const decl = (0, symbolUtils_1.getLastTypedDeclaredForSymbol)(symbol);
|
18148
18073
|
if (decl && decl.type === 5 /* Function */) {
|
18149
|
-
const functionFlags = (0, decorators_1.
|
18074
|
+
const functionFlags = (0, decorators_1.getFunctionInfoFromDecorators)(evaluatorInterface, decl.node, true).flags;
|
18150
18075
|
isAbstract = !!(functionFlags & 8 /* AbstractMethod */);
|
18151
18076
|
}
|
18152
18077
|
else {
|