@zzzen/pyright-internal 1.2.0-dev.20220911 → 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 (41) hide show
  1. package/dist/analyzer/binder.js +11 -6
  2. package/dist/analyzer/binder.js.map +1 -1
  3. package/dist/analyzer/checker.js +10 -4
  4. package/dist/analyzer/checker.js.map +1 -1
  5. package/dist/analyzer/parseTreeUtils.js +0 -6
  6. package/dist/analyzer/parseTreeUtils.js.map +1 -1
  7. package/dist/analyzer/patternMatching.js +3 -2
  8. package/dist/analyzer/patternMatching.js.map +1 -1
  9. package/dist/analyzer/typeEvaluator.js +61 -27
  10. package/dist/analyzer/typeEvaluator.js.map +1 -1
  11. package/dist/analyzer/typeGuards.js +4 -1
  12. package/dist/analyzer/typeGuards.js.map +1 -1
  13. package/dist/analyzer/typeUtils.js +1 -1
  14. package/dist/analyzer/typeUtils.js.map +1 -1
  15. package/dist/analyzer/types.d.ts +2 -0
  16. package/dist/analyzer/types.js +8 -0
  17. package/dist/analyzer/types.js.map +1 -1
  18. package/dist/languageService/indentationUtils.d.ts +5 -0
  19. package/dist/languageService/indentationUtils.js +68 -27
  20. package/dist/languageService/indentationUtils.js.map +1 -1
  21. package/dist/languageService/insertionPointUtils.d.ts +2 -2
  22. package/dist/languageService/insertionPointUtils.js +1 -1
  23. package/dist/languageService/insertionPointUtils.js.map +1 -1
  24. package/dist/languageService/signatureHelpProvider.js +2 -1
  25. package/dist/languageService/signatureHelpProvider.js.map +1 -1
  26. package/dist/parser/parser.js +43 -46
  27. package/dist/parser/parser.js.map +1 -1
  28. package/dist/parser/tokenizer.js +7 -6
  29. package/dist/parser/tokenizer.js.map +1 -1
  30. package/dist/tests/fourslash/signature.paramspec.fourslash.d.ts +1 -0
  31. package/dist/tests/fourslash/signature.paramspec.fourslash.js +30 -0
  32. package/dist/tests/fourslash/signature.paramspec.fourslash.js.map +1 -0
  33. package/dist/tests/parser.test.js +2 -2
  34. package/dist/tests/testUtils.d.ts +2 -0
  35. package/dist/tests/testUtils.js +8 -2
  36. package/dist/tests/testUtils.js.map +1 -1
  37. package/dist/tests/tokenizer.test.js +3 -0
  38. package/dist/tests/tokenizer.test.js.map +1 -1
  39. package/dist/tests/typeEvaluator3.test.js +4 -0
  40. package/dist/tests/typeEvaluator3.test.js.map +1 -1
  41. package/package.json +3 -3
@@ -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 &&
@@ -10997,12 +11009,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
10997
11009
  // completed.
10998
11010
  function runClassTypeHooks(type) {
10999
11011
  classTypeHooks.forEach((hook) => {
11000
- if (hook.dependency === type) {
11012
+ if (types_1.ClassType.isSameGenericClass(hook.dependency, type)) {
11001
11013
  hook.callback();
11002
11014
  }
11003
11015
  });
11004
11016
  // Remove any hooks that depend on this type.
11005
- classTypeHooks = classTypeHooks.filter((hook) => hook.dependency !== type);
11017
+ classTypeHooks = classTypeHooks.filter((hook) => !types_1.ClassType.isSameGenericClass(hook.dependency, type));
11006
11018
  }
11007
11019
  // Recomputes the MRO and effective metaclass for the class after dependent
11008
11020
  // classes have been fully constructed.
@@ -12406,7 +12418,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12406
12418
  // expression or statement that contains it. This contextual evaluation
12407
12419
  // allows for bidirectional type evaluation.
12408
12420
  function evaluateTypesForExpressionInContext(node) {
12409
- var _a, _b, _c, _d, _e;
12421
+ var _a, _b, _c, _d, _e, _f;
12410
12422
  // Check for a couple of special cases where the node is a NameNode but
12411
12423
  // is technically not part of an expression. We'll handle these here so
12412
12424
  // callers don't need to include special-case logic.
@@ -12467,7 +12479,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12467
12479
  });
