@zzzen/pyright-internal 1.2.0-dev.20230924 → 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 +59 -18
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.js +17 -3
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/decorators.d.ts +6 -1
- package/dist/analyzer/decorators.js +34 -24
- package/dist/analyzer/decorators.js.map +1 -1
- package/dist/analyzer/operations.js +4 -2
- package/dist/analyzer/operations.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/patternMatching.js +47 -16
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.d.ts +2 -3
- package/dist/analyzer/program.js +6 -6
- package/dist/analyzer/program.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/service.d.ts +4 -4
- package/dist/analyzer/service.js +4 -18
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceFile.d.ts +3 -1
- package/dist/analyzer/sourceFile.js +9 -5
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/typeEvaluator.d.ts +2 -1
- package/dist/analyzer/typeEvaluator.js +211 -233
- 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.d.ts +1 -0
- package/dist/analyzer/typeUtils.js +22 -3
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/types.d.ts +2 -1
- package/dist/analyzer/types.js +9 -3
- package/dist/analyzer/types.js.map +1 -1
- package/dist/backgroundAnalysisBase.js +0 -22
- package/dist/backgroundAnalysisBase.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 +1 -0
- package/dist/common/configOptions.js +4 -0
- package/dist/common/configOptions.js.map +1 -1
- package/dist/common/diagnosticRules.d.ts +1 -0
- package/dist/common/diagnosticRules.js +1 -0
- package/dist/common/diagnosticRules.js.map +1 -1
- package/dist/common/extensibility.d.ts +26 -28
- package/dist/common/extensibility.js +6 -97
- package/dist/common/extensibility.js.map +1 -1
- package/dist/common/pathUtils.d.ts +3 -0
- package/dist/common/pathUtils.js +13 -8
- 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.js +9 -16
- package/dist/common/realFileSystem.js.map +1 -1
- package/dist/common/serviceProvider.d.ts +22 -3
- package/dist/common/serviceProvider.js +89 -9
- package/dist/common/serviceProvider.js.map +1 -1
- package/dist/common/serviceProviderExtensions.d.ts +5 -1
- package/dist/common/serviceProviderExtensions.js +5 -2
- package/dist/common/serviceProviderExtensions.js.map +1 -1
- package/dist/languageServerBase.d.ts +2 -0
- package/dist/languageServerBase.js +28 -4
- 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.d.ts +3 -2
- package/dist/languageService/definitionProvider.js +13 -11
- 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 +171 -266
- package/dist/languageService/documentSymbolCollector.js.map +1 -1
- package/dist/languageService/hoverProvider.js +5 -9
- 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 +29 -1
- package/dist/localization/localize.js +11 -1
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +8 -1
- package/dist/localization/package.nls.de.json +8 -1
- package/dist/localization/package.nls.en-us.json +11 -1
- package/dist/localization/package.nls.es.json +8 -1
- package/dist/localization/package.nls.fr.json +8 -1
- package/dist/localization/package.nls.it.json +8 -1
- package/dist/localization/package.nls.ja.json +8 -1
- package/dist/localization/package.nls.ko.json +8 -1
- package/dist/localization/package.nls.pl.json +8 -1
- package/dist/localization/package.nls.pt-br.json +8 -1
- package/dist/localization/package.nls.qps-ploc.json +8 -1
- package/dist/localization/package.nls.ru.json +8 -1
- package/dist/localization/package.nls.tr.json +8 -1
- package/dist/localization/package.nls.zh-cn.json +8 -1
- package/dist/localization/package.nls.zh-tw.json +8 -1
- 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/importResolver.test.js +654 -481
- package/dist/tests/importResolver.test.js.map +1 -1
- package/dist/tests/pathUtils.test.js +39 -1
- package/dist/tests/pathUtils.test.js.map +1 -1
- package/dist/tests/sourceFile.test.js +2 -1
- package/dist/tests/sourceFile.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 +12 -6
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +14 -4
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +9 -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 +3 -2
- 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
@@ -103,6 +103,7 @@ const nonSubscriptableBuiltinTypes = new Map([
|
|
103
103
|
const typePromotions = new Map([
|
104
104
|
['builtins.float', ['builtins.int']],
|
105
105
|
['builtins.complex', ['builtins.float', 'builtins.int']],
|
106
|
+
['builtins.bytes', ['builtins.bytearray', 'builtins.memoryview']],
|
106
107
|
]);
|
107
108
|
// How many levels deep should we attempt to infer return
|
108
109
|
// types based on call-site argument types? The deeper we go,
|
@@ -180,6 +181,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
180
181
|
let noneType;
|
181
182
|
let objectType;
|
182
183
|
let typeClassType;
|
184
|
+
let awaitableProtocolType;
|
183
185
|
let functionObj;
|
184
186
|
let tupleClassType;
|
185
187
|
let boolClassType;
|
@@ -391,6 +393,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
391
393
|
}
|
392
394
|
}
|
393
395
|
}
|
396
|
+
if (type) {
|
397
|
+
type = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(type);
|
398
|
+
}
|
394
399
|
return type;
|
395
400
|
}
|
396
401
|
function getTypeResult(node) {
|
@@ -460,6 +465,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
460
465
|
dictClassType = getBuiltInType(node, 'dict');
|
461
466
|
typedDictClassType = getTypingType(node, 'TypedDict');
|
462
467
|
typedDictPrivateClassType = getTypingType(node, '_TypedDict');
|
468
|
+
awaitableProtocolType = getTypingType(node, 'Awaitable');
|
463
469
|
mappingType = getTypeshedType(node, 'SupportsKeysAndGetItem');
|
464
470
|
if (!mappingType) {
|
465
471
|
// Fall back on 'Mapping' if 'SupportsKeysAndGetItem' is not available.
|
@@ -658,6 +664,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
658
664
|
if (expectingInstantiable) {
|
659
665
|
validateTypeIsInstantiable(typeResult, flags, node);
|
660
666
|
}
|
667
|
+
// Should we disable type promotions for bytes?
|
668
|
+
if ((0, types_1.isInstantiableClass)(typeResult.type) &&
|
669
|
+
typeResult.type.includePromotions &&
|
670
|
+
!typeResult.type.includeSubclasses &&
|
671
|
+
types_1.ClassType.isBuiltIn(typeResult.type, 'bytes')) {
|
672
|
+
if (AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.disableBytesTypePromotions) {
|
673
|
+
typeResult = {
|
674
|
+
...typeResult,
|
675
|
+
type: types_1.ClassType.cloneRemoveTypePromotions(typeResult.type),
|
676
|
+
};
|
677
|
+
}
|
678
|
+
}
|
661
679
|
writeTypeCache(node, typeResult, flags, inferenceContext, /* allowSpeculativeCaching */ true);
|
662
680
|
// If there was an expected type, make sure that the result type is compatible.
|
663
681
|
if (inferenceContext &&
|
@@ -928,6 +946,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
928
946
|
type: getBuiltInObject(node, isBytes ? 'bytes' : 'str'),
|
929
947
|
isIncomplete,
|
930
948
|
};
|
949
|
+
if ((0, types_1.isClass)(typeResult.type) && typeResult.type.includePromotions) {
|
950
|
+
typeResult.type = types_1.ClassType.cloneRemoveTypePromotions(typeResult.type);
|
951
|
+
}
|
931
952
|
}
|
932
953
|
}
|
933
954
|
else {
|
@@ -1258,7 +1279,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1258
1279
|
!types_1.ClassType.isSameGenericClass(metaclass, objectType)) {
|
1259
1280
|
memberInfo = getTypeOfClassMemberName(errorNode, metaclass,
|
1260
1281
|
/* isAccessedThroughObject */ false, memberName, usage,
|
1261
|
-
/* diag */ undefined, memberAccessFlags |
|
1282
|
+
/* diag */ undefined, memberAccessFlags |
|
1283
|
+
2 /* AccessInstanceMembersOnly */ |
|
1284
|
+
128 /* SkipAttributeAccessOverride */, types_1.ClassType.cloneAsInstantiable(objectType));
|
1262
1285
|
}
|
1263
1286
|
}
|
1264
1287
|
if (memberInfo) {
|
@@ -1267,6 +1290,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1267
1290
|
classType: memberInfo.classType,
|
1268
1291
|
isIncomplete: !!memberInfo.isTypeIncomplete,
|
1269
1292
|
isAsymmetricAccessor: memberInfo.isAsymmetricAccessor,
|
1293
|
+
memberAccessDeprecationInfo: memberInfo.memberAccessDeprecationInfo,
|
1270
1294
|
};
|
1271
1295
|
}
|
1272
1296
|
return undefined;
|
@@ -1294,7 +1318,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1294
1318
|
!types_1.ClassType.isBuiltIn(metaclass, 'type') &&
|
1295
1319
|
!types_1.ClassType.isSameGenericClass(metaclass, classType)) {
|
1296
1320
|
const metaclassMemberInfo = getTypeOfClassMemberName(errorNode, metaclass,
|
1297
|
-
/* isAccessedThroughObject */ false, memberName, usage, metaclassDiag, memberAccessFlags
|
1321
|
+
/* isAccessedThroughObject */ false, memberName, usage, metaclassDiag, memberAccessFlags | 128 /* SkipAttributeAccessOverride */, classType);
|
1298
1322
|
if (metaclassMemberInfo && (0, typeUtils_1.isDescriptorInstance)(metaclassMemberInfo.type)) {
|
1299
1323
|
considerMetaclassOnly = true;
|
1300
1324
|
}
|
@@ -1318,6 +1342,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1318
1342
|
type: memberInfo.type,
|
1319
1343
|
isIncomplete: !!memberInfo.isTypeIncomplete,
|
1320
1344
|
isAsymmetricAccessor: memberInfo.isAsymmetricAccessor,
|
1345
|
+
memberAccessDeprecationInfo: memberInfo.memberAccessDeprecationInfo,
|
1321
1346
|
};
|
1322
1347
|
}
|
1323
1348
|
// Determine whether to use the class or metaclass diagnostic addendum.
|
@@ -1611,31 +1636,32 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1611
1636
|
// (object that provides an __await__ that returns a generator object).
|
1612
1637
|
// If errorNode is undefined, no errors are reported.
|
1613
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);
|
1614
1645
|
return (0, typeUtils_1.mapSubtypes)(type, (subtype) => {
|
1615
1646
|
subtype = makeTopLevelTypeVarsConcrete(subtype);
|
1616
1647
|
if ((0, types_1.isAnyOrUnknown)(subtype)) {
|
1617
1648
|
return subtype;
|
1618
1649
|
}
|
1650
|
+
const diag = errorNode ? new diagnostic_1.DiagnosticAddendum() : undefined;
|
1619
1651
|
if ((0, types_1.isClassInstance)(subtype)) {
|
1620
|
-
const
|
1621
|
-
if (
|
1622
|
-
|
1623
|
-
|
1624
|
-
|
1625
|
-
|
1626
|
-
|
1627
|
-
if (iterReturnType) {
|
1628
|
-
const generatorReturnType = getReturnTypeFromGenerator(awaitReturnType);
|
1629
|
-
if (generatorReturnType) {
|
1630
|
-
return generatorReturnType;
|
1631
|
-
}
|
1632
|
-
}
|
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];
|
1633
1659
|
}
|
1634
1660
|
}
|
1635
1661
|
}
|
1636
1662
|
if (errorNode) {
|
1637
1663
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
|
1638
|
-
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);
|
1639
1665
|
}
|
1640
1666
|
return types_1.UnknownType.create();
|
1641
1667
|
});
|
@@ -2150,8 +2176,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2150
2176
|
if (setTypeResult.isAsymmetricAccessor) {
|
2151
2177
|
setAsymmetricDescriptorAssignment(target);
|
2152
2178
|
}
|
2153
|
-
|
2154
|
-
|
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 */);
|
2155
2186
|
}
|
2156
2187
|
function assignTypeToMemberVariable(node, srcType, isTypeIncomplete, isInstanceMember, srcExprNode) {
|
2157
2188
|
var _a;
|
@@ -2326,20 +2357,22 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2326
2357
|
writeTypeCache(target, { type, isIncomplete: isTypeIncomplete }, 0 /* None */);
|
2327
2358
|
}
|
2328
2359
|
// If the type includes promotion types, expand these to their constituent types.
|
2329
|
-
function expandPromotionTypes(node, type) {
|
2360
|
+
function expandPromotionTypes(node, type, excludeBytes = false) {
|
2330
2361
|
return (0, typeUtils_1.mapSubtypes)(type, (subtype) => {
|
2331
2362
|
if (!(0, types_1.isClass)(subtype) || !subtype.includePromotions) {
|
2332
2363
|
return subtype;
|
2333
2364
|
}
|
2334
|
-
|
2365
|
+
if (excludeBytes && types_1.ClassType.isBuiltIn(subtype, 'bytes')) {
|
2366
|
+
return subtype;
|
2367
|
+
}
|
2368
|
+
const typesToCombine = [types_1.ClassType.cloneRemoveTypePromotions(subtype)];
|
2335
2369
|
const promotionTypeNames = typePromotions.get(subtype.details.fullName);
|
2336
2370
|
if (promotionTypeNames) {
|
2337
2371
|
for (const promotionTypeName of promotionTypeNames) {
|
2338
2372
|
const nameSplit = promotionTypeName.split('.');
|
2339
2373
|
let promotionSubtype = getBuiltInType(node, nameSplit[nameSplit.length - 1]);
|
2340
2374
|
if (promotionSubtype && (0, types_1.isInstantiableClass)(promotionSubtype)) {
|
2341
|
-
promotionSubtype = types_1.ClassType.
|
2342
|
-
/* includePromotions */ false);
|
2375
|
+
promotionSubtype = types_1.ClassType.cloneRemoveTypePromotions(promotionSubtype);
|
2343
2376
|
if ((0, types_1.isClassInstance)(subtype)) {
|
2344
2377
|
promotionSubtype = types_1.ClassType.cloneAsInstance(promotionSubtype);
|
2345
2378
|
}
|
@@ -2562,6 +2595,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2562
2595
|
inferTypeParameterVarianceForClass(type);
|
2563
2596
|
let typeWasTransformed = false;
|
2564
2597
|
const filteredTypeArgs = type.typeArguments.map((typeArg, index) => {
|
2598
|
+
if (index > type.details.typeParameters.length) {
|
2599
|
+
return typeArg;
|
2600
|
+
}
|
2565
2601
|
const variance = types_1.TypeVarType.getVariance(type.details.typeParameters[index]);
|
2566
2602
|
if (variance !== 3 /* Covariant */) {
|
2567
2603
|
return typeArg;
|
@@ -2756,9 +2792,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2756
2792
|
}
|
2757
2793
|
case 35 /* MemberAccess */: {
|
2758
2794
|
const baseTypeResult = getTypeOfExpression(node.leftExpression, 16777218 /* MemberAccessBaseDefaults */);
|
2759
|
-
const
|
2760
|
-
|
2761
|
-
|
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 */);
|
2762
2802
|
break;
|
2763
2803
|
}
|
2764
2804
|
case 24 /* Index */: {
|
@@ -2795,22 +2835,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2795
2835
|
fileInfo.accessedSymbolSet.add(symbol.id);
|
2796
2836
|
}
|
2797
2837
|
}
|
2798
|
-
function getReturnTypeFromGenerator(type) {
|
2799
|
-
if ((0, types_1.isAnyOrUnknown)(type)) {
|
2800
|
-
return type;
|
2801
|
-
}
|
2802
|
-
if ((0, types_1.isClassInstance)(type)) {
|
2803
|
-
// Is this a Generator? If so, return the third
|
2804
|
-
// type argument, which is the await response type.
|
2805
|
-
if (types_1.ClassType.isBuiltIn(type, 'Generator')) {
|
2806
|
-
const typeArgs = type.typeArguments;
|
2807
|
-
if (typeArgs && typeArgs.length >= 3) {
|
2808
|
-
return typeArgs[2];
|
2809
|
-
}
|
2810
|
-
}
|
2811
|
-
}
|
2812
|
-
return undefined;
|
2813
|
-
}
|
2814
2838
|
function getSpecializedReturnType(objType, memberName, argList, errorNode, bindToClass) {
|
2815
2839
|
const classMember = (0, typeUtils_1.lookUpObjectMember)(objType, memberName, 8 /* SkipInstanceVariables */);
|
2816
2840
|
if (!classMember) {
|
@@ -3433,6 +3457,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3433
3457
|
let isAsymmetricAccessor;
|
3434
3458
|
const isRequired = false;
|
3435
3459
|
const isNotRequired = false;
|
3460
|
+
let memberAccessDeprecationInfo;
|
3436
3461
|
// If the base type was incomplete and unbound, don't proceed
|
3437
3462
|
// because false positive errors will be generated.
|
3438
3463
|
if (baseTypeResult.isIncomplete && (0, types_1.isUnbound)(baseType)) {
|
@@ -3459,8 +3484,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3459
3484
|
if ((0, types_1.isParamSpec)(baseType) && baseType.paramSpecAccess) {
|
3460
3485
|
baseType = makeTopLevelTypeVarsConcrete(baseType);
|
3461
3486
|
}
|
3462
|
-
// Do union expansion for promotion types.
|
3463
|
-
baseType = expandPromotionTypes(node, baseType);
|
3464
3487
|
switch (baseType.category) {
|
3465
3488
|
case 2 /* Any */:
|
3466
3489
|
case 1 /* Unknown */:
|
@@ -3522,6 +3545,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3522
3545
|
if (typeResult === null || typeResult === void 0 ? void 0 : typeResult.isAsymmetricAccessor) {
|
3523
3546
|
isAsymmetricAccessor = true;
|
3524
3547
|
}
|
3548
|
+
if (typeResult === null || typeResult === void 0 ? void 0 : typeResult.memberAccessDeprecationInfo) {
|
3549
|
+
memberAccessDeprecationInfo = typeResult.memberAccessDeprecationInfo;
|
3550
|
+
}
|
3525
3551
|
}
|
3526
3552
|
else {
|
3527
3553
|
// Handle the special case of 'name' and 'value' members within an enum.
|
@@ -3540,6 +3566,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3540
3566
|
if (typeResult === null || typeResult === void 0 ? void 0 : typeResult.isAsymmetricAccessor) {
|
3541
3567
|
isAsymmetricAccessor = true;
|
3542
3568
|
}
|
3569
|
+
if (typeResult === null || typeResult === void 0 ? void 0 : typeResult.memberAccessDeprecationInfo) {
|
3570
|
+
memberAccessDeprecationInfo = typeResult.memberAccessDeprecationInfo;
|
3571
|
+
}
|
3543
3572
|
}
|
3544
3573
|
break;
|
3545
3574
|
}
|
@@ -3642,6 +3671,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3642
3671
|
if (typeResult.isIncomplete) {
|
3643
3672
|
isIncomplete = true;
|
3644
3673
|
}
|
3674
|
+
if (typeResult === null || typeResult === void 0 ? void 0 : typeResult.memberAccessDeprecationInfo) {
|
3675
|
+
memberAccessDeprecationInfo = typeResult.memberAccessDeprecationInfo;
|
3676
|
+
}
|
3645
3677
|
return typeResult.type;
|
3646
3678
|
}
|
3647
3679
|
});
|
@@ -3741,7 +3773,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3741
3773
|
/* ignoreEmptyContainers */ false);
|
3742
3774
|
}
|
3743
3775
|
}
|
3744
|
-
return { type, isIncomplete, isAsymmetricAccessor, isRequired, isNotRequired };
|
3776
|
+
return { type, isIncomplete, isAsymmetricAccessor, isRequired, isNotRequired, memberAccessDeprecationInfo };
|
3745
3777
|
}
|
3746
3778
|
function getTypeOfClassMemberName(errorNode, classType, isAccessedThroughObject, memberName, usage, diag, flags, bindToType) {
|
3747
3779
|
var _a, _b;
|
@@ -3899,6 +3931,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3899
3931
|
isClassVar: memberInfo.isClassVar,
|
3900
3932
|
classType: memberInfo.classType,
|
3901
3933
|
isAsymmetricAccessor: descriptorResult.isAsymmetricAccessor,
|
3934
|
+
memberAccessDeprecationInfo: descriptorResult === null || descriptorResult === void 0 ? void 0 : descriptorResult.memberAccessDeprecationInfo,
|
3902
3935
|
};
|
3903
3936
|
}
|
3904
3937
|
// No attribute of that name was found. If this is a member access
|
@@ -3928,6 +3961,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3928
3961
|
const treatConstructorAsClassMember = (flags & 32 /* TreatConstructorAsClassMethod */) !== 0;
|
3929
3962
|
let isTypeValid = true;
|
3930
3963
|
let isAsymmetricAccessor = false;
|
3964
|
+
let memberAccessDeprecationInfo;
|
3931
3965
|
type = (0, typeUtils_1.mapSubtypes)(type, (subtype) => {
|
3932
3966
|
var _a, _b, _c;
|
3933
3967
|
const concreteSubtype = makeTopLevelTypeVarsConcrete(subtype);
|
@@ -4085,6 +4119,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4085
4119
|
}
|
4086
4120
|
const callResult = validateCallArguments(errorNode, argList, { type: boundMethodType }, typeVarContext,
|
4087
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
|
+
}
|
4088
4135
|
if (callResult.argumentErrors) {
|
4089
4136
|
if (usage.method === 'set') {
|
4090
4137
|
if (usage.setType &&
|
@@ -4230,7 +4277,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4230
4277
|
if (!isTypeValid) {
|
4231
4278
|
return undefined;
|
4232
4279
|
}
|
4233
|
-
return { type, isAsymmetricAccessor };
|
4280
|
+
return { type, isAsymmetricAccessor, memberAccessDeprecationInfo };
|
4234
4281
|
}
|
4235
4282
|
function isAsymmetricDescriptorClass(classType) {
|
4236
4283
|
var _a;
|
@@ -5745,7 +5792,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5745
5792
|
if (node.arguments.length > 2) {
|
5746
5793
|
addError(localize_1.Localizer.Diagnostic.superCallArgCount(), node.arguments[2]);
|
5747
5794
|
}
|
5748
|
-
const enclosingFunction = ParseTreeUtils.
|
5795
|
+
const enclosingFunction = ParseTreeUtils.getEnclosingFunctionEvaluationScope(node);
|
5749
5796
|
const enclosingClass = enclosingFunction
|
5750
5797
|
? ParseTreeUtils.getEnclosingClass(enclosingFunction, /* stopAtFunction */ true)
|
5751
5798
|
: undefined;
|
@@ -6150,9 +6197,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6150
6197
|
// intended behavior according to PEP 484.
|
6151
6198
|
const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, { type: overload, isIncomplete: typeResult.isIncomplete }, overloadIndex);
|
6152
6199
|
if (!matchResults.argumentErrors) {
|
6200
|
+
// If there is an expected return type, see if it's potentially compatible
|
6201
|
+
// with this overload's return type. If not, we'll de-emphasize this overload.
|
6153
6202
|
if (inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType) {
|
6154
6203
|
const returnType = getFunctionEffectiveReturnType(matchResults.overload);
|
6155
|
-
if (!assignType(inferenceContext.expectedType, returnType,
|
6204
|
+
if (!assignType((0, typeUtils_1.replaceTypeVarsWithAny)(inferenceContext.expectedType), (0, typeUtils_1.replaceTypeVarsWithAny)(returnType),
|
6156
6205
|
/* diag */ undefined,
|
6157
6206
|
/* destTypeVarContext */ undefined,
|
6158
6207
|
/* srcTypeVarContext */ undefined, 8 /* SkipSolveTypeVars */)) {
|
@@ -6190,7 +6239,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6190
6239
|
}
|
6191
6240
|
// Create a helper function that evaluates the overload that best
|
6192
6241
|
// matches the arg/param lists.
|
6193
|
-
function evaluateUsingBestMatchingOverload(skipUnknownArgCheck) {
|
6242
|
+
function evaluateUsingBestMatchingOverload(skipUnknownArgCheck, emitNoOverloadFoundError) {
|
6194
6243
|
// Find the match with the smallest argument match score. If there
|
6195
6244
|
// are more than one with the same score, use the one with the
|
6196
6245
|
// largest index. Later overloads tend to be more general.
|
@@ -6200,6 +6249,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6200
6249
|
}
|
6201
6250
|
return current.argumentMatchScore < previous.argumentMatchScore ? current : previous;
|
6202
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
|
+
}
|
6203
6262
|
const effectiveTypeVarContext = typeVarContext !== null && typeVarContext !== void 0 ? typeVarContext : new typeVarContext_1.TypeVarContext();
|
6204
6263
|
effectiveTypeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeIds)(bestMatch.overload));
|
6205
6264
|
effectiveTypeVarContext.unlock();
|
@@ -6209,7 +6268,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6209
6268
|
// use the normal type matching mechanism because it is faster and
|
6210
6269
|
// will provide a clearer error message.
|
6211
6270
|
if (filteredMatchResults.length === 1) {
|
6212
|
-
return evaluateUsingBestMatchingOverload(
|
6271
|
+
return evaluateUsingBestMatchingOverload(
|
6272
|
+
/* skipUnknownArgCheck */ false,
|
6273
|
+
/* emitNoOverloadFoundError */ false);
|
6213
6274
|
}
|
6214
6275
|
let expandedArgTypes = [argList.map((arg) => undefined)];
|
6215
6276
|
while (true) {
|
@@ -6251,7 +6312,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6251
6312
|
// in speculative mode because it's very expensive, and we're going to
|
6252
6313
|
// suppress the diagnostic anyway.
|
6253
6314
|
if (!isDiagnosticSuppressedForNode(errorNode) && !isTypeIncomplete) {
|
6254
|
-
const result = evaluateUsingBestMatchingOverload(
|
6315
|
+
const result = evaluateUsingBestMatchingOverload(
|
6316
|
+
/* skipUnknownArgCheck */ true,
|
6317
|
+
/* emitNoOverloadFoundError */ true);
|
6255
6318
|
// Replace the result with an unknown type since we don't know
|
6256
6319
|
// what overload should have been used.
|
6257
6320
|
result.returnType = types_1.UnknownType.create();
|
@@ -7822,7 +7885,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7822
7885
|
let paramSpecTypeVarContext = [];
|
7823
7886
|
// Handle the assignment of additional arguments that map to a param spec.
|
7824
7887
|
if (matchResults.paramSpecArgList && matchResults.paramSpecTarget) {
|
7825
|
-
const paramSpecArgResult = validateFunctionArgumentsForParamSpec(errorNode, matchResults.paramSpecArgList, matchResults.paramSpecTarget, typeVarContext,
|
7888
|
+
const paramSpecArgResult = validateFunctionArgumentsForParamSpec(errorNode, matchResults.paramSpecArgList, matchResults.paramSpecTarget, typeVarContext, signatureTracker);
|
7826
7889
|
if (paramSpecArgResult.argumentErrors) {
|
7827
7890
|
argumentErrors = true;
|
7828
7891
|
argumentMatchScore += 1;
|
@@ -8030,18 +8093,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8030
8093
|
}
|
8031
8094
|
// Determines whether the specified argument list satisfies the function
|
8032
8095
|
// signature bound to the specified ParamSpec. Return value indicates success.
|
8033
|
-
function validateFunctionArgumentsForParamSpec(errorNode, argList, paramSpec, destTypeVarContext,
|
8096
|
+
function validateFunctionArgumentsForParamSpec(errorNode, argList, paramSpec, destTypeVarContext, signatureTracker) {
|
8034
8097
|
const signatureContexts = destTypeVarContext.getSignatureContexts();
|
8035
8098
|
// Handle the common case where there is only one signature context.
|
8036
8099
|
if (signatureContexts.length === 1) {
|
8037
|
-
return validateFunctionArgumentsForParamSpecSignature(errorNode, argList, paramSpec, signatureContexts[0],
|
8100
|
+
return validateFunctionArgumentsForParamSpecSignature(errorNode, argList, paramSpec, signatureContexts[0], signatureTracker);
|
8038
8101
|
}
|
8039
8102
|
const filteredSignatureContexts = [];
|
8040
8103
|
const typeVarContexts = [];
|
8041
8104
|
signatureContexts.forEach((context) => {
|
8042
8105
|
// Use speculative mode to avoid emitting errors or caching types.
|
8043
8106
|
useSpeculativeMode(errorNode, () => {
|
8044
|
-
const paramSpecArgResult = validateFunctionArgumentsForParamSpecSignature(errorNode, argList, paramSpec, context,
|
8107
|
+
const paramSpecArgResult = validateFunctionArgumentsForParamSpecSignature(errorNode, argList, paramSpec, context, signatureTracker);
|
8045
8108
|
if (!paramSpecArgResult.argumentErrors) {
|
8046
8109
|
filteredSignatureContexts.push(context);
|
8047
8110
|
}
|
@@ -8053,163 +8116,30 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8053
8116
|
destTypeVarContext.copySignatureContexts(filteredSignatureContexts);
|
8054
8117
|
}
|
8055
8118
|
// Evaluate non-speculatively to produce a final result and cache types.
|
8056
|
-
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);
|
8057
8120
|
return { argumentErrors: paramSpecArgResult.argumentErrors, typeVarContexts };
|
8058
8121
|
}
|
8059
|
-
function validateFunctionArgumentsForParamSpecSignature(errorNode, argList, paramSpec, typeVarContext,
|
8122
|
+
function validateFunctionArgumentsForParamSpecSignature(errorNode, argList, paramSpec, typeVarContext, signatureTracker) {
|
8060
8123
|
var _a;
|
8061
8124
|
const paramSpecType = typeVarContext.getParamSpecType(paramSpec);
|
8062
8125
|
if (!paramSpecType) {
|
8063
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);
|
8064
8127
|
return { argumentErrors: true, typeVarContexts: [undefined] };
|
8065
8128
|
}
|
8066
|
-
const
|
8129
|
+
const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, { type: paramSpecType }, 0);
|
8067
8130
|
const srcTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeIds)(paramSpecType));
|
8068
|
-
|
8069
|
-
|
8070
|
-
|
8071
|
-
|
8072
|
-
|
8073
|
-
|
8074
|
-
const passCount = 2;
|
8075
|
-
for (let i = 0; i < passCount; i++) {
|
8076
|
-
// Unless we're on the last pass, use speculative mode to suppress
|
8077
|
-
// any diagnostics.
|
8078
|
-
useSpeculativeMode(i < passCount - 1 ? errorNode : undefined, () => {
|
8079
|
-
// Build a map of all named parameters.
|
8080
|
-
paramMap = new Map();
|
8081
|
-
const paramSpecParams = paramSpecType.details.parameters;
|
8082
|
-
paramSpecParams.forEach((param) => {
|
8083
|
-
if (param.name) {
|
8084
|
-
paramMap.set(param.name, param);
|
8085
|
-
}
|
8086
|
-
});
|
8087
|
-
let positionalIndex = 0;
|
8088
|
-
let positionalIndexLimit = paramSpecParams.findIndex((paramInfo) => paramInfo.category !== 0 /* Simple */);
|
8089
|
-
if (positionalIndexLimit < 0) {
|
8090
|
-
positionalIndexLimit = paramSpecParams.length;
|
8091
|
-
}
|
8092
|
-
const argsParam = paramSpecParams.find((paramInfo) => paramInfo.category === 1 /* ArgsList */);
|
8093
|
-
const kwargsParam = paramSpecParams.find((paramInfo) => paramInfo.category === 2 /* KwargsDict */);
|
8094
|
-
const signatureTracker = new typeUtils_1.UniqueSignatureTracker();
|
8095
|
-
const nestedArgList = [];
|
8096
|
-
argList.forEach((arg) => {
|
8097
|
-
var _a;
|
8098
|
-
if (arg.argumentCategory === 0 /* Simple */) {
|
8099
|
-
let paramType;
|
8100
|
-
if (arg.name) {
|
8101
|
-
const paramInfo = paramMap.get(arg.name.value);
|
8102
|
-
if (paramInfo) {
|
8103
|
-
paramType = paramInfo.type;
|
8104
|
-
paramMap.delete(arg.name.value);
|
8105
|
-
}
|
8106
|
-
else if (kwargsParam) {
|
8107
|
-
paramType = kwargsParam.type;
|
8108
|
-
}
|
8109
|
-
else {
|
8110
|
-
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.paramNameMissing().format({ name: arg.name.value }), arg.name || errorNode);
|
8111
|
-
reportedArgError = true;
|
8112
|
-
}
|
8113
|
-
}
|
8114
|
-
else {
|
8115
|
-
if (positionalIndex < positionalIndexLimit) {
|
8116
|
-
const paramInfo = paramSpecParams[positionalIndex];
|
8117
|
-
paramType = paramInfo.type;
|
8118
|
-
if (paramInfo.name) {
|
8119
|
-
paramMap.delete(paramInfo.name);
|
8120
|
-
}
|
8121
|
-
}
|
8122
|
-
else if (argsParam) {
|
8123
|
-
paramType = argsParam.type;
|
8124
|
-
}
|
8125
|
-
else if (paramSpecType.details.paramSpec) {
|
8126
|
-
nestedArgList.push(arg);
|
8127
|
-
}
|
8128
|
-
else {
|
8129
|
-
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, paramSpecParams.length === 1
|
8130
|
-
? localize_1.Localizer.Diagnostic.argPositionalExpectedOne()
|
8131
|
-
: localize_1.Localizer.Diagnostic.argPositionalExpectedCount().format({
|
8132
|
-
expected: paramSpecParams.length,
|
8133
|
-
}), (_a = arg.valueExpression) !== null && _a !== void 0 ? _a : errorNode);
|
8134
|
-
reportedArgError = true;
|
8135
|
-
}
|
8136
|
-
positionalIndex++;
|
8137
|
-
}
|
8138
|
-
if (paramType) {
|
8139
|
-
const argResult = validateArgType({
|
8140
|
-
paramCategory: 0 /* Simple */,
|
8141
|
-
paramType: (0, typeUtils_1.transformExpectedType)(paramType, liveTypeVarScopes,
|
8142
|
-
/* usageOffset */ undefined),
|
8143
|
-
requiresTypeVarMatching: false,
|
8144
|
-
argument: arg,
|
8145
|
-
errorNode: arg.valueExpression || errorNode,
|
8146
|
-
}, srcTypeVarContext, signatureTracker,
|
8147
|
-
/* functionType */ undefined, { conditionFilter });
|
8148
|
-
if (!argResult.isCompatible) {
|
8149
|
-
reportedArgError = true;
|
8150
|
-
}
|
8151
|
-
}
|
8152
|
-
}
|
8153
|
-
else if (arg.argumentCategory === 1 /* UnpackedList */) {
|
8154
|
-
sawUnpackedListArgument = true;
|
8155
|
-
// See if there is an *args parameter.
|
8156
|
-
const argsParam = paramSpecParams.find((param) => param.category === 1 /* ArgsList */ && param.name);
|
8157
|
-
if (argsParam && paramMap.has(argsParam.name)) {
|
8158
|
-
// TODO - validate args type
|
8159
|
-
paramMap.delete(argsParam.name);
|
8160
|
-
}
|
8161
|
-
}
|
8162
|
-
else {
|
8163
|
-
sawUnpackedDictArgument = true;
|
8164
|
-
(0, debug_1.assert)(arg.argumentCategory === 2 /* UnpackedDictionary */);
|
8165
|
-
// See if there is an *kwargs parameter.
|
8166
|
-
const kwargsParam = paramSpecParams.find((param) => param.category === 2 /* KwargsDict */);
|
8167
|
-
if (kwargsParam && paramMap.has(kwargsParam.name)) {
|
8168
|
-
// TODO - validate kwargs type
|
8169
|
-
paramMap.delete(kwargsParam.name);
|
8170
|
-
}
|
8171
|
-
}
|
8172
|
-
});
|
8173
|
-
// Handle recursive ParamSpecs.
|
8174
|
-
if (paramSpecType.details.paramSpec) {
|
8175
|
-
const boundTypeForParamSpec = srcTypeVarContext
|
8176
|
-
.getPrimarySignature()
|
8177
|
-
.getParamSpecType(paramSpecType.details.paramSpec);
|
8178
|
-
if (boundTypeForParamSpec) {
|
8179
|
-
const paramSpecArgResult = validateFunctionArgumentsForParamSpec(errorNode, nestedArgList, paramSpecType.details.paramSpec, srcTypeVarContext, conditionFilter);
|
8180
|
-
if (paramSpecArgResult.argumentErrors) {
|
8181
|
-
reportedArgError = true;
|
8182
|
-
}
|
8183
|
-
}
|
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);
|
8184
8137
|
}
|
8185
8138
|
});
|
8139
|
+
return { argumentErrors: true, typeVarContexts: [srcTypeVarContext] };
|
8186
8140
|
}
|
8187
|
-
|
8188
|
-
|
8189
|
-
let unassignedParams = Array.from(paramMap.keys());
|
8190
|
-
// Parameters that have defaults can be left unspecified.
|
8191
|
-
unassignedParams = unassignedParams.filter((name) => {
|
8192
|
-
const paramInfo = paramMap.get(name);
|
8193
|
-
return paramInfo.category === 0 /* Simple */ && !paramInfo.hasDefault;
|
8194
|
-
});
|
8195
|
-
if (unassignedParams.length > 0 &&
|
8196
|
-
!paramSpecType.details.paramSpec &&
|
8197
|
-
!sawUnpackedListArgument &&
|
8198
|
-
!sawUnpackedDictArgument) {
|
8199
|
-
const missingParamNames = unassignedParams.map((p) => `"${p}"`).join(', ');
|
8200
|
-
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, unassignedParams.length === 1
|
8201
|
-
? localize_1.Localizer.Diagnostic.argMissingForParam().format({ name: missingParamNames })
|
8202
|
-
: localize_1.Localizer.Diagnostic.argMissingForParams().format({ names: missingParamNames }), errorNode);
|
8203
|
-
reportedArgError = true;
|
8204
|
-
}
|
8205
|
-
}
|
8206
|
-
if (!reportedArgError) {
|
8207
|
-
(0, typeUtils_1.applySourceContextTypeVarsToSignature)(typeVarContext, srcTypeVarContext);
|
8208
|
-
}
|
8209
|
-
return {
|
8210
|
-
argumentErrors: reportedArgError,
|
8211
|
-
typeVarContexts: [reportedArgError ? srcTypeVarContext : undefined],
|
8212
|
-
};
|
8141
|
+
const result = validateFunctionArgumentTypes(errorNode, matchResults, srcTypeVarContext, signatureTracker);
|
8142
|
+
return { argumentErrors: !!result.argumentErrors, typeVarContexts: [srcTypeVarContext] };
|
8213
8143
|
}
|
8214
8144
|
function validateArgType(argParam, typeVarContext, signatureTracker, typeResult, options) {
|
8215
8145
|
var _a;
|
@@ -9160,20 +9090,28 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9160
9090
|
}
|
9161
9091
|
return undefined;
|
9162
9092
|
}
|
9163
|
-
|
9164
|
-
|
9165
|
-
|
9166
|
-
|
9167
|
-
|
9168
|
-
if (!(0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, builtInDict, inferenceContext.expectedType, dictTypeVarContext, ParseTreeUtils.getTypeVarScopesForNode(node), node.start)) {
|
9169
|
-
return undefined;
|
9093
|
+
let expectedKeyType;
|
9094
|
+
let expectedValueType;
|
9095
|
+
if ((0, types_1.isAnyOrUnknown)(inferenceContext.expectedType)) {
|
9096
|
+
expectedKeyType = inferenceContext.expectedType;
|
9097
|
+
expectedValueType = inferenceContext.expectedType;
|
9170
9098
|
}
|
9171
|
-
|
9172
|
-
|
9173
|
-
|
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];
|
9174
9114
|
}
|
9175
|
-
const expectedKeyType = specializedDict.typeArguments[0];
|
9176
|
-
const expectedValueType = specializedDict.typeArguments[1];
|
9177
9115
|
// Dict and MutableMapping types have invariant value types, so they
|
9178
9116
|
// cannot be narrowed further. Other super-types like Mapping, Collection,
|
9179
9117
|
// and Iterable use covariant value types, so they can be narrowed.
|
@@ -9451,22 +9389,28 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9451
9389
|
let isIncomplete = false;
|
9452
9390
|
let typeErrors = false;
|
9453
9391
|
const verifyHashable = node.nodeType === 45 /* Set */;
|
9454
|
-
|
9455
|
-
|
9456
|
-
|
9457
|
-
const builtInListOrSet = getBuiltInObject(node, builtInClassName);
|
9458
|
-
if (!(0, types_1.isClassInstance)(builtInListOrSet)) {
|
9459
|
-
return undefined;
|
9460
|
-
}
|
9461
|
-
const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(builtInListOrSet));
|
9462
|
-
if (!(0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, builtInListOrSet, inferenceContext.expectedType, typeVarContext, ParseTreeUtils.getTypeVarScopesForNode(node), node.start)) {
|
9463
|
-
return undefined;
|
9392
|
+
let expectedEntryType;
|
9393
|
+
if ((0, types_1.isAnyOrUnknown)(inferenceContext.expectedType)) {
|
9394
|
+
expectedEntryType = inferenceContext.expectedType;
|
9464
9395
|
}
|
9465
|
-
|
9466
|
-
|
9467
|
-
|
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];
|
9468
9413
|
}
|
9469
|
-
const expectedEntryType = specializedListOrSet.typeArguments[0];
|
9470
9414
|
const entryTypes = [];
|
9471
9415
|
const expectedTypeDiagAddendum = new diagnostic_1.DiagnosticAddendum();
|
9472
9416
|
node.entries.forEach((entry) => {
|
@@ -10022,6 +9966,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10022
9966
|
functionType.details.declaredReturnType = types_1.UnknownType.create();
|
10023
9967
|
functionType.details.typeVarScopeId = ParseTreeUtils.getScopeIdForNode(errorNode);
|
10024
9968
|
if (typeArgs && typeArgs.length > 0) {
|
9969
|
+
functionType.isCallableWithTypeArgs = true;
|
10025
9970
|
if (typeArgs[0].typeList) {
|
10026
9971
|
const typeList = typeArgs[0].typeList;
|
10027
9972
|
let sawUnpacked = false;
|
@@ -10169,7 +10114,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10169
10114
|
function cloneBuiltinObjectWithLiteral(node, builtInName, value) {
|
10170
10115
|
const type = getBuiltInObject(node, builtInName);
|
10171
10116
|
if ((0, types_1.isClassInstance)(type)) {
|
10172
|
-
return types_1.ClassType.cloneWithLiteral(type, value);
|
10117
|
+
return types_1.ClassType.cloneWithLiteral(types_1.ClassType.cloneRemoveTypePromotions(type), value);
|
10173
10118
|
}
|
10174
10119
|
return types_1.UnknownType.create();
|
10175
10120
|
}
|
@@ -10332,12 +10277,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10332
10277
|
}
|
10333
10278
|
const enclosingFunction = ParseTreeUtils.getEnclosingFunction(errorNode);
|
10334
10279
|
if (enclosingFunction) {
|
10335
|
-
const
|
10280
|
+
const functionInfo = (0, decorators_1.getFunctionInfoFromDecorators)(evaluatorInterface, enclosingFunction,
|
10336
10281
|
/* isInClass */ true);
|
10337
10282
|
const isInnerFunction = !!ParseTreeUtils.getEnclosingFunction(enclosingFunction);
|
10338
10283
|
if (!isInnerFunction) {
|
10339
10284
|
// Check for static methods.
|
10340
|
-
if (
|
10285
|
+
if (functionInfo.flags & 4 /* StaticMethod */) {
|
10341
10286
|
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.selfTypeContext(), errorNode);
|
10342
10287
|
return types_1.UnknownType.create();
|
10343
10288
|
}
|
@@ -11768,7 +11713,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11768
11713
|
node.parameters.forEach((param) => {
|
11769
11714
|
var _a;
|
11770
11715
|
const paramSymbol = AnalyzerNodeInfo.getTypeParameterSymbol(param.name);
|
11771
|
-
|
11716
|
+
if (!paramSymbol) {
|
11717
|
+
// This can happen if the code is unreachable.
|
11718
|
+
return;
|
11719
|
+
}
|
11772
11720
|
const typeOfParam = (_a = getDeclaredTypeOfSymbol(paramSymbol, param.name)) === null || _a === void 0 ? void 0 : _a.type;
|
11773
11721
|
if (!typeOfParam || !(0, types_1.isTypeVar)(typeOfParam)) {
|
11774
11722
|
return;
|
@@ -12030,6 +11978,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12030
11978
|
}
|
12031
11979
|
// See if there are any overloads provided by previous function declarations.
|
12032
11980
|
if ((0, types_1.isFunction)(decoratedType)) {
|
11981
|
+
decoratedType.details.deprecatedMessage = functionType.details.deprecatedMessage;
|
12033
11982
|
if (types_1.FunctionType.isOverloaded(decoratedType)) {
|
12034
11983
|
// Mark all the parameters as accessed.
|
12035
11984
|
node.parameters.forEach((param) => {
|
@@ -12063,7 +12012,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12063
12012
|
if (containingClassNode) {
|
12064
12013
|
containingClassType = (_a = getTypeOfClass(containingClassNode)) === null || _a === void 0 ? void 0 : _a.classType;
|
12065
12014
|
}
|
12066
|
-
|
12015
|
+
const functionInfo = (0, decorators_1.getFunctionInfoFromDecorators)(evaluatorInterface, node, !!containingClassNode);
|
12016
|
+
let functionFlags = functionInfo.flags;
|
12067
12017
|
if (functionDecl === null || functionDecl === void 0 ? void 0 : functionDecl.isGenerator) {
|
12068
12018
|
functionFlags |= 16 /* Generator */;
|
12069
12019
|
}
|
@@ -12078,6 +12028,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12078
12028
|
}
|
12079
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));
|
12080
12030
|
functionType.details.typeVarScopeId = ParseTreeUtils.getScopeIdForNode(node);
|
12031
|
+
functionType.details.deprecatedMessage = functionInfo.deprecationMessage;
|
12081
12032
|
if (node.name.value === '__init__' || node.name.value === '__new__') {
|
12082
12033
|
if (containingClassNode) {
|
12083
12034
|
functionType.details.constructorTypeVarScopeId = ParseTreeUtils.getScopeIdForNode(containingClassNode);
|
@@ -12197,7 +12148,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12197
12148
|
}
|
12198
12149
|
let defaultValueType;
|
12199
12150
|
if (param.defaultValue) {
|
12200
|
-
|
12151
|
+
// If this is a stub file, a protocol, an overload, or a class
|
12152
|
+
// whose body is a placeholder implementation, treat a "...", as
|
12153
|
+
// an "Any" value.
|
12154
|
+
let treatEllipsisAsAny = fileInfo.isStubFile || ParseTreeUtils.isSuiteEmpty(node.suite);
|
12155
|
+
if (containingClassType && types_1.ClassType.isProtocolClass(containingClassType)) {
|
12156
|
+
treatEllipsisAsAny = true;
|
12157
|
+
}
|
12158
|
+
if (types_1.FunctionType.isOverloaded(functionType) || types_1.FunctionType.isAbstractMethod(functionType)) {
|
12159
|
+
treatEllipsisAsAny = true;
|
12160
|
+
}
|
12161
|
+
defaultValueType = getTypeOfExpression(param.defaultValue, treatEllipsisAsAny ? 1 /* ConvertEllipsisToAny */ : 0 /* None */, (0, typeUtils_1.makeInferenceContext)(annotatedType)).type;
|
12201
12162
|
}
|
12202
12163
|
if (annotatedType) {
|
12203
12164
|
// If there was both a type annotation and a default value, verify
|
@@ -13498,7 +13459,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13498
13459
|
// See if the function is a method in a child class. We may be able to
|
13499
13460
|
// infer the type of the parameter from a method of the same name in
|
13500
13461
|
// a parent class if it has an annotated type.
|
13501
|
-
const functionFlags = (0, decorators_1.
|
13462
|
+
const functionFlags = (0, decorators_1.getFunctionInfoFromDecorators)(evaluatorInterface, functionNode,
|
13463
|
+
/* isInClass */ true).flags;
|
13502
13464
|
const inferredParamType = inferParameterType(functionNode, functionFlags, paramIndex, classInfo === null || classInfo === void 0 ? void 0 : classInfo.classType);
|
13503
13465
|
writeTypeCache(node.name, { type: transformVariadicParamType(node, node.category, inferredParamType !== null && inferredParamType !== void 0 ? inferredParamType : types_1.UnknownType.create()) }, 0 /* None */);
|
13504
13466
|
}
|
@@ -15620,6 +15582,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15620
15582
|
sourceType: srcErrorTypeText,
|
15621
15583
|
destType: destErrorTypeText,
|
15622
15584
|
}));
|
15585
|
+
// Tell the user about the disableBytesTypePromotions if that is involved.
|
15586
|
+
if (types_1.ClassType.isBuiltIn(destType, 'bytes')) {
|
15587
|
+
const promotions = typePromotions.get(destType.details.fullName);
|
15588
|
+
if (promotions && promotions.some((name) => name === srcType.details.fullName)) {
|
15589
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.bytesTypePromotions());
|
15590
|
+
}
|
15591
|
+
}
|
15623
15592
|
return false;
|
15624
15593
|
}
|
15625
15594
|
// This function is used to validate or infer the variance of type
|
@@ -15968,6 +15937,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15968
15937
|
if (includeDiagAddendum) {
|
15969
15938
|
childDiag.addAddendum(assignmentDiag);
|
15970
15939
|
}
|
15940
|
+
if (isCompatible && types_1.ClassType.isSameGenericClass(destType, srcType)) {
|
15941
|
+
// Add additional notes to help the user if this is a common type mismatch.
|
15942
|
+
if (types_1.ClassType.isBuiltIn(destType, 'dict') && srcArgIndex === 1) {
|
15943
|
+
childDiag.addMessage(localize_1.Localizer.DiagnosticAddendum.invariantSuggestionDict());
|
15944
|
+
}
|
15945
|
+
else if (types_1.ClassType.isBuiltIn(destType, 'list')) {
|
15946
|
+
childDiag.addMessage(localize_1.Localizer.DiagnosticAddendum.invariantSuggestionList());
|
15947
|
+
}
|
15948
|
+
}
|
15971
15949
|
}
|
15972
15950
|
else {
|
15973
15951
|
diag.addAddendum(assignmentDiag);
|
@@ -18093,7 +18071,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18093
18071
|
let isAbstract;
|
18094
18072
|
const decl = (0, symbolUtils_1.getLastTypedDeclaredForSymbol)(symbol);
|
18095
18073
|
if (decl && decl.type === 5 /* Function */) {
|
18096
|
-
const functionFlags = (0, decorators_1.
|
18074
|
+
const functionFlags = (0, decorators_1.getFunctionInfoFromDecorators)(evaluatorInterface, decl.node, true).flags;
|
18097
18075
|
isAbstract = !!(functionFlags & 8 /* AbstractMethod */);
|
18098
18076
|
}
|
18099
18077
|
else {
|