@zzzen/pyright-internal 1.2.0-dev.20230903 → 1.2.0-dev.20230910
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 +39 -14
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +5 -0
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constructors.js +16 -7
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/declarationUtils.js +2 -0
- package/dist/analyzer/declarationUtils.js.map +1 -1
- package/dist/analyzer/decorators.js +16 -1
- package/dist/analyzer/decorators.js.map +1 -1
- package/dist/analyzer/importResolver.js +4 -7
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/parentDirectoryCache.js +1 -1
- package/dist/analyzer/parentDirectoryCache.js.map +1 -1
- package/dist/analyzer/program.d.ts +2 -2
- package/dist/analyzer/program.js +30 -24
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/pythonPathUtils.js +10 -8
- package/dist/analyzer/pythonPathUtils.js.map +1 -1
- package/dist/analyzer/service.js +14 -12
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/typeDocStringUtils.js +1 -1
- package/dist/analyzer/typeEvaluator.js +162 -102
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +9 -8
- package/dist/analyzer/typeEvaluatorTypes.js +11 -8
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +38 -6
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +6 -4
- package/dist/analyzer/typeUtils.js +81 -54
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/types.d.ts +1 -0
- package/dist/analyzer/types.js +8 -0
- package/dist/analyzer/types.js.map +1 -1
- package/dist/common/configOptions.js +2 -2
- package/dist/common/configOptions.js.map +1 -1
- package/dist/common/extensibility.d.ts +6 -0
- package/dist/common/extensibility.js.map +1 -1
- package/dist/common/pathUtils.d.ts +2 -15
- package/dist/common/pathUtils.js +9 -84
- package/dist/common/pathUtils.js.map +1 -1
- package/dist/common/realFileSystem.js +22 -13
- package/dist/common/realFileSystem.js.map +1 -1
- package/dist/languageServerBase.d.ts +1 -1
- package/dist/languageServerBase.js +2 -2
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/completionProvider.d.ts +3 -2
- package/dist/languageService/completionProvider.js +12 -6
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/localization/localize.d.ts +9 -0
- package/dist/localization/localize.js +7 -0
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +8 -2
- package/dist/localization/package.nls.de.json +8 -2
- package/dist/localization/package.nls.en-us.json +9 -3
- package/dist/localization/package.nls.es.json +8 -2
- package/dist/localization/package.nls.fr.json +8 -2
- package/dist/localization/package.nls.it.json +8 -2
- package/dist/localization/package.nls.ja.json +8 -2
- package/dist/localization/package.nls.ko.json +8 -2
- package/dist/localization/package.nls.pl.json +8 -2
- package/dist/localization/package.nls.pt-br.json +8 -2
- package/dist/localization/package.nls.qps-ploc.json +8 -2
- package/dist/localization/package.nls.ru.json +8 -2
- package/dist/localization/package.nls.tr.json +8 -2
- package/dist/localization/package.nls.zh-cn.json +8 -2
- package/dist/localization/package.nls.zh-tw.json +8 -2
- package/dist/server.js +2 -1
- package/dist/server.js.map +1 -1
- package/dist/tests/checker.test.js +2 -2
- package/dist/tests/completions.test.js +27 -0
- package/dist/tests/completions.test.js.map +1 -1
- package/dist/tests/config.test.js +5 -5
- package/dist/tests/config.test.js.map +1 -1
- package/dist/tests/fourslash/completions.dictionary.keys.complex.fourslash.js +5 -5
- package/dist/tests/fourslash/completions.dictionary.keys.complex.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.dictionary.keys.expression.fourslash.js +11 -9
- package/dist/tests/fourslash/completions.dictionary.keys.expression.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.dictionary.keys.literalTypes.fourslash.js +14 -14
- package/dist/tests/fourslash/completions.dictionary.keys.literalTypes.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.dictionary.keys.simple.fourslash.js +12 -12
- package/dist/tests/fourslash/completions.dictionary.keys.simple.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.dictionary.keys.stringLiterals.fourslash.js +9 -9
- package/dist/tests/fourslash/completions.dictionary.keys.stringLiterals.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.dictionary.keys.symbols.fourslash.js +3 -3
- package/dist/tests/fourslash/completions.dictionary.keys.symbols.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.fstring.stringLiteral.fourslash.js +3 -3
- package/dist/tests/fourslash/completions.fstring.stringLiteral.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.indexer.keys.getitem.fourslash.js +4 -4
- package/dist/tests/fourslash/completions.indexer.keys.getitem.fourslash.js.map +1 -1
- package/dist/tests/fourslash/diagnostics.missingModuleSource.fourslash.js +8 -8
- package/dist/tests/fourslash/diagnostics.missingModuleSource.fourslash.js.map +1 -1
- package/dist/tests/fourslash/fourslash.d.ts +1 -0
- package/dist/tests/fourslash/importnotresolved.fourslash.js +2 -2
- package/dist/tests/fourslash/importnotresolved.fourslash.js.map +1 -1
- package/dist/tests/fourslash/missingModuleSource.fourslash.js +1 -1
- package/dist/tests/fourslash/missingModuleSource.fourslash.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.Consts.d.ts +1 -0
- package/dist/tests/harness/fourslash/testState.Consts.js +2 -0
- package/dist/tests/harness/fourslash/testState.Consts.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.js +4 -1
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/harness/vfs/filesystem.js +10 -6
- package/dist/tests/harness/vfs/filesystem.js.map +1 -1
- package/dist/tests/pathUtils.test.js +13 -21
- package/dist/tests/pathUtils.test.js.map +1 -1
- package/dist/tests/testState.test.js +1 -1
- package/dist/tests/testState.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +5 -1
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +4 -0
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator5.test.js +1 -1
- package/dist/workspaceFactory.js +8 -14
- package/dist/workspaceFactory.js.map +1 -1
- package/package.json +1 -1
@@ -33,12 +33,15 @@ var ClassMemberLookupFlags;
|
|
33
33
|
// By default, both class and instance variables are searched.
|
34
34
|
// If this flag is set, the instance variables are skipped.
|
35
35
|
ClassMemberLookupFlags[ClassMemberLookupFlags["SkipInstanceVariables"] = 8] = "SkipInstanceVariables";
|
36
|
+
// By default, both class and instance variables are searched.
|
37
|
+
// If this flag is set, the class variables are skipped.
|
38
|
+
ClassMemberLookupFlags[ClassMemberLookupFlags["SkipClassVariables"] = 16] = "SkipClassVariables";
|
36
39
|
// By default, the first symbol is returned even if it has only
|
37
40
|
// an inferred type associated with it. If this flag is set,
|
38
41
|
// the search looks only for symbols with declared types.
|
39
|
-
ClassMemberLookupFlags[ClassMemberLookupFlags["DeclaredTypesOnly"] =
|
42
|
+
ClassMemberLookupFlags[ClassMemberLookupFlags["DeclaredTypesOnly"] = 32] = "DeclaredTypesOnly";
|
40
43
|
// Skip the 'type' base class in particular.
|
41
|
-
ClassMemberLookupFlags[ClassMemberLookupFlags["SkipTypeBaseClass"] =
|
44
|
+
ClassMemberLookupFlags[ClassMemberLookupFlags["SkipTypeBaseClass"] = 64] = "SkipTypeBaseClass";
|
42
45
|
})(ClassMemberLookupFlags = exports.ClassMemberLookupFlags || (exports.ClassMemberLookupFlags = {}));
|
43
46
|
var ClassIteratorFlags;
|
44
47
|
(function (ClassIteratorFlags) {
|
@@ -100,6 +103,10 @@ var AssignTypeFlags;
|
|
100
103
|
// default type arguments (typically "Unknown"). This flag skips
|
101
104
|
// this step.
|
102
105
|
AssignTypeFlags[AssignTypeFlags["AllowUnspecifiedTypeArguments"] = 2048] = "AllowUnspecifiedTypeArguments";
|
106
|
+
// PEP 544 says that if the dest type is a type[Proto] class,
|
107
|
+
// the source must be a "concrete" (non-protocol) class. This
|
108
|
+
// flag skips this check.
|
109
|
+
AssignTypeFlags[AssignTypeFlags["IgnoreProtocolAssignmentCheck"] = 4096] = "IgnoreProtocolAssignmentCheck";
|
103
110
|
})(AssignTypeFlags = exports.AssignTypeFlags || (exports.AssignTypeFlags = {}));
|
104
111
|
// Tracks whether a function signature has been seen before within
|
105
112
|
// an expression. For example, in the expression "foo(foo, foo)", the
|
@@ -198,14 +205,15 @@ exports.makeInferenceContext = makeInferenceContext;
|
|
198
205
|
// Calls a callback for each subtype and combines the results
|
199
206
|
// into a final type. It performs no memory allocations if the
|
200
207
|
// transformed type is the same as the original.
|
201
|
-
function mapSubtypes(type, callback) {
|
208
|
+
function mapSubtypes(type, callback, sortSubtypes = false) {
|
202
209
|
if ((0, types_1.isUnion)(type)) {
|
203
|
-
|
204
|
-
|
210
|
+
const subtypes = sortSubtypes ? sortTypes(type.subtypes) : type.subtypes;
|
211
|
+
for (let i = 0; i < subtypes.length; i++) {
|
212
|
+
const subtype = subtypes[i];
|
205
213
|
const transformedType = callback(subtype);
|
206
214
|
// Avoid doing any memory allocations until a change is detected.
|
207
215
|
if (subtype !== transformedType) {
|
208
|
-
const typesToCombine =
|
216
|
+
const typesToCombine = subtypes.slice(0, i);
|
209
217
|
// Create a helper lambda that accumulates transformed subtypes.
|
210
218
|
const accumulateSubtype = (newSubtype) => {
|
211
219
|
if (newSubtype) {
|
@@ -213,8 +221,8 @@ function mapSubtypes(type, callback) {
|
|
213
221
|
}
|
214
222
|
};
|
215
223
|
accumulateSubtype(transformedType);
|
216
|
-
for (i++; i <
|
217
|
-
accumulateSubtype(callback(
|
224
|
+
for (i++; i < subtypes.length; i++) {
|
225
|
+
accumulateSubtype(callback(subtypes[i]));
|
218
226
|
}
|
219
227
|
const newType = (0, types_1.combineTypes)(typesToCombine);
|
220
228
|
// Do our best to retain type aliases.
|
@@ -240,8 +248,12 @@ function sortTypes(types) {
|
|
240
248
|
});
|
241
249
|
}
|
242
250
|
exports.sortTypes = sortTypes;
|
243
|
-
function compareTypes(a, b) {
|
251
|
+
function compareTypes(a, b, recursionCount = 0) {
|
244
252
|
var _a, _b;
|
253
|
+
if (recursionCount > types_1.maxTypeRecursionCount) {
|
254
|
+
return 0;
|
255
|
+
}
|
256
|
+
recursionCount++;
|
245
257
|
if (a.category !== b.category) {
|
246
258
|
return b.category - a.category;
|
247
259
|
}
|
@@ -331,7 +343,29 @@ function compareTypes(a, b) {
|
|
331
343
|
// Sort by class name.
|
332
344
|
const aName = a.details.name;
|
333
345
|
const bName = b.details.name;
|
334
|
-
|
346
|
+
if (aName < bName) {
|
347
|
+
return -1;
|
348
|
+
}
|
349
|
+
else if (aName > bName) {
|
350
|
+
return 1;
|
351
|
+
}
|
352
|
+
// Sort by type argument count.
|
353
|
+
const aTypeArgCount = a.typeArguments ? a.typeArguments.length : 0;
|
354
|
+
const bTypeArgCount = bClass.typeArguments ? bClass.typeArguments.length : 0;
|
355
|
+
if (aTypeArgCount < bTypeArgCount) {
|
356
|
+
return -1;
|
357
|
+
}
|
358
|
+
else if (aTypeArgCount > bTypeArgCount) {
|
359
|
+
return 1;
|
360
|
+
}
|
361
|
+
// Sort by type argument.
|
362
|
+
for (let i = 0; i < aTypeArgCount; i++) {
|
363
|
+
const typeComparison = compareTypes(a.typeArguments[i], bClass.typeArguments[i], recursionCount);
|
364
|
+
if (typeComparison !== 0) {
|
365
|
+
return typeComparison;
|
366
|
+
}
|
367
|
+
}
|
368
|
+
return 0;
|
335
369
|
}
|
336
370
|
case 8 /* Module */: {
|
337
371
|
const aName = a.moduleName;
|
@@ -991,7 +1025,7 @@ exports.lookUpClassMember = lookUpClassMember;
|
|
991
1025
|
// If skipMroClass is defined, all MRO classes up to and including that class
|
992
1026
|
// are skipped.
|
993
1027
|
function* getClassMemberIterator(classType, memberName, flags = 0 /* Default */, skipMroClass) {
|
994
|
-
const declaredTypesOnly = (flags &
|
1028
|
+
const declaredTypesOnly = (flags & 32 /* DeclaredTypesOnly */) !== 0;
|
995
1029
|
let skippedUndeclaredType = false;
|
996
1030
|
if ((0, types_1.isClass)(classType)) {
|
997
1031
|
let classFlags = 0 /* Default */;
|
@@ -1006,7 +1040,7 @@ function* getClassMemberIterator(classType, memberName, flags = 0 /* Default */,
|
|
1006
1040
|
if (flags & 4 /* SkipObjectBaseClass */) {
|
1007
1041
|
classFlags = classFlags | 2 /* SkipObjectBaseClass */;
|
1008
1042
|
}
|
1009
|
-
if (flags &
|
1043
|
+
if (flags & 64 /* SkipTypeBaseClass */) {
|
1010
1044
|
classFlags = classFlags | 4 /* SkipTypeBaseClass */;
|
1011
1045
|
}
|
1012
1046
|
const classItr = getClassIterator(classType, classFlags, skipMroClass);
|
@@ -1055,39 +1089,41 @@ function* getClassMemberIterator(classType, memberName, flags = 0 /* Default */,
|
|
1055
1089
|
}
|
1056
1090
|
}
|
1057
1091
|
// Next look at class members.
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1092
|
+
if ((flags & 16 /* SkipClassVariables */) === 0) {
|
1093
|
+
const symbol = memberFields.get(memberName);
|
1094
|
+
if (symbol && symbol.isClassMember()) {
|
1095
|
+
const hasDeclaredType = symbol.hasTypedDeclarations();
|
1096
|
+
if (!declaredTypesOnly || hasDeclaredType) {
|
1097
|
+
let isInstanceMember = symbol.isInstanceMember();
|
1098
|
+
let isClassMember = true;
|
1099
|
+
// For data classes and typed dicts, variables that are declared
|
1100
|
+
// within the class are treated as instance variables. This distinction
|
1101
|
+
// is important in cases where a variable is a callable type because
|
1102
|
+
// we don't want to bind it to the instance like we would for a
|
1103
|
+
// class member.
|
1104
|
+
const isDataclass = types_1.ClassType.isDataClass(specializedMroClass);
|
1105
|
+
const isTypedDict = types_1.ClassType.isTypedDictClass(specializedMroClass);
|
1106
|
+
if (hasDeclaredType && (isDataclass || isTypedDict)) {
|
1107
|
+
const decls = symbol.getDeclarations();
|
1108
|
+
if (decls.length > 0 && decls[0].type === 1 /* Variable */) {
|
1109
|
+
isInstanceMember = true;
|
1110
|
+
isClassMember = isDataclass;
|
1111
|
+
}
|
1076
1112
|
}
|
1113
|
+
const cm = {
|
1114
|
+
symbol,
|
1115
|
+
isInstanceMember,
|
1116
|
+
isClassMember,
|
1117
|
+
isClassVar: symbol.isClassVar(),
|
1118
|
+
classType: specializedMroClass,
|
1119
|
+
isTypeDeclared: hasDeclaredType,
|
1120
|
+
skippedUndeclaredType,
|
1121
|
+
};
|
1122
|
+
yield cm;
|
1123
|
+
}
|
1124
|
+
else {
|
1125
|
+
skippedUndeclaredType = true;
|
1077
1126
|
}
|
1078
|
-
const cm = {
|
1079
|
-
symbol,
|
1080
|
-
isInstanceMember,
|
1081
|
-
isClassMember,
|
1082
|
-
isClassVar: symbol.isClassVar(),
|
1083
|
-
classType: specializedMroClass,
|
1084
|
-
isTypeDeclared: hasDeclaredType,
|
1085
|
-
skippedUndeclaredType,
|
1086
|
-
};
|
1087
|
-
yield cm;
|
1088
|
-
}
|
1089
|
-
else {
|
1090
|
-
skippedUndeclaredType = true;
|
1091
1127
|
}
|
1092
1128
|
}
|
1093
1129
|
}
|
@@ -1335,7 +1371,8 @@ function specializeClassType(type) {
|
|
1335
1371
|
const typeVarContext = new typeVarContext_1.TypeVarContext(getTypeVarScopeId(type));
|
1336
1372
|
const typeParams = types_1.ClassType.getTypeParameters(type);
|
1337
1373
|
typeParams.forEach((typeParam) => {
|
1338
|
-
|
1374
|
+
var _a;
|
1375
|
+
typeVarContext.setTypeVarType(typeParam, applySolvedTypeVars((_a = typeParam.details.defaultType) !== null && _a !== void 0 ? _a : types_1.UnknownType.create(), typeVarContext));
|
1339
1376
|
});
|
1340
1377
|
return applySolvedTypeVars(type, typeVarContext);
|
1341
1378
|
}
|
@@ -2958,16 +2995,6 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
2958
2995
|
// don't transform that type variable.
|
2959
2996
|
if (typeVar.scopeId && this._typeVarContext.hasSolveForScope(typeVar.scopeId)) {
|
2960
2997
|
let replacement = signatureContext.getTypeVarType(typeVar, !!this._options.useNarrowBoundOnly);
|
2961
|
-
// If the type is unknown, see if there's a known wide bound that we can use.
|
2962
|
-
if (replacement &&
|
2963
|
-
(0, types_1.isUnknown)(replacement) &&
|
2964
|
-
!this._options.useNarrowBoundOnly &&
|
2965
|
-
this._options.unknownIfNotFound) {
|
2966
|
-
const entry = signatureContext.getTypeVar(typeVar);
|
2967
|
-
if (entry === null || entry === void 0 ? void 0 : entry.wideBound) {
|
2968
|
-
replacement = entry === null || entry === void 0 ? void 0 : entry.wideBound;
|
2969
|
-
}
|
2970
|
-
}
|
2971
2998
|
// If there was no narrow bound but there is a wide bound that
|
2972
2999
|
// contains literals or a TypeVar, we'll use the wide bound even if
|
2973
3000
|
// "useNarrowBoundOnly" is specified.
|