@zzzen/pyright-internal 1.2.0-dev.20230521 → 1.2.0-dev.20230528

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 (93) hide show
  1. package/dist/analyzer/checker.js +4 -4
  2. package/dist/analyzer/checker.js.map +1 -1
  3. package/dist/analyzer/commentUtils.js +15 -16
  4. package/dist/analyzer/commentUtils.js.map +1 -1
  5. package/dist/analyzer/constraintSolver.js +6 -2
  6. package/dist/analyzer/constraintSolver.js.map +1 -1
  7. package/dist/analyzer/constructorTransform.js +3 -3
  8. package/dist/analyzer/constructorTransform.js.map +1 -1
  9. package/dist/analyzer/constructors.js +125 -129
  10. package/dist/analyzer/constructors.js.map +1 -1
  11. package/dist/analyzer/dataClasses.js +1 -1
  12. package/dist/analyzer/dataClasses.js.map +1 -1
  13. package/dist/analyzer/docStringConversion.js +1 -1
  14. package/dist/analyzer/enums.js +1 -1
  15. package/dist/analyzer/enums.js.map +1 -1
  16. package/dist/analyzer/parameterUtils.js +7 -7
  17. package/dist/analyzer/parameterUtils.js.map +1 -1
  18. package/dist/analyzer/parseTreeUtils.d.ts +1 -0
  19. package/dist/analyzer/parseTreeUtils.js +21 -6
  20. package/dist/analyzer/parseTreeUtils.js.map +1 -1
  21. package/dist/analyzer/service.js +8 -0
  22. package/dist/analyzer/service.js.map +1 -1
  23. package/dist/analyzer/sourceFile.js +5 -1
  24. package/dist/analyzer/sourceFile.js.map +1 -1
  25. package/dist/analyzer/typeCacheUtils.d.ts +9 -2
  26. package/dist/analyzer/typeCacheUtils.js +52 -9
  27. package/dist/analyzer/typeCacheUtils.js.map +1 -1
  28. package/dist/analyzer/typeEvaluator.js +123 -88
  29. package/dist/analyzer/typeEvaluator.js.map +1 -1
  30. package/dist/analyzer/typeGuards.js +2 -2
  31. package/dist/analyzer/typeGuards.js.map +1 -1
  32. package/dist/analyzer/typePrinter.js +9 -9
  33. package/dist/analyzer/typePrinter.js.map +1 -1
  34. package/dist/analyzer/typeStubWriter.js +2 -2
  35. package/dist/analyzer/typeStubWriter.js.map +1 -1
  36. package/dist/analyzer/typeUtils.d.ts +1 -0
  37. package/dist/analyzer/typeUtils.js +19 -17
  38. package/dist/analyzer/typeUtils.js.map +1 -1
  39. package/dist/analyzer/typedDicts.js +2 -2
  40. package/dist/analyzer/typedDicts.js.map +1 -1
  41. package/dist/analyzer/types.d.ts +2 -0
  42. package/dist/analyzer/types.js +20 -10
  43. package/dist/analyzer/types.js.map +1 -1
  44. package/dist/commands/dumpFileDebugInfoCommand.js +2 -2
  45. package/dist/common/commandLineOptions.d.ts +1 -0
  46. package/dist/common/commandLineOptions.js.map +1 -1
  47. package/dist/common/textRange.d.ts +3 -3
  48. package/dist/common/textRange.js +17 -8
  49. package/dist/common/textRange.js.map +1 -1
  50. package/dist/common/uriParser.d.ts +1 -0
  51. package/dist/common/uriParser.js +9 -0
  52. package/dist/common/uriParser.js.map +1 -1
  53. package/dist/languageServerBase.js +4 -2
  54. package/dist/languageServerBase.js.map +1 -1
  55. package/dist/languageService/analyzerServiceExecutor.js +1 -0
  56. package/dist/languageService/analyzerServiceExecutor.js.map +1 -1
  57. package/dist/languageService/completionProvider.js +5 -5
  58. package/dist/languageService/completionProvider.js.map +1 -1
  59. package/dist/languageService/renameProvider.d.ts +3 -3
  60. package/dist/languageService/renameProvider.js +6 -6
  61. package/dist/languageService/renameProvider.js.map +1 -1
  62. package/dist/localization/localize.d.ts +1 -0
  63. package/dist/localization/localize.js +1 -0
  64. package/dist/localization/localize.js.map +1 -1
  65. package/dist/localization/package.nls.en-us.json +1 -0
  66. package/dist/parser/parseNodes.d.ts +11 -3
  67. package/dist/parser/parseNodes.js +7 -9
  68. package/dist/parser/parseNodes.js.map +1 -1
  69. package/dist/parser/parser.js +13 -10
  70. package/dist/parser/parser.js.map +1 -1
  71. package/dist/parser/tokenizer.js +8 -7
  72. package/dist/parser/tokenizer.js.map +1 -1
  73. package/dist/tests/docStringConversion.test.js +44 -0
  74. package/dist/tests/docStringConversion.test.js.map +1 -1
  75. package/dist/tests/fourslash/fourslash.d.ts +1 -1
  76. package/dist/tests/fourslash/rename.function.untitledFile.fourslash.d.ts +1 -0
  77. package/dist/tests/fourslash/rename.function.untitledFile.fourslash.js +17 -0
  78. package/dist/tests/fourslash/rename.function.untitledFile.fourslash.js.map +1 -0
  79. package/dist/tests/harness/fourslash/testState.d.ts +1 -1
  80. package/dist/tests/harness/fourslash/testState.js +2 -2
  81. package/dist/tests/harness/fourslash/testState.js.map +1 -1
  82. package/dist/tests/tokenizer.test.js +8 -0
  83. package/dist/tests/tokenizer.test.js.map +1 -1
  84. package/dist/tests/typeEvaluator1.test.js +5 -1
  85. package/dist/tests/typeEvaluator1.test.js.map +1 -1
  86. package/dist/tests/typeEvaluator2.test.js +5 -1
  87. package/dist/tests/typeEvaluator2.test.js.map +1 -1
  88. package/dist/tests/typeEvaluator3.test.js +1 -1
  89. package/dist/tests/typePrinter.test.js +3 -3
  90. package/dist/tests/typePrinter.test.js.map +1 -1
  91. package/dist/workspaceFactory.js +4 -4
  92. package/dist/workspaceFactory.js.map +1 -1
  93. package/package.json +1 -1
