@zzzen/pyright-internal 1.2.0-dev.20230924 → 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 (89) hide show
  1. package/dist/analyzer/checker.js +4 -1
  2. package/dist/analyzer/checker.js.map +1 -1
  3. package/dist/analyzer/codeFlowEngine.js +7 -0
  4. package/dist/analyzer/codeFlowEngine.js.map +1 -1
  5. package/dist/analyzer/decorators.js +3 -0
  6. package/dist/analyzer/decorators.js.map +1 -1
  7. package/dist/analyzer/operations.js +4 -2
  8. package/dist/analyzer/operations.js.map +1 -1
  9. package/dist/analyzer/patternMatching.js +47 -16
  10. package/dist/analyzer/patternMatching.js.map +1 -1
  11. package/dist/analyzer/program.d.ts +2 -3
  12. package/dist/analyzer/program.js +6 -6
  13. package/dist/analyzer/program.js.map +1 -1
  14. package/dist/analyzer/service.d.ts +4 -4
  15. package/dist/analyzer/service.js +4 -18
  16. package/dist/analyzer/service.js.map +1 -1
  17. package/dist/analyzer/sourceFile.d.ts +3 -1
  18. package/dist/analyzer/sourceFile.js +9 -5
  19. package/dist/analyzer/sourceFile.js.map +1 -1
  20. package/dist/analyzer/typeEvaluator.js +64 -11
  21. package/dist/analyzer/typeEvaluator.js.map +1 -1
  22. package/dist/analyzer/typeUtils.d.ts +1 -0
  23. package/dist/analyzer/typeUtils.js +21 -2
  24. package/dist/analyzer/typeUtils.js.map +1 -1
  25. package/dist/analyzer/types.d.ts +1 -1
  26. package/dist/analyzer/types.js +6 -3
  27. package/dist/analyzer/types.js.map +1 -1
  28. package/dist/backgroundAnalysisBase.js +0 -22
  29. package/dist/backgroundAnalysisBase.js.map +1 -1
  30. package/dist/common/configOptions.d.ts +1 -0
  31. package/dist/common/configOptions.js +4 -0
  32. package/dist/common/configOptions.js.map +1 -1
  33. package/dist/common/diagnosticRules.d.ts +1 -0
  34. package/dist/common/diagnosticRules.js +1 -0
  35. package/dist/common/diagnosticRules.js.map +1 -1
  36. package/dist/common/extensibility.d.ts +9 -24
  37. package/dist/common/extensibility.js +1 -91
  38. package/dist/common/extensibility.js.map +1 -1
  39. package/dist/common/pathUtils.d.ts +3 -0
  40. package/dist/common/pathUtils.js +13 -8
  41. package/dist/common/pathUtils.js.map +1 -1
  42. package/dist/common/realFileSystem.js +1 -1
  43. package/dist/common/realFileSystem.js.map +1 -1
  44. package/dist/common/serviceProvider.d.ts +22 -3
  45. package/dist/common/serviceProvider.js +89 -9
  46. package/dist/common/serviceProvider.js.map +1 -1
  47. package/dist/common/serviceProviderExtensions.d.ts +4 -1
  48. package/dist/common/serviceProviderExtensions.js +4 -2
  49. package/dist/common/serviceProviderExtensions.js.map +1 -1
  50. package/dist/languageServerBase.js +0 -3
  51. package/dist/languageServerBase.js.map +1 -1
  52. package/dist/languageService/definitionProvider.d.ts +3 -2
  53. package/dist/languageService/definitionProvider.js +13 -10
  54. package/dist/languageService/definitionProvider.js.map +1 -1
  55. package/dist/languageService/documentSymbolCollector.js +16 -14
  56. package/dist/languageService/documentSymbolCollector.js.map +1 -1
  57. package/dist/languageService/hoverProvider.js +7 -7
  58. package/dist/languageService/hoverProvider.js.map +1 -1
  59. package/dist/localization/localize.d.ts +8 -1
  60. package/dist/localization/localize.js +4 -1
  61. package/dist/localization/localize.js.map +1 -1
  62. package/dist/localization/package.nls.cs.json +4 -1
  63. package/dist/localization/package.nls.de.json +4 -1
  64. package/dist/localization/package.nls.en-us.json +4 -1
  65. package/dist/localization/package.nls.es.json +4 -1
  66. package/dist/localization/package.nls.fr.json +4 -1
  67. package/dist/localization/package.nls.it.json +4 -1
  68. package/dist/localization/package.nls.ja.json +4 -1
  69. package/dist/localization/package.nls.ko.json +4 -1
  70. package/dist/localization/package.nls.pl.json +4 -1
  71. package/dist/localization/package.nls.pt-br.json +4 -1
  72. package/dist/localization/package.nls.qps-ploc.json +4 -1
  73. package/dist/localization/package.nls.ru.json +4 -1
  74. package/dist/localization/package.nls.tr.json +4 -1
  75. package/dist/localization/package.nls.zh-cn.json +4 -1
  76. package/dist/localization/package.nls.zh-tw.json +4 -1
  77. package/dist/tests/importResolver.test.js +654 -481
  78. package/dist/tests/importResolver.test.js.map +1 -1
  79. package/dist/tests/pathUtils.test.js +39 -1
  80. package/dist/tests/pathUtils.test.js.map +1 -1
  81. package/dist/tests/sourceFile.test.js +2 -1
  82. package/dist/tests/sourceFile.test.js.map +1 -1
  83. package/dist/tests/typeEvaluator2.test.js +3 -1
  84. package/dist/tests/typeEvaluator2.test.js.map +1 -1
  85. package/dist/tests/typeEvaluator3.test.js +7 -1
  86. package/dist/tests/typeEvaluator3.test.js.map +1 -1
  87. package/dist/tests/typeEvaluator4.test.js +1 -0
  88. package/dist/tests/typeEvaluator4.test.js.map +1 -1
  89. package/package.json +3 -2
