@zzzen/pyright-internal 1.2.0-dev.20231001 → 1.2.0-dev.20231015
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 +82 -41
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.js +11 -4
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +208 -151
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/decorators.d.ts +6 -1
- package/dist/analyzer/decorators.js +34 -25
- package/dist/analyzer/decorators.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.d.ts +2 -1
- package/dist/analyzer/parseTreeUtils.js +21 -2
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/program.js +7 -1
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/properties.d.ts +2 -2
- package/dist/analyzer/properties.js +8 -2
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/protocols.js +102 -149
- 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/service.js +13 -13
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceFile.d.ts +3 -2
- package/dist/analyzer/sourceFile.js +21 -7
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/sourceFileInfo.d.ts +4 -4
- package/dist/analyzer/sourceFileInfo.js +2 -0
- package/dist/analyzer/sourceFileInfo.js.map +1 -1
- package/dist/analyzer/staticExpressions.js +2 -1
- package/dist/analyzer/staticExpressions.js.map +1 -1
- package/dist/analyzer/typeEvaluator.d.ts +2 -1
- package/dist/analyzer/typeEvaluator.js +171 -244
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +10 -2
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.d.ts +1 -1
- package/dist/analyzer/typeGuards.js +127 -55
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +4 -1
- package/dist/analyzer/typeUtils.js +82 -8
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typeVarContext.d.ts +4 -1
- package/dist/analyzer/typeVarContext.js +7 -2
- package/dist/analyzer/typeVarContext.js.map +1 -1
- package/dist/analyzer/types.d.ts +5 -2
- package/dist/analyzer/types.js +25 -14
- package/dist/analyzer/types.js.map +1 -1
- package/dist/backgroundThreadBase.js +5 -1
- package/dist/backgroundThreadBase.js.map +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
- package/dist/common/configOptions.d.ts +2 -1
- package/dist/common/configOptions.js +9 -5
- package/dist/common/configOptions.js.map +1 -1
- package/dist/common/extensibility.d.ts +19 -8
- package/dist/common/extensibility.js +6 -7
- package/dist/common/extensibility.js.map +1 -1
- package/dist/common/fileSystem.d.ts +9 -4
- package/dist/common/fileSystem.js +8 -1
- package/dist/common/fileSystem.js.map +1 -1
- package/dist/common/pathUtils.d.ts +5 -4
- package/dist/common/pathUtils.js +13 -7
- package/dist/common/pathUtils.js.map +1 -1
- package/dist/common/pythonVersion.d.ts +1 -1
- package/dist/common/pythonVersion.js +1 -1
- package/dist/common/realFileSystem.d.ts +7 -1
- package/dist/common/realFileSystem.js +33 -37
- 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 +5 -3
- package/dist/common/serviceProviderExtensions.js +6 -1
- package/dist/common/serviceProviderExtensions.js.map +1 -1
- package/dist/languageServerBase.d.ts +6 -2
- package/dist/languageServerBase.js +31 -4
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/autoImporter.d.ts +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/completionProvider.d.ts +2 -2
- package/dist/languageService/completionProvider.js +20 -23
- package/dist/languageService/completionProvider.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/navigationUtils.d.ts +1 -1
- package/dist/languageService/navigationUtils.js +2 -2
- package/dist/languageService/navigationUtils.js.map +1 -1
- package/dist/languageService/referencesProvider.d.ts +15 -8
- package/dist/languageService/referencesProvider.js +41 -20
- 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 +5 -0
- package/dist/localization/package.nls.de.json +5 -0
- package/dist/localization/package.nls.en-us.json +7 -0
- package/dist/localization/package.nls.es.json +5 -0
- package/dist/localization/package.nls.fr.json +5 -0
- package/dist/localization/package.nls.it.json +5 -0
- package/dist/localization/package.nls.ja.json +5 -0
- package/dist/localization/package.nls.ko.json +5 -0
- package/dist/localization/package.nls.pl.json +5 -0
- package/dist/localization/package.nls.pt-br.json +5 -0
- package/dist/localization/package.nls.qps-ploc.json +5 -0
- package/dist/localization/package.nls.ru.json +5 -0
- package/dist/localization/package.nls.tr.json +5 -0
- package/dist/localization/package.nls.zh-cn.json +5 -0
- package/dist/localization/package.nls.zh-tw.json +5 -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/pyright.js +2 -1
- package/dist/pyright.js.map +1 -1
- package/dist/pyrightFileSystem.d.ts +0 -1
- package/dist/pyrightFileSystem.js +0 -3
- package/dist/pyrightFileSystem.js.map +1 -1
- package/dist/readonlyAugmentedFileSystem.d.ts +1 -4
- package/dist/readonlyAugmentedFileSystem.js +0 -10
- package/dist/readonlyAugmentedFileSystem.js.map +1 -1
- package/dist/server.js +2 -1
- package/dist/server.js.map +1 -1
- package/dist/tests/checker.test.js +8 -0
- package/dist/tests/checker.test.js.map +1 -1
- package/dist/tests/config.test.js +5 -3
- package/dist/tests/config.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/fourslash/completions.indexer.keys.getitem.fourslash.js +56 -10
- package/dist/tests/fourslash/completions.indexer.keys.getitem.fourslash.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.d.ts +5 -2
- package/dist/tests/harness/fourslash/testState.js +13 -14
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/harness/vfs/filesystem.d.ts +2 -2
- package/dist/tests/importResolver.test.js +0 -9
- package/dist/tests/importResolver.test.js.map +1 -1
- package/dist/tests/pathUtils.test.js +2 -2
- package/dist/tests/pathUtils.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 +5 -1
- package/dist/tests/typeEvaluator1.test.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +13 -5
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +12 -4
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +17 -9
- 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,15 +1279,18 @@ 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
|
-
if (memberInfo) {
|
1287
|
+
if (memberInfo && !memberInfo.isSetTypeError) {
|
1284
1288
|
return {
|
1285
1289
|
type: memberInfo.type,
|
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;
|
@@ -1332,11 +1337,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1332
1337
|
/* isAccessedThroughObject */ true, memberName, usage, metaclassDiag, memberAccessFlags, classType);
|
1333
1338
|
}
|
1334
1339
|
}
|
1335
|
-
if (memberInfo) {
|
1340
|
+
if (memberInfo && !memberInfo.isSetTypeError) {
|
1336
1341
|
return {
|
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;
|
@@ -3892,6 +3902,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3892
3902
|
return undefined;
|
3893
3903
|
}
|
3894
3904
|
type = descriptorResult.type;
|
3905
|
+
let isSetTypeError = false;
|
3895
3906
|
if (usage.method === 'set' && usage.setType) {
|
3896
3907
|
// Verify that the assigned type is compatible.
|
3897
3908
|
if (!assignType(type, usage.setType.type, diag === null || diag === void 0 ? void 0 : diag.createAddendum())) {
|
@@ -3902,7 +3913,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3902
3913
|
classType: printObjectTypeForClass(classType),
|
3903
3914
|
}));
|
3904
3915
|
}
|
3905
|
-
|
3916
|
+
isSetTypeError = true;
|
3906
3917
|
}
|
3907
3918
|
if ((0, types_1.isInstantiableClass)(memberInfo.classType) &&
|
3908
3919
|
types_1.ClassType.isFrozenDataClass(memberInfo.classType) &&
|
@@ -3910,17 +3921,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3910
3921
|
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.dataClassFrozen().format({
|
3911
3922
|
name: printType(types_1.ClassType.cloneAsInstance(memberInfo.classType)),
|
3912
3923
|
}));
|
3913
|
-
|
3924
|
+
isSetTypeError = true;
|
3914
3925
|
}
|
3915
3926
|
}
|
3916
3927
|
return {
|
3917
3928
|
symbol: memberInfo.symbol,
|
3918
3929
|
type,
|
3919
3930
|
isTypeIncomplete,
|
3931
|
+
isSetTypeError,
|
3920
3932
|
isClassMember: !memberInfo.isInstanceMember,
|
3921
3933
|
isClassVar: memberInfo.isClassVar,
|
3922
3934
|
classType: memberInfo.classType,
|
3923
3935
|
isAsymmetricAccessor: descriptorResult.isAsymmetricAccessor,
|
3936
|
+
memberAccessDeprecationInfo: descriptorResult === null || descriptorResult === void 0 ? void 0 : descriptorResult.memberAccessDeprecationInfo,
|
3924
3937
|
};
|
3925
3938
|
}
|
3926
3939
|
// No attribute of that name was found. If this is a member access
|
@@ -3934,6 +3947,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3934
3947
|
symbol: undefined,
|
3935
3948
|
type: generalAttrType.type,
|
3936
3949
|
isTypeIncomplete: false,
|
3950
|
+
isSetTypeError: false,
|
3937
3951
|
isClassMember: false,
|
3938
3952
|
isClassVar: false,
|
3939
3953
|
isAsymmetricAccessor: generalAttrType.isAsymmetricAccessor,
|
@@ -3950,6 +3964,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3950
3964
|
const treatConstructorAsClassMember = (flags & 32 /* TreatConstructorAsClassMethod */) !== 0;
|
3951
3965
|
let isTypeValid = true;
|
3952
3966
|
let isAsymmetricAccessor = false;
|
3967
|
+
let memberAccessDeprecationInfo;
|
3953
3968
|
type = (0, typeUtils_1.mapSubtypes)(type, (subtype) => {
|
3954
3969
|
var _a, _b, _c;
|
3955
3970
|
const concreteSubtype = makeTopLevelTypeVarsConcrete(subtype);
|
@@ -4107,6 +4122,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4107
4122
|
}
|
4108
4123
|
const callResult = validateCallArguments(errorNode, argList, { type: boundMethodType }, typeVarContext,
|
4109
4124
|
/* skipUnknownArgCheck */ true);
|
4125
|
+
if (callResult.overloadsUsedForCall &&
|
4126
|
+
callResult.overloadsUsedForCall.length >= 1) {
|
4127
|
+
const overloadUsed = callResult.overloadsUsedForCall[0];
|
4128
|
+
if (overloadUsed.details.deprecatedMessage) {
|
4129
|
+
memberAccessDeprecationInfo = {
|
4130
|
+
deprecationMessage: overloadUsed.details.deprecatedMessage,
|
4131
|
+
accessType: lookupClass && types_1.ClassType.isPropertyClass(lookupClass)
|
4132
|
+
? 'property'
|
4133
|
+
: 'descriptor',
|
4134
|
+
accessMethod: usage.method,
|
4135
|
+
};
|
4136
|
+
}
|
4137
|
+
}
|
4110
4138
|
if (callResult.argumentErrors) {
|
4111
4139
|
if (usage.method === 'set') {
|
4112
4140
|
if (usage.setType &&
|
@@ -4252,7 +4280,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4252
4280
|
if (!isTypeValid) {
|
4253
4281
|
return undefined;
|
4254
4282
|
}
|
4255
|
-
return { type, isAsymmetricAccessor };
|
4283
|
+
return { type, isAsymmetricAccessor, memberAccessDeprecationInfo };
|
4256
4284
|
}
|
4257
4285
|
function isAsymmetricDescriptorClass(classType) {
|
4258
4286
|
var _a;
|
@@ -5767,7 +5795,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5767
5795
|
if (node.arguments.length > 2) {
|
5768
5796
|
addError(localize_1.Localizer.Diagnostic.superCallArgCount(), node.arguments[2]);
|
5769
5797
|
}
|
5770
|
-
const enclosingFunction = ParseTreeUtils.
|
5798
|
+
const enclosingFunction = ParseTreeUtils.getEnclosingFunctionEvaluationScope(node);
|
5771
5799
|
const enclosingClass = enclosingFunction
|
5772
5800
|
? ParseTreeUtils.getEnclosingClass(enclosingFunction, /* stopAtFunction */ true)
|
5773
5801
|
: undefined;
|
@@ -6172,17 +6200,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6172
6200
|
// intended behavior according to PEP 484.
|
6173
6201
|
const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, { type: overload, isIncomplete: typeResult.isIncomplete }, overloadIndex);
|
6174
6202
|
if (!matchResults.argumentErrors) {
|
6175
|
-
// If there is an expected return type, see if it's potentially compatible
|
6176
|
-
// with this overload's return type. If not, we'll de-emphasize this overload.
|
6177
|
-
if (inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType) {
|
6178
|
-
const returnType = getFunctionEffectiveReturnType(matchResults.overload);
|
6179
|
-
if (!assignType((0, typeUtils_1.replaceTypeVarsWithAny)(inferenceContext.expectedType), (0, typeUtils_1.replaceTypeVarsWithAny)(returnType),
|
6180
|
-
/* diag */ undefined,
|
6181
|
-
/* destTypeVarContext */ undefined,
|
6182
|
-
/* srcTypeVarContext */ undefined, 8 /* SkipSolveTypeVars */)) {
|
6183
|
-
matchResults.relevance += -0.5;
|
6184
|
-
}
|
6185
|
-
}
|
6186
6203
|
filteredMatchResults.push(matchResults);
|
6187
6204
|
}
|
6188
6205
|
overloadIndex++;
|
@@ -6214,7 +6231,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6214
6231
|
}
|
6215
6232
|
// Create a helper function that evaluates the overload that best
|
6216
6233
|
// matches the arg/param lists.
|
6217
|
-
function evaluateUsingBestMatchingOverload(skipUnknownArgCheck) {
|
6234
|
+
function evaluateUsingBestMatchingOverload(skipUnknownArgCheck, emitNoOverloadFoundError) {
|
6218
6235
|
// Find the match with the smallest argument match score. If there
|
6219
6236
|
// are more than one with the same score, use the one with the
|
6220
6237
|
// largest index. Later overloads tend to be more general.
|
@@ -6224,6 +6241,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6224
6241
|
}
|
6225
6242
|
return current.argumentMatchScore < previous.argumentMatchScore ? current : previous;
|
6226
6243
|
});
|
6244
|
+
// If there is more than one filtered match, report that no match
|
6245
|
+
// was possible and emit a diagnostic that provides the most likely.
|
6246
|
+
if (emitNoOverloadFoundError) {
|
6247
|
+
const functionName = bestMatch.overload.details.name || '<anonymous function>';
|
6248
|
+
const diagnostic = addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.noOverload().format({ name: functionName }), errorNode);
|
6249
|
+
const overrideDecl = bestMatch.overload.details.declaration;
|
6250
|
+
if (diagnostic && overrideDecl) {
|
6251
|
+
diagnostic.addRelatedInfo(localize_1.Localizer.DiagnosticAddendum.overloadIndex().format({ index: bestMatch.overloadIndex + 1 }), overrideDecl.path, overrideDecl.range);
|
6252
|
+
}
|
6253
|
+
}
|
6227
6254
|
const effectiveTypeVarContext = typeVarContext !== null && typeVarContext !== void 0 ? typeVarContext : new typeVarContext_1.TypeVarContext();
|
6228
6255
|
effectiveTypeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeIds)(bestMatch.overload));
|
6229
6256
|
effectiveTypeVarContext.unlock();
|
@@ -6233,7 +6260,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6233
6260
|
// use the normal type matching mechanism because it is faster and
|
6234
6261
|
// will provide a clearer error message.
|
6235
6262
|
if (filteredMatchResults.length === 1) {
|
6236
|
-
return evaluateUsingBestMatchingOverload(
|
6263
|
+
return evaluateUsingBestMatchingOverload(
|
6264
|
+
/* skipUnknownArgCheck */ false,
|
6265
|
+
/* emitNoOverloadFoundError */ false);
|
6237
6266
|
}
|
6238
6267
|
let expandedArgTypes = [argList.map((arg) => undefined)];
|
6239
6268
|
while (true) {
|
@@ -6275,7 +6304,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6275
6304
|
// in speculative mode because it's very expensive, and we're going to
|
6276
6305
|
// suppress the diagnostic anyway.
|
6277
6306
|
if (!isDiagnosticSuppressedForNode(errorNode) && !isTypeIncomplete) {
|
6278
|
-
const result = evaluateUsingBestMatchingOverload(
|
6307
|
+
const result = evaluateUsingBestMatchingOverload(
|
6308
|
+
/* skipUnknownArgCheck */ true,
|
6309
|
+
/* emitNoOverloadFoundError */ true);
|
6279
6310
|
// Replace the result with an unknown type since we don't know
|
6280
6311
|
// what overload should have been used.
|
6281
6312
|
result.returnType = types_1.UnknownType.create();
|
@@ -7846,7 +7877,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7846
7877
|
let paramSpecTypeVarContext = [];
|
7847
7878
|
// Handle the assignment of additional arguments that map to a param spec.
|
7848
7879
|
if (matchResults.paramSpecArgList && matchResults.paramSpecTarget) {
|
7849
|
-
const paramSpecArgResult = validateFunctionArgumentsForParamSpec(errorNode, matchResults.paramSpecArgList, matchResults.paramSpecTarget, typeVarContext,
|
7880
|
+
const paramSpecArgResult = validateFunctionArgumentsForParamSpec(errorNode, matchResults.paramSpecArgList, matchResults.paramSpecTarget, typeVarContext, signatureTracker);
|
7850
7881
|
if (paramSpecArgResult.argumentErrors) {
|
7851
7882
|
argumentErrors = true;
|
7852
7883
|
argumentMatchScore += 1;
|
@@ -8054,18 +8085,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8054
8085
|
}
|
8055
8086
|
// Determines whether the specified argument list satisfies the function
|
8056
8087
|
// signature bound to the specified ParamSpec. Return value indicates success.
|
8057
|
-
function validateFunctionArgumentsForParamSpec(errorNode, argList, paramSpec, destTypeVarContext,
|
8088
|
+
function validateFunctionArgumentsForParamSpec(errorNode, argList, paramSpec, destTypeVarContext, signatureTracker) {
|
8058
8089
|
const signatureContexts = destTypeVarContext.getSignatureContexts();
|
8059
8090
|
// Handle the common case where there is only one signature context.
|
8060
8091
|
if (signatureContexts.length === 1) {
|
8061
|
-
return validateFunctionArgumentsForParamSpecSignature(errorNode, argList, paramSpec, signatureContexts[0],
|
8092
|
+
return validateFunctionArgumentsForParamSpecSignature(errorNode, argList, paramSpec, signatureContexts[0], signatureTracker);
|
8062
8093
|
}
|
8063
8094
|
const filteredSignatureContexts = [];
|
8064
8095
|
const typeVarContexts = [];
|
8065
8096
|
signatureContexts.forEach((context) => {
|
8066
8097
|
// Use speculative mode to avoid emitting errors or caching types.
|
8067
8098
|
useSpeculativeMode(errorNode, () => {
|
8068
|
-
const paramSpecArgResult = validateFunctionArgumentsForParamSpecSignature(errorNode, argList, paramSpec, context,
|
8099
|
+
const paramSpecArgResult = validateFunctionArgumentsForParamSpecSignature(errorNode, argList, paramSpec, context, signatureTracker);
|
8069
8100
|
if (!paramSpecArgResult.argumentErrors) {
|
8070
8101
|
filteredSignatureContexts.push(context);
|
8071
8102
|
}
|
@@ -8077,163 +8108,30 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8077
8108
|
destTypeVarContext.copySignatureContexts(filteredSignatureContexts);
|
8078
8109
|
}
|
8079
8110
|
// 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],
|
8111
|
+
const paramSpecArgResult = validateFunctionArgumentsForParamSpecSignature(errorNode, argList, paramSpec, filteredSignatureContexts.length > 0 ? filteredSignatureContexts[0] : signatureContexts[0], signatureTracker);
|
8081
8112
|
return { argumentErrors: paramSpecArgResult.argumentErrors, typeVarContexts };
|
8082
8113
|
}
|
8083
|
-
function validateFunctionArgumentsForParamSpecSignature(errorNode, argList, paramSpec, typeVarContext,
|
8114
|
+
function validateFunctionArgumentsForParamSpecSignature(errorNode, argList, paramSpec, typeVarContext, signatureTracker) {
|
8084
8115
|
var _a;
|
8085
8116
|
const paramSpecType = typeVarContext.getParamSpecType(paramSpec);
|
8086
8117
|
if (!paramSpecType) {
|
8087
8118
|
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
8119
|
return { argumentErrors: true, typeVarContexts: [undefined] };
|
8089
8120
|
}
|
8090
|
-
const
|
8121
|
+
const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, { type: paramSpecType }, 0);
|
8091
8122
|
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
|
-
}
|
8123
|
+
if (matchResults.argumentErrors) {
|
8124
|
+
// Evaluate types of all args. This will ensure that referenced symbols are
|
8125
|
+
// not reported as unaccessed.
|
8126
|
+
argList.forEach((arg) => {
|
8127
|
+
if (arg.valueExpression && !isSpeculativeModeInUse(arg.valueExpression)) {
|
8128
|
+
getTypeOfExpression(arg.valueExpression);
|
8208
8129
|
}
|
8209
8130
|
});
|
8131
|
+
return { argumentErrors: true, typeVarContexts: [srcTypeVarContext] };
|
8210
8132
|
}
|
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
|
-
};
|
8133
|
+
const result = validateFunctionArgumentTypes(errorNode, matchResults, srcTypeVarContext, signatureTracker);
|
8134
|
+
return { argumentErrors: !!result.argumentErrors, typeVarContexts: [srcTypeVarContext] };
|
8237
8135
|
}
|
8238
8136
|
function validateArgType(argParam, typeVarContext, signatureTracker, typeResult, options) {
|
8239
8137
|
var _a;
|
@@ -9184,20 +9082,28 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9184
9082
|
}
|
9185
9083
|
return undefined;
|
9186
9084
|
}
|
9187
|
-
|
9188
|
-
|
9189
|
-
|
9190
|
-
|
9191
|
-
|
9192
|
-
if (!(0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, builtInDict, inferenceContext.expectedType, dictTypeVarContext, ParseTreeUtils.getTypeVarScopesForNode(node), node.start)) {
|
9193
|
-
return undefined;
|
9085
|
+
let expectedKeyType;
|
9086
|
+
let expectedValueType;
|
9087
|
+
if ((0, types_1.isAnyOrUnknown)(inferenceContext.expectedType)) {
|
9088
|
+
expectedKeyType = inferenceContext.expectedType;
|
9089
|
+
expectedValueType = inferenceContext.expectedType;
|
9194
9090
|
}
|
9195
|
-
|
9196
|
-
|
9197
|
-
|
9091
|
+
else {
|
9092
|
+
const builtInDict = getBuiltInObject(node, 'dict');
|
9093
|
+
if (!(0, types_1.isClassInstance)(builtInDict)) {
|
9094
|
+
return undefined;
|
9095
|
+
}
|
9096
|
+
const dictTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(builtInDict));
|
9097
|
+
if (!(0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, builtInDict, inferenceContext.expectedType, dictTypeVarContext, ParseTreeUtils.getTypeVarScopesForNode(node), node.start)) {
|
9098
|
+
return undefined;
|
9099
|
+
}
|
9100
|
+
const specializedDict = (0, typeUtils_1.applySolvedTypeVars)(types_1.ClassType.cloneAsInstantiable(builtInDict), dictTypeVarContext);
|
9101
|
+
if (!specializedDict.typeArguments || specializedDict.typeArguments.length !== 2) {
|
9102
|
+
return undefined;
|
9103
|
+
}
|
9104
|
+
expectedKeyType = specializedDict.typeArguments[0];
|
9105
|
+
expectedValueType = specializedDict.typeArguments[1];
|
9198
9106
|
}
|
9199
|
-
const expectedKeyType = specializedDict.typeArguments[0];
|
9200
|
-
const expectedValueType = specializedDict.typeArguments[1];
|
9201
9107
|
// Dict and MutableMapping types have invariant value types, so they
|
9202
9108
|
// cannot be narrowed further. Other super-types like Mapping, Collection,
|
9203
9109
|
// and Iterable use covariant value types, so they can be narrowed.
|
@@ -9372,9 +9278,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9372
9278
|
}
|
9373
9279
|
else if (mappingType && (0, types_1.isInstantiableClass)(mappingType)) {
|
9374
9280
|
const mappingTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(mappingType));
|
9375
|
-
|
9376
|
-
mappingType = types_1.ClassType.cloneForSpecialization(mappingType, mappingType.details.typeParameters,
|
9377
|
-
/* isTypeArgumentExplicit */ true);
|
9281
|
+
mappingType = (0, typeUtils_1.selfSpecializeClass)(mappingType);
|
9378
9282
|
if (assignType(types_1.ClassType.cloneAsInstance(mappingType), unexpandedType,
|
9379
9283
|
/* diag */ undefined, mappingTypeVarContext,
|
9380
9284
|
/* srcTypeVarContext */ undefined, 128 /* RetainLiteralsForTypeVar */)) {
|
@@ -9475,22 +9379,28 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9475
9379
|
let isIncomplete = false;
|
9476
9380
|
let typeErrors = false;
|
9477
9381
|
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;
|
9382
|
+
let expectedEntryType;
|
9383
|
+
if ((0, types_1.isAnyOrUnknown)(inferenceContext.expectedType)) {
|
9384
|
+
expectedEntryType = inferenceContext.expectedType;
|
9488
9385
|
}
|
9489
|
-
|
9490
|
-
|
9491
|
-
|
9386
|
+
else {
|
9387
|
+
if (!(0, types_1.isClassInstance)(inferenceContext.expectedType)) {
|
9388
|
+
return undefined;
|
9389
|
+
}
|
9390
|
+
const builtInListOrSet = getBuiltInObject(node, builtInClassName);
|
9391
|
+
if (!(0, types_1.isClassInstance)(builtInListOrSet)) {
|
9392
|
+
return undefined;
|
9393
|
+
}
|
9394
|
+
const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(builtInListOrSet));
|
9395
|
+
if (!(0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, builtInListOrSet, inferenceContext.expectedType, typeVarContext, ParseTreeUtils.getTypeVarScopesForNode(node), node.start)) {
|
9396
|
+
return undefined;
|
9397
|
+
}
|
9398
|
+
const specializedListOrSet = (0, typeUtils_1.applySolvedTypeVars)(types_1.ClassType.cloneAsInstantiable(builtInListOrSet), typeVarContext);
|
9399
|
+
if (!specializedListOrSet.typeArguments || specializedListOrSet.typeArguments.length !== 1) {
|
9400
|
+
return undefined;
|
9401
|
+
}
|
9402
|
+
expectedEntryType = specializedListOrSet.typeArguments[0];
|
9492
9403
|
}
|
9493
|
-
const expectedEntryType = specializedListOrSet.typeArguments[0];
|
9494
9404
|
const entryTypes = [];
|
9495
9405
|
const expectedTypeDiagAddendum = new diagnostic_1.DiagnosticAddendum();
|
9496
9406
|
node.entries.forEach((entry) => {
|
@@ -10046,6 +9956,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10046
9956
|
functionType.details.declaredReturnType = types_1.UnknownType.create();
|
10047
9957
|
functionType.details.typeVarScopeId = ParseTreeUtils.getScopeIdForNode(errorNode);
|
10048
9958
|
if (typeArgs && typeArgs.length > 0) {
|
9959
|
+
functionType.isCallableWithTypeArgs = true;
|
10049
9960
|
if (typeArgs[0].typeList) {
|
10050
9961
|
const typeList = typeArgs[0].typeList;
|
10051
9962
|
let sawUnpacked = false;
|
@@ -10356,12 +10267,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10356
10267
|
}
|
10357
10268
|
const enclosingFunction = ParseTreeUtils.getEnclosingFunction(errorNode);
|
10358
10269
|
if (enclosingFunction) {
|
10359
|
-
const
|
10270
|
+
const functionInfo = (0, decorators_1.getFunctionInfoFromDecorators)(evaluatorInterface, enclosingFunction,
|
10360
10271
|
/* isInClass */ true);
|
10361
10272
|
const isInnerFunction = !!ParseTreeUtils.getEnclosingFunction(enclosingFunction);
|
10362
10273
|
if (!isInnerFunction) {
|
10363
10274
|
// Check for static methods.
|
10364
|
-
if (
|
10275
|
+
if (functionInfo.flags & 4 /* StaticMethod */) {
|
10365
10276
|
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.selfTypeContext(), errorNode);
|
10366
10277
|
return types_1.UnknownType.create();
|
10367
10278
|
}
|
@@ -10902,7 +10813,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10902
10813
|
const nameNode = node.leftExpression;
|
10903
10814
|
const assignedName = nameNode.value;
|
10904
10815
|
if (assignedName === 'Any') {
|
10905
|
-
return types_1.AnyType.
|
10816
|
+
return types_1.AnyType.createSpecialForm();
|
10906
10817
|
}
|
10907
10818
|
const specialTypes = new Map([
|
10908
10819
|
['overload', { alias: '', module: 'builtins' }],
|
@@ -11270,6 +11181,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11270
11181
|
if ((0, types_1.isUnion)(argType)) {
|
11271
11182
|
argType = (0, types_1.removeUnbound)(argType);
|
11272
11183
|
}
|
11184
|
+
// Any is allowed as a base class. Remove its "special form" flag to avoid
|
11185
|
+
// false positive errors.
|
11186
|
+
if ((0, types_1.isAny)(argType) && types_1.TypeBase.isSpecialForm(argType)) {
|
11187
|
+
argType = types_1.AnyType.create();
|
11188
|
+
}
|
11273
11189
|
if (!(0, types_1.isAnyOrUnknown)(argType) && !(0, types_1.isUnbound)(argType)) {
|
11274
11190
|
if ((0, typeUtils_1.isMetaclassInstance)(argType)) {
|
11275
11191
|
(0, debug_1.assert)((0, types_1.isClassInstance)(argType));
|
@@ -12057,6 +11973,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12057
11973
|
}
|
12058
11974
|
// See if there are any overloads provided by previous function declarations.
|
12059
11975
|
if ((0, types_1.isFunction)(decoratedType)) {
|
11976
|
+
decoratedType.details.deprecatedMessage = functionType.details.deprecatedMessage;
|
12060
11977
|
if (types_1.FunctionType.isOverloaded(decoratedType)) {
|
12061
11978
|
// Mark all the parameters as accessed.
|
12062
11979
|
node.parameters.forEach((param) => {
|
@@ -12090,7 +12007,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12090
12007
|
if (containingClassNode) {
|
12091
12008
|
containingClassType = (_a = getTypeOfClass(containingClassNode)) === null || _a === void 0 ? void 0 : _a.classType;
|
12092
12009
|
}
|
12093
|
-
|
12010
|
+
const functionInfo = (0, decorators_1.getFunctionInfoFromDecorators)(evaluatorInterface, node, !!containingClassNode);
|
12011
|
+
let functionFlags = functionInfo.flags;
|
12094
12012
|
if (functionDecl === null || functionDecl === void 0 ? void 0 : functionDecl.isGenerator) {
|
12095
12013
|
functionFlags |= 16 /* Generator */;
|
12096
12014
|
}
|
@@ -12105,6 +12023,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12105
12023
|
}
|
12106
12024
|
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
12025
|
functionType.details.typeVarScopeId = ParseTreeUtils.getScopeIdForNode(node);
|
12026
|
+
functionType.details.deprecatedMessage = functionInfo.deprecationMessage;
|
12108
12027
|
if (node.name.value === '__init__' || node.name.value === '__new__') {
|
12109
12028
|
if (containingClassNode) {
|
12110
12029
|
functionType.details.constructorTypeVarScopeId = ParseTreeUtils.getScopeIdForNode(containingClassNode);
|
@@ -13535,7 +13454,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13535
13454
|
// See if the function is a method in a child class. We may be able to
|
13536
13455
|
// infer the type of the parameter from a method of the same name in
|
13537
13456
|
// a parent class if it has an annotated type.
|
13538
|
-
const functionFlags = (0, decorators_1.
|
13457
|
+
const functionFlags = (0, decorators_1.getFunctionInfoFromDecorators)(evaluatorInterface, functionNode,
|
13458
|
+
/* isInClass */ true).flags;
|
13539
13459
|
const inferredParamType = inferParameterType(functionNode, functionFlags, paramIndex, classInfo === null || classInfo === void 0 ? void 0 : classInfo.classType);
|
13540
13460
|
writeTypeCache(node.name, { type: transformVariadicParamType(node, node.category, inferredParamType !== null && inferredParamType !== void 0 ? inferredParamType : types_1.UnknownType.create()) }, 0 /* None */);
|
13541
13461
|
}
|
@@ -15570,6 +15490,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15570
15490
|
};
|
15571
15491
|
}
|
15572
15492
|
}
|
15493
|
+
else if ((0, types_1.isAnyOrUnknown)(member.classType)) {
|
15494
|
+
return {
|
15495
|
+
type: member.classType,
|
15496
|
+
isIncomplete: false,
|
15497
|
+
};
|
15498
|
+
}
|
15573
15499
|
return undefined;
|
15574
15500
|
}
|
15575
15501
|
function assignClass(destType, srcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount, reportErrorsUsingObjType) {
|
@@ -16242,7 +16168,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16242
16168
|
if ((0, types_1.isAnyOrUnknown)(destType)) {
|
16243
16169
|
return true;
|
16244
16170
|
}
|
16245
|
-
if ((0, types_1.isAnyOrUnknown)(srcType)) {
|
16171
|
+
if ((0, types_1.isAnyOrUnknown)(srcType) && !types_1.TypeBase.isSpecialForm(srcType)) {
|
16246
16172
|
const targetTypeVarContext = (flags & 2 /* ReverseTypeVarMatching */) === 0 ? destTypeVarContext : srcTypeVarContext;
|
16247
16173
|
if (targetTypeVarContext) {
|
16248
16174
|
// If it's an ellipsis type, convert it to a regular "Any"
|
@@ -16468,7 +16394,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16468
16394
|
}
|
16469
16395
|
}
|
16470
16396
|
}
|
16471
|
-
else if ((0, types_1.isAnyOrUnknown)(concreteSrcType)) {
|
16397
|
+
else if ((0, types_1.isAnyOrUnknown)(concreteSrcType) && !types_1.TypeBase.isSpecialForm(concreteSrcType)) {
|
16472
16398
|
return (flags & 16 /* OverloadOverlapCheck */) === 0;
|
16473
16399
|
}
|
16474
16400
|
else if ((0, types_1.isUnion)(concreteSrcType)) {
|
@@ -17454,7 +17380,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17454
17380
|
category: p.category,
|
17455
17381
|
name: p.name,
|
17456
17382
|
isNameSynthesized: p.isNameSynthesized,
|
17457
|
-
hasDefault:
|
17383
|
+
hasDefault: p.hasDefault,
|
17384
|
+
hasDeclaredType: p.hasDeclaredType,
|
17458
17385
|
defaultValueExpression: p.defaultValueExpression,
|
17459
17386
|
type: types_1.FunctionType.getEffectiveParameterType(effectiveSrcType, index),
|
17460
17387
|
});
|
@@ -18146,7 +18073,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18146
18073
|
let isAbstract;
|
18147
18074
|
const decl = (0, symbolUtils_1.getLastTypedDeclaredForSymbol)(symbol);
|
18148
18075
|
if (decl && decl.type === 5 /* Function */) {
|
18149
|
-
const functionFlags = (0, decorators_1.
|
18076
|
+
const functionFlags = (0, decorators_1.getFunctionInfoFromDecorators)(evaluatorInterface, decl.node, true).flags;
|
18150
18077
|
isAbstract = !!(functionFlags & 8 /* AbstractMethod */);
|
18151
18078
|
}
|
18152
18079
|
else {
|