@zzzen/pyright-internal 1.2.0-dev.20220904 → 1.2.0-dev.20220918

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 (84) hide show
  1. package/dist/analyzer/binder.js +22 -21
  2. package/dist/analyzer/binder.js.map +1 -1
  3. package/dist/analyzer/checker.d.ts +1 -0
  4. package/dist/analyzer/checker.js +27 -4
  5. package/dist/analyzer/checker.js.map +1 -1
  6. package/dist/analyzer/importResolver.d.ts +6 -1
  7. package/dist/analyzer/importResolver.js +76 -28
  8. package/dist/analyzer/importResolver.js.map +1 -1
  9. package/dist/analyzer/parseTreeUtils.d.ts +1 -0
  10. package/dist/analyzer/parseTreeUtils.js +54 -13
  11. package/dist/analyzer/parseTreeUtils.js.map +1 -1
  12. package/dist/analyzer/patternMatching.js +3 -2
  13. package/dist/analyzer/patternMatching.js.map +1 -1
  14. package/dist/analyzer/program.js +8 -1
  15. package/dist/analyzer/program.js.map +1 -1
  16. package/dist/analyzer/scope.js +5 -3
  17. package/dist/analyzer/scope.js.map +1 -1
  18. package/dist/analyzer/service.js +18 -6
  19. package/dist/analyzer/service.js.map +1 -1
  20. package/dist/analyzer/typeEvaluator.js +72 -42
  21. package/dist/analyzer/typeEvaluator.js.map +1 -1
  22. package/dist/analyzer/typeGuards.js +4 -1
  23. package/dist/analyzer/typeGuards.js.map +1 -1
  24. package/dist/analyzer/typePrinter.d.ts +3 -3
  25. package/dist/analyzer/typePrinter.js +24 -20
  26. package/dist/analyzer/typePrinter.js.map +1 -1
  27. package/dist/analyzer/typeUtils.js +1 -1
  28. package/dist/analyzer/typeUtils.js.map +1 -1
  29. package/dist/analyzer/types.d.ts +2 -0
  30. package/dist/analyzer/types.js +8 -0
  31. package/dist/analyzer/types.js.map +1 -1
  32. package/dist/common/commandLineOptions.d.ts +2 -0
  33. package/dist/common/commandLineOptions.js +7 -0
  34. package/dist/common/commandLineOptions.js.map +1 -1
  35. package/dist/common/debug.js +7 -1
  36. package/dist/common/debug.js.map +1 -1
  37. package/dist/common/envVarUtils.d.ts +1 -0
  38. package/dist/common/envVarUtils.js +34 -0
  39. package/dist/common/envVarUtils.js.map +1 -0
  40. package/dist/common/realFileSystem.js +1 -1
  41. package/dist/common/realFileSystem.js.map +1 -1
  42. package/dist/languageServerBase.d.ts +3 -1
  43. package/dist/languageServerBase.js +2 -24
  44. package/dist/languageServerBase.js.map +1 -1
  45. package/dist/languageService/analyzerServiceExecutor.js +4 -1
  46. package/dist/languageService/analyzerServiceExecutor.js.map +1 -1
  47. package/dist/languageService/indentationUtils.d.ts +5 -0
  48. package/dist/languageService/indentationUtils.js +68 -27
  49. package/dist/languageService/indentationUtils.js.map +1 -1
  50. package/dist/languageService/insertionPointUtils.d.ts +2 -2
  51. package/dist/languageService/insertionPointUtils.js +1 -1
  52. package/dist/languageService/insertionPointUtils.js.map +1 -1
  53. package/dist/languageService/signatureHelpProvider.js +2 -1
  54. package/dist/languageService/signatureHelpProvider.js.map +1 -1
  55. package/dist/localization/localize.d.ts +4 -3
  56. package/dist/localization/localize.js +1 -1
  57. package/dist/localization/localize.js.map +1 -1
  58. package/dist/localization/package.nls.en-us.json +1 -1
  59. package/dist/parser/parser.js +43 -46
  60. package/dist/parser/parser.js.map +1 -1
  61. package/dist/parser/tokenizer.js +9 -7
  62. package/dist/parser/tokenizer.js.map +1 -1
  63. package/dist/server.js +6 -5
  64. package/dist/server.js.map +1 -1
  65. package/dist/tests/fourslash/signature.paramspec.fourslash.d.ts +1 -0
  66. package/dist/tests/fourslash/signature.paramspec.fourslash.js +30 -0
  67. package/dist/tests/fourslash/signature.paramspec.fourslash.js.map +1 -0
  68. package/dist/tests/ipythonMode.test.js +27 -0
  69. package/dist/tests/ipythonMode.test.js.map +1 -1
  70. package/dist/tests/parseTreeUtils.test.js +8 -2
  71. package/dist/tests/parseTreeUtils.test.js.map +1 -1
  72. package/dist/tests/parser.test.js +2 -2
  73. package/dist/tests/testUtils.d.ts +2 -0
  74. package/dist/tests/testUtils.js +8 -2
  75. package/dist/tests/testUtils.js.map +1 -1
  76. package/dist/tests/tokenizer.test.js +3 -0
  77. package/dist/tests/tokenizer.test.js.map +1 -1
  78. package/dist/tests/typeEvaluator1.test.js +5 -1
  79. package/dist/tests/typeEvaluator1.test.js.map +1 -1
  80. package/dist/tests/typeEvaluator3.test.js +5 -1
  81. package/dist/tests/typeEvaluator3.test.js.map +1 -1
  82. package/dist/tests/typeEvaluator4.test.js +1 -1
  83. package/dist/tests/typeEvaluator5.test.js +2 -2
  84. package/package.json +7 -7