@@ -103,6 +103,7 @@ const nonSubscriptableBuiltinTypes = new Map([
103
103
  const typePromotions = new Map([
104
104
  ['builtins.float', ['builtins.int']],
105
105
  ['builtins.complex', ['builtins.float', 'builtins.int']],
106
+ ['builtins.bytes', ['builtins.bytearray', 'builtins.memoryview']],
106
107
  ]);
107
108
  // How many levels deep should we attempt to infer return
108
109
  // types based on call-site argument types? The deeper we go,
@@ -391,6 +392,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
391
392
  }
392
393
  }
393
394
  }
395
+ if (type) {
396
+ type = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(type);
397
+ }
394
398
  return type;
395
399
  }
396
400
  function getTypeResult(node) {
@@ -658,6 +662,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
658
662
  if (expectingInstantiable) {
659
663
  validateTypeIsInstantiable(typeResult, flags, node);
660
664
  }
665
+ // Should we disable type promotions for bytes?
666
+ if ((0, types_1.isInstantiableClass)(typeResult.type) &&
667
+ typeResult.type.includePromotions &&
668
+ !typeResult.type.includeSubclasses &&
669
+ types_1.ClassType.isBuiltIn(typeResult.type, 'bytes')) {
670
+ if (AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.disableBytesTypePromotions) {
671
+ typeResult = {
672
+ ...typeResult,
673
+ type: types_1.ClassType.cloneRemoveTypePromotions(typeResult.type),
674
+ };
675
+ }
676
+ }
661
677
  writeTypeCache(node, typeResult, flags, inferenceContext, /* allowSpeculativeCaching */ true);
662
678
  // If there was an expected type, make sure that the result type is compatible.
663
679
  if (inferenceContext &&
@@ -928,6 +944,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
928
944
  type: getBuiltInObject(node, isBytes ? 'bytes' : 'str'),
929
945
  isIncomplete,
930
946
  };
947
+ if ((0, types_1.isClass)(typeResult.type) && typeResult.type.includePromotions) {
948
+ typeResult.type = types_1.ClassType.cloneRemoveTypePromotions(typeResult.type);
949
+ }
931
950
  }
932
951
  }
933
952
  else {
@@ -1294,7 +1313,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1294
1313
  !types_1.ClassType.isBuiltIn(metaclass, 'type') &&
1295
1314
  !types_1.ClassType.isSameGenericClass(metaclass, classType)) {
1296
1315
  const metaclassMemberInfo = getTypeOfClassMemberName(errorNode, metaclass,
1297
- /* isAccessedThroughObject */ false, memberName, usage, metaclassDiag, memberAccessFlags, classType);
1316
+ /* isAccessedThroughObject */ false, memberName, usage, metaclassDiag, memberAccessFlags | 128 /* SkipAttributeAccessOverride */, classType);
1298
1317
  if (metaclassMemberInfo && (0, typeUtils_1.isDescriptorInstance)(metaclassMemberInfo.type)) {
1299
1318
  considerMetaclassOnly = true;
1300
1319
  }
