@zzzen/pyright-internal 1.2.0-dev.20230917 → 1.2.0-dev.20231001

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 (111) hide show
  1. package/dist/analyzer/checker.d.ts +1 -0
  2. package/dist/analyzer/checker.js +64 -4
  3. package/dist/analyzer/checker.js.map +1 -1
  4. package/dist/analyzer/codeFlowEngine.js +8 -1
  5. package/dist/analyzer/codeFlowEngine.js.map +1 -1
  6. package/dist/analyzer/constructors.js +6 -0
  7. package/dist/analyzer/constructors.js.map +1 -1
  8. package/dist/analyzer/decorators.js +5 -2
  9. package/dist/analyzer/decorators.js.map +1 -1
  10. package/dist/analyzer/operations.js +4 -2
  11. package/dist/analyzer/operations.js.map +1 -1
  12. package/dist/analyzer/parseTreeUtils.js +3 -0
  13. package/dist/analyzer/parseTreeUtils.js.map +1 -1
  14. package/dist/analyzer/patternMatching.js +48 -16
  15. package/dist/analyzer/patternMatching.js.map +1 -1
  16. package/dist/analyzer/program.d.ts +2 -3
  17. package/dist/analyzer/program.js +6 -6
  18. package/dist/analyzer/program.js.map +1 -1
  19. package/dist/analyzer/protocols.js +7 -5
  20. package/dist/analyzer/protocols.js.map +1 -1
  21. package/dist/analyzer/service.d.ts +4 -4
  22. package/dist/analyzer/service.js +4 -18
  23. package/dist/analyzer/service.js.map +1 -1
  24. package/dist/analyzer/sourceFile.d.ts +3 -1
  25. package/dist/analyzer/sourceFile.js +9 -5
  26. package/dist/analyzer/sourceFile.js.map +1 -1
  27. package/dist/analyzer/sourceMapper.d.ts +1 -0
  28. package/dist/analyzer/sourceMapper.js +9 -4
  29. package/dist/analyzer/sourceMapper.js.map +1 -1
  30. package/dist/analyzer/typeEvaluator.js +119 -20
  31. package/dist/analyzer/typeEvaluator.js.map +1 -1
  32. package/dist/analyzer/typeEvaluatorTypes.d.ts +3 -1
  33. package/dist/analyzer/typeGuards.d.ts +1 -1
  34. package/dist/analyzer/typeGuards.js +4 -3
  35. package/dist/analyzer/typeGuards.js.map +1 -1
  36. package/dist/analyzer/typeUtils.d.ts +1 -0
  37. package/dist/analyzer/typeUtils.js +21 -2
  38. package/dist/analyzer/typeUtils.js.map +1 -1
  39. package/dist/analyzer/typedDicts.js +20 -16
  40. package/dist/analyzer/typedDicts.js.map +1 -1
  41. package/dist/analyzer/types.d.ts +2 -0
  42. package/dist/analyzer/types.js +11 -2
  43. package/dist/analyzer/types.js.map +1 -1
  44. package/dist/backgroundAnalysisBase.js +1 -23
  45. package/dist/backgroundAnalysisBase.js.map +1 -1
  46. package/dist/common/configOptions.d.ts +1 -0
  47. package/dist/common/configOptions.js +4 -0
  48. package/dist/common/configOptions.js.map +1 -1
  49. package/dist/common/diagnosticRules.d.ts +1 -0
  50. package/dist/common/diagnosticRules.js +1 -0
  51. package/dist/common/diagnosticRules.js.map +1 -1
  52. package/dist/common/extensibility.d.ts +9 -24
  53. package/dist/common/extensibility.js +1 -91
  54. package/dist/common/extensibility.js.map +1 -1
  55. package/dist/common/pathUtils.d.ts +3 -0
  56. package/dist/common/pathUtils.js +14 -9
  57. package/dist/common/pathUtils.js.map +1 -1
  58. package/dist/common/realFileSystem.js +3 -3
  59. package/dist/common/realFileSystem.js.map +1 -1
  60. package/dist/common/serviceProvider.d.ts +23 -4
  61. package/dist/common/serviceProvider.js +92 -7
  62. package/dist/common/serviceProvider.js.map +1 -1
  63. package/dist/common/serviceProviderExtensions.d.ts +4 -1
  64. package/dist/common/serviceProviderExtensions.js +4 -2
  65. package/dist/common/serviceProviderExtensions.js.map +1 -1
  66. package/dist/languageServerBase.js +0 -3
  67. package/dist/languageServerBase.js.map +1 -1
  68. package/dist/languageService/autoImporter.d.ts +4 -1
  69. package/dist/languageService/autoImporter.js +12 -1
  70. package/dist/languageService/autoImporter.js.map +1 -1
  71. package/dist/languageService/definitionProvider.d.ts +3 -2
  72. package/dist/languageService/definitionProvider.js +13 -10
  73. package/dist/languageService/definitionProvider.js.map +1 -1
  74. package/dist/languageService/documentSymbolCollector.js +16 -14
  75. package/dist/languageService/documentSymbolCollector.js.map +1 -1
  76. package/dist/languageService/hoverProvider.js +7 -7
  77. package/dist/languageService/hoverProvider.js.map +1 -1
  78. package/dist/localization/localize.d.ts +8 -1
  79. package/dist/localization/localize.js +4 -1
  80. package/dist/localization/localize.js.map +1 -1
  81. package/dist/localization/package.nls.cs.json +10 -6
  82. package/dist/localization/package.nls.de.json +13 -9
  83. package/dist/localization/package.nls.en-us.json +4 -1
  84. package/dist/localization/package.nls.es.json +10 -6
  85. package/dist/localization/package.nls.fr.json +10 -6
  86. package/dist/localization/package.nls.it.json +10 -6
  87. package/dist/localization/package.nls.ja.json +10 -6
  88. package/dist/localization/package.nls.ko.json +10 -6
  89. package/dist/localization/package.nls.pl.json +9 -5
  90. package/dist/localization/package.nls.pt-br.json +10 -6
  91. package/dist/localization/package.nls.qps-ploc.json +8 -4
  92. package/dist/localization/package.nls.ru.json +9 -5
  93. package/dist/localization/package.nls.tr.json +10 -6
  94. package/dist/localization/package.nls.zh-cn.json +10 -6
  95. package/dist/localization/package.nls.zh-tw.json +10 -6
  96. package/dist/tests/importResolver.test.js +654 -481
  97. package/dist/tests/importResolver.test.js.map +1 -1
  98. package/dist/tests/pathUtils.test.js +64 -4
  99. package/dist/tests/pathUtils.test.js.map +1 -1
  100. package/dist/tests/sourceFile.test.js +2 -1
  101. package/dist/tests/sourceFile.test.js.map +1 -1
  102. package/dist/tests/typeEvaluator1.test.js +2 -2
  103. package/dist/tests/typeEvaluator1.test.js.map +1 -1
  104. package/dist/tests/typeEvaluator2.test.js +3 -1
  105. package/dist/tests/typeEvaluator2.test.js.map +1 -1
  106. package/dist/tests/typeEvaluator3.test.js +7 -1
  107. package/dist/tests/typeEvaluator3.test.js.map +1 -1
  108. package/dist/tests/typeEvaluator4.test.js +5 -0
  109. package/dist/tests/typeEvaluator4.test.js.map +1 -1
  110. package/dist/tests/typeEvaluator5.test.js +1 -1
  111. package/package.json +3 -2
