@zzzen/pyright-internal 1.2.0-dev.20240901 → 1.2.0-dev.20240908
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.js +14 -8
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.js +23 -41
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.js +7 -2
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +2 -2
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constructors.js +7 -1
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.js +6 -1
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/namedTuples.js +4 -1
- package/dist/analyzer/namedTuples.js.map +1 -1
- package/dist/analyzer/operations.js +5 -0
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/parseTreeWalker.js +1 -1
- package/dist/analyzer/parseTreeWalker.js.map +1 -1
- package/dist/analyzer/protocols.js +5 -8
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/sourceMapper.js +2 -1
- package/dist/analyzer/sourceMapper.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +536 -155
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +11 -5
- package/dist/analyzer/typeEvaluatorTypes.js +4 -1
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +11 -8
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.d.ts +2 -1
- package/dist/analyzer/typePrinter.js +24 -4
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +4 -0
- package/dist/analyzer/typeUtils.js +54 -1
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/types.d.ts +8 -4
- package/dist/analyzer/types.js +68 -26
- package/dist/analyzer/types.js.map +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js +0 -1
- package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
- package/dist/languageService/callHierarchyProvider.js +2 -1
- package/dist/languageService/callHierarchyProvider.js.map +1 -1
- package/dist/languageService/completionProvider.js +12 -12
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/definitionProvider.js +6 -6
- package/dist/languageService/definitionProvider.js.map +1 -1
- package/dist/languageService/documentSymbolCollector.js +9 -9
- package/dist/languageService/documentSymbolCollector.js.map +1 -1
- package/dist/languageService/hoverProvider.d.ts +1 -0
- package/dist/languageService/hoverProvider.js +30 -3
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/signatureHelpProvider.js +2 -2
- package/dist/languageService/signatureHelpProvider.js.map +1 -1
- package/dist/languageService/tooltipUtils.js +2 -2
- package/dist/languageService/tooltipUtils.js.map +1 -1
- package/dist/localization/localize.d.ts +2 -0
- package/dist/localization/localize.js +2 -0
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.en-us.json +2 -0
- package/dist/parser/parseNodes.d.ts +2 -3
- package/dist/parser/parseNodes.js.map +1 -1
- package/dist/parser/parser.js +6 -20
- package/dist/parser/parser.js.map +1 -1
- package/dist/tests/checker.test.js +5 -1
- package/dist/tests/checker.test.js.map +1 -1
- package/dist/tests/importStatementUtils.test.js +1 -1
- package/dist/tests/importStatementUtils.test.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +1 -1
- package/dist/tests/typeEvaluator2.test.js +13 -1
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +1 -1
- package/dist/tests/typeEvaluator5.test.js +6 -0
- package/dist/tests/typeEvaluator5.test.js.map +1 -1
- package/dist/tests/typeEvaluator8.test.js +40 -0
- package/dist/tests/typeEvaluator8.test.js.map +1 -1
- package/dist/workspaceFactory.js +7 -7
- package/dist/workspaceFactory.js.map +1 -1
- package/package.json +1 -1
package/dist/analyzer/types.js
CHANGED
@@ -119,6 +119,7 @@ var TypeBase;
|
|
119
119
|
type.props = {
|
120
120
|
instantiableDepth: undefined,
|
121
121
|
specialForm: undefined,
|
122
|
+
typeForm: undefined,
|
122
123
|
typeAliasInfo: undefined,
|
123
124
|
condition: undefined,
|
124
125
|
};
|
@@ -138,6 +139,10 @@ var TypeBase;
|
|
138
139
|
TypeBase.addProps(type).typeAliasInfo = typeAliasInfo;
|
139
140
|
}
|
140
141
|
TypeBase.setTypeAliasInfo = setTypeAliasInfo;
|
142
|
+
function setTypeForm(type, typeForm) {
|
143
|
+
TypeBase.addProps(type).typeForm = typeForm;
|
144
|
+
}
|
145
|
+
TypeBase.setTypeForm = setTypeForm;
|
141
146
|
function setCondition(type, condition) {
|
142
147
|
TypeBase.addProps(type).condition = condition;
|
143
148
|
}
|
@@ -161,10 +166,14 @@ var TypeBase;
|
|
161
166
|
}
|
162
167
|
TypeBase.cloneAsSpecialForm = cloneAsSpecialForm;
|
163
168
|
function cloneTypeAsInstance(type, cache) {
|
164
|
-
var _a;
|
169
|
+
var _a, _b;
|
165
170
|
(0, debug_1.assert)(TypeBase.isInstantiable(type));
|
166
171
|
const newInstance = TypeBase.cloneType(type);
|
167
|
-
|
172
|
+
// Remove type form information from the type.
|
173
|
+
if ((_a = newInstance.props) === null || _a === void 0 ? void 0 : _a.typeForm) {
|
174
|
+
TypeBase.setTypeForm(newInstance, undefined);
|
175
|
+
}
|
176
|
+
const depth = (_b = newInstance.props) === null || _b === void 0 ? void 0 : _b.instantiableDepth;
|
168
177
|
if (depth === undefined) {
|
169
178
|
newInstance.flags &= ~1 /* TypeFlags.Instantiable */;
|
170
179
|
newInstance.flags |= 2 /* TypeFlags.Instance */;
|
@@ -186,7 +195,7 @@ var TypeBase;
|
|
186
195
|
}
|
187
196
|
TypeBase.cloneTypeAsInstance = cloneTypeAsInstance;
|
188
197
|
function cloneTypeAsInstantiable(type, cache) {
|
189
|
-
var _a, _b;
|
198
|
+
var _a, _b, _c;
|
190
199
|
const newInstance = TypeBase.cloneType(type);
|
191
200
|
if (TypeBase.isInstance(type)) {
|
192
201
|
newInstance.flags &= ~2 /* TypeFlags.Instance */;
|
@@ -201,6 +210,10 @@ var TypeBase;
|
|
201
210
|
if ((_b = newInstance.props) === null || _b === void 0 ? void 0 : _b.typeAliasInfo) {
|
202
211
|
TypeBase.setTypeAliasInfo(newInstance, undefined);
|
203
212
|
}
|
213
|
+
// Remove type form information from the type.
|
214
|
+
if ((_c = newInstance.props) === null || _c === void 0 ? void 0 : _c.typeForm) {
|
215
|
+
TypeBase.setTypeForm(newInstance, undefined);
|
216
|
+
}
|
204
217
|
// Should we cache it for next time?
|
205
218
|
if (cache) {
|
206
219
|
if (!type.cached) {
|
@@ -217,6 +230,12 @@ var TypeBase;
|
|
217
230
|
return typeClone;
|
218
231
|
}
|
219
232
|
TypeBase.cloneForTypeAlias = cloneForTypeAlias;
|
233
|
+
function cloneWithTypeForm(type, typeForm) {
|
234
|
+
const typeClone = cloneType(type);
|
235
|
+
TypeBase.setTypeForm(typeClone, typeForm);
|
236
|
+
return typeClone;
|
237
|
+
}
|
238
|
+
TypeBase.cloneWithTypeForm = cloneWithTypeForm;
|
220
239
|
function cloneForCondition(type, condition) {
|
221
240
|
var _a;
|
222
241
|
// Handle the common case where there are no conditions. In this case,
|
@@ -419,9 +438,6 @@ var ClassTypeFlags;
|
|
419
438
|
ClassTypeFlags[ClassTypeFlags["ClassProperty"] = 131072] = "ClassProperty";
|
420
439
|
// Class is declared within a type stub file.
|
421
440
|
ClassTypeFlags[ClassTypeFlags["DefinedInStub"] = 262144] = "DefinedInStub";
|
422
|
-
// Class does not allow writing or deleting its instance variables
|
423
|
-
// through a member access. Used with named tuples.
|
424
|
-
ClassTypeFlags[ClassTypeFlags["ReadOnlyInstanceVariables"] = 524288] = "ReadOnlyInstanceVariables";
|
425
441
|
// Decorated with @type_check_only.
|
426
442
|
ClassTypeFlags[ClassTypeFlags["TypeCheckOnly"] = 1048576] = "TypeCheckOnly";
|
427
443
|
// Created with the NewType call.
|
@@ -822,10 +838,6 @@ var ClassType;
|
|
822
838
|
return !!(classType.shared.flags & 32768 /* ClassTypeFlags.TupleClass */);
|
823
839
|
}
|
824
840
|
ClassType.isTupleClass = isTupleClass;
|
825
|
-
function isReadOnlyInstanceVariables(classType) {
|
826
|
-
return !!(classType.shared.flags & 524288 /* ClassTypeFlags.ReadOnlyInstanceVariables */);
|
827
|
-
}
|
828
|
-
ClassType.isReadOnlyInstanceVariables = isReadOnlyInstanceVariables;
|
829
841
|
function getTypeParams(classType) {
|
830
842
|
return classType.shared.typeParams;
|
831
843
|
}
|
@@ -857,6 +869,13 @@ var ClassType;
|
|
857
869
|
classType.shared.mro.some((mroClass) => isClass(mroClass) && ClassType.isPartiallyEvaluated(mroClass)));
|
858
870
|
}
|
859
871
|
ClassType.isHierarchyPartiallyEvaluated = isHierarchyPartiallyEvaluated;
|
872
|
+
function hasNamedTupleEntry(classType, name) {
|
873
|
+
if (!classType.shared.namedTupleEntries) {
|
874
|
+
return false;
|
875
|
+
}
|
876
|
+
return classType.shared.namedTupleEntries.has(name);
|
877
|
+
}
|
878
|
+
ClassType.hasNamedTupleEntry = hasNamedTupleEntry;
|
860
879
|
// Same as isTypeSame except that it doesn't compare type arguments.
|
861
880
|
function isSameGenericClass(classType, type2, recursionCount = 0) {
|
862
881
|
if (!classType.priv.isTypedDictPartial !== !type2.priv.isTypedDictPartial) {
|
@@ -1556,6 +1575,9 @@ var OverloadedType;
|
|
1556
1575
|
overloads.forEach((overload) => {
|
1557
1576
|
OverloadedType.addOverload(newType, overload);
|
1558
1577
|
});
|
1578
|
+
if (implementation && isFunction(implementation)) {
|
1579
|
+
implementation.priv.overloaded = newType;
|
1580
|
+
}
|
1559
1581
|
return newType;
|
1560
1582
|
}
|
1561
1583
|
OverloadedType.create = create;
|
@@ -1601,9 +1623,9 @@ var NeverType;
|
|
1601
1623
|
}
|
1602
1624
|
NeverType.createNoReturn = createNoReturn;
|
1603
1625
|
function convertToInstance(type) {
|
1604
|
-
var _a;
|
1605
|
-
// Remove the
|
1606
|
-
if (!((_a = type.props) === null || _a === void 0 ? void 0 : _a.specialForm)) {
|
1626
|
+
var _a, _b;
|
1627
|
+
// Remove the specialForm or typeForm if present. Otherwise return the existing type.
|
1628
|
+
if (!((_a = type.props) === null || _a === void 0 ? void 0 : _a.specialForm) && !((_b = type.props) === null || _b === void 0 ? void 0 : _b.typeForm)) {
|
1607
1629
|
return type;
|
1608
1630
|
}
|
1609
1631
|
return type.priv.isNoReturn ? NeverType.createNoReturn() : NeverType.createNever();
|
@@ -1793,7 +1815,7 @@ var UnionType;
|
|
1793
1815
|
// Determines whether the union contains a specified subtype. If exclusionSet is passed,
|
1794
1816
|
// the method skips any subtype indexes that are in the set and adds a found index to
|
1795
1817
|
// the exclusion set. This speeds up union type comparisons.
|
1796
|
-
function containsType(unionType, subtype, exclusionSet, recursionCount = 0) {
|
1818
|
+
function containsType(unionType, subtype, options = {}, exclusionSet, recursionCount = 0) {
|
1797
1819
|
var _a;
|
1798
1820
|
// Handle string literals as a special case because unions can sometimes
|
1799
1821
|
// contain hundreds of string literal types.
|
@@ -1816,7 +1838,7 @@ var UnionType;
|
|
1816
1838
|
if (exclusionSet === null || exclusionSet === void 0 ? void 0 : exclusionSet.has(i)) {
|
1817
1839
|
return false;
|
1818
1840
|
}
|
1819
|
-
return isTypeSame(t, subtype,
|
1841
|
+
return isTypeSame(t, subtype, options, recursionCount);
|
1820
1842
|
});
|
1821
1843
|
if (foundIndex < 0) {
|
1822
1844
|
return false;
|
@@ -1912,18 +1934,19 @@ var TypeVarType;
|
|
1912
1934
|
}
|
1913
1935
|
TypeVarType.cloneAsInstantiable = cloneAsInstantiable;
|
1914
1936
|
function cloneForNewName(type, name) {
|
1937
|
+
var _a;
|
1915
1938
|
const newInstance = TypeBase.cloneType(type);
|
1916
1939
|
newInstance.shared = { ...type.shared };
|
1917
1940
|
newInstance.shared.name = name;
|
1918
1941
|
if (newInstance.priv.scopeId) {
|
1919
|
-
newInstance.priv.nameWithScope = makeNameWithScope(name, newInstance.priv.scopeId);
|
1942
|
+
newInstance.priv.nameWithScope = makeNameWithScope(name, newInstance.priv.scopeId, (_a = newInstance.priv.scopeName) !== null && _a !== void 0 ? _a : '');
|
1920
1943
|
}
|
1921
1944
|
return newInstance;
|
1922
1945
|
}
|
1923
1946
|
TypeVarType.cloneForNewName = cloneForNewName;
|
1924
1947
|
function cloneForScopeId(type, scopeId, scopeName, scopeType) {
|
1925
1948
|
const newInstance = TypeBase.cloneType(type);
|
1926
|
-
newInstance.priv.nameWithScope = makeNameWithScope(type.shared.name, scopeId);
|
1949
|
+
newInstance.priv.nameWithScope = makeNameWithScope(type.shared.name, scopeId, scopeName !== null && scopeName !== void 0 ? scopeName : '');
|
1927
1950
|
newInstance.priv.scopeId = scopeId;
|
1928
1951
|
newInstance.priv.scopeName = scopeName;
|
1929
1952
|
newInstance.priv.scopeType = scopeType;
|
@@ -2006,8 +2029,12 @@ var TypeVarType;
|
|
2006
2029
|
return newInstance;
|
2007
2030
|
}
|
2008
2031
|
TypeVarType.cloneAsUnificationVar = cloneAsUnificationVar;
|
2009
|
-
function makeNameWithScope(name, scopeId) {
|
2010
|
-
|
2032
|
+
function makeNameWithScope(name, scopeId, scopeName) {
|
2033
|
+
// We include the scopeName here even though it's normally already part
|
2034
|
+
// of the scopeId. There are cases where it can diverge, specifically
|
2035
|
+
// in scenarios involving higher-order functions that return generic
|
2036
|
+
// callable types. See adjustCallableReturnType for details.
|
2037
|
+
return `${name}.${scopeId}.${scopeName}`;
|
2011
2038
|
}
|
2012
2039
|
TypeVarType.makeNameWithScope = makeNameWithScope;
|
2013
2040
|
function makeBoundScopeId(scopeId) {
|
@@ -2203,7 +2230,7 @@ function getTypeAliasInfo(type) {
|
|
2203
2230
|
// type arguments for "pseudo-generic" classes (non-generic classes whose init
|
2204
2231
|
// methods are not annotated and are therefore treated as generic) are ignored.
|
2205
2232
|
function isTypeSame(type1, type2, options = {}, recursionCount = 0) {
|
2206
|
-
var _a, _b, _c, _d, _e, _f;
|
2233
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
2207
2234
|
if (type1 === type2) {
|
2208
2235
|
return true;
|
2209
2236
|
}
|
@@ -2227,6 +2254,21 @@ function isTypeSame(type1, type2, options = {}, recursionCount = 0) {
|
|
2227
2254
|
return true;
|
2228
2255
|
}
|
2229
2256
|
recursionCount++;
|
2257
|
+
if (options.honorTypeForm) {
|
2258
|
+
const typeForm1 = (_a = type1.props) === null || _a === void 0 ? void 0 : _a.typeForm;
|
2259
|
+
const typeForm2 = (_b = type2.props) === null || _b === void 0 ? void 0 : _b.typeForm;
|
2260
|
+
if (typeForm1) {
|
2261
|
+
if (!typeForm2) {
|
2262
|
+
return false;
|
2263
|
+
}
|
2264
|
+
if (!isTypeSame(typeForm1, typeForm2, options, recursionCount)) {
|
2265
|
+
return false;
|
2266
|
+
}
|
2267
|
+
}
|
2268
|
+
else if (typeForm2) {
|
2269
|
+
return false;
|
2270
|
+
}
|
2271
|
+
}
|
2230
2272
|
switch (type1.category) {
|
2231
2273
|
case 6 /* TypeCategory.Class */: {
|
2232
2274
|
const classType2 = type2;
|
@@ -2234,7 +2276,7 @@ function isTypeSame(type1, type2, options = {}, recursionCount = 0) {
|
|
2234
2276
|
if (!ClassType.isSameGenericClass(type1, classType2, recursionCount)) {
|
2235
2277
|
return false;
|
2236
2278
|
}
|
2237
|
-
if (!options.ignoreConditions && !TypeCondition.isSame((
|
2279
|
+
if (!options.ignoreConditions && !TypeCondition.isSame((_c = type1.props) === null || _c === void 0 ? void 0 : _c.condition, (_d = type2.props) === null || _d === void 0 ? void 0 : _d.condition)) {
|
2238
2280
|
return false;
|
2239
2281
|
}
|
2240
2282
|
if (!options.ignorePseudoGeneric || !ClassType.isPseudoGenericClass(type1)) {
|
@@ -2374,7 +2416,7 @@ function isTypeSame(type1, type2, options = {}, recursionCount = 0) {
|
|
2374
2416
|
// The types do not have a particular order, so we need to
|
2375
2417
|
// do the comparison in an order-independent manner.
|
2376
2418
|
const exclusionSet = new Set();
|
2377
|
-
return (findSubtype(type1, (subtype) => !UnionType.containsType(unionType2, subtype, exclusionSet, recursionCount)) === undefined);
|
2419
|
+
return (findSubtype(type1, (subtype) => !UnionType.containsType(unionType2, subtype, options, exclusionSet, recursionCount)) === undefined);
|
2378
2420
|
}
|
2379
2421
|
case 9 /* TypeCategory.TypeVar */: {
|
2380
2422
|
const type2TypeVar = type2;
|
@@ -2384,8 +2426,8 @@ function isTypeSame(type1, type2, options = {}, recursionCount = 0) {
|
|
2384
2426
|
// Handle the case where this is a generic recursive type alias. Make
|
2385
2427
|
// sure that the type argument types match.
|
2386
2428
|
if (type1.shared.recursiveAlias && type2TypeVar.shared.recursiveAlias) {
|
2387
|
-
const type1TypeArgs = ((
|
2388
|
-
const type2TypeArgs = ((
|
2429
|
+
const type1TypeArgs = ((_f = (_e = type1 === null || type1 === void 0 ? void 0 : type1.props) === null || _e === void 0 ? void 0 : _e.typeAliasInfo) === null || _f === void 0 ? void 0 : _f.typeArgs) || [];
|
2430
|
+
const type2TypeArgs = ((_h = (_g = type2 === null || type2 === void 0 ? void 0 : type2.props) === null || _g === void 0 ? void 0 : _g.typeAliasInfo) === null || _h === void 0 ? void 0 : _h.typeArgs) || [];
|
2389
2431
|
const typeArgCount = Math.max(type1TypeArgs.length, type2TypeArgs.length);
|
2390
2432
|
for (let i = 0; i < typeArgCount; i++) {
|
2391
2433
|
// Assume that missing type args are "Any".
|
@@ -2662,7 +2704,7 @@ function _addTypeIfUnique(unionType, typeToAdd, elideRedundantLiterals) {
|
|
2662
2704
|
for (let i = 0; i < unionType.priv.subtypes.length; i++) {
|
2663
2705
|
const type = unionType.priv.subtypes[i];
|
2664
2706
|
// Does this type already exist in the types array?
|
2665
|
-
if (isTypeSame(type, typeToAdd)) {
|
2707
|
+
if (isTypeSame(type, typeToAdd, { honorTypeForm: true })) {
|
2666
2708
|
return;
|
2667
2709
|
}
|
2668
2710
|
// Handle the case where pseudo-generic classes with different
|
@@ -2672,7 +2714,7 @@ function _addTypeIfUnique(unionType, typeToAdd, elideRedundantLiterals) {
|
|
2672
2714
|
// we can hit recursive cases (where a pseudo-generic class is
|
2673
2715
|
// parameterized with its own class) ad infinitum.
|
2674
2716
|
if (isPseudoGeneric) {
|
2675
|
-
if (isTypeSame(type, typeToAdd, { ignorePseudoGeneric: true })) {
|
2717
|
+
if (isTypeSame(type, typeToAdd, { ignorePseudoGeneric: true, honorTypeForm: true })) {
|
2676
2718
|
unionType.priv.subtypes[i] = ClassType.specialize(typeToAdd, typeToAdd.shared.typeParams.map(() => UnknownType.create()));
|
2677
2719
|
return;
|
2678
2720
|
}
|