@@ -1255,13 +1255,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1255
1255
  // it to the class.
1256
1256
  function getTypeOfClassMember(errorNode, classType, memberName, usage = { method: 'get' }, diag = undefined, memberAccessFlags = 0 /* None */, bindToType) {
1257
1257
  let memberInfo;
1258
+ const classDiag = diag ? new diagnostic_1.DiagnosticAddendum() : undefined;
1259
+ const metaclassDiag = diag ? new diagnostic_1.DiagnosticAddendum() : undefined;
1258
1260
  if (types_1.ClassType.isPartiallyEvaluated(classType)) {
1259
1261
  addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.classDefinitionCycle().format({ name: classType.details.name }), errorNode);
1260
1262
  return { type: types_1.UnknownType.create() };
1261
1263
  }
1262
1264
  if ((memberAccessFlags & 32 /* ConsiderMetaclassOnly */) === 0) {
1263
1265
  memberInfo = getTypeOfClassMemberName(errorNode, classType,
1264
- /* isAccessedThroughObject */ false, memberName, usage, diag, memberAccessFlags | 1 /* AccessClassMembersOnly */, bindToType);
1266
+ /* isAccessedThroughObject */ false, memberName, usage, classDiag, memberAccessFlags | 1 /* AccessClassMembersOnly */, bindToType);
1265
1267
  }
1266
1268
  // If this is a protocol class X and we're accessing a non ClassVar,
1267
1269
  // emit an error.
@@ -1278,13 +1280,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1278
1280
  }), errorNode);
1279
1281
  }
1280
1282
  }
1283
+ const isMemberPresentOnClass = (memberInfo === null || memberInfo === void 0 ? void 0 : memberInfo.classType) !== undefined;
1281
1284
  // If it wasn't found on the class, see if it's part of the metaclass.
1282
1285
  if (!memberInfo) {
1283
1286
  const metaclass = classType.details.effectiveMetaclass;
1284
1287
  if (metaclass && (0, types_1.isInstantiableClass)(metaclass) && !types_1.ClassType.isSameGenericClass(metaclass, classType)) {
1285
1288
  memberInfo = getTypeOfClassMemberName(errorNode, metaclass,
1286
- /* isAccessedThroughObject */ true, memberName, usage,
1287
- /* diag */ undefined, memberAccessFlags, classType);
1289
+ /* isAccessedThroughObject */ true, memberName, usage, metaclassDiag, memberAccessFlags, classType);
1288
1290
  }
1289
1291
  }
1290
1292
  if (memberInfo) {
@@ -1294,6 +1296,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1294
1296
  isAsymmetricDescriptor: memberInfo.isAsymmetricDescriptor,
1295
1297
  };
1296
1298
  }
1299
+ // Determine whether to use the class or metaclass diagnostic addendum.
1300
+ const subDiag = isMemberPresentOnClass ? classDiag : metaclassDiag;
1301
+ if (diag && subDiag) {
1302
+ diag.addAddendum(subDiag);
1303
+ }
1297
1304
  return undefined;
1298
1305
  }