@@ -858,6 +858,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
858
858
  return typeResult;
859
859
  }
860
860
  function stripLiteralValue(type) {
861
+ var _a, _b, _c;
862
+ // Handle the not-uncommon case where the type is a union that consists
863
+ // only of literal str or literal int values.
864
+ if ((0, types_1.isUnion)(type) && type.subtypes.length > 0) {
865
+ if (((_a = type.literalStrMap) === null || _a === void 0 ? void 0 : _a.size) === type.subtypes.length ||
866
+ ((_b = type.literalIntMap) === null || _b === void 0 ? void 0 : _b.size) === type.subtypes.length ||
867
+ ((_c = type.literalEnumMap) === null || _c === void 0 ? void 0 : _c.size) === type.subtypes.length) {
868
+ return stripLiteralValue(type.subtypes[0]);
869
+ }
870
+ }
861
871
  return (0, typeUtils_1.mapSubtypes)(type, (subtype) => {
862
872
  if ((0, types_1.isClass)(subtype)) {
863
873
  if (subtype.literalValue !== undefined) {
@@ -880,9 +890,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
880
890
  function getTypeOfParameterAnnotation(paramTypeNode, paramCategory) {
881
891
  return getTypeOfAnnotation(paramTypeNode, {
882
892
  associateTypeVarsWithScope: true,
883
- allowTypeVarTuple: paramCategory === 1 /* VarArgList */,
884
- allowUnpackedTypedDict: paramCategory === 2 /* VarArgDictionary */,
885
- allowUnpackedTuple: paramCategory === 1 /* VarArgList */,
893
+ allowTypeVarTuple: paramCategory === 1 /* ArgsList */,
894
+ allowUnpackedTypedDict: paramCategory === 2 /* KwargsDict */,
895
+ allowUnpackedTuple: paramCategory === 1 /* ArgsList */,
886
896
  });
887
897
  }
888
898
  function getTypeOfAnnotation(node, options) {
@@ -3338,7 +3348,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3338
3348
  if (baseType.details.isParamSpec) {
3339
3349
  if (memberName === 'args') {
3340
3350
  const paramNode = ParseTreeUtils.getEnclosingParameter(node);
3341
- if (!paramNode || paramNode.category !== 1 /* VarArgList */) {
3351
+ if (!paramNode || paramNode.category !== 1 /* ArgsList */) {
3342
3352
  addError(localize_1.Localizer.Diagnostic.paramSpecArgsUsage(), node);
3343
3353
  return { type: types_1.UnknownType.create(isIncomplete), isIncomplete };
3344
3354
  }
@@ -3346,7 +3356,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3346
3356
  }
3347
3357
  if (memberName === 'kwargs') {
3348
3358
  const paramNode = ParseTreeUtils.getEnclosingParameter(node);
3349
- if (!paramNode || paramNode.category !== 2 /* VarArgDictionary */) {
3359
+ if (!paramNode || paramNode.category !== 2 /* KwargsDict */) {
3350
3360
  addError(localize_1.Localizer.Diagnostic.paramSpecKwargsUsage(), node);
3351
3361
  return { type: types_1.UnknownType.create(isIncomplete), isIncomplete };
3352
3362
  }
@@ -6487,6 +6497,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6487
6497
  // Build a map of parameters by name.
6488
6498
  const paramMap = new Map();
6489
6499
  paramDetails.params.forEach((paramInfo) => {
6500
+ (0, debug_1.assert)(paramInfo !== undefined, 'paramInfo is undefined for param name map');
6490
6501
  const param = paramInfo.param;
6491
6502
  if (param.name && param.category === 0 /* Simple */) {
6492
6503
  paramMap.set(param.name, {
@@ -6537,8 +6548,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6537
6548
  if (argList.some((arg) => arg.argumentCategory === 1 /* UnpackedList */)) {
6538
6549
  argList.forEach((arg) => {
6539
6550
  if (arg.name) {
6540
- const keywordParamIndex = paramDetails.params.findIndex((paramInfo) => paramInfo.param.name === arg.name.value &&
6541
- paramInfo.param.category === 0 /* Simple */);
6551
+ const keywordParamIndex = paramDetails.params.findIndex((paramInfo) => {
6552
+ (0, debug_1.assert)(paramInfo, 'paramInfo entry is undefined fork kwargs check');
6553
+ return (paramInfo.param.name === arg.name.value &&
6554
+ paramInfo.param.category === 0 /* Simple */);
6555
+ });
6542
6556
  // Is this a parameter that can be interpreted as either a keyword or a positional?
6543
6557
  // If so, we'll treat it as a keyword parameter in this case because it's being
6544
6558
  // targeted by a keyword argument.
@@ -6616,7 +6630,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6616
6630
  (0, debug_1.assert)(paramDetails.params[paramIndex], 'paramIndex params entry is undefined');
6617
6631
  const paramType = paramDetails.params[paramIndex].type;
6618
6632
  const paramName = paramDetails.params[paramIndex].param.name;
6619
- const isParamVariadic = paramDetails.params[paramIndex].param.category === 1 /* VarArgList */ &&
6633
+ const isParamVariadic = paramDetails.params[paramIndex].param.category === 1 /* ArgsList */ &&
6620
6634
  (0, types_1.isVariadicTypeVar)(paramType);
6621
6635
  if (argList[argIndex].argumentCategory === 1 /* UnpackedList */) {
6622
6636
  let isArgCompatibleWithVariadic = false;
@@ -6677,7 +6691,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6677
6691
  listElementType =
6678
6692
  (_e = (_d = getTypeOfIterator({ type: argType, isIncomplete: argTypeResult.isIncomplete },
6679
6693
  /* isAsync */ false, argList[argIndex].valueExpression)) === null || _d === void 0 ? void 0 : _d.type) !== null && _e !== void 0 ? _e : types_1.UnknownType.create();
6680
- if (paramDetails.params[paramIndex].param.category !== 1 /* VarArgList */) {
6694
+ if (paramDetails.params[paramIndex].param.category !== 1 /* ArgsList */) {
6681
6695
  matchedUnpackedListOfUnknownLength = true;
6682
6696
  }
6683
6697
  }
@@ -6722,16 +6736,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6722
6736
  paramMap.has(paramName)) {
6723
6737
  paramMap.get(paramName).argsReceived++;
6724
6738
  }
6725
- if (advanceToNextArg ||
6726
- paramDetails.params[paramIndex].param.category === 1 /* VarArgList */) {
6739
+ if (advanceToNextArg || paramDetails.params[paramIndex].param.category === 1 /* ArgsList */) {
6727
6740
  argIndex++;
6728
6741
  }
6729
6742
  if (isVariadicTypeVarFullyMatched ||
6730
- paramDetails.params[paramIndex].param.category !== 1 /* VarArgList */) {
6743
+ paramDetails.params[paramIndex].param.category !== 1 /* ArgsList */) {
6731
6744
  paramIndex++;
6732
6745
  }
6733
6746
  }
6734
- else if (paramDetails.params[paramIndex].param.category === 1 /* VarArgList */) {
6747
+ else if (paramDetails.params[paramIndex].param.category === 1 /* ArgsList */) {
6735
6748
  trySetActive(argList[argIndex], paramDetails.params[paramIndex].param);
6736
6749
  if (paramSpecArgList) {
6737
6750
  paramSpecArgList.push(argList[argIndex]);
@@ -6747,7 +6760,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6747
6760
  effectiveParamType = paramType.tupleTypeArguments[0].type;
6748
6761
  }
6749
6762
  paramCategory = (0, types_1.isVariadicTypeVar)(effectiveParamType)
6750
- ? 1 /* VarArgList */
6763
+ ? 1 /* ArgsList */
6751
6764
  : 0 /* Simple */;
6752
6765
  if (remainingArgCount <= remainingParamCount) {
6753
6766
  if (remainingArgCount < remainingParamCount) {
@@ -6804,7 +6817,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6804
6817
  let skippedArgsParam = false;
6805
6818
  if (positionalOnlyLimitIndex >= 0 &&
6806
6819
  paramIndex < positionalOnlyLimitIndex &&
6807
- paramDetails.params[paramIndex].param.category === 1 /* VarArgList */ &&
6820
+ paramIndex < paramDetails.params.length &&
6821
+ paramDetails.params[paramIndex].param.category === 1 /* ArgsList */ &&
6808
6822
  !(0, types_1.isParamSpec)(paramDetails.params[paramIndex].param.type)) {
6809
6823
  paramIndex++;
6810
6824
  skippedArgsParam = true;
@@ -6825,7 +6839,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6825
6839
  // because it's permitted to pass zero arguments to *args.
6826
6840
  argsRemainingCount--;
6827
6841
  }
6828
- const firstArgsParam = paramDetails.params.findIndex((paramInfo) => paramInfo.param.category === 1 /* VarArgList */ && !(0, types_1.isParamSpec)(paramInfo.param.type));
6842
+ const firstArgsParam = paramDetails.params.findIndex((paramInfo) => paramInfo.param.category === 1 /* ArgsList */ && !(0, types_1.isParamSpec)(paramInfo.param.type));
6829
6843
  if (firstArgsParam >= paramIndex && firstArgsParam < positionalOnlyLimitIndex) {
6830
6844
  // If there is another args parameter beyond the current param index,
6831
6845
  // reduce the count by one because it's permitted to pass zero arguments
@@ -6887,7 +6901,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6887
6901
  else if (paramDetails.kwargsIndex !== undefined) {
6888
6902
  const paramType = paramDetails.params[paramDetails.kwargsIndex].type;
6889
6903
  validateArgTypeParams.push({
6890
- paramCategory: 2 /* VarArgDictionary */,
6904
+ paramCategory: 2 /* KwargsDict */,
6891
6905
  paramType,
6892
6906
  requiresTypeVarMatching: (0, typeUtils_1.requiresSpecialization)(paramType),
6893
6907
  argument: {
@@ -6925,7 +6939,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6925
6939
  unpackedDictionaryArgType = types_1.AnyType.create();
6926
6940
  if (typeResult.type.details.paramSpec) {
6927
6941
  validateArgTypeParams.push({
6928
- paramCategory: 2 /* VarArgDictionary */,
6942
+ paramCategory: 2 /* KwargsDict */,
6929
6943
  paramType: typeResult.type.details.paramSpec,
6930
6944
  requiresTypeVarMatching: false,
6931
6945
  argument: argList[argIndex],
@@ -7010,7 +7024,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7010
7024
  else {
7011
7025
  const paramType = paramDetails.params[paramDetails.kwargsIndex].type;
7012
7026
  validateArgTypeParams.push({
7013
- paramCategory: 2 /* VarArgDictionary */,
7027
+ paramCategory: 2 /* KwargsDict */,
7014
7028
  paramType,
7015
7029
  requiresTypeVarMatching: (0, typeUtils_1.requiresSpecialization)(paramType),
7016
7030
  argument: argList[argIndex],
@@ -7054,7 +7068,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7054
7068
  }
7055
7069
  if ((0, types_1.isParamSpec)(argType) && argType.paramSpecAccess === 'args') {
7056
7070
  validateArgTypeParams.push({
7057
- paramCategory: 1 /* VarArgList */,
7071
+ paramCategory: 1 /* ArgsList */,
7058
7072
  paramType: typeResult.type.details.paramSpec,
7059
7073
  requiresTypeVarMatching: false,
7060
7074
  argument: argList[argIndex],
@@ -7157,6 +7171,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7157
7171
  // already been matched, see if the type of that *args parameter is a variadic
7158
7172
  // type variable. If so, we'll preprocess those arguments and combine them
7159
7173
  // into a tuple.
7174
+ (0, debug_1.assert)(paramDetails.argsIndex === undefined || paramDetails.argsIndex < paramDetails.params.length, 'paramDetails.argsIndex params entry is invalid');
7160
7175
  if (paramDetails.argsIndex !== undefined &&
7161
7176
  paramDetails.argsIndex >= 0 &&
7162
7177
  paramDetails.params[paramDetails.argsIndex].param.hasDeclaredType &&
@@ -7203,7 +7218,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7203
7218
  /* isUnpackedTuple */ true));
7204
7219
  }
7205
7220
  const combinedArg = {
7206
- paramCategory: 1 /* VarArgList */,
7221
+ paramCategory: 1 /* ArgsList */,
7207
7222
  paramType,
7208
7223
  requiresTypeVarMatching: true,
7209
7224
  argument: {
@@ -7253,6 +7268,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7253
7268
  function validateFunctionArgumentTypesWithContext(errorNode, matchResults, typeVarContext, skipUnknownArgCheck = false, inferenceContext) {
7254
7269
  var _a;
7255
7270
  const type = matchResults.overload;
7271
+ // Can we safely ignore the inference context (either because it's not provided
7272
+ // or will have no effect)? If so, we can eliminate a bunch of extra work.
7256
7273
  if (!inferenceContext ||
7257
7274
  (0, types_1.isAnyOrUnknown)(inferenceContext.expectedType) ||
7258
7275
  (0, types_1.isNever)(inferenceContext.expectedType) ||
@@ -7282,6 +7299,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7282
7299
  });
7283
7300
  }
7284
7301
  if (effectiveExpectedType) {
7302
+ const liveTypeVarScopes = ParseTreeUtils.getTypeVarScopesForNode(errorNode);
7285
7303
  // Prepopulate the typeVarContext based on the specialized expected type if the
7286
7304
  // callee has a declared return type. This will allow us to more closely match
7287
7305
  // the expected type if possible.
@@ -7301,7 +7319,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7301
7319
  }
7302
7320
  if ((0, types_1.isClassInstance)(effectiveExpectedType) && !(0, types_1.isTypeSame)(effectiveReturnType, effectiveExpectedType)) {
7303
7321
  const tempTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(effectiveReturnType));
7304
- (0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, effectiveReturnType, effectiveExpectedType, tempTypeVarContext, ParseTreeUtils.getTypeVarScopesForNode(errorNode));
7322
+ (0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, effectiveReturnType, effectiveExpectedType, tempTypeVarContext, liveTypeVarScopes);
7305
7323
  const genericReturnType = types_1.ClassType.cloneForSpecialization(effectiveReturnType,
7306
7324
  /* typeArguments */ undefined,
7307
7325
  /* isTypeArgumentExplicit */ false);
@@ -7317,6 +7335,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7317
7335
  });
7318
7336
  }
7319
7337
  }
7338
+ effectiveExpectedType = (0, typeUtils_1.transformExpectedType)(effectiveExpectedType, liveTypeVarScopes);
7320
7339
  assignType(effectiveReturnType, effectiveExpectedType,
7321
7340
  /* diag */ undefined, typeVarContext,
7322
7341
  /* srcTypeVarContext */ undefined, effectiveFlags | 1024 /* PopulatingExpectedType */);
@@ -7413,17 +7432,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7413
7432
  if (argResult.isTypeIncomplete) {
7414
7433
  isTypeIncomplete = true;
7415
7434
  }
7416
- // If we skipped a overload arg during the first pass,
7417
- // add another pass to ensure that we handle all of the
7418
- // type variables.
7435
+ // If we skipped an overload arg or a bare type var during the first pass,
7436
+ // add another pass to ensure that we handle all of the type variables.
7419
7437
  if (i === 0 && (argResult.skippedOverloadArg || argResult.skippedBareTypeVarExpectedType)) {
7420
7438
  passCount++;
7421
7439
  }
7422
7440
  });
7423
7441
  });
7424
7442
  }
7425
- // Lock the type var map so it cannot be modified and revalidate the
7426
- // arguments in a second pass.
7443
+ // Lock the type var map so it cannot be modified when revalidating
7444
+ // the arguments in a second pass.
7427
7445
  typeVarContext.lock();
7428
7446
  }
7429
7447
  let sawParamSpecArgs = false;
@@ -7511,21 +7529,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7511
7529
  type.details.typeVarScopeId === types_1.WildcardTypeVarScopeId) {
7512
7530
  eliminateUnsolvedInUnions = false;
7513
7531
  }
7514
- // In general, we want to replace in-scope TypeVars with Unknown
7515
- // if they were not solved. However, if the return type is a
7516
- // Callable, we'll leave the TypeVars unsolved because
7517
- // the call below to adjustCallableReturnType will "detach" these
7518
- // TypeVars from the scope of this function and "attach" them to
7519
- // the scope of the callable.
7520
- let unknownIfNotFound = !(0, types_1.isFunction)(returnType);
7521
- // We'll also leave TypeVars unsolved if the call is a recursive
7532
+ // We'll leave TypeVars unsolved if the call is a recursive
7522
7533
  // call to a generic function.
7523
- const typeVarScopes = ParseTreeUtils.getTypeVarScopesForNode(errorNode);
7524
- if (typeVarScopes.some((typeVarScope) => typeVarContext.hasSolveForScope(typeVarScope))) {
7525
- unknownIfNotFound = false;
7526
- }
7534
+ const unknownIfNotFound = !ParseTreeUtils.getTypeVarScopesForNode(errorNode).some((typeVarScope) => typeVarContext.hasSolveForScope(typeVarScope));
7527
7535
  let specializedReturnType = (0, typeUtils_1.applySolvedTypeVars)(returnType, typeVarContext, {
7528
7536
  unknownIfNotFound,
7537
+ unknownExemptTypeVars: getUnknownExemptTypeVarsForReturnType(type, returnType),
7529
7538
  useUnknownOverDefault: skipUnknownArgCheck,
7530
7539
  eliminateUnsolvedInUnions,
7531
7540
  applyInScopePlaceholders: true,
@@ -7578,6 +7587,32 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7578
7587
  overloadsUsedForCall: argumentErrors ? [] : [type],
7579
7588
  };
7580
7589
  }
7590
+ // In general, all in-scope type variables left in a return type should be
7591
+ // replaced with Unknown. However, if the return type is a callable that uses
7592
+ // type vars that are found nowhere within the function's input parameters,
7593
+ // we'll treat these as though they're scoped to the callable and leave them
7594
+ // unsolved.
7595
+ function getUnknownExemptTypeVarsForReturnType(functionType, returnType) {
7596
+ if ((0, types_1.isFunction)(returnType) && !returnType.details.name) {
7597
+ const returnTypeScopeId = returnType.details.typeVarScopeId;
7598
+ // If one or more type vars found within the return type are scoped to
7599
+ // the functionType but don't appear anywhere else within the functionType's
7600
+ // input parameters, rescope them to the return type callable so they are
7601
+ // not replaced with Unknown.
7602
+ if (returnTypeScopeId && functionType.details.typeVarScopeId) {
7603
+ let typeVarsInReturnType = (0, typeUtils_1.getTypeVarArgumentsRecursive)(returnType);
7604
+ // Remove any type variables that appear in the function's input parameters.
7605
+ functionType.details.parameters.forEach((param, index) => {
7606
+ if (param.hasDeclaredType) {
7607
+ const typeVarsInInputParam = (0, typeUtils_1.getTypeVarArgumentsRecursive)(param.type);
7608
+ typeVarsInReturnType = typeVarsInReturnType.filter((returnTypeVar) => !typeVarsInInputParam.some((inputTypeVar) => (0, types_1.isTypeSame)(returnTypeVar, inputTypeVar)));
7609
+ }
7610
+ });
7611
+ return typeVarsInReturnType;
7612
+ }
7613
+ }
7614
+ return [];
7615
+ }
7581
7616
  function adjustCallableReturnType(returnType) {
7582
7617
  // If the return type includes a generic Callable type, set the type var
7583
7618
  // scope to a wildcard to allow these type vars to be solved. This won't
@@ -7657,8 +7692,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7657
7692
  if (positionalIndexLimit < 0) {
7658
7693
  positionalIndexLimit = paramSpecParams.length;
7659
7694
  }
7660
- const argsParam = paramSpecParams.find((paramInfo) => paramInfo.category === 1 /* VarArgList */);
7661
- const kwargsParam = paramSpecParams.find((paramInfo) => paramInfo.category === 2 /* VarArgDictionary */);
7695
+ const argsParam = paramSpecParams.find((paramInfo) => paramInfo.category === 1 /* ArgsList */);
7696
+ const kwargsParam = paramSpecParams.find((paramInfo) => paramInfo.category === 2 /* KwargsDict */);
7662
7697
  const signatureTracker = new typeUtils_1.UniqueSignatureTracker();
7663
7698
  let sawUnpackedListArgument = false;
7664
7699
  let sawUnpackedDictArgument = false;
@@ -7718,7 +7753,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7718
7753
  else if (arg.argumentCategory === 1 /* UnpackedList */) {
7719
7754
  sawUnpackedListArgument = true;
7720
7755
  // See if there is an *args parameter.
7721
- const argsParam = paramSpecParams.find((param) => param.category === 1 /* VarArgList */ && param.name);
7756
+ const argsParam = paramSpecParams.find((param) => param.category === 1 /* ArgsList */ && param.name);
7722
7757
  if (argsParam && paramMap.has(argsParam.name)) {
7723
7758
  // TODO - validate args type
7724
7759
  paramMap.delete(argsParam.name);
@@ -7728,7 +7763,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7728
7763
  sawUnpackedDictArgument = true;
7729
7764
  (0, debug_1.assert)(arg.argumentCategory === 2 /* UnpackedDictionary */);
7730
7765
  // See if there is an *kwargs parameter.
7731
- const kwargsParam = paramSpecParams.find((param) => param.category === 2 /* VarArgDictionary */);
7766
+ const kwargsParam = paramSpecParams.find((param) => param.category === 2 /* KwargsDict */);
7732
7767
  if (kwargsParam && paramMap.has(kwargsParam.name)) {
7733
7768
  // TODO - validate kwargs type
7734
7769
  paramMap.delete(kwargsParam.name);
@@ -7856,7 +7891,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7856
7891
  // If we're assigning to a var arg dictionary with a TypeVar type,
7857
7892
  // strip literals before performing the assignment. This is used in
7858
7893
  // places like a dict constructor.
7859
- if (argParam.paramCategory === 2 /* VarArgDictionary */ && (0, types_1.isTypeVar)(argParam.paramType)) {
7894
+ if (argParam.paramCategory === 2 /* KwargsDict */ && (0, types_1.isTypeVar)(argParam.paramType)) {
7860
7895
  argType = stripLiteralValue(argType);
7861
7896
  }
7862
7897
  // If there's a constraint filter, apply it to top-level type variables
@@ -9230,28 +9265,28 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9230
9265
  type: types_1.UnknownType.create(),
9231
9266
  });
9232
9267
  }
9268
+ // Handle the case where the expected type contains a ParamSpec.
9269
+ if (expectedFunctionType === null || expectedFunctionType === void 0 ? void 0 : expectedFunctionType.details.paramSpec) {
9270
+ functionType.details.paramSpec = expectedFunctionType.details.paramSpec;
9271
+ }
9233
9272
  const expectedReturnType = expectedFunctionType
9234
9273
  ? getFunctionEffectiveReturnType(expectedFunctionType)
9235
9274
  : undefined;
9236
9275
  // If we're speculatively evaluating the lambda, create another speculative
9237
9276
  // evaluation scope for the return expression and do not allow retention
9238
9277
  // of the cached types.
9239
- const inferLambdaReturnType = () => {
9278
+ // We need to set allowCacheRetention to false because we don't want to
9279
+ // cache the type of the lambda return expression because it depends on
9280
+ // the parameter types that we set above, and the speculative type cache
9281
+ // doesn't know about that context.
9282
+ useSpeculativeMode(isSpeculativeModeInUse(node) || (inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.isTypeIncomplete) ? node.expression : undefined, () => {
9240
9283
  const returnTypeResult = getTypeOfExpression(node.expression,
9241
9284
  /* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedReturnType));
9242
9285
  functionType.inferredReturnType = returnTypeResult.type;
9243
9286
  if (returnTypeResult.isIncomplete) {
9244
9287
  isIncomplete = true;
9245
9288
  }
9246
- };
9247
- // We need to set allowCacheRetention to false because we don't want to
9248
- // cache the type of the lambda return expression because it depends on
9249
- // the parameter types that we set above, and the speculative type cache
9250
- // doesn't know about that context.
9251
- useSpeculativeMode(isSpeculativeModeInUse(node) || (inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.isTypeIncomplete) ? node.expression : undefined, () => {
9252
- inferLambdaReturnType();
9253
- },
9254
- /* allowCacheRetention */ false);
9289
+ }, inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType);
9255
9290
  // Mark the function type as no longer being evaluated.
9256
9291
  functionType.details.flags &= ~131072 /* PartiallyEvaluated */;
9257
9292
  return { type: functionType, isIncomplete };
@@ -9260,13 +9295,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9260
9295
  var _a;
9261
9296
  let isIncomplete = false;
9262
9297
  let typeErrors = false;
9298
+ // If any of the "for" clauses are marked async or any of the "if" clauses
9299
+ // or the final expression contain an "await" operator anywhere within
9300
+ // the expression, it is treated as an async generator.
9263
9301
  let isAsync = node.forIfNodes.some((comp) => {
9264
9302
  return ((comp.nodeType === 33 /* ListComprehensionFor */ && comp.isAsync) ||
9265
9303
  (comp.nodeType === 34 /* ListComprehensionIf */ &&
9266
- comp.testExpression.nodeType === 6 /* Await */));
9304
+ ParseTreeUtils.containsAwaitNode(comp.testExpression)));
9267
9305
  });
9268
9306
  let type = types_1.UnknownType.create();
9269
- if (node.expression.nodeType === 6 /* Await */) {
9307
+ if (ParseTreeUtils.containsAwaitNode(node.expression)) {
9270
9308
  isAsync = true;
9271
9309
  }
9272
9310
  let expectedElementType;
@@ -9506,12 +9544,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9506
9544
  const paramName = `__p${index.toString()}`;
9507
9545
  if ((0, types_1.isVariadicTypeVar)(entryType)) {
9508
9546
  validateVariadicTypeVarIsUnpacked(entryType, entry.node);
9509
- paramCategory = 1 /* VarArgList */;
9547
+ paramCategory = 1 /* ArgsList */;
9510
9548
  noteSawUnpacked(entry);
9511
9549
  }
9512
9550
  else if (validateTypeArg(entry, { allowUnpackedTuples: true })) {
9513
9551
  if ((0, types_1.isUnpackedClass)(entryType)) {
9514
- paramCategory = 1 /* VarArgList */;
9552
+ paramCategory = 1 /* ArgsList */;
9515
9553
  noteSawUnpacked(entry);
9516
9554
  }
9517
9555
  }
@@ -11896,17 +11934,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11896
11934
  param.defaultValue.constType === 26 /* None */ &&
11897
11935
  !(0, typeUtils_1.isOptionalType)(type) &&
11898
11936
  !AnalyzerNodeInfo.getFileInfo(param).diagnosticRuleSet.strictParameterNoneValue) {
11899
- type = (0, types_1.combineTypes)([type, types_1.NoneType.createInstance()]);
11900
- }
11901
- else if ((0, types_1.isTypeVar)(type) && param.defaultValue && type.scopeType === 1 /* Function */) {
11902
- // Handle the case where a default argument type is provided when the
11903
- // parameter is annotated with a "raw" function-scoped type variable, as in:
11904
- // "def foo(value: T = 3)"
11905
- // In this case, we need to include the default value type in a union.
11906
- const defaultArgType = getTypeOfExpression(param.defaultValue, 1 /* ConvertEllipsisToAny */, (0, typeUtils_1.makeInferenceContext)(type)).type;
11907
- if (!(0, types_1.isAny)(defaultArgType)) {
11908
- type = (0, types_1.combineTypes)([type, defaultArgType]);
11909
- }
11937
+ return (0, types_1.combineTypes)([type, types_1.NoneType.createInstance()]);
11910
11938
  }
11911
11939
  return type;
11912
11940
  }
@@ -11990,7 +12018,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11990
12018
  case 0 /* Simple */: {
11991
12019
  return type;
11992
12020
  }
11993
- case 1 /* VarArgList */: {
12021
+ case 1 /* ArgsList */: {
11994
12022
  if ((0, types_1.isTypeVar)(type) && type.paramSpecAccess) {
11995
12023
  return type;
11996
12024
  }
@@ -12003,7 +12031,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12003
12031
  }
12004
12032
  return types_1.UnknownType.create();
12005
12033
  }
12006
- case 2 /* VarArgDictionary */: {
12034
+ case 2 /* KwargsDict */: {
12007
12035
  // Leave a ParamSpec alone.
12008
12036
  if ((0, types_1.isTypeVar)(type) && type.paramSpecAccess) {
12009
12037
  return type;
@@ -12961,9 +12989,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12961
12989
  getTypeOfAnnotation(annotationNode, {
12962
12990
  isVariableAnnotation: ((_a = annotationNode.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 54 /* TypeAnnotation */,
12963
12991
  allowUnpackedTuple: annotationParent.nodeType === 41 /* Parameter */ &&
12964
- annotationParent.category === 1 /* VarArgList */,
12992
+ annotationParent.category === 1 /* ArgsList */,
12965
12993
  allowUnpackedTypedDict: annotationParent.nodeType === 41 /* Parameter */ &&
12966
- annotationParent.category === 2 /* VarArgDictionary */,
12994
+ annotationParent.category === 2 /* KwargsDict */,
12967
12995
  });
12968
12996
  return;
12969
12997
  }
@@ -13879,11 +13907,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
13879
13907
  // types, under the assumption that we're performing speculative evaluations.
13880
13908
  // If speculativeNode is undefined, speculative mode is not used. This is
13881
13909
  // useful in cases where we conditionally want to use speculative mode.
13882
- function useSpeculativeMode(speculativeNode, callback, allowCacheRetention = true) {
13910
+ function useSpeculativeMode(speculativeNode, callback, dependentType) {
13883
13911
  if (!speculativeNode) {
13884
13912
  return callback();
13885
13913
  }
13886
- speculativeTypeTracker.enterSpeculativeContext(speculativeNode, allowCacheRetention);
13914
+ speculativeTypeTracker.enterSpeculativeContext(speculativeNode, dependentType);
13887
13915
  try {
13888
13916
  const result = callback();
13889
13917
  speculativeTypeTracker.leaveSpeculativeContext();
@@ -16638,7 +16666,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16638
16666
  const srcPositionalsToPack = srcDetails.params.slice(destDetails.argsIndex, srcLastToPackIndex - suffixLength);
16639
16667
  const srcTupleTypes = [];
16640
16668
  srcPositionalsToPack.forEach((entry) => {
16641
- if (entry.param.category === 1 /* VarArgList */) {
16669
+ if (entry.param.category === 1 /* ArgsList */) {
16642
16670
  if ((0, types_1.isUnpackedVariadicTypeVar)(entry.type)) {
16643
16671
  srcTupleTypes.push({ type: entry.type, isUnbounded: false });
16644
16672
  }
@@ -16670,7 +16698,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16670
16698
  ...srcDetails.params.slice(0, destDetails.argsIndex),
16671
16699
  {
16672
16700
  param: {
16673
- category: 1 /* VarArgList */,
16701
+ category: 1 /* ArgsList */,
16674
16702
  name: '_arg_combined',
16675
16703
  isNameSynthesized: true,
16676
16704
  hasDeclaredType: true,
@@ -16682,9 +16710,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16682
16710
  },
16683
16711
  ...srcDetails.params.slice(destDetails.argsIndex + srcPositionalsToPack.length, srcDetails.params.length),
16684
16712
  ];
16685
- const argsIndex = srcDetails.params.findIndex((param) => param.param.category === 1 /* VarArgList */);
16713
+ const argsIndex = srcDetails.params.findIndex((param) => param.param.category === 1 /* ArgsList */);
16686
16714
  srcDetails.argsIndex = argsIndex >= 0 ? argsIndex : undefined;
16687
- const kwargsIndex = srcDetails.params.findIndex((param) => param.param.category === 2 /* VarArgDictionary */);
16715
+ const kwargsIndex = srcDetails.params.findIndex((param) => param.param.category === 2 /* KwargsDict */);
16688
16716
  srcDetails.kwargsIndex = kwargsIndex >= 0 ? kwargsIndex : undefined;
16689
16717
  const firstKeywordOnlyIndex = srcDetails.params.findIndex((param) => param.source === parameterUtils_1.ParameterSource.KeywordOnly);
16690
16718
  srcDetails.firstKeywordOnlyIndex = firstKeywordOnlyIndex >= 0 ? firstKeywordOnlyIndex : undefined;
@@ -16722,8 +16750,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16722
16750
  if (destParamName && !(0, symbolNameUtils_1.isPrivateOrProtectedName)(destParamName) && !(0, symbolNameUtils_1.isPrivateOrProtectedName)(srcParamName)) {
16723
16751
  const isDestPositionalOnly = destParam.source === parameterUtils_1.ParameterSource.PositionOnly;
16724
16752
  if (!isDestPositionalOnly &&
16725
- destParam.param.category !== 1 /* VarArgList */ &&
16726
- srcParam.param.category !== 1 /* VarArgList */ &&
16753
+ destParam.param.category !== 1 /* ArgsList */ &&
16754
+ srcParam.param.category !== 1 /* ArgsList */ &&
16727
16755
  destParamName !== srcParamName) {
16728
16756
  diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.Localizer.DiagnosticAddendum.functionParamName().format({
16729
16757
  srcName: srcParamName,
@@ -17019,7 +17047,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17019
17047
  matchedParamCount++;
17020
17048
  }
17021
17049
  }
17022
- else if (!p.name && p.category === 0 /* Simple */ && remainingParams.length === 0) {
17050
+ else if ((0, types_1.isPositionOnlySeparator)(p) && remainingParams.length === 0) {
17023
17051
  // Don't bother pushing a position-only separator if it
17024
17052
  // is the first remaining param.
17025
17053
  }
@@ -17348,7 +17376,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17348
17376
  baseParam.category === 0 /* Simple */ &&
17349
17377
  baseParam.name !== overrideParam.name) {
17350
17378
  if (overrideParam.category === 0 /* Simple */) {
17351
- if (enforceParamNames) {
17379
+ if (enforceParamNames && !baseParam.isNameSynthesized) {
17352
17380
  if (overrideParamDetails.params[i].source === parameterUtils_1.ParameterSource.PositionOnly) {
17353
17381
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNamePositionOnly().format({
17354
17382
  index: i + 1,
@@ -17368,11 +17396,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17368
17396
  }
17369
17397
  else if (i < overrideParamDetails.positionOnlyParamCount &&
17370
17398
  i >= baseParamDetails.positionOnlyParamCount) {
17371
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNamePositionOnly().format({
17372
- index: i + 1,
17373
- baseName: baseParam.name || '*',
17374
- }));
17375
- canOverride = false;
17399
+ if (!baseParam.isNameSynthesized) {
17400
+ diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNamePositionOnly().format({
17401
+ index: i + 1,
17402
+ baseName: baseParam.name || '*',
17403
+ }));
17404
+ canOverride = false;
17405
+ }
17376
17406
  }
17377
17407
  else {
17378
17408
  const baseParamType = baseParamDetails.params[i].type;
@@ -17483,6 +17513,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17483
17513
  canOverride = false;
17484
17514
  }
17485
17515
  }
17516
+ // Verify that one or the other method doesn't contain a ParamSpec.
17517
+ if (baseMethod.details.paramSpec && !overrideMethod.details.paramSpec) {
17518
+ diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.paramSpecMissingInOverride());
17519
+ canOverride = false;
17520
+ }
17486
17521
  // Now check the return type.
17487
17522
  const baseReturnType = getFunctionEffectiveReturnType(baseMethod);
17488
17523
  const overrideReturnType = getFunctionEffectiveReturnType(overrideMethod);