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

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 (110) 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.d.ts +1 -1
  6. package/dist/analyzer/constraintSolver.js +24 -8
  7. package/dist/analyzer/constraintSolver.js.map +1 -1
  8. package/dist/analyzer/constructorTransform.js +3 -3
  9. package/dist/analyzer/constructorTransform.js.map +1 -1
  10. package/dist/analyzer/constructors.js +153 -132
  11. package/dist/analyzer/constructors.js.map +1 -1
  12. package/dist/analyzer/dataClasses.js +1 -1
  13. package/dist/analyzer/dataClasses.js.map +1 -1
  14. package/dist/analyzer/docStringConversion.js +1 -1
  15. package/dist/analyzer/enums.js +1 -1
  16. package/dist/analyzer/enums.js.map +1 -1
  17. package/dist/analyzer/parameterUtils.js +7 -7
  18. package/dist/analyzer/parameterUtils.js.map +1 -1
  19. package/dist/analyzer/parseTreeUtils.d.ts +1 -0
  20. package/dist/analyzer/parseTreeUtils.js +21 -6
  21. package/dist/analyzer/parseTreeUtils.js.map +1 -1
  22. package/dist/analyzer/patternMatching.js +2 -1
  23. package/dist/analyzer/patternMatching.js.map +1 -1
  24. package/dist/analyzer/program.js +9 -4
  25. package/dist/analyzer/program.js.map +1 -1
  26. package/dist/analyzer/service.js +8 -0
  27. package/dist/analyzer/service.js.map +1 -1
  28. package/dist/analyzer/sourceFile.d.ts +3 -2
  29. package/dist/analyzer/sourceFile.js +204 -190
  30. package/dist/analyzer/sourceFile.js.map +1 -1
  31. package/dist/analyzer/typeCacheUtils.d.ts +9 -2
  32. package/dist/analyzer/typeCacheUtils.js +52 -9
  33. package/dist/analyzer/typeCacheUtils.js.map +1 -1
  34. package/dist/analyzer/typeEvaluator.js +220 -128
  35. package/dist/analyzer/typeEvaluator.js.map +1 -1
  36. package/dist/analyzer/typeGuards.js +3 -3
  37. package/dist/analyzer/typeGuards.js.map +1 -1
  38. package/dist/analyzer/typePrinter.js +9 -9
  39. package/dist/analyzer/typePrinter.js.map +1 -1
  40. package/dist/analyzer/typeStubWriter.js +2 -2
  41. package/dist/analyzer/typeStubWriter.js.map +1 -1
  42. package/dist/analyzer/typeUtils.d.ts +6 -6
  43. package/dist/analyzer/typeUtils.js +145 -159
  44. package/dist/analyzer/typeUtils.js.map +1 -1
  45. package/dist/analyzer/typeVarContext.js +12 -1
  46. package/dist/analyzer/typeVarContext.js.map +1 -1
  47. package/dist/analyzer/typeWalker.d.ts +22 -0
  48. package/dist/analyzer/typeWalker.js +164 -0
  49. package/dist/analyzer/typeWalker.js.map +1 -0
  50. package/dist/analyzer/typedDicts.js +2 -2
  51. package/dist/analyzer/typedDicts.js.map +1 -1
  52. package/dist/analyzer/types.d.ts +5 -2
  53. package/dist/analyzer/types.js +39 -22
  54. package/dist/analyzer/types.js.map +1 -1
  55. package/dist/backgroundAnalysisBase.d.ts +4 -2
  56. package/dist/commands/dumpFileDebugInfoCommand.js +2 -2
  57. package/dist/common/commandLineOptions.d.ts +1 -0
  58. package/dist/common/commandLineOptions.js.map +1 -1
  59. package/dist/common/textRange.d.ts +3 -3
  60. package/dist/common/textRange.js +17 -8
  61. package/dist/common/textRange.js.map +1 -1
  62. package/dist/common/uriParser.d.ts +1 -0
  63. package/dist/common/uriParser.js +9 -0
  64. package/dist/common/uriParser.js.map +1 -1
  65. package/dist/languageServerBase.js +4 -2
  66. package/dist/languageServerBase.js.map +1 -1
  67. package/dist/languageService/analyzerServiceExecutor.js +1 -0
  68. package/dist/languageService/analyzerServiceExecutor.js.map +1 -1
  69. package/dist/languageService/completionProvider.js +5 -5
  70. package/dist/languageService/completionProvider.js.map +1 -1
  71. package/dist/languageService/renameProvider.d.ts +3 -3
  72. package/dist/languageService/renameProvider.js +6 -6
  73. package/dist/languageService/renameProvider.js.map +1 -1
  74. package/dist/localization/localize.d.ts +5 -0
  75. package/dist/localization/localize.js +3 -0
  76. package/dist/localization/localize.js.map +1 -1
  77. package/dist/localization/package.nls.en-us.json +3 -0
  78. package/dist/parser/parseNodes.d.ts +11 -3
  79. package/dist/parser/parseNodes.js +7 -9
  80. package/dist/parser/parseNodes.js.map +1 -1
  81. package/dist/parser/parser.js +13 -10
  82. package/dist/parser/parser.js.map +1 -1
  83. package/dist/parser/tokenizer.js +8 -7
  84. package/dist/parser/tokenizer.js.map +1 -1
  85. package/dist/tests/docStringConversion.test.js +44 -0
  86. package/dist/tests/docStringConversion.test.js.map +1 -1
  87. package/dist/tests/fourslash/fourslash.d.ts +1 -1
  88. package/dist/tests/fourslash/rename.function.untitledFile.fourslash.d.ts +1 -0
  89. package/dist/tests/fourslash/rename.function.untitledFile.fourslash.js +17 -0
  90. package/dist/tests/fourslash/rename.function.untitledFile.fourslash.js.map +1 -0
  91. package/dist/tests/harness/fourslash/testState.d.ts +1 -1
  92. package/dist/tests/harness/fourslash/testState.js +2 -2
  93. package/dist/tests/harness/fourslash/testState.js.map +1 -1
  94. package/dist/tests/service.test.js +10 -0
  95. package/dist/tests/service.test.js.map +1 -1
  96. package/dist/tests/tokenizer.test.js +8 -0
  97. package/dist/tests/tokenizer.test.js.map +1 -1
  98. package/dist/tests/typeEvaluator1.test.js +5 -1
  99. package/dist/tests/typeEvaluator1.test.js.map +1 -1
  100. package/dist/tests/typeEvaluator2.test.js +12 -0
  101. package/dist/tests/typeEvaluator2.test.js.map +1 -1
  102. package/dist/tests/typeEvaluator3.test.js +17 -1
  103. package/dist/tests/typeEvaluator3.test.js.map +1 -1
  104. package/dist/tests/typeEvaluator4.test.js +4 -0
  105. package/dist/tests/typeEvaluator4.test.js.map +1 -1
  106. package/dist/tests/typePrinter.test.js +3 -3
  107. package/dist/tests/typePrinter.test.js.map +1 -1
  108. package/dist/workspaceFactory.js +4 -4
  109. package/dist/workspaceFactory.js.map +1 -1
  110. 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
  }
@@ -5160,7 +5170,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5160
5170
  }
5161
5171
  else {
5162
5172
  const tupleTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(tupleClassType));