1299
1306
  function getBoundMethod(classType, memberName, recursionCount = 0, treatConstructorAsClassMember = false) {
@@ -8963,8 +8970,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8963
8970
  // Remove any expected subtypes that don't satisfy the minimum
8964
8971
  // parameter count requirement.
8965
8972
  expectedFunctionTypes = expectedFunctionTypes.filter((functionType) => {
8966
- const functionParamCount = functionType.details.parameters.filter((param) => !!param.name && !param.hasDefault).length;
8967
- const hasVarArgs = functionType.details.parameters.some((param) => !!param.name && param.category !== 0 /* Simple */);
8973
+ const params = types_1.FunctionType.getFunctionParameters(functionType);
8974
+ const functionParamCount = params.filter((param) => !param.hasDefault).length;
8975
+ const hasVarArgs = params.some((param) => param.category !== 0 /* Simple */);
8968
8976
  return (hasVarArgs ||
8969
8977
  (functionParamCount >= minLambdaParamCount && functionParamCount <= maxLambdaParamCount));
8970
8978
  });
@@ -9057,14 +9065,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9057
9065
  function getTypeOfListComprehension(node, expectedType) {
9058
9066
  let isIncomplete = false;
9059
9067
  let typeErrors = false;
9060
- const elementTypeResult = getElementTypeFromListComprehension(node);
9061
- if (elementTypeResult.isIncomplete) {
9062
- isIncomplete = true;
9063
- }
9064
- if (elementTypeResult.typeErrors) {
9065
- typeErrors = true;
9066
- }
9067
- const elementType = elementTypeResult.type;
9068
9068
  let isAsync = node.forIfNodes.some((comp) => {
9069
9069
  return ((comp.nodeType === 33 /* ListComprehensionFor */ && comp.isAsync) ||
9070
9070
  (comp.nodeType === 34 /* ListComprehensionIf */ &&
@@ -9074,6 +9074,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9074
9074
  if (node.expression.nodeType === 6 /* Await */) {
9075
9075
  isAsync = true;
9076
9076
  }
9077
+ let expectedElementType;
9078
+ if (expectedType) {
9079
+ expectedElementType = getTypeOfIterator(expectedType, isAsync, /* errorNode */ undefined);
9080
+ }
9081
+ const elementTypeResult = getElementTypeFromListComprehension(node, expectedElementType);
9082
+ if (elementTypeResult.isIncomplete) {
9083
+ isIncomplete = true;
9084
+ }
9085
+ if (elementTypeResult.typeErrors) {
9086
+ typeErrors = true;
9087
+ }
9088
+ const elementType = elementTypeResult.type;
9077
9089
  // Handle the special case where a generator function (e.g. `(await x for x in y)`)
9078
9090
  // is expected to be an AsyncGenerator.
9079
9091
  if (!isAsync &&
@@ -10729,29 +10741,25 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
10729
10741
  // See if there's already a non-synthesized __init__ method.
10730
10742
  // We shouldn't override it.
10731
10743
  if (!skipSynthesizedInit) {
10732
- const initSymbol = (0, typeUtils_1.lookUpClassMember)(classType, '__init__', 4 /* SkipObjectBaseClass */);
10744
+ const initSymbol = (0, typeUtils_1.lookUpClassMember)(classType, '__init__', 2 /* SkipBaseClasses */);
10733
10745
  if (initSymbol) {
10734
- if (!(0, types_1.isClass)(initSymbol.classType) || !types_1.ClassType.isBuiltIn(initSymbol.classType, 'NamedTuple')) {
10735
- const initSymbolType = getTypeOfMember(initSymbol);
10736
- if ((0, types_1.isFunction)(initSymbolType)) {
10737
- if (!types_1.FunctionType.isSynthesizedMethod(initSymbolType)) {
10738
- hasExistingInitMethod = true;
10739
- }
10740
- }
10741
- else {
10746
+ const initSymbolType = getTypeOfMember(initSymbol);
10747
+ if ((0, types_1.isFunction)(initSymbolType)) {
10748
+ if (!types_1.FunctionType.isSynthesizedMethod(initSymbolType)) {
10742
10749
  hasExistingInitMethod = true;
10743
10750
  }
10744
10751
  }
10752
+ else {
10753
+ hasExistingInitMethod = true;
10754
+ }
10745
10755
  }
10746
10756
  }
10747
10757
  let skipSynthesizeHash = false;
10748
- const hashSymbol = (0, typeUtils_1.lookUpClassMember)(classType, '__hash__', 4 /* SkipObjectBaseClass */);
10758
+ const hashSymbol = (0, typeUtils_1.lookUpClassMember)(classType, '__hash__', 2 /* SkipBaseClasses */);
10749
10759
  if (hashSymbol) {
10750
- if (!(0, types_1.isClass)(hashSymbol.classType) || !types_1.ClassType.isBuiltIn(hashSymbol.classType, 'NamedTuple')) {
10751
- const hashSymbolType = getTypeOfMember(hashSymbol);
10752
- if ((0, types_1.isFunction)(hashSymbolType) && !types_1.FunctionType.isSynthesizedMethod(hashSymbolType)) {
10753
- skipSynthesizeHash = true;
10754
- }
10760
+ const hashSymbolType = getTypeOfMember(hashSymbol);
10761
+ if ((0, types_1.isFunction)(hashSymbolType) && !types_1.FunctionType.isSynthesizedMethod(hashSymbolType)) {
10762
+ skipSynthesizeHash = true;
10755
10763
  }
10756
10764
  }
10757
10765
  (0, dataClasses_1.synthesizeDataClassMethods)(evaluatorInterface, node, classType, skipSynthesizedInit, hasExistingInitMethod, skipSynthesizeHash);
@@ -11001,12 +11009,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11001
11009
  // completed.
11002
11010
  function runClassTypeHooks(type) {
11003
11011
  classTypeHooks.forEach((hook) => {
11004
- if (hook.dependency === type) {
11012
+ if (types_1.ClassType.isSameGenericClass(hook.dependency, type)) {
11005
11013
  hook.callback();
11006
11014
  }
11007
11015
  });
11008
11016
  // Remove any hooks that depend on this type.
11009
- classTypeHooks = classTypeHooks.filter((hook) => hook.dependency !== type);
11017
+ classTypeHooks = classTypeHooks.filter((hook) => !types_1.ClassType.isSameGenericClass(hook.dependency, type));
11010
11018
  }
11011
11019
  // Recomputes the MRO and effective metaclass for the class after dependent
11012
11020
  // classes have been fully constructed.
@@ -12410,7 +12418,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12410
12418
  // expression or statement that contains it. This contextual evaluation
12411
12419
  // allows for bidirectional type evaluation.
12412
12420
  function evaluateTypesForExpressionInContext(node) {
12413
- var _a, _b, _c, _d, _e;
12421
+ var _a, _b, _c, _d, _e, _f;
12414
12422
  // Check for a couple of special cases where the node is a NameNode but
12415
12423
  // is technically not part of an expression. We'll handle these here so
12416
12424
  // callers don't need to include special-case logic.
@@ -12471,7 +12479,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12471
12479
  });
12472
12480
  return;
12473
12481
  }
12474
- getTypeOfAnnotation(annotationNode);
12482
+ getTypeOfAnnotation(annotationNode, {
12483
+ isVariableAnnotation: ((_a = annotationNode.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 54 /* TypeAnnotation */,
12484
+ });
12475
12485
  return;
12476
12486
  }
12477
12487
  // See if the expression is part of a pattern used in a case statement.
@@ -12582,8 +12592,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12582
12592
  // If this is the name node within a type parameter list, see if it's a type alias
12583
12593
  // definition. If so, we need to evaluate the type alias contextually.
12584
12594
  if (nodeToEvaluate === parent.name &&
12585
- ((_a = parent.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 76 /* TypeParameterList */ &&
12586
- ((_b = parent.parent.parent) === null || _b === void 0 ? void 0 : _b.nodeType) === 77 /* TypeAlias */) {
12595
+ ((_b = parent.parent) === null || _b === void 0 ? void 0 : _b.nodeType) === 76 /* TypeParameterList */ &&
12596
+ ((_c = parent.parent.parent) === null || _c === void 0 ? void 0 : _c.nodeType) === 77 /* TypeAlias */) {
12587
12597
  getTypeOfTypeAlias(parent.parent.parent);
12588
12598
  return;
12589
12599
  }
@@ -12594,10 +12604,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12594
12604
  return;
12595
12605
  }
12596
12606
  case 13 /* Decorator */: {
12597
- if (((_c = parent.parent) === null || _c === void 0 ? void 0 : _c.nodeType) === 10 /* Class */) {
12607
+ if (((_d = parent.parent) === null || _d === void 0 ? void 0 : _d.nodeType) === 10 /* Class */) {
12598
12608
  getTypeOfClass(parent.parent);
12599
12609
  }
12600
- else if (((_d = parent.parent) === null || _d === void 0 ? void 0 : _d.nodeType) === 28 /* Function */) {
12610
+ else if (((_e = parent.parent) === null || _e === void 0 ? void 0 : _e.nodeType) === 28 /* Function */) {
12601
12611
  getTypeOfFunction(parent.parent);
12602
12612
  }
12603
12613
  return;
@@ -12615,7 +12625,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12615
12625
  // expression, so there's nothing we can evaluate here.
12616
12626
  return;
12617
12627
  }
12618
- if (((_e = parent.parent) === null || _e === void 0 ? void 0 : _e.nodeType) === 10 /* Class */) {
12628
+ if (((_f = parent.parent) === null || _f === void 0 ? void 0 : _f.nodeType) === 10 /* Class */) {
12619
12629
  // A class argument must be evaluated in the context of the class declaration.
12620
12630
  getTypeOfClass(parent.parent);
12621
12631
  return;
@@ -13026,8 +13036,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
13026
13036
  received: typeArgCount,
13027
13037
  }), typeArgs[typeParameters.length].node);
13028
13038
  }
13039
+ typeArgCount = typeParameters.length;
13029
13040
  }
13030
- typeArgCount = typeParameters.length;
13031
13041
  }
13032
13042
  else if (typeArgCount < typeParameters.length) {
13033
13043
  const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
@@ -13164,6 +13174,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
13164
13174
  }
13165
13175
  return typeArgType;
13166
13176
  });
13177
+ // If the class is partially constructed and doesn't yet have
13178
+ // type parameters, assume that the number and types of supplied type
13179
+ // arguments are correct.
13180
+ if (typeArgs && classType.details.typeParameters.length === 0 && types_1.ClassType.isPartiallyEvaluated(classType)) {
13181
+ typeArgTypes = typeArgs.map((t) => (0, typeUtils_1.convertToInstance)(t.type));
13182
+ }
13167
13183
  const specializedClass = types_1.ClassType.cloneForSpecialization(classType, typeArgTypes, typeArgs !== undefined);
13168
13184
  return specializedClass;
13169
13185
  }
@@ -14115,6 +14131,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14115
14131
  }
14116
14132
  }
14117
14133
  else {
14134
+ // If this resolves to a class decl, we can use a partially-evaluated
14135
+ // version of the class type.
14136
+ const resolvedDecl = resolveAliasDeclaration(decl,
14137
+ /* resolveLocalNames */ true,
14138
+ /* allowExternallyHiddenAccess */ AnalyzerNodeInfo.getFileInfo(decl.node).isStubFile);
14139
+ if ((resolvedDecl === null || resolvedDecl === void 0 ? void 0 : resolvedDecl.type) === 6 /* Class */) {
14140
+ const classTypeInfo = getTypeOfClass(resolvedDecl.node);
14141
+ if (classTypeInfo === null || classTypeInfo === void 0 ? void 0 : classTypeInfo.decoratedType) {
14142
+ typesToCombine.push(classTypeInfo.decoratedType);
14143
+ }
14144
+ }
14118
14145
  isIncomplete = true;
14119
14146
  }
14120
14147
  }
@@ -16300,10 +16327,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16300
16327
  const effectiveDestType = (flags & 2 /* ReverseTypeVarMatching */) === 0 ? destType : srcType;
16301
16328
  const effectiveSrcType = (flags & 2 /* ReverseTypeVarMatching */) === 0 ? srcType : destType;
16302
16329
  if (effectiveDestType.details.paramSpec) {
16303
- const requiredMatchParamCount = effectiveDestType.details.parameters.filter((p) => {
16304
- if (!p.name) {
16305
- return false;
16306
- }
16330
+ const requiredMatchParamCount = types_1.FunctionType.getFunctionParameters(effectiveDestType).filter((p) => {
16307
16331
  if (p.category === 0 /* Simple */ && (0, types_1.isParamSpec)(p.type)) {
16308
16332
  return false;
16309
16333
  }
@@ -16767,6 +16791,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16767
16791
  }
16768
16792
  effectiveSrcType = makeTopLevelTypeVarsConcrete(srcType);
16769
16793
  }
16794
+ // If this is a partially-evaluated class, don't perform any further
16795
+ // checks. Assume in this case that the type is compatible with the
16796
+ // bound or constraint.
16797
+ if ((0, types_1.isClass)(effectiveSrcType) && types_1.ClassType.isPartiallyEvaluated(effectiveSrcType)) {
16798
+ return srcType;
16799
+ }
16770
16800
  // If there's a bound type, make sure the source is derived from it.
16771
16801
  if (destType.details.boundType) {
16772
16802
  if (!assignType(destType.details.boundType, effectiveSrcType, diag.createAddendum(),