@zzzen/pyright-internal 1.2.0-dev.20240825 → 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.
Files changed (97) hide show
  1. package/dist/analyzer/binder.js +14 -8
  2. package/dist/analyzer/binder.js.map +1 -1
  3. package/dist/analyzer/checker.js +25 -45
  4. package/dist/analyzer/checker.js.map +1 -1
  5. package/dist/analyzer/codeFlowEngine.js +7 -2
  6. package/dist/analyzer/codeFlowEngine.js.map +1 -1
  7. package/dist/analyzer/constraintSolution.js.map +1 -1
  8. package/dist/analyzer/constraintSolver.js +3 -2
  9. package/dist/analyzer/constraintSolver.js.map +1 -1
  10. package/dist/analyzer/constructors.js +8 -2
  11. package/dist/analyzer/constructors.js.map +1 -1
  12. package/dist/analyzer/dataClasses.js +6 -1
  13. package/dist/analyzer/dataClasses.js.map +1 -1
  14. package/dist/analyzer/namedTuples.js +4 -1
  15. package/dist/analyzer/namedTuples.js.map +1 -1
  16. package/dist/analyzer/operations.js +63 -53
  17. package/dist/analyzer/operations.js.map +1 -1
  18. package/dist/analyzer/parseTreeWalker.js +1 -1
  19. package/dist/analyzer/parseTreeWalker.js.map +1 -1
  20. package/dist/analyzer/protocols.js +5 -8
  21. package/dist/analyzer/protocols.js.map +1 -1
  22. package/dist/analyzer/sourceMapper.js +2 -1
  23. package/dist/analyzer/sourceMapper.js.map +1 -1
  24. package/dist/analyzer/typeEvaluator.js +783 -322
  25. package/dist/analyzer/typeEvaluator.js.map +1 -1
  26. package/dist/analyzer/typeEvaluatorTypes.d.ts +11 -5
  27. package/dist/analyzer/typeEvaluatorTypes.js +4 -1
  28. package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
  29. package/dist/analyzer/typeGuards.js +11 -8
  30. package/dist/analyzer/typeGuards.js.map +1 -1
  31. package/dist/analyzer/typePrinter.d.ts +2 -1
  32. package/dist/analyzer/typePrinter.js +144 -119
  33. package/dist/analyzer/typePrinter.js.map +1 -1
  34. package/dist/analyzer/typeUtils.d.ts +6 -2
  35. package/dist/analyzer/typeUtils.js +71 -17
  36. package/dist/analyzer/typeUtils.js.map +1 -1
  37. package/dist/analyzer/types.d.ts +9 -5
  38. package/dist/analyzer/types.js +68 -26
  39. package/dist/analyzer/types.js.map +1 -1
  40. package/dist/commands/dumpFileDebugInfoCommand.js +0 -1
  41. package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
  42. package/dist/common/configOptions.js +3 -3
  43. package/dist/common/configOptions.js.map +1 -1
  44. package/dist/languageService/callHierarchyProvider.js +2 -1
  45. package/dist/languageService/callHierarchyProvider.js.map +1 -1
  46. package/dist/languageService/completionProvider.js +12 -12
  47. package/dist/languageService/completionProvider.js.map +1 -1
  48. package/dist/languageService/definitionProvider.js +6 -6
  49. package/dist/languageService/definitionProvider.js.map +1 -1
  50. package/dist/languageService/documentSymbolCollector.js +9 -9
  51. package/dist/languageService/documentSymbolCollector.js.map +1 -1
  52. package/dist/languageService/hoverProvider.d.ts +1 -0
  53. package/dist/languageService/hoverProvider.js +30 -3
  54. package/dist/languageService/hoverProvider.js.map +1 -1
  55. package/dist/languageService/signatureHelpProvider.js +2 -2
  56. package/dist/languageService/signatureHelpProvider.js.map +1 -1
  57. package/dist/languageService/tooltipUtils.js +2 -2
  58. package/dist/languageService/tooltipUtils.js.map +1 -1
  59. package/dist/localization/localize.d.ts +2 -0
  60. package/dist/localization/localize.js +2 -0
  61. package/dist/localization/localize.js.map +1 -1
  62. package/dist/localization/package.nls.cs.json +4 -4
  63. package/dist/localization/package.nls.de.json +4 -4
  64. package/dist/localization/package.nls.en-us.json +27 -25
  65. package/dist/localization/package.nls.es.json +4 -4
  66. package/dist/localization/package.nls.fr.json +4 -4
  67. package/dist/localization/package.nls.it.json +4 -4
  68. package/dist/localization/package.nls.ja.json +4 -4
  69. package/dist/localization/package.nls.ko.json +4 -4
  70. package/dist/localization/package.nls.pl.json +4 -4
  71. package/dist/localization/package.nls.pt-br.json +4 -4
  72. package/dist/localization/package.nls.ru.json +4 -4
  73. package/dist/localization/package.nls.tr.json +4 -4
  74. package/dist/localization/package.nls.zh-cn.json +4 -4
  75. package/dist/localization/package.nls.zh-tw.json +4 -4
  76. package/dist/parser/parseNodes.d.ts +2 -3
  77. package/dist/parser/parseNodes.js.map +1 -1
  78. package/dist/parser/parser.js +6 -20
  79. package/dist/parser/parser.js.map +1 -1
  80. package/dist/tests/checker.test.js +5 -1
  81. package/dist/tests/checker.test.js.map +1 -1
  82. package/dist/tests/importStatementUtils.test.js +1 -1
  83. package/dist/tests/importStatementUtils.test.js.map +1 -1
  84. package/dist/tests/typeEvaluator1.test.js +1 -1
  85. package/dist/tests/typeEvaluator2.test.js +15 -3
  86. package/dist/tests/typeEvaluator2.test.js.map +1 -1
  87. package/dist/tests/typeEvaluator3.test.js +1 -1
  88. package/dist/tests/typeEvaluator4.test.js +1 -1
  89. package/dist/tests/typeEvaluator5.test.js +6 -0
  90. package/dist/tests/typeEvaluator5.test.js.map +1 -1
  91. package/dist/tests/typeEvaluator6.test.js +34 -36
  92. package/dist/tests/typeEvaluator6.test.js.map +1 -1
  93. package/dist/tests/typeEvaluator8.test.js +40 -0
  94. package/dist/tests/typeEvaluator8.test.js.map +1 -1
  95. package/dist/workspaceFactory.js +7 -7
  96. package/dist/workspaceFactory.js.map +1 -1
  97. package/package.json +5 -5
