@zzzen/pyright-internal 1.2.0-dev.20230604 → 1.2.0-dev.20230618
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.js +53 -32
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +17 -11
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constructors.js +3 -2
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.js +1 -1
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/importResolver.d.ts +2 -0
- package/dist/analyzer/importResolver.js +57 -35
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/operations.js +2 -0
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/program.d.ts +2 -2
- package/dist/analyzer/program.js +12 -33
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/protocols.d.ts +1 -1
- package/dist/analyzer/protocols.js +225 -205
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/service.d.ts +2 -2
- package/dist/analyzer/service.js +15 -7
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +272 -137
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +5 -2
- package/dist/analyzer/typeEvaluatorTypes.js +2 -0
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +1 -1
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +20 -21
- package/dist/analyzer/typeUtils.js +162 -107
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/types.d.ts +2 -0
- package/dist/analyzer/types.js +7 -3
- package/dist/analyzer/types.js.map +1 -1
- package/dist/backgroundAnalysisBase.d.ts +1 -1
- package/dist/backgroundAnalysisBase.js +2 -2
- package/dist/backgroundAnalysisBase.js.map +1 -1
- package/dist/backgroundThreadBase.d.ts +12 -9
- package/dist/backgroundThreadBase.js +28 -20
- package/dist/backgroundThreadBase.js.map +1 -1
- package/dist/common/charCodes.d.ts +147 -0
- package/dist/common/charCodes.js +164 -0
- package/dist/common/charCodes.js.map +1 -0
- package/dist/common/extensibility.d.ts +6 -2
- package/dist/common/extensibility.js.map +1 -1
- package/dist/common/fileSystem.d.ts +1 -0
- package/dist/common/fileSystem.js.map +1 -1
- package/dist/common/pathUtils.js.map +1 -1
- package/dist/common/realFileSystem.js +3 -0
- package/dist/common/realFileSystem.js.map +1 -1
- package/dist/common/workspaceEditUtils.d.ts +3 -3
- package/dist/common/workspaceEditUtils.js +23 -13
- package/dist/common/workspaceEditUtils.js.map +1 -1
- package/dist/languageServerBase.d.ts +51 -3
- package/dist/languageServerBase.js +5 -5
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/completionProvider.js +2 -0
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/definitionProvider.d.ts +2 -0
- package/dist/languageService/definitionProvider.js +82 -74
- package/dist/languageService/definitionProvider.js.map +1 -1
- package/dist/languageService/hoverProvider.d.ts +16 -8
- package/dist/languageService/hoverProvider.js +53 -53
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/localization/localize.d.ts +7 -6
- package/dist/localization/localize.js +3 -3
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.en-us.json +3 -3
- package/dist/parser/characterStream.js.map +1 -1
- package/dist/parser/characters.js.map +1 -1
- package/dist/parser/parser.js +5 -2
- package/dist/parser/parser.js.map +1 -1
- package/dist/parser/stringTokenUtils.js.map +1 -1
- package/dist/parser/tokenizer.js +10 -1
- package/dist/parser/tokenizer.js.map +1 -1
- package/dist/pyright.js +1 -1
- package/dist/pyright.js.map +1 -1
- package/dist/pyrightFileSystem.d.ts +1 -0
- package/dist/pyrightFileSystem.js +3 -0
- package/dist/pyrightFileSystem.js.map +1 -1
- package/dist/readonlyAugmentedFileSystem.d.ts +1 -0
- package/dist/readonlyAugmentedFileSystem.js +3 -0
- package/dist/readonlyAugmentedFileSystem.js.map +1 -1
- package/dist/tests/checker.test.js +1 -1
- package/dist/tests/harness/fourslash/testLanguageService.d.ts +1 -0
- package/dist/tests/harness/fourslash/testLanguageService.js +3 -0
- package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.js +2 -2
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/harness/vfs/filesystem.d.ts +12 -1
- package/dist/tests/harness/vfs/filesystem.js +33 -6
- package/dist/tests/harness/vfs/filesystem.js.map +1 -1
- package/dist/tests/tokenizer.test.js +13 -2
- package/dist/tests/tokenizer.test.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 +17 -1
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +10 -2
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +1 -1
- package/dist/tests/typeEvaluator5.test.js +1 -1
- package/dist/tests/workspaceEditUtils.test.js +2 -3
- package/dist/tests/workspaceEditUtils.test.js.map +1 -1
- package/dist/workspaceFactory.d.ts +2 -0
- package/dist/workspaceFactory.js +11 -2
- package/dist/workspaceFactory.js.map +1 -1
- package/package.json +1 -2
@@ -9,7 +9,7 @@
|
|
9
9
|
*/
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
11
11
|
exports.lookUpClassMember = exports.lookUpObjectMember = exports.getContainerDepth = exports.getProtocolSymbolsRecursive = exports.getProtocolSymbols = exports.transformExpectedType = exports.validateTypeVarDefault = exports.applyInScopePlaceholders = exports.applySourceContextTypeVarsToSignature = exports.applySourceContextTypeVars = exports.applySolvedTypeVars = exports.ensureFunctionSignaturesAreUnique = exports.populateTypeVarContextForSelfType = exports.partiallySpecializeType = exports.isUnboundedTupleClass = exports.isTupleClass = exports.isMaybeDescriptorInstance = exports.isDescriptorInstance = exports.isCallableType = exports.isProperty = exports.isEllipsisType = exports.getUnionSubtypeCount = exports.getLiteralTypeClassName = exports.containsLiteralType = exports.isLiteralTypeOrUnion = exports.isLiteralType = exports.getSpecializedTupleType = exports.getTypeVarScopeIds = exports.getTypeVarScopeId = exports.transformPossibleRecursiveTypeAlias = exports.isTypeAliasRecursive = exports.isTypeAliasPlaceholder = exports.getTypeCondition = exports.addConditionToType = exports.getFullNameOfType = exports.derivesFromAnyOrUnknown = exports.isUnionableType = exports.preserveUnknown = exports.areTypesSame = exports.doForEachSubtype = exports.sortTypes = exports.mapSubtypes = exports.makeInferenceContext = exports.isTypeVarSame = exports.isIncompleteUnknown = exports.isOptionalType = exports.UniqueSignatureTracker = exports.AssignTypeFlags = exports.ClassIteratorFlags = exports.ClassMemberLookupFlags = void 0;
|
12
|
-
exports.convertParamSpecValueToType = exports.convertTypeToParamSpecValue = exports.getDeclaringModulesForType = exports.computeMroLinearization = exports.isVarianceOfTypeArgumentCompatible = exports.combineVariances = exports.requiresSpecialization = exports.requiresTypeArguments = exports.getGeneratorTypeArgs = exports.removeParamSpecVariadicsFromFunction = exports.removeParamSpecVariadicsFromSignature = exports.
|
12
|
+
exports.convertParamSpecValueToType = exports.convertTypeToParamSpecValue = exports.getDeclaringModulesForType = exports.computeMroLinearization = exports.isVarianceOfTypeArgumentCompatible = exports.combineVariances = exports.requiresSpecialization = exports.requiresTypeArguments = exports.getGeneratorTypeArgs = exports.removeParamSpecVariadicsFromFunction = exports.removeParamSpecVariadicsFromSignature = exports.specializeTupleClass = exports.combineSameSizedTuples = exports.explodeGenericClass = exports.isPartlyUnknown = exports.containsAnyOrUnknown = exports.getMembersForModule = exports.getMembersForClass = exports.convertToInstantiable = exports.convertToInstance = exports.isEffectivelyInstantiable = exports.isMetaclassInstance = exports.isInstantiableMetaclass = exports.getGeneratorYieldType = exports.getDeclaredGeneratorReturnType = exports.synthesizeTypeVarForSelfCls = exports.derivesFromClassRecursive = exports.specializeForBaseClass = exports.buildTypeVarContext = exports.buildTypeVarContextFromSpecializedClass = exports.setTypeArgumentsRecursive = exports.specializeClassType = exports.isTypeVarLimitedToCallable = exports.getTypeVarArgumentsRecursive = exports.addTypeVarsToListIfUnique = exports.getClassFieldsRecursive = exports.getClassIterator = exports.getClassMemberIterator = void 0;
|
13
13
|
const collectionUtils_1 = require("../common/collectionUtils");
|
14
14
|
const debug_1 = require("../common/debug");
|
15
15
|
const symbol_1 = require("./symbol");
|
@@ -43,18 +43,14 @@ var ClassMemberLookupFlags;
|
|
43
43
|
var ClassIteratorFlags;
|
44
44
|
(function (ClassIteratorFlags) {
|
45
45
|
ClassIteratorFlags[ClassIteratorFlags["Default"] = 0] = "Default";
|
46
|
-
// By default, the original (derived) class is searched along
|
47
|
-
// with its base classes. If this flag is set, the original
|
48
|
-
// class is skipped and only the base classes are searched.
|
49
|
-
ClassIteratorFlags[ClassIteratorFlags["SkipOriginalClass"] = 1] = "SkipOriginalClass";
|
50
46
|
// By default, base classes are searched as well as the
|
51
47
|
// original (derived) class. If this flag is set, no recursion
|
52
48
|
// is performed.
|
53
|
-
ClassIteratorFlags[ClassIteratorFlags["SkipBaseClasses"] =
|
49
|
+
ClassIteratorFlags[ClassIteratorFlags["SkipBaseClasses"] = 1] = "SkipBaseClasses";
|
54
50
|
// Skip the 'object' base class in particular.
|
55
|
-
ClassIteratorFlags[ClassIteratorFlags["SkipObjectBaseClass"] =
|
51
|
+
ClassIteratorFlags[ClassIteratorFlags["SkipObjectBaseClass"] = 2] = "SkipObjectBaseClass";
|
56
52
|
// Skip the 'type' base class in particular.
|
57
|
-
ClassIteratorFlags[ClassIteratorFlags["SkipTypeBaseClass"] =
|
53
|
+
ClassIteratorFlags[ClassIteratorFlags["SkipTypeBaseClass"] = 4] = "SkipTypeBaseClass";
|
58
54
|
})(ClassIteratorFlags = exports.ClassIteratorFlags || (exports.ClassIteratorFlags = {}));
|
59
55
|
var AssignTypeFlags;
|
60
56
|
(function (AssignTypeFlags) {
|
@@ -100,22 +96,38 @@ var AssignTypeFlags;
|
|
100
96
|
// employing narrowing or widening, and don't strip literals.
|
101
97
|
AssignTypeFlags[AssignTypeFlags["PopulatingExpectedType"] = 1024] = "PopulatingExpectedType";
|
102
98
|
})(AssignTypeFlags = exports.AssignTypeFlags || (exports.AssignTypeFlags = {}));
|
99
|
+
// Tracks whether a function signature has been seen before within
|
100
|
+
// an expression. For example, in the expression "foo(foo, foo)", the
|
101
|
+
// signature for "foo" will be seen three times at three different
|
102
|
+
// file offsets. If the signature is generic, we need to create unique
|
103
|
+
// type variables for each instance because they are independent of
|
104
|
+
// each other.
|
103
105
|
class UniqueSignatureTracker {
|
104
106
|
constructor() {
|
105
|
-
this.
|
107
|
+
this._signaturesSeen = [];
|
106
108
|
}
|
107
109
|
findSignature(signature) {
|
108
|
-
|
109
|
-
|
110
|
+
// Use the associated overload type if this is a function associated with an overload.
|
111
|
+
let effectiveSignature = signature;
|
112
|
+
if ((0, types_1.isFunction)(signature) && signature.overloaded) {
|
113
|
+
effectiveSignature = signature.overloaded;
|
114
|
+
}
|
115
|
+
return this._signaturesSeen.find((s) => {
|
116
|
+
return (0, types_1.isTypeSame)(effectiveSignature, s.type);
|
110
117
|
});
|
111
118
|
}
|
112
|
-
addSignature(signature) {
|
113
|
-
|
119
|
+
addSignature(signature, offset) {
|
120
|
+
var _a;
|
121
|
+
// If this function is part of a broader overload, use the overload instead.
|
122
|
+
const effectiveSignature = (_a = signature.overloaded) !== null && _a !== void 0 ? _a : signature;
|
123
|
+
const existingSignature = this.findSignature(effectiveSignature);
|
114
124
|
if (existingSignature) {
|
115
|
-
existingSignature.
|
125
|
+
if (!existingSignature.expressionOffsets.some((o) => o === offset)) {
|
126
|
+
existingSignature.expressionOffsets.push(offset);
|
127
|
+
}
|
116
128
|
}
|
117
129
|
else {
|
118
|
-
this.
|
130
|
+
this._signaturesSeen.push({ type: effectiveSignature, expressionOffsets: [offset] });
|
119
131
|
}
|
120
132
|
}
|
121
133
|
}
|
@@ -161,11 +173,11 @@ function isTypeVarSame(type1, type2) {
|
|
161
173
|
return isCompatible;
|
162
174
|
}
|
163
175
|
exports.isTypeVarSame = isTypeVarSame;
|
164
|
-
function makeInferenceContext(expectedType, isTypeIncomplete) {
|
176
|
+
function makeInferenceContext(expectedType, isTypeIncomplete, signatureTracker) {
|
165
177
|
if (!expectedType) {
|
166
178
|
return undefined;
|
167
179
|
}
|
168
|
-
return { expectedType, isTypeIncomplete };
|
180
|
+
return { expectedType, isTypeIncomplete, signatureTracker };
|
169
181
|
}
|
170
182
|
exports.makeInferenceContext = makeInferenceContext;
|
171
183
|
// Calls a callback for each subtype and combines the results
|
@@ -712,7 +724,7 @@ function partiallySpecializeType(type, contextClassType, selfClass, typeClassTyp
|
|
712
724
|
return type;
|
713
725
|
}
|
714
726
|
// Partially specialize the type using the specialized class type vars.
|
715
|
-
const typeVarContext = buildTypeVarContextFromSpecializedClass(contextClassType
|
727
|
+
const typeVarContext = buildTypeVarContextFromSpecializedClass(contextClassType);
|
716
728
|
if (selfClass) {
|
717
729
|
populateTypeVarContextForSelfType(typeVarContext, contextClassType, selfClass);
|
718
730
|
}
|
@@ -726,8 +738,8 @@ function populateTypeVarContextForSelfType(typeVarContext, contextClassType, sel
|
|
726
738
|
exports.populateTypeVarContextForSelfType = populateTypeVarContextForSelfType;
|
727
739
|
// Looks for duplicate function types within the type and ensures that
|
728
740
|
// if they are generic, they have unique type variables.
|
729
|
-
function ensureFunctionSignaturesAreUnique(type, signatureTracker) {
|
730
|
-
const transformer = new UniqueFunctionSignatureTransformer(signatureTracker);
|
741
|
+
function ensureFunctionSignaturesAreUnique(type, signatureTracker, expressionOffset) {
|
742
|
+
const transformer = new UniqueFunctionSignatureTransformer(signatureTracker, expressionOffset);
|
731
743
|
return transformer.apply(type, 0);
|
732
744
|
}
|
733
745
|
exports.ensureFunctionSignaturesAreUnique = ensureFunctionSignaturesAreUnique;
|
@@ -895,18 +907,18 @@ function getContainerDepth(type, recursionCount = 0) {
|
|
895
907
|
return 1 + maxChildDepth;
|
896
908
|
}
|
897
909
|
exports.getContainerDepth = getContainerDepth;
|
898
|
-
function lookUpObjectMember(objectType, memberName, flags = 0 /* Default
|
910
|
+
function lookUpObjectMember(objectType, memberName, flags = 0 /* Default */, skipMroClass) {
|
899
911
|
if ((0, types_1.isClassInstance)(objectType)) {
|
900
|
-
return lookUpClassMember(objectType, memberName, flags);
|
912
|
+
return lookUpClassMember(objectType, memberName, flags, skipMroClass);
|
901
913
|
}
|
902
914
|
return undefined;
|
903
915
|
}
|
904
916
|
exports.lookUpObjectMember = lookUpObjectMember;
|
905
917
|
// Looks up a member in a class using the multiple-inheritance rules
|
906
918
|
// defined by Python.
|
907
|
-
function lookUpClassMember(classType, memberName, flags = 0 /* Default
|
919
|
+
function lookUpClassMember(classType, memberName, flags = 0 /* Default */, skipMroClass) {
|
908
920
|
var _a;
|
909
|
-
const memberItr = getClassMemberIterator(classType, memberName, flags);
|
921
|
+
const memberItr = getClassMemberIterator(classType, memberName, flags, skipMroClass);
|
910
922
|
return (_a = memberItr.next()) === null || _a === void 0 ? void 0 : _a.value;
|
911
923
|
}
|
912
924
|
exports.lookUpClassMember = lookUpClassMember;
|
@@ -918,24 +930,28 @@ exports.lookUpClassMember = lookUpClassMember;
|
|
918
930
|
// ClassB[str] which inherits from Dict[_T1, int], a search for '__iter__'
|
919
931
|
// would return a class type of Dict[str, int] and a symbolType of
|
920
932
|
// (self) -> Iterator[str].
|
921
|
-
|
933
|
+
// If skipMroClass is defined, all MRO classes up to and including that class
|
934
|
+
// are skipped.
|
935
|
+
function* getClassMemberIterator(classType, memberName, flags = 0 /* Default */, skipMroClass) {
|
922
936
|
const declaredTypesOnly = (flags & 16 /* DeclaredTypesOnly */) !== 0;
|
923
937
|
let skippedUndeclaredType = false;
|
924
938
|
if ((0, types_1.isClass)(classType)) {
|
925
939
|
let classFlags = 0 /* Default */;
|
926
940
|
if (flags & 1 /* SkipOriginalClass */) {
|
927
|
-
|
941
|
+
if ((0, types_1.isClass)(classType)) {
|
942
|
+
skipMroClass = classType;
|
943
|
+
}
|
928
944
|
}
|
929
945
|
if (flags & 2 /* SkipBaseClasses */) {
|
930
|
-
classFlags = classFlags |
|
946
|
+
classFlags = classFlags | 1 /* SkipBaseClasses */;
|
931
947
|
}
|
932
948
|
if (flags & 4 /* SkipObjectBaseClass */) {
|
933
|
-
classFlags = classFlags |
|
949
|
+
classFlags = classFlags | 2 /* SkipObjectBaseClass */;
|
934
950
|
}
|
935
951
|
if (flags & 32 /* SkipTypeBaseClass */) {
|
936
|
-
classFlags = classFlags |
|
952
|
+
classFlags = classFlags | 4 /* SkipTypeBaseClass */;
|
937
953
|
}
|
938
|
-
const classItr = getClassIterator(classType, classFlags);
|
954
|
+
const classItr = getClassIterator(classType, classFlags, skipMroClass);
|
939
955
|
for (const [mroClass, specializedMroClass] of classItr) {
|
940
956
|
if (!(0, types_1.isInstantiableClass)(mroClass)) {
|
941
957
|
if (!declaredTypesOnly) {
|
@@ -1035,19 +1051,28 @@ function* getClassMemberIterator(classType, memberName, flags = 0 /* Default */)
|
|
1035
1051
|
return undefined;
|
1036
1052
|
}
|
1037
1053
|
exports.getClassMemberIterator = getClassMemberIterator;
|
1038
|
-
function* getClassIterator(classType, flags = 0 /* Default
|
1054
|
+
function* getClassIterator(classType, flags = 0 /* Default */, skipMroClass) {
|
1039
1055
|
if ((0, types_1.isClass)(classType)) {
|
1040
|
-
let
|
1056
|
+
let foundSkipMroClass = skipMroClass === undefined;
|
1041
1057
|
for (const mroClass of classType.details.mro) {
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1058
|
+
// Are we still searching fro teh skipMroClass?
|
1059
|
+
if (!foundSkipMroClass && skipMroClass) {
|
1060
|
+
if (!(0, types_1.isClass)(mroClass)) {
|
1061
|
+
foundSkipMroClass = true;
|
1062
|
+
}
|
1063
|
+
else if (types_1.ClassType.isSameGenericClass(mroClass, skipMroClass)) {
|
1064
|
+
foundSkipMroClass = true;
|
1065
|
+
continue;
|
1066
|
+
}
|
1067
|
+
else {
|
1068
|
+
continue;
|
1069
|
+
}
|
1045
1070
|
}
|
1046
1071
|
// If mroClass is an ancestor of classType, partially specialize
|
1047
1072
|
// it in the context of classType.
|
1048
1073
|
const specializedMroClass = partiallySpecializeType(mroClass, classType);
|
1049
1074
|
// Should we ignore members on the 'object' base class?
|
1050
|
-
if (flags &
|
1075
|
+
if (flags & 2 /* SkipObjectBaseClass */) {
|
1051
1076
|
if ((0, types_1.isInstantiableClass)(specializedMroClass)) {
|
1052
1077
|
if (types_1.ClassType.isBuiltIn(specializedMroClass, 'object')) {
|
1053
1078
|
break;
|
@@ -1055,7 +1080,7 @@ function* getClassIterator(classType, flags = 0 /* Default */) {
|
|
1055
1080
|
}
|
1056
1081
|
}
|
1057
1082
|
// Should we ignore members on the 'type' base class?
|
1058
|
-
if (flags &
|
1083
|
+
if (flags & 4 /* SkipTypeBaseClass */) {
|
1059
1084
|
if ((0, types_1.isInstantiableClass)(specializedMroClass)) {
|
1060
1085
|
if (types_1.ClassType.isBuiltIn(specializedMroClass, 'type')) {
|
1061
1086
|
break;
|
@@ -1063,7 +1088,7 @@ function* getClassIterator(classType, flags = 0 /* Default */) {
|
|
1063
1088
|
}
|
1064
1089
|
}
|
1065
1090
|
yield [mroClass, specializedMroClass];
|
1066
|
-
if ((flags &
|
1091
|
+
if ((flags & 1 /* SkipBaseClasses */) !== 0) {
|
1067
1092
|
break;
|
1068
1093
|
}
|
1069
1094
|
}
|
@@ -1328,16 +1353,9 @@ exports.setTypeArgumentsRecursive = setTypeArgumentsRecursive;
|
|
1328
1353
|
// types. For example, if the generic type is Dict[_T1, _T2] and the
|
1329
1354
|
// specialized type is Dict[str, int], it returns a map that associates
|
1330
1355
|
// _T1 with str and _T2 with int.
|
1331
|
-
function buildTypeVarContextFromSpecializedClass(classType
|
1356
|
+
function buildTypeVarContextFromSpecializedClass(classType) {
|
1332
1357
|
const typeParameters = types_1.ClassType.getTypeParameters(classType);
|
1333
|
-
|
1334
|
-
// If there are no type arguments, we can either use the type variables
|
1335
|
-
// from the type parameters (keeping the type arguments generic) or
|
1336
|
-
// fill in concrete types.
|
1337
|
-
if (!typeArguments && !makeConcrete) {
|
1338
|
-
typeArguments = typeParameters;
|
1339
|
-
}
|
1340
|
-
const typeVarContext = buildTypeVarContext(typeParameters, typeArguments, getTypeVarScopeId(classType));
|
1358
|
+
const typeVarContext = buildTypeVarContext(typeParameters, classType.typeArguments, getTypeVarScopeId(classType));
|
1341
1359
|
if (types_1.ClassType.isTupleClass(classType) && classType.tupleTypeArguments && typeParameters.length >= 1) {
|
1342
1360
|
typeVarContext.setTupleTypeVar(typeParameters[0], classType.tupleTypeArguments);
|
1343
1361
|
}
|
@@ -1349,7 +1367,7 @@ function buildTypeVarContext(typeParameters, typeArgs, typeVarScopeId) {
|
|
1349
1367
|
typeParameters.forEach((typeParam, index) => {
|
1350
1368
|
let typeArgType;
|
1351
1369
|
if (typeArgs) {
|
1352
|
-
if (
|
1370
|
+
if (typeParam.details.isParamSpec) {
|
1353
1371
|
if (index < typeArgs.length) {
|
1354
1372
|
typeArgType = typeArgs[index];
|
1355
1373
|
if ((0, types_1.isFunction)(typeArgType) && types_1.FunctionType.isParamSpecValue(typeArgType)) {
|
@@ -1692,27 +1710,71 @@ function containsAnyOrUnknown(type, recurse) {
|
|
1692
1710
|
}
|
1693
1711
|
exports.containsAnyOrUnknown = containsAnyOrUnknown;
|
1694
1712
|
// Determines if any part of the type contains "Unknown", including any type arguments.
|
1695
|
-
function
|
1696
|
-
|
1697
|
-
|
1698
|
-
|
1699
|
-
|
1700
|
-
|
1713
|
+
// This function does not use the TypeWalker because it is called very frequently,
|
1714
|
+
// and allocating a memory walker object for every call significantly increases
|
1715
|
+
// peak memory usage.
|
1716
|
+
function isPartlyUnknown(type, allowUnknownTypeArgsForClasses = false, recursionCount = 0) {
|
1717
|
+
var _a, _b;
|
1718
|
+
if (recursionCount > types_1.maxTypeRecursionCount) {
|
1719
|
+
return false;
|
1720
|
+
}
|
1721
|
+
recursionCount++;
|
1722
|
+
if ((0, types_1.isUnknown)(type)) {
|
1723
|
+
return true;
|
1724
|
+
}
|
1725
|
+
// If this is a generic type alias, see if any of its type arguments
|
1726
|
+
// are either unspecified or are partially known.
|
1727
|
+
if ((_a = type.typeAliasInfo) === null || _a === void 0 ? void 0 : _a.typeArguments) {
|
1728
|
+
if (type.typeAliasInfo.typeArguments.some((typeArg) => isPartlyUnknown(typeArg, allowUnknownTypeArgsForClasses, recursionCount))) {
|
1729
|
+
return true;
|
1701
1730
|
}
|
1702
|
-
|
1703
|
-
|
1704
|
-
|
1705
|
-
|
1731
|
+
}
|
1732
|
+
// See if a union contains an unknown type.
|
1733
|
+
if ((0, types_1.isUnion)(type)) {
|
1734
|
+
return ((0, types_1.findSubtype)(type, (subtype) => isPartlyUnknown(subtype, allowUnknownTypeArgsForClasses, recursionCount)) !==
|
1735
|
+
undefined);
|
1736
|
+
}
|
1737
|
+
// See if an object or class has an unknown type argument.
|
1738
|
+
if ((0, types_1.isClass)(type)) {
|
1739
|
+
if (types_1.TypeBase.isInstance(type)) {
|
1740
|
+
allowUnknownTypeArgsForClasses = false;
|
1741
|
+
}
|
1742
|
+
if (!allowUnknownTypeArgsForClasses && !types_1.ClassType.isPseudoGenericClass(type)) {
|
1743
|
+
const typeArgs = ((_b = type.tupleTypeArguments) === null || _b === void 0 ? void 0 : _b.map((t) => t.type)) || type.typeArguments;
|
1744
|
+
if (typeArgs) {
|
1745
|
+
for (const argType of typeArgs) {
|
1746
|
+
if (isPartlyUnknown(argType, allowUnknownTypeArgsForClasses, recursionCount)) {
|
1747
|
+
return true;
|
1748
|
+
}
|
1749
|
+
}
|
1750
|
+
}
|
1706
1751
|
}
|
1707
|
-
|
1708
|
-
|
1709
|
-
|
1752
|
+
return false;
|
1753
|
+
}
|
1754
|
+
// See if a function has an unknown type.
|
1755
|
+
if ((0, types_1.isOverloadedFunction)(type)) {
|
1756
|
+
return types_1.OverloadedFunctionType.getOverloads(type).some((overload) => {
|
1757
|
+
return isPartlyUnknown(overload, /* allowUnknownTypeArgsForClasses */ false, recursionCount);
|
1758
|
+
});
|
1759
|
+
}
|
1760
|
+
if ((0, types_1.isFunction)(type)) {
|
1761
|
+
for (let i = 0; i < type.details.parameters.length; i++) {
|
1762
|
+
// Ignore parameters such as "*" that have no name.
|
1763
|
+
if (type.details.parameters[i].name) {
|
1764
|
+
const paramType = types_1.FunctionType.getEffectiveParameterType(type, i);
|
1765
|
+
if (isPartlyUnknown(paramType, /* allowUnknownTypeArgsForClasses */ false, recursionCount)) {
|
1766
|
+
return true;
|
1767
|
+
}
|
1710
1768
|
}
|
1711
1769
|
}
|
1770
|
+
if (type.details.declaredReturnType &&
|
1771
|
+
!types_1.FunctionType.isParamSpecValue(type) &&
|
1772
|
+
isPartlyUnknown(type.details.declaredReturnType, /* allowUnknownTypeArgsForClasses */ false, recursionCount)) {
|
1773
|
+
return true;
|
1774
|
+
}
|
1775
|
+
return false;
|
1712
1776
|
}
|
1713
|
-
|
1714
|
-
walker.walk(type);
|
1715
|
-
return walker.isPartlyUnknown;
|
1777
|
+
return false;
|
1716
1778
|
}
|
1717
1779
|
exports.isPartlyUnknown = isPartlyUnknown;
|
1718
1780
|
// If the specified type is a generic class with a single type argument
|
@@ -1800,31 +1862,6 @@ function specializeTupleClass(classType, typeArgs, isTypeArgumentExplicit = true
|
|
1800
1862
|
return clonedClassType;
|
1801
1863
|
}
|
1802
1864
|
exports.specializeTupleClass = specializeTupleClass;
|
1803
|
-
// If the array contains two or more class types that are all the same
|
1804
|
-
// generic type, return the common "erased" type — a type that
|
1805
|
-
// replaces all of the type arguments with Unknown.
|
1806
|
-
function getCommonErasedType(types) {
|
1807
|
-
if (types.length < 2) {
|
1808
|
-
return undefined;
|
1809
|
-
}
|
1810
|
-
if (!(0, types_1.isClass)(types[0])) {
|
1811
|
-
return undefined;
|
1812
|
-
}
|
1813
|
-
for (let i = 1; i < types.length; i++) {
|
1814
|
-
const candidate = types[i];
|
1815
|
-
if (!(0, types_1.isClass)(candidate) ||
|
1816
|
-
types_1.TypeBase.isInstance(candidate) !== types_1.TypeBase.isInstance(types[0]) ||
|
1817
|
-
!types_1.ClassType.isSameGenericClass(types[0], candidate)) {
|
1818
|
-
return undefined;
|
1819
|
-
}
|
1820
|
-
}
|
1821
|
-
if (isTupleClass(types[0])) {
|
1822
|
-
return specializeTupleClass(types[0], [{ type: types_1.UnknownType.create(), isUnbounded: true }]);
|
1823
|
-
}
|
1824
|
-
return types_1.ClassType.cloneForSpecialization(types[0], types[0].details.typeParameters.map((t) => types_1.UnknownType.create()),
|
1825
|
-
/* isTypeArgumentExplicit */ true);
|
1826
|
-
}
|
1827
|
-
exports.getCommonErasedType = getCommonErasedType;
|
1828
1865
|
// If the type is a function or overloaded function that has a paramSpec
|
1829
1866
|
// associated with it and P.args and P.kwargs at the end of the signature,
|
1830
1867
|
// it removes these parameters from the function.
|
@@ -2101,7 +2138,7 @@ function computeMroLinearization(classType) {
|
|
2101
2138
|
const classListsToMerge = [];
|
2102
2139
|
filteredBaseClasses.forEach((baseClass) => {
|
2103
2140
|
if ((0, types_1.isInstantiableClass)(baseClass)) {
|
2104
|
-
const typeVarContext = buildTypeVarContextFromSpecializedClass(baseClass
|
2141
|
+
const typeVarContext = buildTypeVarContextFromSpecializedClass(baseClass);
|
2105
2142
|
classListsToMerge.push(baseClass.details.mro.map((mroClass) => {
|
2106
2143
|
return applySolvedTypeVars(mroClass, typeVarContext);
|
2107
2144
|
}));
|
@@ -2111,11 +2148,11 @@ function computeMroLinearization(classType) {
|
|
2111
2148
|
}
|
2112
2149
|
});
|
2113
2150
|
classListsToMerge.push(filteredBaseClasses.map((baseClass) => {
|
2114
|
-
const typeVarContext = buildTypeVarContextFromSpecializedClass(classType
|
2151
|
+
const typeVarContext = buildTypeVarContextFromSpecializedClass(classType);
|
2115
2152
|
return applySolvedTypeVars(baseClass, typeVarContext);
|
2116
2153
|
}));
|
2117
2154
|
// The first class in the MRO is the class itself.
|
2118
|
-
const typeVarContext = buildTypeVarContextFromSpecializedClass(classType
|
2155
|
+
const typeVarContext = buildTypeVarContextFromSpecializedClass(classType);
|
2119
2156
|
classType.details.mro.push(applySolvedTypeVars(classType, typeVarContext));
|
2120
2157
|
// Helper function that returns true if the specified searchClass
|
2121
2158
|
// is found in the "tail" (i.e. in elements 1 through n) of any
|
@@ -2758,9 +2795,18 @@ class TypeVarDefaultValidator extends TypeVarTransformer {
|
|
2758
2795
|
}
|
2759
2796
|
}
|
2760
2797
|
class UniqueFunctionSignatureTransformer extends TypeVarTransformer {
|
2761
|
-
constructor(_signatureTracker) {
|
2798
|
+
constructor(_signatureTracker, _expressionOffset) {
|
2762
2799
|
super();
|
2763
2800
|
this._signatureTracker = _signatureTracker;
|
2801
|
+
this._expressionOffset = _expressionOffset;
|
2802
|
+
}
|
2803
|
+
transformGenericTypeAlias(type, recursionCount) {
|
2804
|
+
// Don't transform type aliases.
|
2805
|
+
return type;
|
2806
|
+
}
|
2807
|
+
transformTypeVarsInClassType(classType, recursionCount) {
|
2808
|
+
// Don't transform classes.
|
2809
|
+
return classType;
|
2764
2810
|
}
|
2765
2811
|
transformTypeVarsInFunctionType(sourceType, recursionCount) {
|
2766
2812
|
// If this function is not generic, there's no need to check for uniqueness.
|
@@ -2771,19 +2817,25 @@ class UniqueFunctionSignatureTransformer extends TypeVarTransformer {
|
|
2771
2817
|
const existingSignature = this._signatureTracker.findSignature(sourceType);
|
2772
2818
|
if (existingSignature) {
|
2773
2819
|
const typeVarContext = new typeVarContext_1.TypeVarContext(getTypeVarScopeId(sourceType));
|
2774
|
-
|
2775
|
-
|
2776
|
-
|
2777
|
-
|
2778
|
-
|
2779
|
-
|
2780
|
-
|
2781
|
-
|
2782
|
-
|
2783
|
-
|
2784
|
-
|
2820
|
+
let offsetIndex = existingSignature.expressionOffsets.findIndex((offset) => offset === this._expressionOffset);
|
2821
|
+
if (offsetIndex < 0) {
|
2822
|
+
offsetIndex = existingSignature.expressionOffsets.length;
|
2823
|
+
}
|
2824
|
+
if (offsetIndex > 0) {
|
2825
|
+
// Create new type variables with the same scope but with
|
2826
|
+
// different (unique) names.
|
2827
|
+
sourceType.details.typeParameters.forEach((typeParam) => {
|
2828
|
+
let replacement = types_1.TypeVarType.cloneForNewName(typeParam, `${typeParam.details.name}(${offsetIndex})`);
|
2829
|
+
if (replacement.details.isParamSpec) {
|
2830
|
+
replacement = convertTypeToParamSpecValue(replacement);
|
2831
|
+
}
|
2832
|
+
typeVarContext.setTypeVarType(typeParam, replacement);
|
2833
|
+
});
|
2834
|
+
updatedSourceType = applySolvedTypeVars(sourceType, typeVarContext);
|
2835
|
+
(0, debug_1.assert)((0, types_1.isFunction)(updatedSourceType) || (0, types_1.isOverloadedFunction)(updatedSourceType));
|
2836
|
+
}
|
2785
2837
|
}
|
2786
|
-
this._signatureTracker.addSignature(sourceType);
|
2838
|
+
this._signatureTracker.addSignature(sourceType, this._expressionOffset);
|
2787
2839
|
return updatedSourceType;
|
2788
2840
|
}
|
2789
2841
|
}
|
@@ -2921,7 +2973,7 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
2921
2973
|
return signatureContext.getTupleTypeVar(typeVar);
|
2922
2974
|
}
|
2923
2975
|
transformParamSpec(paramSpec, recursionCount) {
|
2924
|
-
var _a;
|
2976
|
+
var _a, _b;
|
2925
2977
|
const signatureContext = this._typeVarContext.getSignatureContext((_a = this._activeTypeVarSignatureContextIndex) !== null && _a !== void 0 ? _a : 0);
|
2926
2978
|
// If we're solving a default type, handle param specs with no scope ID.
|
2927
2979
|
if (this._isSolvingDefaultType && !paramSpec.scopeId) {
|
@@ -2945,7 +2997,10 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
2945
2997
|
}
|
2946
2998
|
let useDefaultOrUnknown = false;
|
2947
2999
|
if (this._options.unknownIfNotFound && !this._typeVarContext.hasSolveForScope(types_1.WildcardTypeVarScopeId)) {
|
2948
|
-
|
3000
|
+
const exemptTypeVars = (_b = this._options.unknownExemptTypeVars) !== null && _b !== void 0 ? _b : [];
|
3001
|
+
if (!exemptTypeVars.some((t) => (0, types_1.isTypeSame)(t, paramSpec, { ignoreTypeFlags: true }))) {
|
3002
|
+
useDefaultOrUnknown = true;
|
3003
|
+
}
|
2949
3004
|
}
|
2950
3005
|
else if (this._options.applyInScopePlaceholders && paramSpec.isInScopePlaceholder) {
|
2951
3006
|
useDefaultOrUnknown = true;
|