@@ -2326,20 +2345,22 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2326
2345
  writeTypeCache(target, { type, isIncomplete: isTypeIncomplete }, 0 /* None */);
2327
2346
  }
2328
2347
  // If the type includes promotion types, expand these to their constituent types.
2329
- function expandPromotionTypes(node, type) {
2348
+ function expandPromotionTypes(node, type, excludeBytes = false) {
2330
2349
  return (0, typeUtils_1.mapSubtypes)(type, (subtype) => {
2331
2350
  if (!(0, types_1.isClass)(subtype) || !subtype.includePromotions) {
2332
2351
  return subtype;
2333
2352
  }
2334
- const typesToCombine = [types_1.ClassType.cloneForPromotionType(subtype, /* includePromotions */ false)];
2353
+ if (excludeBytes && types_1.ClassType.isBuiltIn(subtype, 'bytes')) {
2354
+ return subtype;
2355
+ }
2356
+ const typesToCombine = [types_1.ClassType.cloneRemoveTypePromotions(subtype)];
2335
2357
  const promotionTypeNames = typePromotions.get(subtype.details.fullName);
2336
2358
  if (promotionTypeNames) {
2337
2359
  for (const promotionTypeName of promotionTypeNames) {
2338
2360
  const nameSplit = promotionTypeName.split('.');
2339
2361
  let promotionSubtype = getBuiltInType(node, nameSplit[nameSplit.length - 1]);
2340
2362
  if (promotionSubtype && (0, types_1.isInstantiableClass)(promotionSubtype)) {
2341
- promotionSubtype = types_1.ClassType.cloneForPromotionType(promotionSubtype,
2342
- /* includePromotions */ false);
2363
+ promotionSubtype = types_1.ClassType.cloneRemoveTypePromotions(promotionSubtype);
2343
2364
  if ((0, types_1.isClassInstance)(subtype)) {
2344
2365
  promotionSubtype = types_1.ClassType.cloneAsInstance(promotionSubtype);
2345
2366
  }
@@ -2562,6 +2583,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2562
2583
  inferTypeParameterVarianceForClass(type);
2563
2584
  let typeWasTransformed = false;
2564
2585
  const filteredTypeArgs = type.typeArguments.map((typeArg, index) => {
2586
+ if (index > type.details.typeParameters.length) {
2587
+ return typeArg;
2588
+ }
2565
2589
  const variance = types_1.TypeVarType.getVariance(type.details.typeParameters[index]);
2566
2590
  if (variance !== 3 /* Covariant */) {
2567
2591
  return typeArg;
@@ -3459,8 +3483,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3459
3483
  if ((0, types_1.isParamSpec)(baseType) && baseType.paramSpecAccess) {
3460
3484
  baseType = makeTopLevelTypeVarsConcrete(baseType);
3461
3485
  }
3462
- // Do union expansion for promotion types.
3463
- baseType = expandPromotionTypes(node, baseType);
3464
3486
  switch (baseType.category) {
3465
3487
  case 2 /* Any */:
3466
3488
  case 1 /* Unknown */:
@@ -6150,9 +6172,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6150
6172
  // intended behavior according to PEP 484.
6151
6173
  const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, { type: overload, isIncomplete: typeResult.isIncomplete }, overloadIndex);
6152
6174
  if (!matchResults.argumentErrors) {
6175
+ // If there is an expected return type, see if it's potentially compatible
6176
+ // with this overload's return type. If not, we'll de-emphasize this overload.
6153
6177
  if (inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType) {
6154
6178
  const returnType = getFunctionEffectiveReturnType(matchResults.overload);
6155
- if (!assignType(inferenceContext.expectedType, returnType,
6179
+ if (!assignType((0, typeUtils_1.replaceTypeVarsWithAny)(inferenceContext.expectedType), (0, typeUtils_1.replaceTypeVarsWithAny)(returnType),
6156
6180
  /* diag */ undefined,
6157
6181
  /* destTypeVarContext */ undefined,
6158
6182
  /* srcTypeVarContext */ undefined, 8 /* SkipSolveTypeVars */)) {
@@ -10169,7 +10193,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
10169
10193
  function cloneBuiltinObjectWithLiteral(node, builtInName, value) {
10170
10194
  const type = getBuiltInObject(node, builtInName);
10171
10195
  if ((0, types_1.isClassInstance)(type)) {
10172
- return types_1.ClassType.cloneWithLiteral(type, value);
10196
+ return types_1.ClassType.cloneWithLiteral(types_1.ClassType.cloneRemoveTypePromotions(type), value);
10173
10197
  }
10174
10198
  return types_1.UnknownType.create();
10175
10199
  }
@@ -11768,7 +11792,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11768
11792
  node.parameters.forEach((param) => {
11769
11793
  var _a;
11770
11794
  const paramSymbol = AnalyzerNodeInfo.getTypeParameterSymbol(param.name);
11771
- (0, debug_1.assert)(paramSymbol);
11795
+ if (!paramSymbol) {
11796
+ // This can happen if the code is unreachable.
11797
+ return;
11798
+ }
11772
11799
  const typeOfParam = (_a = getDeclaredTypeOfSymbol(paramSymbol, param.name)) === null || _a === void 0 ? void 0 : _a.type;
11773
11800
  if (!typeOfParam || !(0, types_1.isTypeVar)(typeOfParam)) {
11774
11801
  return;
@@ -12197,7 +12224,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12197
12224
  }
12198
12225
  let defaultValueType;
12199
12226
  if (param.defaultValue) {
12200
- defaultValueType = getTypeOfExpression(param.defaultValue, 1 /* ConvertEllipsisToAny */, (0, typeUtils_1.makeInferenceContext)(annotatedType)).type;
12227
+ // If this is a stub file, a protocol, an overload, or a class
12228
+ // whose body is a placeholder implementation, treat a "...", as
12229
+ // an "Any" value.
12230
+ let treatEllipsisAsAny = fileInfo.isStubFile || ParseTreeUtils.isSuiteEmpty(node.suite);
12231
+ if (containingClassType && types_1.ClassType.isProtocolClass(containingClassType)) {
12232
+ treatEllipsisAsAny = true;
12233
+ }
12234
+ if (types_1.FunctionType.isOverloaded(functionType) || types_1.FunctionType.isAbstractMethod(functionType)) {
12235
+ treatEllipsisAsAny = true;
12236
+ }
12237
+ defaultValueType = getTypeOfExpression(param.defaultValue, treatEllipsisAsAny ? 1 /* ConvertEllipsisToAny */ : 0 /* None */, (0, typeUtils_1.makeInferenceContext)(annotatedType)).type;
12201
12238
  }
12202
12239
  if (annotatedType) {
12203
12240
  // If there was both a type annotation and a default value, verify
@@ -15620,6 +15657,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15620
15657
  sourceType: srcErrorTypeText,
15621
15658
  destType: destErrorTypeText,
15622
15659
  }));
15660
+ // Tell the user about the disableBytesTypePromotions if that is involved.
15661
+ if (types_1.ClassType.isBuiltIn(destType, 'bytes')) {
15662
+ const promotions = typePromotions.get(destType.details.fullName);
15663
+ if (promotions && promotions.some((name) => name === srcType.details.fullName)) {
15664
+ diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.bytesTypePromotions());
15665
+ }
15666
+ }
15623
15667
  return false;
15624
15668
  }
15625
15669
  // This function is used to validate or infer the variance of type
@@ -15968,6 +16012,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15968
16012
  if (includeDiagAddendum) {
15969
16013
  childDiag.addAddendum(assignmentDiag);
15970
16014
  }
16015
+ if (isCompatible && types_1.ClassType.isSameGenericClass(destType, srcType)) {
16016
+ // Add additional notes to help the user if this is a common type mismatch.
16017
+ if (types_1.ClassType.isBuiltIn(destType, 'dict') && srcArgIndex === 1) {
16018
+ childDiag.addMessage(localize_1.Localizer.DiagnosticAddendum.invariantSuggestionDict());
16019
+ }
16020
+ else if (types_1.ClassType.isBuiltIn(destType, 'list')) {
16021
+ childDiag.addMessage(localize_1.Localizer.DiagnosticAddendum.invariantSuggestionList());
16022
+ }
16023
+ }
15971
16024
  }
15972
16025
  else {
15973
16026
  diag.addAddendum(assignmentDiag);