@@ -36,7 +36,6 @@ exports.isTypeAliasRecursive = isTypeAliasRecursive;
36
36
  exports.transformPossibleRecursiveTypeAlias = transformPossibleRecursiveTypeAlias;
37
37
  exports.getTypeVarScopeId = getTypeVarScopeId;
38
38
  exports.getTypeVarScopeIds = getTypeVarScopeIds;
39
- exports.specializeWithDefaultTypeArgs = specializeWithDefaultTypeArgs;
40
39
  exports.specializeWithUnknownTypeArgs = specializeWithUnknownTypeArgs;
41
40
  exports.getUnknownForTypeVar = getUnknownForTypeVar;
42
41
  exports.getUnknownForTypeVarTuple = getUnknownForTypeVarTuple;
@@ -45,8 +44,11 @@ exports.selfSpecializeClass = selfSpecializeClass;
45
44
  exports.getSpecializedTupleType = getSpecializedTupleType;
46
45
  exports.isLiteralType = isLiteralType;
47
46
  exports.isLiteralTypeOrUnion = isLiteralTypeOrUnion;
47
+ exports.isLiteralLikeType = isLiteralLikeType;
48
48
  exports.containsLiteralType = containsLiteralType;
49
49
  exports.getLiteralTypeClassName = getLiteralTypeClassName;
50
+ exports.stripTypeForm = stripTypeForm;
51
+ exports.stripTypeFormRecursive = stripTypeFormRecursive;
50
52
  exports.getUnionSubtypeCount = getUnionSubtypeCount;