5163
- if (!(0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, types_1.ClassType.cloneAsInstance(tupleClassType), inferenceContext.expectedType, tupleTypeVarContext, ParseTreeUtils.getTypeVarScopesForNode(node))) {
5173
+ if (!(0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, types_1.ClassType.cloneAsInstance(tupleClassType), inferenceContext.expectedType, tupleTypeVarContext, ParseTreeUtils.getTypeVarScopesForNode(node), node.start)) {
5164
5174
  return undefined;
5165
5175
  }
5166
5176
  const specializedTuple = (0, typeUtils_1.applySolvedTypeVars)(tupleClassType, tupleTypeVarContext);
@@ -5675,7 +5685,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5675
5685
  // (one for each argument) will be undefined. On subsequent calls, this
5676
5686
  // list will grow to include union expansions.
5677
5687
  function validateOverloadsWithExpandedTypes(errorNode, expandedArgTypes, argParamMatches, typeVarContext, skipUnknownArgCheck, inferenceContext) {
5678
- var _a, _b;
5688
+ var _a, _b, _c;
5679
5689
  const returnTypes = [];
5680
5690
  const matchedOverloads = [];
5681
5691
  let isTypeIncomplete = false;
@@ -5764,19 +5774,22 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5764
5774
  let isSubtypeSubsumed = false;
5765
5775
  for (let dedupedIndex = 0; dedupedIndex < dedupedMatchResults.length; dedupedIndex++) {
5766
5776
  if (assignType(dedupedMatchResults[dedupedIndex], result.returnType)) {
5767
- if (!(0, typeUtils_1.containsAnyOrUnknown)(dedupedMatchResults[dedupedIndex])) {
5777
+ const anyOrUnknown = (0, typeUtils_1.containsAnyOrUnknown)(dedupedMatchResults[dedupedIndex],
5778
+ /* recurse */ false);
5779
+ if (!anyOrUnknown) {
5768
5780
  isSubtypeSubsumed = true;
5769
5781
  }
5770
- else if (!(0, typeUtils_1.containsUnknown)(dedupedMatchResults[dedupedIndex])) {
5782
+ else if ((0, types_1.isAny)(anyOrUnknown)) {
5771
5783
  dedupedResultsIncludeAny = true;
5772
5784
  }
5773
5785
  break;
5774
5786
  }
5775
5787
  else if (assignType(result.returnType, dedupedMatchResults[dedupedIndex])) {
5776
- if (!(0, typeUtils_1.containsAnyOrUnknown)(result.returnType)) {
5788
+ const anyOrUnknown = (0, typeUtils_1.containsAnyOrUnknown)(result.returnType, /* recurse */ false);
5789
+ if (!anyOrUnknown) {
5777
5790
  dedupedMatchResults[dedupedIndex] = types_1.NeverType.createNever();
5778
5791
  }
5779
- else if (!(0, typeUtils_1.containsUnknown)(dedupedMatchResults[dedupedIndex])) {
5792
+ else if ((0, types_1.isAny)(anyOrUnknown)) {
5780
5793
  dedupedResultsIncludeAny = true;
5781
5794
  }
5782
5795
  break;
@@ -5799,7 +5812,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5799
5812
  effectiveReturnType = types_1.AnyType.create();
5800
5813
  }
5801
5814
  else {
5802
- effectiveReturnType = types_1.UnknownType.createPossibleType(combinedTypes, possibleMatchInvolvesIncompleteUnknown);
5815
+ // If all of the return types are the same generic class,
5816
+ // replace the type arguments with Unknown. Otherwise return
5817
+ // an Unknown type that has associated "possible types" to aid
5818
+ // with completion suggestions.
5819
+ effectiveReturnType =
5820
+ (_c = (0, typeUtils_1.getCommonErasedType)(dedupedMatchResults)) !== null && _c !== void 0 ? _c : types_1.UnknownType.createPossibleType(combinedTypes, possibleMatchInvolvesIncompleteUnknown);
5803
5821
  }
5804
5822
  }
5805
5823
  returnTypes.push(effectiveReturnType);
@@ -5840,6 +5858,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5840
5858
  if (matches.length < 2) {
5841
5859
  return matches;
5842
5860
  }
5861
+ // If the relevance of some matches differs, filter out the ones that
5862
+ // are lower relevance. This favors *args parameters in cases where
5863
+ // a *args argument is used.
5864
+ if (matches[0].matchResults.relevance !== matches[matches.length - 1].matchResults.relevance) {
5865
+ matches = matches.filter((m) => m.matchResults.relevance === matches[0].matchResults.relevance);
5866
+ if (matches.length < 2) {
5867
+ return matches;
5868
+ }
5869
+ }
5843
5870
  // If all of the return types match, select the first one.
5844
5871
  if ((0, typeUtils_1.areTypesSame)(matches.map((match) => match.returnType), { treatAnySameAsUnknown: true })) {
5845
5872
  return [matches[0]];
@@ -5849,9 +5876,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5849
5876
  return matches;
5850
5877
  }
5851
5878
  for (let i = 0; i < firstArgResults.length; i++) {
5852
- // If the arg is Any or Unknown, see if the corresponding
5879
+ // If the arg contains Any or Unknown, see if the corresponding
5853
5880
  // parameter types differ in any way.
5854
- if ((0, types_1.isAnyOrUnknown)(firstArgResults[i].argType)) {
5881
+ const anyOrUnknownInArg = (0, typeUtils_1.containsAnyOrUnknown)(firstArgResults[i].argType, /* recurse */ true);
5882
+ if (anyOrUnknownInArg) {
5855
5883
  const paramTypes = matches.map((match) => i < match.matchResults.argParams.length
5856
5884
  ? match.matchResults.argParams[i].paramType
5857
5885
  : types_1.UnknownType.create());
@@ -6487,6 +6515,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6487
6515
  // Build a map of parameters by name.
6488
6516
  const paramMap = new Map();
6489
6517
  paramDetails.params.forEach((paramInfo) => {
6518
+ (0, debug_1.assert)(paramInfo !== undefined, 'paramInfo is undefined for param name map');
6490
6519
  const param = paramInfo.param;
6491
6520
  if (param.name && param.category === 0 /* Simple */) {
6492
6521
  paramMap.set(param.name, {
@@ -6537,8 +6566,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6537
6566
  if (argList.some((arg) => arg.argumentCategory === 1 /* UnpackedList */)) {
6538
6567
  argList.forEach((arg) => {
6539
6568
  if (arg.name) {
6540
- const keywordParamIndex = paramDetails.params.findIndex((paramInfo) => paramInfo.param.name === arg.name.value &&
6541
- paramInfo.param.category === 0 /* Simple */);
6569
+ const keywordParamIndex = paramDetails.params.findIndex((paramInfo) => {
6570
+ (0, debug_1.assert)(paramInfo, 'paramInfo entry is undefined fork kwargs check');
6571
+ return (paramInfo.param.name === arg.name.value &&
6572
+ paramInfo.param.category === 0 /* Simple */);
6573
+ });
6542
6574
  // Is this a parameter that can be interpreted as either a keyword or a positional?
6543
6575
  // If so, we'll treat it as a keyword parameter in this case because it's being
6544
6576
  // targeted by a keyword argument.
@@ -6616,7 +6648,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6616
6648
  (0, debug_1.assert)(paramDetails.params[paramIndex], 'paramIndex params entry is undefined');
6617
6649
  const paramType = paramDetails.params[paramIndex].type;
6618
6650
  const paramName = paramDetails.params[paramIndex].param.name;
6619
- const isParamVariadic = paramDetails.params[paramIndex].param.category === 1 /* VarArgList */ &&
6651
+ const isParamVariadic = paramDetails.params[paramIndex].param.category === 1 /* ArgsList */ &&
6620
6652
  (0, types_1.isVariadicTypeVar)(paramType);
6621
6653
  if (argList[argIndex].argumentCategory === 1 /* UnpackedList */) {
6622
6654
  let isArgCompatibleWithVariadic = false;
@@ -6677,7 +6709,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6677
6709
  listElementType =
6678
6710
  (_e = (_d = getTypeOfIterator({ type: argType, isIncomplete: argTypeResult.isIncomplete },
6679
6711
  /* 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 */) {
6712
+ if (paramDetails.params[paramIndex].param.category !== 1 /* ArgsList */) {
6681
6713
  matchedUnpackedListOfUnknownLength = true;
6682
6714
  }
6683
6715
  }
@@ -6722,16 +6754,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6722
6754
  paramMap.has(paramName)) {
6723
6755
  paramMap.get(paramName).argsReceived++;
6724
6756
  }
6725
- if (advanceToNextArg ||
6726
- paramDetails.params[paramIndex].param.category === 1 /* VarArgList */) {
6757
+ if (advanceToNextArg || paramDetails.params[paramIndex].param.category === 1 /* ArgsList */) {
6727
6758
  argIndex++;
6728
6759
  }
6729
6760
  if (isVariadicTypeVarFullyMatched ||
6730
- paramDetails.params[paramIndex].param.category !== 1 /* VarArgList */) {
6761
+ paramDetails.params[paramIndex].param.category !== 1 /* ArgsList */) {
6731
6762
  paramIndex++;
6732
6763
  }
6733
6764
  }
6734
- else if (paramDetails.params[paramIndex].param.category === 1 /* VarArgList */) {
6765
+ else if (paramDetails.params[paramIndex].param.category === 1 /* ArgsList */) {
6735
6766
  trySetActive(argList[argIndex], paramDetails.params[paramIndex].param);
6736
6767
  if (paramSpecArgList) {
6737
6768
  paramSpecArgList.push(argList[argIndex]);
@@ -6747,7 +6778,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6747
6778
  effectiveParamType = paramType.tupleTypeArguments[0].type;
6748
6779
  }
6749
6780
  paramCategory = (0, types_1.isVariadicTypeVar)(effectiveParamType)
6750
- ? 1 /* VarArgList */
6781
+ ? 1 /* ArgsList */
6751
6782
  : 0 /* Simple */;
6752
6783
  if (remainingArgCount <= remainingParamCount) {
6753
6784
  if (remainingArgCount < remainingParamCount) {
@@ -6804,7 +6835,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6804
6835
  let skippedArgsParam = false;
6805
6836
  if (positionalOnlyLimitIndex >= 0 &&
6806
6837
  paramIndex < positionalOnlyLimitIndex &&
6807
- paramDetails.params[paramIndex].param.category === 1 /* VarArgList */ &&
6838
+ paramIndex < paramDetails.params.length &&
6839
+ paramDetails.params[paramIndex].param.category === 1 /* ArgsList */ &&
6808
6840
  !(0, types_1.isParamSpec)(paramDetails.params[paramIndex].param.type)) {
6809
6841
  paramIndex++;
6810
6842
  skippedArgsParam = true;
@@ -6825,7 +6857,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6825
6857
  // because it's permitted to pass zero arguments to *args.
6826
6858
  argsRemainingCount--;
6827
6859
  }
6828
- const firstArgsParam = paramDetails.params.findIndex((paramInfo) => paramInfo.param.category === 1 /* VarArgList */ && !(0, types_1.isParamSpec)(paramInfo.param.type));
6860
+ const firstArgsParam = paramDetails.params.findIndex((paramInfo) => paramInfo.param.category === 1 /* ArgsList */ && !(0, types_1.isParamSpec)(paramInfo.param.type));
6829
6861
  if (firstArgsParam >= paramIndex && firstArgsParam < positionalOnlyLimitIndex) {
6830
6862
  // If there is another args parameter beyond the current param index,
6831
6863
  // reduce the count by one because it's permitted to pass zero arguments
@@ -6887,7 +6919,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6887
6919
  else if (paramDetails.kwargsIndex !== undefined) {
6888
6920
  const paramType = paramDetails.params[paramDetails.kwargsIndex].type;
6889
6921
  validateArgTypeParams.push({
6890
- paramCategory: 2 /* VarArgDictionary */,
6922
+ paramCategory: 2 /* KwargsDict */,
6891
6923
  paramType,
6892
6924
  requiresTypeVarMatching: (0, typeUtils_1.requiresSpecialization)(paramType),
6893
6925
  argument: {
@@ -6925,7 +6957,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6925
6957
  unpackedDictionaryArgType = types_1.AnyType.create();
6926
6958
  if (typeResult.type.details.paramSpec) {
6927
6959
  validateArgTypeParams.push({
6928
- paramCategory: 2 /* VarArgDictionary */,
6960
+ paramCategory: 2 /* KwargsDict */,
6929
6961
  paramType: typeResult.type.details.paramSpec,
6930
6962
  requiresTypeVarMatching: false,
6931
6963
  argument: argList[argIndex],
@@ -7010,7 +7042,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7010
7042
  else {
7011
7043
  const paramType = paramDetails.params[paramDetails.kwargsIndex].type;
7012
7044
  validateArgTypeParams.push({
7013
- paramCategory: 2 /* VarArgDictionary */,
7045
+ paramCategory: 2 /* KwargsDict */,
7014
7046
  paramType,
7015
7047
  requiresTypeVarMatching: (0, typeUtils_1.requiresSpecialization)(paramType),
7016
7048
  argument: argList[argIndex],
@@ -7054,7 +7086,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7054
7086
  }
7055
7087
  if ((0, types_1.isParamSpec)(argType) && argType.paramSpecAccess === 'args') {
7056
7088
  validateArgTypeParams.push({
7057
- paramCategory: 1 /* VarArgList */,
7089
+ paramCategory: 1 /* ArgsList */,
7058
7090
  paramType: typeResult.type.details.paramSpec,
7059
7091
  requiresTypeVarMatching: false,
7060
7092
  argument: argList[argIndex],
@@ -7157,6 +7189,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7157
7189
  // already been matched, see if the type of that *args parameter is a variadic
7158
7190
  // type variable. If so, we'll preprocess those arguments and combine them
7159
7191
  // into a tuple.
7192
+ (0, debug_1.assert)(paramDetails.argsIndex === undefined || paramDetails.argsIndex < paramDetails.params.length, 'paramDetails.argsIndex params entry is invalid');
7160
7193
  if (paramDetails.argsIndex !== undefined &&
7161
7194
  paramDetails.argsIndex >= 0 &&
7162
7195
  paramDetails.params[paramDetails.argsIndex].param.hasDeclaredType &&
@@ -7203,7 +7236,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7203
7236
  /* isUnpackedTuple */ true));
7204
7237
  }
7205
7238
  const combinedArg = {
7206
- paramCategory: 1 /* VarArgList */,
7239
+ paramCategory: 1 /* ArgsList */,
7207
7240
  paramType,
7208
7241
  requiresTypeVarMatching: true,
7209
7242
  argument: {
@@ -7253,6 +7286,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7253
7286
  function validateFunctionArgumentTypesWithContext(errorNode, matchResults, typeVarContext, skipUnknownArgCheck = false, inferenceContext) {
7254
7287
  var _a;
7255
7288
  const type = matchResults.overload;
7289
+ // Can we safely ignore the inference context (either because it's not provided
7290
+ // or will have no effect)? If so, we can eliminate a bunch of extra work.
7256
7291
  if (!inferenceContext ||
7257
7292
  (0, types_1.isAnyOrUnknown)(inferenceContext.expectedType) ||
7258
7293
  (0, types_1.isNever)(inferenceContext.expectedType) ||
@@ -7282,6 +7317,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7282
7317
  });
7283
7318
  }
7284
7319
  if (effectiveExpectedType) {
7320
+ const liveTypeVarScopes = ParseTreeUtils.getTypeVarScopesForNode(errorNode);
7285
7321
  // Prepopulate the typeVarContext based on the specialized expected type if the
7286
7322
  // callee has a declared return type. This will allow us to more closely match
7287
7323
  // the expected type if possible.
@@ -7301,7 +7337,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7301
7337
  }
7302
7338
  if ((0, types_1.isClassInstance)(effectiveExpectedType) && !(0, types_1.isTypeSame)(effectiveReturnType, effectiveExpectedType)) {
7303
7339
  const tempTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(effectiveReturnType));
7304
- (0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, effectiveReturnType, effectiveExpectedType, tempTypeVarContext, ParseTreeUtils.getTypeVarScopesForNode(errorNode));
7340
+ (0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, effectiveReturnType, effectiveExpectedType, tempTypeVarContext, liveTypeVarScopes, errorNode.start);
7305
7341
  const genericReturnType = types_1.ClassType.cloneForSpecialization(effectiveReturnType,
7306
7342
  /* typeArguments */ undefined,
7307
7343
  /* isTypeArgumentExplicit */ false);
@@ -7317,6 +7353,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7317
7353
  });
7318
7354
  }
7319
7355
  }
7356
+ effectiveExpectedType = (0, typeUtils_1.transformExpectedType)(effectiveExpectedType, liveTypeVarScopes, errorNode.start);
7320
7357
  assignType(effectiveReturnType, effectiveExpectedType,
7321
7358
  /* diag */ undefined, typeVarContext,
7322
7359
  /* srcTypeVarContext */ undefined, effectiveFlags | 1024 /* PopulatingExpectedType */);
@@ -7328,7 +7365,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7328
7365
  let isTypeIncomplete = matchResults.isTypeIncomplete;
7329
7366
  let argumentErrors = false;
7330
7367
  let specializedInitSelfType;
7331
- let anyOrUnknownArgument;
7368
+ let accumulatedAnyOrUnknownArg;
7332
7369
  const typeCondition = (0, typeUtils_1.getTypeCondition)(type);
7333
7370
  if (type.boundTypeVarScopeId) {
7334
7371
  // If the function was bound to a class or object and was a constructor, a
@@ -7381,11 +7418,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7381
7418
  // example of this is the built-in "map" method whose first parameter is
7382
7419
  // a lambda and second parameter indicates what type the lambda should accept.
7383
7420
  // In practice, we will limit the number of passes to 2 because it can get
7384
- // very expensive to go beyond this, and we don't see generally see cases
7421
+ // very expensive to go beyond this, and we don't generally see cases
7385
7422
  // where more than two passes are needed.
7386
7423
  let passCount = Math.min(typeVarMatchingCount, 2);
7387
7424
  for (let i = 0; i < passCount; i++) {
7388
7425
  const signatureTracker = new typeUtils_1.UniqueSignatureTracker();
7426
+ signatureTracker.addSignature(type);
7389
7427
  useSpeculativeMode(errorNode, () => {
7390
7428
  matchResults.argParams.forEach((argParam) => {
7391
7429
  if (!argParam.requiresTypeVarMatching) {
@@ -7413,17 +7451,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7413
7451
  if (argResult.isTypeIncomplete) {
7414
7452
  isTypeIncomplete = true;
7415
7453
  }
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.
7454
+ // If we skipped an overload arg or a bare type var during the first pass,
7455
+ // add another pass to ensure that we handle all of the type variables.
7419
7456
  if (i === 0 && (argResult.skippedOverloadArg || argResult.skippedBareTypeVarExpectedType)) {
7420
7457
  passCount++;
7421
7458
  }
7422
7459
  });
7423
7460
  });
7424
7461
  }
7425
- // Lock the type var map so it cannot be modified and revalidate the
7426
- // arguments in a second pass.
7462
+ // Lock the type var map so it cannot be modified when revalidating
7463
+ // the arguments in a second pass.
7427
7464
  typeVarContext.lock();
7428
7465
  }
7429
7466
  let sawParamSpecArgs = false;
@@ -7431,6 +7468,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7431
7468
  let condition = [];
7432
7469
  const argResults = [];
7433
7470
  const signatureTracker = new typeUtils_1.UniqueSignatureTracker();
7471
+ signatureTracker.addSignature(type);
7434
7472
  matchResults.argParams.forEach((argParam) => {
7435
7473
  var _a;
7436
7474
  const argResult = validateArgType(argParam, typeVarContext, signatureTracker, { type, isIncomplete: matchResults.isTypeIncomplete }, {
@@ -7447,10 +7485,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7447
7485
  if (argResult.condition) {
7448
7486
  condition = (_a = types_1.TypeCondition.combine(condition, argResult.condition)) !== null && _a !== void 0 ? _a : [];
7449
7487
  }
7450
- if ((0, types_1.isAnyOrUnknown)(argResult.argType)) {
7451
- anyOrUnknownArgument = anyOrUnknownArgument
7452
- ? (0, typeUtils_1.preserveUnknown)(argResult.argType, anyOrUnknownArgument)
7453
- : argResult.argType;
7488
+ // Determine if the argument type contains an Any or Unknown. Accumulate
7489
+ // these across all arguments.
7490
+ const anyOrUnknownInArg = (0, typeUtils_1.containsAnyOrUnknown)(argResult.argType, /* recurs */ true);
7491
+ if (anyOrUnknownInArg) {
7492
+ accumulatedAnyOrUnknownArg = accumulatedAnyOrUnknownArg
7493
+ ? (0, typeUtils_1.preserveUnknown)(anyOrUnknownInArg, accumulatedAnyOrUnknownArg)
7494
+ : anyOrUnknownInArg;
7454
7495
  }
7455
7496
  if (type.details.paramSpec) {
7456
7497
  if (argParam.argument.argumentCategory === 1 /* UnpackedList */) {
@@ -7511,21 +7552,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7511
7552
  type.details.typeVarScopeId === types_1.WildcardTypeVarScopeId) {
7512
7553
  eliminateUnsolvedInUnions = false;
7513
7554
  }
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
7555
+ // We'll leave TypeVars unsolved if the call is a recursive
7522
7556
  // call to a generic function.
7523
- const typeVarScopes = ParseTreeUtils.getTypeVarScopesForNode(errorNode);
7524
- if (typeVarScopes.some((typeVarScope) => typeVarContext.hasSolveForScope(typeVarScope))) {
7525
- unknownIfNotFound = false;
7526
- }
7557
+ const unknownIfNotFound = !ParseTreeUtils.getTypeVarScopesForNode(errorNode).some((typeVarScope) => typeVarContext.hasSolveForScope(typeVarScope));
7527
7558
  let specializedReturnType = (0, typeUtils_1.applySolvedTypeVars)(returnType, typeVarContext, {
7528
7559
  unknownIfNotFound,
7560
+ unknownExemptTypeVars: getUnknownExemptTypeVarsForReturnType(type, returnType),
7529
7561
  useUnknownOverDefault: skipUnknownArgCheck,
7530
7562
  eliminateUnsolvedInUnions,
7531
7563
  applyInScopePlaceholders: true,
@@ -7570,7 +7602,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7570
7602
  return {
7571
7603
  argumentErrors,
7572
7604
  argResults,
7573
- anyOrUnknownArgument,
7605
+ anyOrUnknownArgument: accumulatedAnyOrUnknownArg,
7574
7606
  returnType: specializedReturnType,
7575
7607
  isTypeIncomplete,
7576
7608
  activeParam: matchResults.activeParam,
@@ -7578,6 +7610,32 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7578
7610
  overloadsUsedForCall: argumentErrors ? [] : [type],
7579
7611
  };
7580
7612
  }
7613
+ // In general, all in-scope type variables left in a return type should be
7614
+ // replaced with Unknown. However, if the return type is a callable that uses
7615
+ // type vars that are found nowhere within the function's input parameters,
7616
+ // we'll treat these as though they're scoped to the callable and leave them
7617
+ // unsolved.
7618
+ function getUnknownExemptTypeVarsForReturnType(functionType, returnType) {
7619
+ if ((0, types_1.isFunction)(returnType) && !returnType.details.name) {
7620
+ const returnTypeScopeId = returnType.details.typeVarScopeId;
7621
+ // If one or more type vars found within the return type are scoped to
7622
+ // the functionType but don't appear anywhere else within the functionType's
7623
+ // input parameters, rescope them to the return type callable so they are
7624
+ // not replaced with Unknown.
7625
+ if (returnTypeScopeId && functionType.details.typeVarScopeId) {
7626
+ let typeVarsInReturnType = (0, typeUtils_1.getTypeVarArgumentsRecursive)(returnType);
7627
+ // Remove any type variables that appear in the function's input parameters.
7628
+ functionType.details.parameters.forEach((param, index) => {
7629
+ if (param.hasDeclaredType) {
7630
+ const typeVarsInInputParam = (0, typeUtils_1.getTypeVarArgumentsRecursive)(param.type);
7631
+ typeVarsInReturnType = typeVarsInReturnType.filter((returnTypeVar) => !typeVarsInInputParam.some((inputTypeVar) => (0, types_1.isTypeSame)(returnTypeVar, inputTypeVar)));
7632
+ }
7633
+ });
7634
+ return typeVarsInReturnType;
7635
+ }
7636
+ }
7637
+ return [];
7638
+ }
7581
7639
  function adjustCallableReturnType(returnType) {
7582
7640
  // If the return type includes a generic Callable type, set the type var
7583
7641
  // scope to a wildcard to allow these type vars to be solved. This won't
@@ -7657,8 +7715,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7657
7715
  if (positionalIndexLimit < 0) {
7658
7716
  positionalIndexLimit = paramSpecParams.length;
7659
7717
  }
7660
- const argsParam = paramSpecParams.find((paramInfo) => paramInfo.category === 1 /* VarArgList */);
7661
- const kwargsParam = paramSpecParams.find((paramInfo) => paramInfo.category === 2 /* VarArgDictionary */);
7718
+ const argsParam = paramSpecParams.find((paramInfo) => paramInfo.category === 1 /* ArgsList */);
7719
+ const kwargsParam = paramSpecParams.find((paramInfo) => paramInfo.category === 2 /* KwargsDict */);
7662
7720
  const signatureTracker = new typeUtils_1.UniqueSignatureTracker();
7663
7721
  let sawUnpackedListArgument = false;
7664
7722
  let sawUnpackedDictArgument = false;
@@ -7704,7 +7762,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7704
7762
  if (paramType) {
7705
7763
  const argResult = validateArgType({
7706
7764
  paramCategory: 0 /* Simple */,
7707
- paramType: (0, typeUtils_1.transformExpectedType)(paramType, liveTypeVarScopes),
7765
+ paramType: (0, typeUtils_1.transformExpectedType)(paramType, liveTypeVarScopes, /* usageOffset */ undefined),
7708
7766
  requiresTypeVarMatching: false,
7709
7767
  argument: arg,
7710
7768
  errorNode: arg.valueExpression || errorNode,
@@ -7718,7 +7776,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7718
7776
  else if (arg.argumentCategory === 1 /* UnpackedList */) {
7719
7777
  sawUnpackedListArgument = true;
7720
7778
  // See if there is an *args parameter.
7721
- const argsParam = paramSpecParams.find((param) => param.category === 1 /* VarArgList */ && param.name);
7779
+ const argsParam = paramSpecParams.find((param) => param.category === 1 /* ArgsList */ && param.name);
7722
7780
  if (argsParam && paramMap.has(argsParam.name)) {
7723
7781
  // TODO - validate args type
7724
7782
  paramMap.delete(argsParam.name);
@@ -7728,7 +7786,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7728
7786
  sawUnpackedDictArgument = true;
7729
7787
  (0, debug_1.assert)(arg.argumentCategory === 2 /* UnpackedDictionary */);
7730
7788
  // See if there is an *kwargs parameter.
7731
- const kwargsParam = paramSpecParams.find((param) => param.category === 2 /* VarArgDictionary */);
7789
+ const kwargsParam = paramSpecParams.find((param) => param.category === 2 /* KwargsDict */);
7732
7790
  if (kwargsParam && paramMap.has(kwargsParam.name)) {
7733
7791
  // TODO - validate kwargs type
7734
7792
  paramMap.delete(kwargsParam.name);
@@ -7856,7 +7914,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7856
7914
  // If we're assigning to a var arg dictionary with a TypeVar type,
7857
7915
  // strip literals before performing the assignment. This is used in
7858
7916
  // places like a dict constructor.
7859
- if (argParam.paramCategory === 2 /* VarArgDictionary */ && (0, types_1.isTypeVar)(argParam.paramType)) {
7917
+ if (argParam.paramCategory === 2 /* KwargsDict */ && (0, types_1.isTypeVar)(argParam.paramType)) {
7860
7918
  argType = stripLiteralValue(argType);
7861
7919
  }
7862
7920
  // If there's a constraint filter, apply it to top-level type variables
@@ -7982,7 +8040,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7982
8040
  if (!options.skipUnknownArgCheck) {
7983
8041
  const simplifiedType = (0, types_1.removeUnbound)(argType);
7984
8042
  const fileInfo = AnalyzerNodeInfo.getFileInfo(argParam.errorNode);
7985
- const getDiagAddendum = () => {
8043
+ function getDiagAddendum() {
7986
8044
  const diagAddendum = new diagnostic_1.DiagnosticAddendum();
7987
8045
  if (argParam.paramName) {
7988
8046
  diagAddendum.addMessage((functionName
@@ -7994,7 +8052,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7994
8052
  diagAddendum.getString());
7995
8053
  }
7996
8054
  return diagAddendum;
7997
- };
8055
+ }
7998
8056
  // Do not check for unknown types if the expected type is "Any".
7999
8057
  // Don't print types if reportUnknownArgumentType is disabled for performance.
8000
8058
  if (fileInfo.diagnosticRuleSet.reportUnknownArgumentType !== 'none' &&
@@ -8685,7 +8743,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8685
8743
  return undefined;
8686
8744
  }
8687
8745
  const dictTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(builtInDict));
8688
- if (!(0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, builtInDict, inferenceContext.expectedType, dictTypeVarContext, ParseTreeUtils.getTypeVarScopesForNode(node))) {
8746
+ if (!(0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, builtInDict, inferenceContext.expectedType, dictTypeVarContext, ParseTreeUtils.getTypeVarScopesForNode(node), node.start)) {
8689
8747
  return undefined;
8690
8748
  }
8691
8749
  const specializedDict = (0, typeUtils_1.applySolvedTypeVars)(types_1.ClassType.cloneAsInstantiable(builtInDict), dictTypeVarContext);
@@ -8947,7 +9005,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8947
9005
  return undefined;
8948
9006
  }
8949
9007
  const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(builtInListOrSet));
8950
- if (!(0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, builtInListOrSet, inferenceContext.expectedType, typeVarContext, ParseTreeUtils.getTypeVarScopesForNode(node))) {
9008
+ if (!(0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, builtInListOrSet, inferenceContext.expectedType, typeVarContext, ParseTreeUtils.getTypeVarScopesForNode(node), node.start)) {
8951
9009
  return undefined;
8952
9010
  }
8953
9011
  const specializedListOrSet = (0, typeUtils_1.applySolvedTypeVars)(types_1.ClassType.cloneAsInstantiable(builtInListOrSet), typeVarContext);
@@ -9168,7 +9226,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9168
9226
  expectedFunctionTypes = expectedFunctionTypes.filter((functionType) => {
9169
9227
  const functionParamCount = functionType.details.parameters.filter((param) => !!param.name && !param.hasDefault).length;
9170
9228
  const hasVarArgs = functionType.details.parameters.some((param) => !!param.name && param.category !== 0 /* Simple */);
9229
+ const hasParamSpec = !!functionType.details.paramSpec;
9171
9230
  return (hasVarArgs ||
9231
+ hasParamSpec ||
9172
9232
  (functionParamCount >= minLambdaParamCount && functionParamCount <= maxLambdaParamCount));
9173
9233
  });
9174
9234
  }
@@ -9236,22 +9296,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9236
9296
  // If we're speculatively evaluating the lambda, create another speculative
9237
9297
  // evaluation scope for the return expression and do not allow retention
9238
9298
  // of the cached types.
9239
- const inferLambdaReturnType = () => {
9299
+ // We need to set allowCacheRetention to false because we don't want to
9300
+ // cache the type of the lambda return expression because it depends on
9301
+ // the parameter types that we set above, and the speculative type cache
9302
+ // doesn't know about that context.
9303
+ useSpeculativeMode(isSpeculativeModeInUse(node) || (inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.isTypeIncomplete) ? node.expression : undefined, () => {
9240
9304
  const returnTypeResult = getTypeOfExpression(node.expression,
9241
9305
  /* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedReturnType));
9242
9306
  functionType.inferredReturnType = returnTypeResult.type;
9243
9307
  if (returnTypeResult.isIncomplete) {
9244
9308
  isIncomplete = true;
9245
9309
  }
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);
9310
+ }, inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType);
9255
9311
  // Mark the function type as no longer being evaluated.
9256
9312
  functionType.details.flags &= ~131072 /* PartiallyEvaluated */;
9257
9313
  return { type: functionType, isIncomplete };
@@ -9260,13 +9316,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9260
9316
  var _a;
9261
9317
  let isIncomplete = false;
9262
9318
  let typeErrors = false;
9319
+ // If any of the "for" clauses are marked async or any of the "if" clauses
9320
+ // or the final expression contain an "await" operator anywhere within
9321
+ // the expression, it is treated as an async generator.
9263
9322
  let isAsync = node.forIfNodes.some((comp) => {
9264
9323
  return ((comp.nodeType === 33 /* ListComprehensionFor */ && comp.isAsync) ||
9265
9324
  (comp.nodeType === 34 /* ListComprehensionIf */ &&
9266
- comp.testExpression.nodeType === 6 /* Await */));
9325
+ ParseTreeUtils.containsAwaitNode(comp.testExpression)));
9267
9326
  });
9268
9327
  let type = types_1.UnknownType.create();
9269
- if (node.expression.nodeType === 6 /* Await */) {
9328
+ if (ParseTreeUtils.containsAwaitNode(node.expression)) {
9270
9329
  isAsync = true;
9271
9330
  }
9272
9331
  let expectedElementType;
@@ -9506,12 +9565,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9506
9565
  const paramName = `__p${index.toString()}`;
9507
9566
  if ((0, types_1.isVariadicTypeVar)(entryType)) {
9508
9567
  validateVariadicTypeVarIsUnpacked(entryType, entry.node);
9509
- paramCategory = 1 /* VarArgList */;
9568
+ paramCategory = 1 /* ArgsList */;
9510
9569
  noteSawUnpacked(entry);
9511
9570
  }
9512
9571
  else if (validateTypeArg(entry, { allowUnpackedTuples: true })) {
9513
9572
  if ((0, types_1.isUnpackedClass)(entryType)) {
9514
- paramCategory = 1 /* VarArgList */;
9573
+ paramCategory = 1 /* ArgsList */;
9515
9574
  noteSawUnpacked(entry);
9516
9575
  }
9517
9576
  }
@@ -9704,7 +9763,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9704
9763
  let isLiteralType = true;
9705
9764
  (0, typeUtils_1.doForEachSubtype)(exprType.type, (subtype) => {
9706
9765
  if (!(0, types_1.isInstantiableClass)(subtype) || subtype.literalValue === undefined) {
9707
- isLiteralType = false;
9766
+ if (!(0, types_1.isNoneTypeClass)(subtype)) {
9767
+ isLiteralType = false;
9768
+ }
9708
9769
  }
9709
9770
  });
9710
9771
  if (isLiteralType) {
@@ -10995,7 +11056,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
10995
11056
  for (let i = node.decorators.length - 1; i >= 0; i--) {
10996
11057
  const decorator = node.decorators[i];
10997
11058
  const newDecoratedType = applyClassDecorator(decoratedType, classType, decorator);
10998
- if ((0, typeUtils_1.containsUnknown)(newDecoratedType)) {
11059
+ const unknownOrAny = (0, typeUtils_1.containsAnyOrUnknown)(newDecoratedType, /* recurse */ false);
11060
+ if (unknownOrAny && (0, types_1.isUnknown)(unknownOrAny)) {
10999
11061
  // Report this error only on the first unknown type.
11000
11062
  if (!foundUnknown) {
11001
11063
  addDiagnostic(fileInfo.diagnosticRuleSet.reportUntypedClassDecorator, diagnosticRules_1.DiagnosticRule.reportUntypedClassDecorator, localize_1.Localizer.Diagnostic.classDecoratorTypeUnknown(), node.decorators[i].expression);
@@ -11829,7 +11891,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11829
11891
  for (let i = node.decorators.length - 1; i >= 0; i--) {
11830
11892
  const decorator = node.decorators[i];
11831
11893
  const newDecoratedType = applyFunctionDecorator(decoratedType, functionType, decorator, node);
11832
- if ((0, typeUtils_1.containsUnknown)(newDecoratedType)) {
11894
+ const unknownOrAny = (0, typeUtils_1.containsAnyOrUnknown)(newDecoratedType, /* recurse */ false);
11895
+ if (unknownOrAny && (0, types_1.isUnknown)(unknownOrAny)) {
11833
11896
  // Report this error only on the first unknown type.
11834
11897
  if (!foundUnknown) {
11835
11898
  addDiagnostic(fileInfo.diagnosticRuleSet.reportUntypedFunctionDecorator, diagnosticRules_1.DiagnosticRule.reportUntypedFunctionDecorator, localize_1.Localizer.Diagnostic.functionDecoratorTypeUnknown(), node.decorators[i].expression);
@@ -11896,17 +11959,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11896
11959
  param.defaultValue.constType === 26 /* None */ &&
11897
11960
  !(0, typeUtils_1.isOptionalType)(type) &&
11898
11961
  !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
- }
11962
+ return (0, types_1.combineTypes)([type, types_1.NoneType.createInstance()]);
11910
11963
  }
11911
11964
  return type;
11912
11965
  }
@@ -11990,7 +12043,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11990
12043
  case 0 /* Simple */: {
11991
12044
  return type;
11992
12045
  }
11993
- case 1 /* VarArgList */: {
12046
+ case 1 /* ArgsList */: {
11994
12047
  if ((0, types_1.isTypeVar)(type) && type.paramSpecAccess) {
11995
12048
  return type;
11996
12049
  }
@@ -12003,7 +12056,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12003
12056
  }
12004
12057
  return types_1.UnknownType.create();
12005
12058
  }
12006
- case 2 /* VarArgDictionary */: {
12059
+ case 2 /* KwargsDict */: {
12007
12060
  // Leave a ParamSpec alone.
12008
12061
  if ((0, types_1.isTypeVar)(type) && type.paramSpecAccess) {
12009
12062
  return type;
@@ -12961,9 +13014,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12961
13014
  getTypeOfAnnotation(annotationNode, {
12962
13015
  isVariableAnnotation: ((_a = annotationNode.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 54 /* TypeAnnotation */,
12963
13016
  allowUnpackedTuple: annotationParent.nodeType === 41 /* Parameter */ &&
12964
- annotationParent.category === 1 /* VarArgList */,
13017
+ annotationParent.category === 1 /* ArgsList */,
12965
13018
  allowUnpackedTypedDict: annotationParent.nodeType === 41 /* Parameter */ &&
12966
- annotationParent.category === 2 /* VarArgDictionary */,
13019
+ annotationParent.category === 2 /* KwargsDict */,
12967
13020
  });
12968
13021
  return;
12969
13022
  }
@@ -13879,11 +13932,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
13879
13932
  // types, under the assumption that we're performing speculative evaluations.
13880
13933
  // If speculativeNode is undefined, speculative mode is not used. This is
13881
13934
  // useful in cases where we conditionally want to use speculative mode.
13882
- function useSpeculativeMode(speculativeNode, callback, allowCacheRetention = true) {
13935
+ function useSpeculativeMode(speculativeNode, callback, dependentType) {
13883
13936
  if (!speculativeNode) {
13884
13937
  return callback();
13885
13938
  }
13886
- speculativeTypeTracker.enterSpeculativeContext(speculativeNode, allowCacheRetention);
13939
+ speculativeTypeTracker.enterSpeculativeContext(speculativeNode, dependentType);
13887
13940
  try {
13888
13941
  const result = callback();
13889
13942
  speculativeTypeTracker.leaveSpeculativeContext();
@@ -15006,6 +15059,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15006
15059
  types_1.FunctionType.hasUnannotatedParams(type) &&
15007
15060
  !types_1.FunctionType.isStubDefinition(type) &&
15008
15061
  !types_1.FunctionType.isPyTypedDefinition(type) &&
15062
+ !types_1.FunctionType.isWrapReturnTypeInAwait(type) &&
15009
15063
  args) {
15010
15064
  const contextualReturnType = getFunctionInferredReturnTypeUsingArguments(type, args);
15011
15065
  if (contextualReturnType) {
@@ -15358,10 +15412,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15358
15412
  });
15359
15413
  return isAssignable;
15360
15414
  }
15361
- function assignTupleTypeArgs(destType, srcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount) {
15362
- var _a, _b;
15363
- const destTypeArgs = [...((_a = destType.tupleTypeArguments) !== null && _a !== void 0 ? _a : [])];
15364
- const srcTypeArgs = [...((_b = srcType.tupleTypeArguments) !== null && _b !== void 0 ? _b : [])];
15415
+ // Adjusts the source type arguments list to match the length of the
15416
+ // dest type arguments list if the dest list contains an unbounded
15417
+ // or variadic entry.
15418
+ function adjustSourceTupleTypeArgs(destTypeArgs, srcTypeArgs) {
15365
15419
  const destVariadicIndex = destTypeArgs.findIndex((t) => (0, types_1.isVariadicTypeVar)(t.type));
15366
15420
  const destUnboundedIndex = destTypeArgs.findIndex((t) => t.isUnbounded);
15367
15421
  const srcUnboundedIndex = srcTypeArgs.findIndex((t) => t.isUnbounded);
@@ -15409,6 +15463,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15409
15463
  }
15410
15464
  }
15411
15465
  }
15466
+ }
15467
+ function assignTupleTypeArgs(destType, srcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount) {
15468
+ var _a, _b;
15469
+ const destTypeArgs = [...((_a = destType.tupleTypeArguments) !== null && _a !== void 0 ? _a : [])];
15470
+ const srcTypeArgs = [...((_b = srcType.tupleTypeArguments) !== null && _b !== void 0 ? _b : [])];
15471
+ let srcUnboundedIndex;
15472
+ if (flags & 2 /* ReverseTypeVarMatching */) {
15473
+ adjustSourceTupleTypeArgs(srcTypeArgs, destTypeArgs);
15474
+ srcUnboundedIndex = destTypeArgs.findIndex((t) => t.isUnbounded);
15475
+ }
15476
+ else {
15477
+ adjustSourceTupleTypeArgs(destTypeArgs, srcTypeArgs);
15478
+ srcUnboundedIndex = srcTypeArgs.findIndex((t) => t.isUnbounded);
15479
+ }
15412
15480
  if (srcTypeArgs.length === destTypeArgs.length) {
15413
15481
  for (let argIndex = 0; argIndex < srcTypeArgs.length; argIndex++) {
15414
15482
  const entryDiag = diag === null || diag === void 0 ? void 0 : diag.createAddendum();
@@ -16638,7 +16706,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16638
16706
  const srcPositionalsToPack = srcDetails.params.slice(destDetails.argsIndex, srcLastToPackIndex - suffixLength);
16639
16707
  const srcTupleTypes = [];
16640
16708
  srcPositionalsToPack.forEach((entry) => {
16641
- if (entry.param.category === 1 /* VarArgList */) {
16709
+ if (entry.param.category === 1 /* ArgsList */) {
16642
16710
  if ((0, types_1.isUnpackedVariadicTypeVar)(entry.type)) {
16643
16711
  srcTupleTypes.push({ type: entry.type, isUnbounded: false });
16644
16712
  }
@@ -16670,7 +16738,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16670
16738
  ...srcDetails.params.slice(0, destDetails.argsIndex),
16671
16739
  {
16672
16740
  param: {
16673
- category: 1 /* VarArgList */,
16741
+ category: 1 /* ArgsList */,
16674
16742
  name: '_arg_combined',
16675
16743
  isNameSynthesized: true,
16676
16744
  hasDeclaredType: true,
@@ -16682,9 +16750,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16682
16750
  },
16683
16751
  ...srcDetails.params.slice(destDetails.argsIndex + srcPositionalsToPack.length, srcDetails.params.length),
16684
16752
  ];
16685
- const argsIndex = srcDetails.params.findIndex((param) => param.param.category === 1 /* VarArgList */);
16753
+ const argsIndex = srcDetails.params.findIndex((param) => param.param.category === 1 /* ArgsList */);
16686
16754
  srcDetails.argsIndex = argsIndex >= 0 ? argsIndex : undefined;
16687
- const kwargsIndex = srcDetails.params.findIndex((param) => param.param.category === 2 /* VarArgDictionary */);
16755
+ const kwargsIndex = srcDetails.params.findIndex((param) => param.param.category === 2 /* KwargsDict */);
16688
16756
  srcDetails.kwargsIndex = kwargsIndex >= 0 ? kwargsIndex : undefined;
16689
16757
  const firstKeywordOnlyIndex = srcDetails.params.findIndex((param) => param.source === parameterUtils_1.ParameterSource.KeywordOnly);
16690
16758
  srcDetails.firstKeywordOnlyIndex = firstKeywordOnlyIndex >= 0 ? firstKeywordOnlyIndex : undefined;
@@ -16722,8 +16790,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16722
16790
  if (destParamName && !(0, symbolNameUtils_1.isPrivateOrProtectedName)(destParamName) && !(0, symbolNameUtils_1.isPrivateOrProtectedName)(srcParamName)) {
16723
16791
  const isDestPositionalOnly = destParam.source === parameterUtils_1.ParameterSource.PositionOnly;
16724
16792
  if (!isDestPositionalOnly &&
16725
- destParam.param.category !== 1 /* VarArgList */ &&
16726
- srcParam.param.category !== 1 /* VarArgList */ &&
16793
+ destParam.param.category !== 1 /* ArgsList */ &&
16794
+ srcParam.param.category !== 1 /* ArgsList */ &&
16727
16795
  destParamName !== srcParamName) {
16728
16796
  diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.Localizer.DiagnosticAddendum.functionParamName().format({
16729
16797
  srcName: srcParamName,
@@ -17019,7 +17087,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17019
17087
  matchedParamCount++;
17020
17088
  }
17021
17089
  }
17022
- else if (!p.name && p.category === 0 /* Simple */ && remainingParams.length === 0) {
17090
+ else if ((0, types_1.isPositionOnlySeparator)(p) && remainingParams.length === 0) {
17023
17091
  // Don't bother pushing a position-only separator if it
17024
17092
  // is the first remaining param.
17025
17093
  }
@@ -17142,7 +17210,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17142
17210
  const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(assignedType));
17143
17211
  (0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, types_1.ClassType.cloneForSpecialization(assignedType,
17144
17212
  /* typeArguments */ undefined,
17145
- /* isTypeArgumentExplicit */ false), declaredType, typeVarContext, ParseTreeUtils.getTypeVarScopesForNode(node));
17213
+ /* isTypeArgumentExplicit */ false), declaredType, typeVarContext, ParseTreeUtils.getTypeVarScopesForNode(node), node.start);
17146
17214
  let replacedTypeArg = false;
17147
17215
  const newTypeArgs = assignedType.typeArguments.map((typeArg, index) => {
17148
17216
  const typeParam = assignedType.details.typeParameters[index];
@@ -17239,25 +17307,42 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17239
17307
  return validateOverrideMethodInternal(baseMethod, overrideMethod, diag, enforceParamNames);
17240
17308
  }
17241
17309
  // For an overload overriding a base method, at least one overload
17242
- // must be compatible with the base method.
17243
- if (types_1.OverloadedFunctionType.getOverloads(overrideMethod).some((overrideOverload) => {
17310
+ // or the implementation must be compatible with the base method.
17311
+ if (overrideMethod.overloads.some((overrideOverload) => {
17244
17312
  return validateOverrideMethodInternal(baseMethod, overrideOverload,
17245
17313
  /* diag */ undefined, enforceParamNames);
17246
17314
  })) {
17247
17315
  return true;
17248
17316
  }
17249
- // Or the implementation must be compatible.
17250
- const overrideImplementation = types_1.OverloadedFunctionType.getImplementation(overrideMethod);
17251
- if (overrideImplementation) {
17252
- if (validateOverrideMethodInternal(baseMethod, overrideImplementation,
17253
- /* diag */ undefined, enforceParamNames)) {
17254
- return true;
17255
- }
17256
- }
17257
17317
  diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideNoOverloadMatches());
17258
17318
  return false;
17259
17319
  }
17260
- // TODO - need to implement the case where the base method is overloaded
17320
+ // For a non-overloaded method overriding an overloaded method, the
17321
+ // override must match all of the overloads.
17322
+ if ((0, types_1.isFunction)(overrideMethod)) {
17323
+ return types_1.OverloadedFunctionType.getOverloads(baseMethod).every((overload) => validateOverrideMethodInternal(overload, overrideMethod, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), enforceParamNames));
17324
+ }
17325
+ // For an overloaded method overriding an overloaded method, the overrides
17326
+ // must all match and be in the correct order. It is OK if the base method
17327
+ // has additional overloads that are not present in the override.
17328
+ let previousMatchIndex = -1;
17329
+ let overrideOverloadIndex = 0;
17330
+ for (const overrideOverload of types_1.OverloadedFunctionType.getOverloads(overrideMethod)) {
17331
+ const matchIndex = types_1.OverloadedFunctionType.getOverloads(baseMethod).findIndex((baseOverload) => {
17332
+ return validateOverrideMethodInternal(baseOverload, overrideOverload,
17333
+ /* diag */ undefined, enforceParamNames);
17334
+ });
17335
+ if (matchIndex < 0) {
17336
+ diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideOverloadNoMatch().format({ index: overrideOverloadIndex }));
17337
+ return false;
17338
+ }
17339
+ if (matchIndex < previousMatchIndex) {
17340
+ diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideOverloadOrder());
17341
+ return false;
17342
+ }
17343
+ previousMatchIndex = matchIndex;
17344
+ overrideOverloadIndex++;
17345
+ }
17261
17346
  return true;
17262
17347
  }
17263
17348
  function validateOverrideMethodInternal(baseMethod, overrideMethod, diag, enforceParamNames) {
@@ -17348,7 +17433,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17348
17433
  baseParam.category === 0 /* Simple */ &&
17349
17434
  baseParam.name !== overrideParam.name) {
17350
17435
  if (overrideParam.category === 0 /* Simple */) {
17351
- if (enforceParamNames) {
17436
+ if (enforceParamNames && !baseParam.isNameSynthesized) {
17352
17437
  if (overrideParamDetails.params[i].source === parameterUtils_1.ParameterSource.PositionOnly) {
17353
17438
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNamePositionOnly().format({
17354
17439
  index: i + 1,
@@ -17368,11 +17453,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17368
17453
  }
17369
17454
  else if (i < overrideParamDetails.positionOnlyParamCount &&
17370
17455
  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;
17456
+ if (!baseParam.isNameSynthesized) {
17457
+ diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNamePositionOnly().format({
17458
+ index: i + 1,
17459
+ baseName: baseParam.name || '*',
17460
+ }));
17461
+ canOverride = false;
17462
+ }
17376
17463
  }
17377
17464
  else {
17378
17465
  const baseParamType = baseParamDetails.params[i].type;
@@ -17483,6 +17570,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17483
17570
  canOverride = false;
17484
17571
  }
17485
17572
  }
17573
+ // Verify that one or the other method doesn't contain a ParamSpec.
17574
+ if (baseMethod.details.paramSpec && !overrideMethod.details.paramSpec) {
17575
+ diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.paramSpecMissingInOverride());
17576
+ canOverride = false;
17577
+ }
17486
17578
  // Now check the return type.
17487
17579
  const baseReturnType = getFunctionEffectiveReturnType(baseMethod);
17488
17580
  const overrideReturnType = getFunctionEffectiveReturnType(overrideMethod);