@@ -82,6 +82,7 @@ export declare class Checker extends ParseTreeWalker {
82
82
  private _validateComparisonTypesForIsOperator;
83
83
  private _validateComparisonTypes;
84
84
  private _isTypeComparable;
85
+ private _validateGeneratorReturnType;
85
86
  private _isTypeValidForUnusedValueTest;
86
87
  private _validateFunctionTypeVarUsage;
87
88
  private _validateOverloadConsistency;
@@ -358,6 +358,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
358
358
  // Verify TypeGuard functions.
359
359
  this._validateTypeGuardFunction(node, functionTypeResult.functionType, containingClassNode !== undefined);
360
360
  this._validateFunctionTypeVarUsage(node, functionTypeResult);
361
+ this._validateGeneratorReturnType(node, functionTypeResult.functionType);
361
362
  }
362
363
  // If we're at the module level within a stub file, report a diagnostic
363
364
  // if there is a '__getattr__' function defined when in strict mode.
@@ -723,7 +724,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
723
724
  const baseType = this._evaluator.getType(node.baseExpression);
724
725
  if (baseType) {
725
726
  (0, typeUtils_1.doForEachSubtype)(baseType, (subtype) => {
726
- if ((0, types_1.isClassInstance)(subtype) && subtype.tupleTypeArguments && !(0, typeUtils_1.isUnboundedTupleClass)(subtype)) {
727
+ if ((0, types_1.isClassInstance)(subtype) &&
728
+ subtype.tupleTypeArguments &&
729
+ !(0, typeUtils_1.isUnboundedTupleClass)(subtype) &&
730
+ !this._evaluator.isTypeSubsumedByOtherType(subtype, baseType, /* allowAnyToSubsume */ false)) {
727
731
  const tupleLength = subtype.tupleTypeArguments.length;
728
732
  if (node.items.length === 1 &&
729
733
  !node.trailingComma &&
@@ -1412,6 +1416,49 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
1412
1416
  }
1413
1417
  return true;
1414
1418
  }
1419
+ // If the function is a generator, validates that its annotated return type
1420
+ // is appropriate for a generator.
1421
+ _validateGeneratorReturnType(node, functionType) {
1422
+ var _a;
1423
+ if (!types_1.FunctionType.isGenerator(functionType)) {
1424
+ return;
1425
+ }
1426
+ const declaredReturnType = functionType.details.declaredReturnType;
1427
+ if (!declaredReturnType) {
1428
+ return;
1429
+ }
1430
+ if ((0, types_1.isNever)(declaredReturnType)) {
1431
+ return;
1432
+ }
1433
+ const functionDecl = functionType.details.declaration;
1434
+ if (!functionDecl || !functionDecl.yieldStatements || functionDecl.yieldStatements.length === 0) {
1435
+ return;
1436
+ }
1437
+ let generatorType;
1438
+ if (!node.isAsync &&
1439
+ (0, types_1.isClassInstance)(declaredReturnType) &&
1440
+ types_1.ClassType.isBuiltIn(declaredReturnType, 'AwaitableGenerator')) {
1441
+ // Handle the old-style (pre-await) generator case
1442
+ // if the return type explicitly uses AwaitableGenerator.
1443
+ generatorType = this._evaluator.getTypingType(node, 'AwaitableGenerator');
1444
+ }
1445
+ else {
1446
+ generatorType = this._evaluator.getTypingType(node, node.isAsync ? 'AsyncGenerator' : 'Generator');
1447
+ }
1448
+ if (!generatorType || !(0, types_1.isInstantiableClass)(generatorType)) {
1449
+ return;
1450
+ }
1451
+ const specializedGenerator = types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneForSpecialization(generatorType, [types_1.AnyType.create(), types_1.AnyType.create(), types_1.AnyType.create()],
1452
+ /* isTypeArgumentExplicit */ true));
1453
+ const diagAddendum = new diagnostic_1.DiagnosticAddendum();
1454
+ if (!this._evaluator.assignType(declaredReturnType, specializedGenerator, diagAddendum)) {
1455
+ const errorMessage = node.isAsync
1456
+ ? localize_1.Localizer.Diagnostic.generatorAsyncReturnType()
1457
+ : localize_1.Localizer.Diagnostic.generatorSyncReturnType();
1458
+ this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, errorMessage.format({ yieldType: this._evaluator.printType(types_1.AnyType.create()) }) +
1459
+ diagAddendum.getString(), (_a = node.returnTypeAnnotation) !== null && _a !== void 0 ? _a : node.name);
1460
+ }
1461
+ }
1415
1462
  // Determines whether the specified type is one that should trigger
1416
1463
  // an "unused" value diagnostic.
1417
1464
  _isTypeValidForUnusedValueTest(type) {
@@ -1872,7 +1919,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
1872
1919
  for (const paramList of this._typeParameterLists) {
1873
1920
  for (const param of paramList.parameters) {
1874
1921
  const symbol = AnalyzerNodeInfo.getTypeParameterSymbol(param.name);
1875
- (0, debug_1.assert)(symbol);
1922
+ if (!symbol) {
1923
+ // This can happen if the code is unreachable.
1924
+ return;
1925
+ }
1876
1926
  if (!accessedSymbolSet.has(symbol.id)) {
1877
1927
  const decls = symbol.getDeclarations();
1878
1928
  decls.forEach((decl) => {
@@ -2375,6 +2425,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
2375
2425
  arg0Type = (0, typeUtils_1.mapSubtypes)(arg0Type, (subtype) => {
2376
2426
  return (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(subtype);
2377
2427
  });
2428
+ arg0Type = this._evaluator.expandPromotionTypes(node, arg0Type);
2378
2429
  const arg1Type = this._evaluator.getType(node.arguments[1].valueExpression);
2379
2430
  if (!arg1Type) {
2380
2431
  return;
@@ -2491,7 +2542,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
2491
2542
  const filteredTypes = [];
2492
2543
  for (const filterType of classTypeList) {
2493
2544
  const filterIsSuperclass = (0, typeGuards_1.isIsinstanceFilterSuperclass)(this._evaluator, varType, filterType, filterType, isInstanceCheck);
2494
- const filterIsSubclass = (0, typeGuards_1.isIsinstanceFilterSubclass)(this._evaluator, varType, filterType, filterType, isInstanceCheck);
2545
+ const filterIsSubclass = (0, typeGuards_1.isIsinstanceFilterSubclass)(this._evaluator, varType, filterType, isInstanceCheck);
2495
2546
  // Normally, a class should never be both a subclass and a
2496
2547
  // superclass. However, this can happen if one of the classes
2497
2548
  // derives from an unknown type. In this case, we'll add an
@@ -4126,7 +4177,16 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
4126
4177
  const primaryDecl = decls[0];
4127
4178
  // Verify that the override type is assignable to (same or narrower than)
4128
4179
  // the declared type of the base symbol.
4129
- const isInvariant = (primaryDecl === null || primaryDecl === void 0 ? void 0 : primaryDecl.type) === 1 /* Variable */ && !primaryDecl.isFinal;
4180
+ let isInvariant = (primaryDecl === null || primaryDecl === void 0 ? void 0 : primaryDecl.type) === 1 /* Variable */ && !primaryDecl.isFinal;
4181
+ // If the entry is a member of a frozen dataclass, it is immutable,
4182
+ // so it does not need to be invariant.
4183
+ if (types_1.ClassType.isFrozenDataClass(baseClassAndSymbol.classType) &&
4184
+ baseClassAndSymbol.classType.details.dataClassEntries) {
4185
+ const dataclassEntry = baseClassAndSymbol.classType.details.dataClassEntries.find((entry) => entry.name === memberName);
4186
+ if (dataclassEntry) {
4187
+ isInvariant = false;
4188
+ }
4189
+ }
4130
4190
  let diagAddendum = new diagnostic_1.DiagnosticAddendum();
4131
4191
  if (!this._evaluator.assignType(baseType, overrideType, diagAddendum,
4132
4192
  /* destTypeVarContext */ undefined,