51
53
  exports.isEllipsisType = isEllipsisType;
52
54
  exports.isProperty = isProperty;
@@ -72,11 +74,12 @@ exports.getContainerDepth = getContainerDepth;
72
74
  exports.lookUpObjectMember = lookUpObjectMember;
73
75
  exports.lookUpClassMember = lookUpClassMember;
74
76
  exports.getClassMemberIterator = getClassMemberIterator;
77
+ exports.isMemberReadOnly = isMemberReadOnly;
75
78
  exports.getClassIterator = getClassIterator;
76
79
  exports.getClassFieldsRecursive = getClassFieldsRecursive;
77
80
  exports.addTypeVarsToListIfUnique = addTypeVarsToListIfUnique;
78
81
  exports.getTypeVarArgsRecursive = getTypeVarArgsRecursive;
79
- exports.specializeClassType = specializeClassType;
82
+ exports.specializeWithDefaultTypeArgs = specializeWithDefaultTypeArgs;
80
83
  exports.buildSolutionFromSpecializedClass = buildSolutionFromSpecializedClass;
81
84
  exports.buildSolution = buildSolution;
82
85
  exports.specializeForBaseClass = specializeForBaseClass;
@@ -689,6 +692,11 @@ function preserveUnknown(type1, type2) {
689
692
  // Determines whether the specified type is a type that can be
690
693
  // combined with other types for a union.
691
694
  function isUnionableType(subtypes) {
695
+ // If all of the subtypes are TypeForm types, we know that they
696
+ // are unionable.
697
+ if (subtypes.every((t) => { var _a; return ((_a = t.props) === null || _a === void 0 ? void 0 : _a.typeForm) !== undefined; })) {
698
+ return true;
699
+ }
692
700
  let typeFlags = 2 /* TypeFlags.Instance */ | 1 /* TypeFlags.Instantiable */;
693
701
  for (const subtype of subtypes) {
694
702
  typeFlags &= subtype.flags;
@@ -871,17 +879,6 @@ function getTypeVarScopeIds(type) {
871
879
  }
872
880
  return scopeIds;
873
881
  }
874
- // If the class type is generic and does not already have type arguments
875
- // specified, specialize it with default type arguments (Unknown or the
876
- // default type if provided).
877
- function specializeWithDefaultTypeArgs(type) {
878
- if (type.shared.typeParams.length === 0 || type.priv.typeArgs) {
879
- return type;
880
- }
881
- return types_1.ClassType.specialize(type, type.shared.typeParams.map((param) => param.shared.defaultType),
882
- /* isTypeArgExplicit */ false,
883
- /* includeSubclasses */ type.priv.includeSubclasses);
884
- }
885
882
  // Specializes the class with "Unknown" type args (or the equivalent for ParamSpecs
886
883
  // or TypeVarTuples).
887
884
  function specializeWithUnknownTypeArgs(type, tupleClassType) {
@@ -982,6 +979,15 @@ function isLiteralTypeOrUnion(type, allowNone = false) {
982
979
  }
983
980
  return false;
984
981
  }
982
+ function isLiteralLikeType(type) {
983
+ if (type.priv.literalValue !== undefined) {
984
+ return true;
985
+ }
986
+ if (types_1.ClassType.isBuiltIn(type, 'LiteralString')) {
987
+ return true;
988
+ }
989
+ return false;
990
+ }
985
991
  function containsLiteralType(type, includeTypeArgs = false) {
986
992
  class ContainsLiteralTypeWalker extends typeWalker_1.TypeWalker {
987
993
  constructor(_includeTypeArgs) {
@@ -991,7 +997,7 @@ function containsLiteralType(type, includeTypeArgs = false) {
991
997
  }
992
998
  visitClass(classType) {
993
999
  if ((0, types_1.isClassInstance)(classType)) {
994
- if (isLiteralType(classType) || types_1.ClassType.isBuiltIn(classType, 'LiteralString')) {
1000
+ if (isLiteralLikeType(classType)) {
995
1001
  this.foundLiteral = true;
996
1002
  this.cancelWalk();
997
1003
  }
@@ -1032,6 +1038,24 @@ function getLiteralTypeClassName(type) {
1032
1038
  }
1033
1039
  return undefined;
1034
1040
  }
1041
+ function stripTypeForm(type) {
1042
+ var _a;
1043
+ if ((_a = type.props) === null || _a === void 0 ? void 0 : _a.typeForm) {
1044
+ return types_1.TypeBase.cloneWithTypeForm(type, undefined);
1045
+ }
1046
+ return type;
1047
+ }
1048
+ function stripTypeFormRecursive(type, recursionCount = 0) {
1049
+ var _a;
1050
+ if (recursionCount > types_1.maxTypeRecursionCount) {
1051
+ return type;
1052
+ }
1053
+ recursionCount++;
1054
+ if ((_a = type.props) === null || _a === void 0 ? void 0 : _a.typeForm) {
1055
+ type = types_1.TypeBase.cloneWithTypeForm(type, undefined);
1056
+ }
1057
+ return mapSubtypes(type, (subtype) => stripTypeFormRecursive(subtype, recursionCount));
1058
+ }
1035
1059
  function getUnionSubtypeCount(type) {
1036
1060
  if ((0, types_1.isUnion)(type)) {
1037
1061
  return type.priv.subtypes.length;
@@ -1250,6 +1274,7 @@ function getProtocolSymbolsRecursive(classType, symbolMap, classFlags = 512 /* C
1250
1274
  isInstanceMember: symbol.isInstanceMember(),
1251
1275
  isClassMember: symbol.isClassMember(),
1252
1276
  isClassVar: (0, symbolUtils_1.isEffectivelyClassVar)(symbol, /* isDataclass */ false),
1277
+ isReadOnly: false,
1253
1278
  isTypeDeclared: symbol.hasTypedDeclarations(),
1254
1279
  skippedUndeclaredType: false,
1255
1280
  });
@@ -1360,6 +1385,7 @@ function* getClassMemberIterator(classType, memberName, flags = 0 /* MemberAcces
1360
1385
  isClassVar: false,
1361
1386
  classType,
1362
1387
  unspecializedClassType: classType,
1388
+ isReadOnly: false,
1363
1389
  isTypeDeclared: false,
1364
1390
  skippedUndeclaredType: false,
1365
1391
  };
@@ -1384,6 +1410,7 @@ function* getClassMemberIterator(classType, memberName, flags = 0 /* MemberAcces
1384
1410
  isClassVar: (0, symbolUtils_1.isEffectivelyClassVar)(symbol, types_1.ClassType.isDataClass(specializedMroClass)),
1385
1411
  classType: specializedMroClass,
1386
1412
  unspecializedClassType: mroClass,
1413
+ isReadOnly: isMemberReadOnly(specializedMroClass, memberName),
1387
1414
  isTypeDeclared: hasDeclaredType,
1388
1415
  skippedUndeclaredType,
1389
1416
  };
@@ -1423,6 +1450,7 @@ function* getClassMemberIterator(classType, memberName, flags = 0 /* MemberAcces
1423
1450
  isClassVar: (0, symbolUtils_1.isEffectivelyClassVar)(symbol, isDataclass),
1424
1451
  classType: specializedMroClass,
1425
1452
  unspecializedClassType: mroClass,
1453
+ isReadOnly: false,
1426
1454
  isTypeDeclared: hasDeclaredType,
1427
1455
  skippedUndeclaredType,
1428
1456
  };
@@ -1445,6 +1473,7 @@ function* getClassMemberIterator(classType, memberName, flags = 0 /* MemberAcces
1445
1473
  isClassVar: false,
1446
1474
  classType,
1447
1475
  unspecializedClassType: classType,
1476
+ isReadOnly: false,
1448
1477
  isTypeDeclared: false,
1449
1478
  skippedUndeclaredType: false,
1450
1479
  };
@@ -1452,6 +1481,21 @@ function* getClassMemberIterator(classType, memberName, flags = 0 /* MemberAcces
1452
1481
  }
1453
1482
  return undefined;
1454
1483
  }
1484
+ // Checks for whether the member is effectively read only because it
1485
+ // belongs to a frozen dataclass or a named tuple.
1486
+ function isMemberReadOnly(classType, name) {
1487
+ var _a;
1488
+ if (types_1.ClassType.hasNamedTupleEntry(classType, name)) {
1489
+ return true;
1490
+ }
1491
+ if (types_1.ClassType.isDataClassFrozen(classType)) {
1492
+ const dcEntries = (_a = classType.shared) === null || _a === void 0 ? void 0 : _a.dataClassEntries;
1493
+ if (dcEntries === null || dcEntries === void 0 ? void 0 : dcEntries.some((entry) => entry.name === name)) {
1494
+ return true;
1495
+ }
1496
+ }
1497
+ return false;
1498
+ }
1455
1499
  function* getClassIterator(classType, flags = 0 /* ClassIteratorFlags.Default */, skipMroClass) {
1456
1500
  if ((0, types_1.isClass)(classType)) {
1457
1501
  let foundSkipMroClass = skipMroClass === undefined;
@@ -1511,6 +1555,7 @@ function getClassFieldsRecursive(classType) {
1511
1555
  isInstanceMember: symbol.isInstanceMember(),
1512
1556
  isClassMember: symbol.isClassMember(),
1513
1557
  isClassVar: (0, symbolUtils_1.isEffectivelyClassVar)(symbol, types_1.ClassType.isDataClass(specializedMroClass)),
1558
+ isReadOnly: isMemberReadOnly(specializedMroClass, name),
1514
1559
  isTypeDeclared: true,
1515
1560
  skippedUndeclaredType: false,
1516
1561
  });
@@ -1598,8 +1643,11 @@ function getTypeVarArgsRecursive(type, recursionCount = 0) {
1598
1643
  return [];
1599
1644
  }
1600
1645
  // Creates a specialized version of the class, filling in any unspecified
1601
- // type arguments with Unknown.
1602
- function specializeClassType(type) {
1646
+ // type arguments with Unknown or default value.
1647
+ function specializeWithDefaultTypeArgs(type) {
1648
+ if (type.shared.typeParams.length === 0 || type.priv.typeArgs) {
1649
+ return type;
1650
+ }
1603
1651
  const solution = new constraintSolution_1.ConstraintSolution();
1604
1652
  const typeParams = types_1.ClassType.getTypeParams(type);
1605
1653
  typeParams.forEach((typeParam) => {
@@ -1679,8 +1727,9 @@ function synthesizeTypeVarForSelfCls(classType, isClsParam) {
1679
1727
  const scopeId = (_a = getTypeVarScopeId(classType)) !== null && _a !== void 0 ? _a : '';
1680
1728
  selfType.shared.isSynthesized = true;
1681
1729
  selfType.shared.isSynthesizedSelf = true;
1682
- selfType.priv.nameWithScope = types_1.TypeVarType.makeNameWithScope(selfType.shared.name, scopeId);
1683
1730
  selfType.priv.scopeId = scopeId;
1731
+ selfType.priv.scopeName = '';
1732
+ selfType.priv.nameWithScope = types_1.TypeVarType.makeNameWithScope(selfType.shared.name, scopeId, selfType.priv.scopeName);
1684
1733
  const boundType = types_1.ClassType.specialize(classType,
1685
1734
  /* typeArgs */ undefined,
1686
1735
  /* isTypeArgExplicit */ false,
@@ -3283,6 +3332,11 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
3283
3332
  if (solutionSets.length <= 1) {
3284
3333
  return callback();
3285
3334
  }
3335
+ // Handle the case where we're already processing one of the signature contexts
3336
+ // and are called recursively. Don't loop over all the signature contexts again.
3337
+ if (this._activeConstraintSetIndex !== undefined) {
3338
+ return callback();
3339
+ }
3286
3340
  // Loop through all of the signature contexts in the type var context
3287
3341
  // to create an overload type.
3288
3342
  const overloadTypes = solutionSets.map((_, index) => {