12468
12480
  return;
12469
12481
  }
12470
- getTypeOfAnnotation(annotationNode);
12482
+ getTypeOfAnnotation(annotationNode, {
12483
+ isVariableAnnotation: ((_a = annotationNode.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 54 /* TypeAnnotation */,
12484
+ });
12471
12485
  return;
12472
12486
  }
12473
12487
  // See if the expression is part of a pattern used in a case statement.
@@ -12578,8 +12592,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12578
12592
  // If this is the name node within a type parameter list, see if it's a type alias
12579
12593
  // definition. If so, we need to evaluate the type alias contextually.
12580
12594
  if (nodeToEvaluate === parent.name &&
12581
- ((_a = parent.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 76 /* TypeParameterList */ &&
12582
- ((_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 */) {
12583
12597
  getTypeOfTypeAlias(parent.parent.parent);
12584
12598
  return;
12585
12599
  }
@@ -12590,10 +12604,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12590
12604
  return;
12591
12605
  }
12592
12606
  case 13 /* Decorator */: {
12593
- 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 */) {
12594
12608
  getTypeOfClass(parent.parent);
12595
12609
  }
12596
- 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 */) {
12597
12611
  getTypeOfFunction(parent.parent);
12598
12612
  }
12599
12613
  return;
@@ -12611,7 +12625,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12611
12625
  // expression, so there's nothing we can evaluate here.
12612
12626
  return;
12613
12627
  }
12614
- 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 */) {
12615
12629
  // A class argument must be evaluated in the context of the class declaration.
12616
12630
  getTypeOfClass(parent.parent);
12617
12631
  return;
@@ -13022,8 +13036,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
13022
13036
  received: typeArgCount,
13023
13037
  }), typeArgs[typeParameters.length].node);
13024
13038
  }
13039
+ typeArgCount = typeParameters.length;
13025
13040
  }
13026
- typeArgCount = typeParameters.length;
13027
13041
  }
13028
13042
  else if (typeArgCount < typeParameters.length) {
13029
13043
  const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
@@ -13160,6 +13174,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
13160
13174
  }
13161
13175
  return typeArgType;
13162
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
+ }
13163
13183
  const specializedClass = types_1.ClassType.cloneForSpecialization(classType, typeArgTypes, typeArgs !== undefined);
13164
13184
  return specializedClass;
13165
13185
  }
@@ -14111,6 +14131,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14111
14131
  }
14112
14132
  }
14113
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
+ }
14114
14145
  isIncomplete = true;
14115
14146
  }
14116
14147
  }
@@ -16296,10 +16327,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16296
16327
  const effectiveDestType = (flags & 2 /* ReverseTypeVarMatching */) === 0 ? destType : srcType;
16297
16328
  const effectiveSrcType = (flags & 2 /* ReverseTypeVarMatching */) === 0 ? srcType : destType;
16298
16329
  if (effectiveDestType.details.paramSpec) {
16299
- const requiredMatchParamCount = effectiveDestType.details.parameters.filter((p) => {
16300
- if (!p.name) {
16301
- return false;
16302
- }
16330
+ const requiredMatchParamCount = types_1.FunctionType.getFunctionParameters(effectiveDestType).filter((p) => {
16303
16331
  if (p.category === 0 /* Simple */ && (0, types_1.isParamSpec)(p.type)) {
16304
16332
  return false;
16305
16333
  }
@@ -16763,6 +16791,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16763
16791
  }
16764
16792
  effectiveSrcType = makeTopLevelTypeVarsConcrete(srcType);
16765
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
+ }
16766
16800
  // If there's a bound type, make sure the source is derived from it.
16767
16801
  if (destType.details.boundType) {
16768
16802
  if (!assignType(destType.details.boundType, effectiveSrcType, diag.createAddendum(),