@zzzen/pyright-internal 1.2.0-dev.20261108 → 1.2.0-dev.20261122
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyzer/binder.d.ts +2 -0
- package/dist/analyzer/binder.js +238 -18
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.js +28 -3
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/constructors.d.ts +1 -1
- package/dist/analyzer/constructors.js +68 -9
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/enums.d.ts +10 -3
- package/dist/analyzer/enums.js +389 -2
- package/dist/analyzer/enums.js.map +1 -1
- package/dist/analyzer/operations.js +81 -4
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.js +9 -1
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/patternMatching.js +12 -3
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/protocols.d.ts +1 -0
- package/dist/analyzer/protocols.js +171 -10
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/scope.d.ts +3 -0
- package/dist/analyzer/scope.js +28 -6
- package/dist/analyzer/scope.js.map +1 -1
- package/dist/analyzer/sentinel.d.ts +4 -2
- package/dist/analyzer/sentinel.js +46 -28
- package/dist/analyzer/sentinel.js.map +1 -1
- package/dist/analyzer/symbol.d.ts +4 -1
- package/dist/analyzer/symbol.js +8 -0
- package/dist/analyzer/symbol.js.map +1 -1
- package/dist/analyzer/tupleComparison.js +69 -85
- package/dist/analyzer/tupleComparison.js.map +1 -1
- package/dist/analyzer/typeEvaluator/collectionInference.d.ts +1 -1
- package/dist/analyzer/typeEvaluator/collectionInference.js +162 -87
- package/dist/analyzer/typeEvaluator/collectionInference.js.map +1 -1
- package/dist/analyzer/typeEvaluator/evaluatorCore.js +6 -0
- package/dist/analyzer/typeEvaluator/evaluatorCore.js.map +1 -1
- package/dist/analyzer/typeEvaluator/expressionEvaluation.d.ts +1 -1
- package/dist/analyzer/typeEvaluator/expressionEvaluation.js +8 -4
- package/dist/analyzer/typeEvaluator/expressionEvaluation.js.map +1 -1
- package/dist/analyzer/typeEvaluator/internals.d.ts +1 -0
- package/dist/analyzer/typeEvaluator/specialFormCreation.js +11 -0
- package/dist/analyzer/typeEvaluator/specialFormCreation.js.map +1 -1
- package/dist/analyzer/typeEvaluator/typeCompatibility.js +14 -1
- package/dist/analyzer/typeEvaluator/typeCompatibility.js.map +1 -1
- package/dist/analyzer/typeEvaluator/typeGuardNarrowing.d.ts +3 -1
- package/dist/analyzer/typeEvaluator/typeGuardNarrowing.js +88 -7
- package/dist/analyzer/typeEvaluator/typeGuardNarrowing.js.map +1 -1
- package/dist/analyzer/typeEvaluator.d.ts +1 -1
- package/dist/analyzer/typeEvaluator.js +241 -22
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeGuards.d.ts +2 -2
- package/dist/analyzer/typeGuards.js +45 -14
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typeUtils.js +23 -20
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typedDicts.js +15 -2
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +16 -2
- package/dist/analyzer/types.js +34 -4
- package/dist/analyzer/types.js.map +1 -1
- package/dist/common/languageInfoUtils.js +1 -1
- package/dist/common/languageInfoUtils.js.map +1 -1
- package/dist/common/processUtils.d.ts +1 -0
- package/dist/common/processUtils.js +38 -0
- package/dist/common/processUtils.js.map +1 -1
- package/dist/common/realFileSystem.d.ts +6 -0
- package/dist/common/realFileSystem.js +83 -1
- package/dist/common/realFileSystem.js.map +1 -1
- package/dist/common/windowsProcessTree.json +20 -2
- package/dist/languageService/documentSymbolCollector.js +1 -1
- package/dist/languageService/documentSymbolCollector.js.map +1 -1
- package/dist/languageService/renameProvider.js +1 -1
- package/dist/languageService/renameProvider.js.map +1 -1
- package/dist/languageService/symbolIndexer.js +1 -1
- package/dist/languageService/symbolIndexer.js.map +1 -1
- package/dist/localization/localize.d.ts +8 -0
- package/dist/localization/localize.js +10 -1
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +8 -0
- package/dist/localization/package.nls.de.json +8 -0
- package/dist/localization/package.nls.en-us.json +8 -0
- package/dist/localization/package.nls.es.json +8 -0
- package/dist/localization/package.nls.fr.json +8 -0
- package/dist/localization/package.nls.it.json +8 -0
- package/dist/localization/package.nls.ja.json +8 -0
- package/dist/localization/package.nls.ko.json +8 -0
- package/dist/localization/package.nls.pl.json +8 -0
- package/dist/localization/package.nls.pt-br.json +8 -0
- package/dist/localization/package.nls.qps-ploc.json +8 -0
- package/dist/localization/package.nls.ru.json +8 -0
- package/dist/localization/package.nls.tr.json +8 -0
- package/dist/localization/package.nls.zh-cn.json +8 -0
- package/dist/localization/package.nls.zh-tw.json +8 -0
- package/dist/parser/parseNodes.d.ts +3 -4
- package/dist/parser/parseNodes.js +6 -11
- package/dist/parser/parseNodes.js.map +1 -1
- package/dist/parser/parseTreeTokenReuse.js +3 -0
- package/dist/parser/parseTreeTokenReuse.js.map +1 -1
- package/dist/parser/parser.d.ts +3 -0
- package/dist/parser/parser.js +137 -36
- package/dist/parser/parser.js.map +1 -1
- package/dist/parser/stringTokenUtils.js +11 -13
- package/dist/parser/stringTokenUtils.js.map +1 -1
- package/dist/tests/checker.test.js +19 -2
- package/dist/tests/checker.test.js.map +1 -1
- package/dist/tests/localizer.test.js +23 -0
- package/dist/tests/localizer.test.js.map +1 -1
- package/dist/tests/parser.test.js +357 -1
- package/dist/tests/parser.test.js.map +1 -1
- package/dist/tests/signatureHelp.test.js +22 -0
- package/dist/tests/signatureHelp.test.js.map +1 -1
- package/dist/tests/tokenizer.test.js +32 -0
- package/dist/tests/tokenizer.test.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +33 -0
- package/dist/tests/typeEvaluator1.test.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +16 -2
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +36 -0
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator5.test.js +7 -1
- package/dist/tests/typeEvaluator5.test.js.map +1 -1
- package/dist/tests/typeEvaluator6.test.js +24 -0
- package/dist/tests/typeEvaluator6.test.js.map +1 -1
- package/dist/tests/typeEvaluator7.test.js +244 -17
- package/dist/tests/typeEvaluator7.test.js.map +1 -1
- package/dist/tests/typeEvaluator8.test.js +56 -12
- package/dist/tests/typeEvaluator8.test.js.map +1 -1
- package/dist/tests/typeUtils.test.js +73 -0
- package/dist/tests/typeUtils.test.js.map +1 -1
- package/dist/typeServer/stubGenerator.d.ts +9 -0
- package/dist/typeServer/stubGenerator.js +90 -0
- package/dist/typeServer/stubGenerator.js.map +1 -1
- package/package.json +2 -2
|
@@ -128,6 +128,16 @@ const typePromotions = new Map([
|
|
|
128
128
|
['builtins.complex', ['builtins.float', 'builtins.int']],
|
|
129
129
|
['builtins.bytes', ['builtins.bytearray', 'builtins.memoryview']],
|
|
130
130
|
]);
|
|
131
|
+
// Non-dunder names owned by CPython's Annotated wrapper rather than its origin.
|
|
132
|
+
const annotatedAliasOwnMembers = new Set([
|
|
133
|
+
'copy_with',
|
|
134
|
+
'_determine_new_args',
|
|
135
|
+
'_make_substitution',
|
|
136
|
+
'_inst',
|
|
137
|
+
'_name',
|
|
138
|
+
'_paramspec_tvars',
|
|
139
|
+
'_typevar_types',
|
|
140
|
+
]);
|
|
131
141
|
// How many levels deep should we attempt to infer return
|
|
132
142
|
// types based on call-site argument types? The deeper we go,
|
|
133
143
|
// the more types we may be able to infer, but the worse the
|
|
@@ -1231,7 +1241,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
1231
1241
|
diag.addAddendum(subDiag);
|
|
1232
1242
|
}
|
|
1233
1243
|
return {
|
|
1234
|
-
type:
|
|
1244
|
+
type: usage.method === 'get'
|
|
1245
|
+
? (0, enums_1.getTypeOfIntFlagMember)(evaluatorInterface, objectType, memberInfo.type, nodeInfo)
|
|
1246
|
+
: memberInfo.type,
|
|
1235
1247
|
classType: memberInfo.classType,
|
|
1236
1248
|
isIncomplete: !!memberInfo.isTypeIncomplete,
|
|
1237
1249
|
isAsymmetricAccessor: memberInfo.isAsymmetricAccessor,
|
|
@@ -1380,7 +1392,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
1380
1392
|
}
|
|
1381
1393
|
case 6 /* TypeCategory.Class */: {
|
|
1382
1394
|
if (types_1.TypeBase.isInstantiable(subtype)) {
|
|
1383
|
-
const constructorType = (0, constructors_1.createFunctionFromConstructor)(evaluatorInterface, subtype
|
|
1395
|
+
const constructorType = (0, constructors_1.createFunctionFromConstructor)(evaluatorInterface, subtype,
|
|
1396
|
+
/* selfType */ undefined,
|
|
1397
|
+
/* recursionCount */ 0,
|
|
1398
|
+
/* retainUnboundNewOverloads */ true);
|
|
1384
1399
|
if (constructorType) {
|
|
1385
1400
|
(0, typeUtils_1.doForEachSubtype)(constructorType, (subtype) => {
|
|
1386
1401
|
if ((0, types_1.isFunctionOrOverloaded)(subtype)) {
|
|
@@ -1469,8 +1484,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
1469
1484
|
}
|
|
1470
1485
|
// Validates that the type is an iterator and returns the iterated type
|
|
1471
1486
|
// (i.e. the type returned from the '__next__' or '__anext__' method).
|
|
1472
|
-
function getTypeOfIterator(typeResult, isAsync, errorNode, emitNotIterableError = true) {
|
|
1473
|
-
return expressionEvaluation.getTypeOfIterator(typeResult, isAsync, errorNode, emitNotIterableError);
|
|
1487
|
+
function getTypeOfIterator(typeResult, isAsync, errorNode, emitNotIterableError = true, preserveInvalidSubtypes = false) {
|
|
1488
|
+
return expressionEvaluation.getTypeOfIterator(typeResult, isAsync, errorNode, emitNotIterableError, preserveInvalidSubtypes);
|
|
1474
1489
|
}
|
|
1475
1490
|
// Validates that the type is an iterable and returns the iterable type argument.
|
|
1476
1491
|
function getTypeOfIterable(typeResult, isAsync, errorNode, emitNotIterableError = true) {
|
|
@@ -2404,9 +2419,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2404
2419
|
// Handles the case where a variable or parameter is defined in an outer
|
|
2405
2420
|
// scope and captured by an inner scope (a function, lambda, or comprehension).
|
|
2406
2421
|
function getCodeFlowTypeForCapturedVariable(node, symbolWithScope, effectiveType) {
|
|
2407
|
-
//
|
|
2408
|
-
//
|
|
2409
|
-
if (symbolWithScope.usesGlobalBinding || symbolWithScope.
|
|
2422
|
+
// Global bindings and cells that can be unbound in another scope
|
|
2423
|
+
// cannot safely retain the type at capture.
|
|
2424
|
+
if (symbolWithScope.usesGlobalBinding || symbolWithScope.symbol.isUnboundInOtherScope()) {
|
|
2410
2425
|
return undefined;
|
|
2411
2426
|
}
|
|
2412
2427
|
// This function applies only to variables, parameters, and imports, not to other
|
|
@@ -2765,6 +2780,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2765
2780
|
if (baseTypeResult.isIncomplete) {
|
|
2766
2781
|
typeResult.isIncomplete = true;
|
|
2767
2782
|
}
|
|
2783
|
+
if ((flags & 128 /* EvalFlags.InstantiableType */) !== 0 &&
|
|
2784
|
+
(0, types_1.isClassInstance)(typeResult.type) &&
|
|
2785
|
+
(0, typeUtils_1.isSentinelLiteral)(typeResult.type)) {
|
|
2786
|
+
typeResult.type = types_1.ClassType.cloneAsInstantiable(typeResult.type);
|
|
2787
|
+
}
|
|
2768
2788
|
// See if we need to log an "unknown member access" diagnostic.
|
|
2769
2789
|
let skipPartialUnknownCheck = typeResult.isIncomplete;
|
|
2770
2790
|
// Don't report an error if the type is a partially-specialized
|
|
@@ -2787,6 +2807,90 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2787
2807
|
writeTypeCache(node.d.member, typeResult, flags);
|
|
2788
2808
|
return typeResult;
|
|
2789
2809
|
}
|
|
2810
|
+
function getSingleValueDeclaration(node) {
|
|
2811
|
+
let decls;
|
|
2812
|
+
if (node.nodeType === 38 /* ParseNodeType.Name */) {
|
|
2813
|
+
decls = getDeclInfoForNameNode(node)?.decls;
|
|
2814
|
+
}
|
|
2815
|
+
else if (node.nodeType === 35 /* ParseNodeType.MemberAccess */) {
|
|
2816
|
+
const receiver = readTypeCache(node.d.leftExpr, /* flags */ undefined);
|
|
2817
|
+
if (receiver && (0, types_1.isModule)(receiver)) {
|
|
2818
|
+
decls = types_1.ModuleType.getField(receiver, node.d.member.d.value)?.getDeclarations();
|
|
2819
|
+
}
|
|
2820
|
+
else if (receiver &&
|
|
2821
|
+
(0, types_1.isInstantiableClass)(receiver) &&
|
|
2822
|
+
!receiver.priv.includeSubclasses &&
|
|
2823
|
+
hasDefaultMetaclass(receiver)) {
|
|
2824
|
+
decls = (0, typeUtils_1.lookUpClassMember)(receiver, node.d.member.d.value, 16 /* MemberAccessFlags.SkipInstanceMembers */)?.symbol.getDeclarations();
|
|
2825
|
+
}
|
|
2826
|
+
}
|
|
2827
|
+
return decls?.length === 1 ? resolveAliasDeclaration(decls[0], /* resolveLocalNames */ true) : undefined;
|
|
2828
|
+
}
|
|
2829
|
+
function hasDefaultMetaclass(classType) {
|
|
2830
|
+
const metaclass = classType.shared.effectiveMetaclass;
|
|
2831
|
+
return !!metaclass && (0, types_1.isInstantiableClass)(metaclass) && types_1.ClassType.isBuiltIn(metaclass, 'type');
|
|
2832
|
+
}
|
|
2833
|
+
function getAnnotatedOriginExpression(node) {
|
|
2834
|
+
if (node?.nodeType === 27 /* ParseNodeType.Index */) {
|
|
2835
|
+
const base = readTypeCache(node.d.leftExpr, /* flags */ undefined);
|
|
2836
|
+
const arg = node.d.items[0];
|
|
2837
|
+
if (base &&
|
|
2838
|
+
(0, types_1.isInstantiableClass)(base) &&
|
|
2839
|
+
types_1.ClassType.isBuiltIn(base, 'Annotated') &&
|
|
2840
|
+
arg?.d.argCategory === 0 /* ArgCategory.Simple */ &&
|
|
2841
|
+
!arg.d.name) {
|
|
2842
|
+
return arg.d.valueExpr;
|
|
2843
|
+
}
|
|
2844
|
+
}
|
|
2845
|
+
return undefined;
|
|
2846
|
+
}
|
|
2847
|
+
// The erased annotation can describe a class even when the runtime origin
|
|
2848
|
+
// is a ForwardRef, NewType, or another typing object. Follow only expressions
|
|
2849
|
+
// whose runtime lookup is known to reach the class that the annotation describes.
|
|
2850
|
+
function isAnnotatedAliasOfClass(node, aliasType, classType) {
|
|
2851
|
+
const aliasInfo = aliasType.props?.typeAliasInfo;
|
|
2852
|
+
if (!aliasInfo || aliasInfo.shared.isTypeAliasType || types_1.ClassType.isPartiallyEvaluated(classType)) {
|
|
2853
|
+
return false;
|
|
2854
|
+
}
|
|
2855
|
+
const decl = getSingleValueDeclaration(node);
|
|
2856
|
+
let origin = getAnnotatedOriginExpression(decl?.type === 1 /* DeclarationType.Variable */ && decl.typeAliasName ? decl.inferredTypeSource : undefined);
|
|
2857
|
+
for (let depth = 0; origin && depth < maxRecursiveTypeAliasRecursionCount; depth++) {
|
|
2858
|
+
if (origin.nodeType === 27 /* ParseNodeType.Index */) {
|
|
2859
|
+
const nestedOrigin = getAnnotatedOriginExpression(origin);
|
|
2860
|
+
if (nestedOrigin) {
|
|
2861
|
+
// Annotated flattens nested wrappers at runtime.
|
|
2862
|
+
origin = nestedOrigin;
|
|
2863
|
+
continue;
|
|
2864
|
+
}
|
|
2865
|
+
// Only standard generic subscription forwards to the same class. A
|
|
2866
|
+
// metaclass or a user-defined __class_getitem__ can return another object.
|
|
2867
|
+
const genericDecl = getSingleValueDeclaration(origin.d.leftExpr);
|
|
2868
|
+
if (genericDecl?.type !== 6 /* DeclarationType.Class */ ||
|
|
2869
|
+
genericDecl !== classType.shared.declaration ||
|
|
2870
|
+
!classType.priv.typeArgs ||
|
|
2871
|
+
!hasDefaultMetaclass(classType) ||
|
|
2872
|
+
types_1.ClassType.isBuiltIn(classType, 'type')) {
|
|
2873
|
+
return false;
|
|
2874
|
+
}
|
|
2875
|
+
const getItem = (0, typeUtils_1.lookUpClassMember)(classType, '__class_getitem__', 16 /* MemberAccessFlags.SkipInstanceMembers */);
|
|
2876
|
+
return getItem
|
|
2877
|
+
? (0, types_1.isClass)(getItem.classType) &&
|
|
2878
|
+
(getItem.classType.shared.moduleName === 'builtins' ||
|
|
2879
|
+
getItem.classType.shared.fullName === 'typing.Generic')
|
|
2880
|
+
: !!genericDecl.node.d.typeParams ||
|
|
2881
|
+
classType.shared.mro.some((base) => (0, types_1.isClass)(base) && base.shared.fullName === 'typing.Generic');
|
|
2882
|
+
}
|
|
2883
|
+
const originDecl = getSingleValueDeclaration(origin);
|
|
2884
|
+
if (originDecl?.type === 6 /* DeclarationType.Class */) {
|
|
2885
|
+
return originDecl === classType.shared.declaration;
|
|
2886
|
+
}
|
|
2887
|
+
origin =
|
|
2888
|
+
originDecl?.type === 1 /* DeclarationType.Variable */ && originDecl.typeAliasName
|
|
2889
|
+
? originDecl.inferredTypeSource
|
|
2890
|
+
: undefined;
|
|
2891
|
+
}
|
|
2892
|
+
return false;
|
|
2893
|
+
}
|
|
2790
2894
|
function getTypeOfMemberAccessWithBaseType(node, baseTypeResult, usage, flags, allowFunctionSignatureAssignment = true) {
|
|
2791
2895
|
let baseType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(baseTypeResult.type);
|
|
2792
2896
|
const memberName = node.d.member.d.value;
|
|
@@ -2794,6 +2898,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2794
2898
|
const fileInfo = nodeInfo.getFileInfo(node);
|
|
2795
2899
|
let type;
|
|
2796
2900
|
let narrowedTypeForSet;
|
|
2901
|
+
let memberAccessDiagType;
|
|
2797
2902
|
let typeErrors = false;
|
|
2798
2903
|
let isIncomplete = !!baseTypeResult.isIncomplete;
|
|
2799
2904
|
let isAsymmetricAccessor;
|
|
@@ -2808,6 +2913,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2808
2913
|
if (baseTypeResult.isIncomplete && (0, types_1.isUnbound)(baseType)) {
|
|
2809
2914
|
return { type: types_1.UnknownType.create(/* isIncomplete */ true), isIncomplete: true };
|
|
2810
2915
|
}
|
|
2916
|
+
const baseTypeForm = baseType.props?.typeForm;
|
|
2811
2917
|
if (baseType.props?.specialForm && (flags & 256 /* EvalFlags.TypeExpression */) === 0) {
|
|
2812
2918
|
baseType = baseType.props.specialForm;
|
|
2813
2919
|
}
|
|
@@ -2875,6 +2981,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2875
2981
|
}
|
|
2876
2982
|
case 6 /* TypeCategory.Class */: {
|
|
2877
2983
|
let typeResult;
|
|
2984
|
+
if (usage.method === 'get' && memberName === '__class__' && (0, types_1.isClassInstance)(baseType)) {
|
|
2985
|
+
const sentinelClass = (0, sentinel_1.getSentinelClass)(baseType);
|
|
2986
|
+
if (sentinelClass) {
|
|
2987
|
+
typeResult = { type: types_1.ClassType.cloneIncludeSubclasses(sentinelClass) };
|
|
2988
|
+
}
|
|
2989
|
+
}
|
|
2878
2990
|
// If this is a class-like function created via NewType, treat
|
|
2879
2991
|
// it like a function for purposes of member accesses.
|
|
2880
2992
|
if (types_1.ClassType.isNewTypeClass(baseType) &&
|
|
@@ -2899,7 +3011,29 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2899
3011
|
}
|
|
2900
3012
|
}
|
|
2901
3013
|
if (!typeResult) {
|
|
2902
|
-
|
|
3014
|
+
const memberFlags = (flags & 256 /* EvalFlags.TypeExpression */) === 0
|
|
3015
|
+
? 0 /* MemberAccessFlags.Default */
|
|
3016
|
+
: 2048 /* MemberAccessFlags.TypeExpression */;
|
|
3017
|
+
typeResult = getTypeOfBoundMember(node.d.member, baseType, memberName, usage, diag, memberFlags, baseTypeResult.bindToSelfType);
|
|
3018
|
+
if (!typeResult &&
|
|
3019
|
+
usage.method === 'get' &&
|
|
3020
|
+
(flags & 256 /* EvalFlags.TypeExpression */) === 0 &&
|
|
3021
|
+
baseTypeForm &&
|
|
3022
|
+
(0, types_1.isClassInstance)(baseTypeForm) &&
|
|
3023
|
+
types_1.ClassType.isBuiltIn(baseType, 'Annotated') &&
|
|
3024
|
+
!(memberName.startsWith('__') && memberName.endsWith('__')) &&
|
|
3025
|
+
!annotatedAliasOwnMembers.has(memberName) &&
|
|
3026
|
+
isAnnotatedAliasOfClass(node.d.leftExpr, baseTypeResult.type, baseTypeForm)) {
|
|
3027
|
+
const originClass = types_1.ClassType.cloneAsInstantiable(baseTypeForm);
|
|
3028
|
+
const fallbackDiag = new diagnostic_1.DiagnosticAddendum();
|
|
3029
|
+
typeResult =
|
|
3030
|
+
(0, enums_1.getTypeOfEnumMember)(evaluatorInterface, node, originClass, memberName, isIncomplete, nodeInfo) ??
|
|
3031
|
+
getTypeOfBoundMember(node.d.member, originClass, memberName, usage, fallbackDiag, memberFlags);
|
|
3032
|
+
if (typeResult?.typeErrors) {
|
|
3033
|
+
diag = fallbackDiag;
|
|
3034
|
+
memberAccessDiagType = originClass;
|
|
3035
|
+
}
|
|
3036
|
+
}
|
|
2903
3037
|
}
|
|
2904
3038
|
if (typeResult) {
|
|
2905
3039
|
if (!typeResult.typeErrors) {
|
|
@@ -3115,7 +3249,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
3115
3249
|
const rule = isFunctionRule
|
|
3116
3250
|
? diagnosticRules_1.DiagnosticRule.reportFunctionMemberAccess
|
|
3117
3251
|
: diagnosticRules_1.DiagnosticRule.reportAttributeAccessIssue;
|
|
3118
|
-
addDiagnostic(rule, diagMessage.format({ name: memberName, type: printType(baseType) }) +
|
|
3252
|
+
addDiagnostic(rule, diagMessage.format({ name: memberName, type: printType(memberAccessDiagType ?? baseType) }) +
|
|
3253
|
+
diag.getString(), node.d.member, diag.getEffectiveTextRange() ?? node.d.member);
|
|
3119
3254
|
}
|
|
3120
3255
|
// If this is member access on a function, use "Any" so if the
|
|
3121
3256
|
// reportFunctionMemberAccess rule is disabled, we don't trigger
|
|
@@ -5637,12 +5772,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
5637
5772
|
return prefetched.functionClass;
|
|
5638
5773
|
}
|
|
5639
5774
|
}
|
|
5640
|
-
|
|
5641
|
-
|
|
5642
|
-
|
|
5643
|
-
|
|
5644
|
-
: stripLiteralValue(subtype);
|
|
5645
|
-
return (0, typeUtils_1.convertToInstantiable)(classSubtype);
|
|
5775
|
+
const sentinelClass = (0, types_1.isClassInstance)(subtype) ? (0, sentinel_1.getSentinelClass)(subtype) : undefined;
|
|
5776
|
+
return sentinelClass
|
|
5777
|
+
? types_1.ClassType.cloneIncludeSubclasses(sentinelClass)
|
|
5778
|
+
: (0, typeUtils_1.convertToInstantiable)(stripLiteralValue(subtype));
|
|
5646
5779
|
}
|
|
5647
5780
|
if (types_1.TypeBase.isInstance(subtype)) {
|
|
5648
5781
|
if ((0, types_1.isFunction)(subtype) || (0, types_1.isTypeVar)(subtype)) {
|
|
@@ -5705,12 +5838,22 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
5705
5838
|
return { returnType: createNewType(errorNode, argList) };
|
|
5706
5839
|
}
|
|
5707
5840
|
// Handle sentinel calls specially.
|
|
5708
|
-
if (
|
|
5709
|
-
|
|
5710
|
-
|
|
5711
|
-
|
|
5712
|
-
|
|
5713
|
-
|
|
5841
|
+
if ((0, sentinel_1.isSentinelClass)(expandedCallType)) {
|
|
5842
|
+
const constructorResult = (0, constructors_1.validateConstructorArgs)(evaluatorInterface, errorNode, argList, expandedCallType, skipUnknownArgCheck, inferenceContext);
|
|
5843
|
+
if (!constructorResult.argumentErrors) {
|
|
5844
|
+
constructorResult.returnType =
|
|
5845
|
+
(0, sentinel_1.createSentinelType)(errorNode, argList, expandedCallType, nodeInfo) ??
|
|
5846
|
+
constructorResult.returnType;
|
|
5847
|
+
if (constructorResult.returnType &&
|
|
5848
|
+
(0, types_1.isClassInstance)(constructorResult.returnType) &&
|
|
5849
|
+
(0, sentinel_1.isSentinelClass)(constructorResult.returnType) &&
|
|
5850
|
+
!(0, typeUtils_1.isSentinelLiteral)(constructorResult.returnType) &&
|
|
5851
|
+
constructorResult.returnType.props?.typeAliasInfo) {
|
|
5852
|
+
constructorResult.returnType = types_1.TypeBase.cloneType(constructorResult.returnType);
|
|
5853
|
+
types_1.TypeBase.setTypeAliasInfo(constructorResult.returnType, undefined);
|
|
5854
|
+
}
|
|
5855
|
+
}
|
|
5856
|
+
return constructorResult;
|
|
5714
5857
|
}
|
|
5715
5858
|
if (types_1.ClassType.isSpecialFormClass(expandedCallType)) {
|
|
5716
5859
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.typeNotIntantiable().format({ type: className }), errorNode);
|
|
@@ -5842,6 +5985,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
5842
5985
|
// This logic is based on PEP 3102: https://www.python.org/dev/peps/pep-3102/
|
|
5843
5986
|
function matchArgsToParams(errorNode, argList, typeResult, overloadIndex) {
|
|
5844
5987
|
const overload = typeResult.type;
|
|
5988
|
+
const unexpandedArgList = (0, enums_1.isIntFlagBitwiseFunction)(overload) && !overload.priv.strippedFirstParamType ? argList : undefined;
|
|
5845
5989
|
const paramDetails = (0, parameterUtils_1.getParamListDetails)(overload, { disallowExtraKwargsForTd: true });
|
|
5846
5990
|
const paramSpec = types_1.FunctionType.getParamSpecFromArgsKwargs(overload);
|
|
5847
5991
|
let argIndex = 0;
|
|
@@ -6669,6 +6813,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
6669
6813
|
argumentErrors: reportedArgError,
|
|
6670
6814
|
isTypeIncomplete,
|
|
6671
6815
|
argParams: validateArgTypeParams,
|
|
6816
|
+
unexpandedArgList,
|
|
6672
6817
|
paramSpecTarget,
|
|
6673
6818
|
paramSpecArgList,
|
|
6674
6819
|
activeParam,
|
|
@@ -6977,6 +7122,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
6977
7122
|
specializedInitSelfType = solveAndApplyConstraints(specializedInitSelfType, constraints);
|
|
6978
7123
|
}
|
|
6979
7124
|
matchResults.argumentMatchScore = argumentMatchScore;
|
|
7125
|
+
if (!argumentErrors && (0, enums_1.isIntFlagBitwiseFunction)(type)) {
|
|
7126
|
+
const transformed = applyIntFlagCallTransform(errorNode, matchResults, argResults, {
|
|
7127
|
+
argumentErrors,
|
|
7128
|
+
returnType: specializedReturnType,
|
|
7129
|
+
isTypeIncomplete,
|
|
7130
|
+
});
|
|
7131
|
+
specializedReturnType = transformed.returnType;
|
|
7132
|
+
isTypeIncomplete = transformed.isTypeIncomplete;
|
|
7133
|
+
}
|
|
6980
7134
|
return {
|
|
6981
7135
|
argumentErrors,
|
|
6982
7136
|
argResults,
|
|
@@ -6988,6 +7142,67 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
6988
7142
|
overloadsUsedForCall: argumentErrors ? [] : [type],
|
|
6989
7143
|
};
|
|
6990
7144
|
}
|
|
7145
|
+
function applyIntFlagCallTransform(errorNode, matchResults, argResults, result) {
|
|
7146
|
+
const argumentTypes = new Map();
|
|
7147
|
+
matchResults.argParams.forEach((param, index) => {
|
|
7148
|
+
if (param.paramName) {
|
|
7149
|
+
argumentTypes.set(param.paramName, argResults[index].argType);
|
|
7150
|
+
}
|
|
7151
|
+
});
|
|
7152
|
+
result = (0, enums_1.applyIntFlagTransform)(evaluatorInterface, matchResults.overload, argumentTypes, result);
|
|
7153
|
+
const argList = matchResults.unexpandedArgList;
|
|
7154
|
+
if (!argList?.some((arg) => arg.argCategory !== 0 /* ArgCategory.Simple */)) {
|
|
7155
|
+
return result;
|
|
7156
|
+
}
|
|
7157
|
+
// Keep correlated packed alternatives together rather than treating their
|
|
7158
|
+
// independently combined parameter types as a Cartesian product.
|
|
7159
|
+
const contextFreeArgTypes = argList.map((arg) => arg.argCategory === 0 /* ArgCategory.Simple */
|
|
7160
|
+
? types_1.UnknownType.create()
|
|
7161
|
+
: getTypeOfArg(arg, /* inferenceContext */ undefined).type);
|
|
7162
|
+
let expandedArgTypes = [argList.map(() => undefined)];
|
|
7163
|
+
while (true) {
|
|
7164
|
+
const expanded = expressionEvaluation.expandArgTypes(contextFreeArgTypes, expandedArgTypes);
|
|
7165
|
+
if (!expanded) {
|
|
7166
|
+
break;
|
|
7167
|
+
}
|
|
7168
|
+
if (expanded.length > maxTotalOverloadArgTypeExpansionCount) {
|
|
7169
|
+
return result;
|
|
7170
|
+
}
|
|
7171
|
+
expandedArgTypes = expanded;
|
|
7172
|
+
}
|
|
7173
|
+
if (expandedArgTypes.length === 1) {
|
|
7174
|
+
return result;
|
|
7175
|
+
}
|
|
7176
|
+
const returnTypes = [];
|
|
7177
|
+
let isTypeIncomplete = result.isTypeIncomplete;
|
|
7178
|
+
for (const expandedTypes of expandedArgTypes) {
|
|
7179
|
+
const expandedArgs = argList.map((arg, index) => {
|
|
7180
|
+
const type = expandedTypes[index];
|
|
7181
|
+
return type
|
|
7182
|
+
? {
|
|
7183
|
+
...arg,
|
|
7184
|
+
valueExpression: undefined,
|
|
7185
|
+
typeResult: { type, isIncomplete: result.isTypeIncomplete },
|
|
7186
|
+
}
|
|
7187
|
+
: arg;
|
|
7188
|
+
});
|
|
7189
|
+
const expandedMatch = useSpeculativeMode(getSpeculativeNodeForCall(errorNode), () => matchArgsToParams(errorNode, expandedArgs, { type: matchResults.overload, isIncomplete: result.isTypeIncomplete }, matchResults.overloadIndex));
|
|
7190
|
+
isTypeIncomplete || (isTypeIncomplete = expandedMatch.isTypeIncomplete);
|
|
7191
|
+
if (expandedMatch.argumentErrors) {
|
|
7192
|
+
return { ...result, isTypeIncomplete };
|
|
7193
|
+
}
|
|
7194
|
+
const expandedArgumentTypes = new Map(argumentTypes);
|
|
7195
|
+
expandedMatch.argParams.forEach((param) => {
|
|
7196
|
+
const type = param.argType ?? param.argument.typeResult?.type;
|
|
7197
|
+
if (param.paramName && type) {
|
|
7198
|
+
expandedArgumentTypes.set(param.paramName, type);
|
|
7199
|
+
}
|
|
7200
|
+
});
|
|
7201
|
+
returnTypes.push((0, enums_1.applyIntFlagTransform)(evaluatorInterface, matchResults.overload, expandedArgumentTypes, result)
|
|
7202
|
+
.returnType);
|
|
7203
|
+
}
|
|
7204
|
+
return { ...result, returnType: (0, types_1.combineTypes)(returnTypes), isTypeIncomplete };
|
|
7205
|
+
}
|
|
6991
7206
|
// In general, all in-scope type variables left in a return type should be
|
|
6992
7207
|
// replaced with Unknown. However, if the return type is a callable that uses
|
|
6993
7208
|
// type vars that are found nowhere within the function's input parameters,
|
|
@@ -8009,7 +8224,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
8009
8224
|
else if (aliasMapEntry.module === 'internals') {
|
|
8010
8225
|
// Handle TypedDict specially.
|
|
8011
8226
|
(0, debug_1.assert)(baseClassName === 'TypedDictFallback');
|
|
8012
|
-
baseClass =
|
|
8227
|
+
baseClass = fileInfo.isTypingExtensionsStubFile
|
|
8228
|
+
? getTypeOfModule(node, '_TypedDict', ['typing_extensions']) ?? prefetched?.typedDictPrivateClass
|
|
8229
|
+
: prefetched?.typedDictPrivateClass;
|
|
8013
8230
|
if (baseClass) {
|
|
8014
8231
|
// The TypedDictFallback class is marked as abstract, but the
|
|
8015
8232
|
// methods that are abstract are overridden and shouldn't
|
|
@@ -8931,6 +9148,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
8931
9148
|
}
|
|
8932
9149
|
// Clear the "partially constructed" flag.
|
|
8933
9150
|
classType.shared.flags &= ~8192 /* ClassTypeFlags.PartiallyEvaluated */;
|
|
9151
|
+
(0, enums_1.synthesizeEnumBoundary)(evaluatorInterface, classType, initSubclassArgs);
|
|
8934
9152
|
// Now determine the decorated type of the class.
|
|
8935
9153
|
let decoratedType = classType;
|
|
8936
9154
|
let isDecoratedTypeUnknown = false;
|
|
@@ -12420,6 +12638,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
12420
12638
|
}
|
|
12421
12639
|
}
|
|
12422
12640
|
if (recursionCount > types_1.maxTypeRecursionCount) {
|
|
12641
|
+
(0, protocols_1.noteAssignTypeRecursionLimit)();
|
|
12423
12642
|
return true;
|
|
12424
12643
|
}
|
|
12425
12644
|
recursionCount++;
|