@zzzen/pyright-internal 1.2.0-dev.20230709 → 1.2.0-dev.20230716

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 (108) hide show
  1. package/dist/analyzer/backgroundAnalysisProgram.d.ts +2 -2
  2. package/dist/analyzer/backgroundAnalysisProgram.js +3 -3
  3. package/dist/analyzer/backgroundAnalysisProgram.js.map +1 -1
  4. package/dist/analyzer/binder.d.ts +1 -0
  5. package/dist/analyzer/binder.js +19 -2
  6. package/dist/analyzer/binder.js.map +1 -1
  7. package/dist/analyzer/checker.js +1 -3
  8. package/dist/analyzer/checker.js.map +1 -1
  9. package/dist/analyzer/constraintSolver.js +17 -34
  10. package/dist/analyzer/constraintSolver.js.map +1 -1
  11. package/dist/analyzer/enums.js +21 -8
  12. package/dist/analyzer/enums.js.map +1 -1
  13. package/dist/analyzer/namedTuples.js +32 -1
  14. package/dist/analyzer/namedTuples.js.map +1 -1
  15. package/dist/analyzer/patternMatching.d.ts +1 -1
  16. package/dist/analyzer/patternMatching.js +79 -66
  17. package/dist/analyzer/patternMatching.js.map +1 -1
  18. package/dist/analyzer/program.d.ts +5 -2
  19. package/dist/analyzer/program.js +18 -7
  20. package/dist/analyzer/program.js.map +1 -1
  21. package/dist/analyzer/protocols.js +57 -19
  22. package/dist/analyzer/protocols.js.map +1 -1
  23. package/dist/analyzer/service.js +1 -10
  24. package/dist/analyzer/service.js.map +1 -1
  25. package/dist/analyzer/sourceFile.d.ts +4 -3
  26. package/dist/analyzer/sourceFile.js +26 -22
  27. package/dist/analyzer/sourceFile.js.map +1 -1
  28. package/dist/analyzer/typeEvaluator.js +180 -106
  29. package/dist/analyzer/typeEvaluator.js.map +1 -1
  30. package/dist/analyzer/typeEvaluatorTypes.d.ts +5 -0
  31. package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
  32. package/dist/analyzer/typeGuards.d.ts +2 -2
  33. package/dist/analyzer/typeGuards.js +30 -5
  34. package/dist/analyzer/typeGuards.js.map +1 -1
  35. package/dist/analyzer/typePrinter.d.ts +2 -1
  36. package/dist/analyzer/typePrinter.js +26 -5
  37. package/dist/analyzer/typePrinter.js.map +1 -1
  38. package/dist/analyzer/typeUtils.js +1 -1
  39. package/dist/analyzer/typedDicts.js +1 -3
  40. package/dist/analyzer/typedDicts.js.map +1 -1
  41. package/dist/analyzer/types.d.ts +8 -1
  42. package/dist/analyzer/types.js.map +1 -1
  43. package/dist/backgroundAnalysisBase.d.ts +5 -5
  44. package/dist/backgroundAnalysisBase.js +2 -2
  45. package/dist/backgroundAnalysisBase.js.map +1 -1
  46. package/dist/common/console.d.ts +4 -1
  47. package/dist/common/console.js +7 -0
  48. package/dist/common/console.js.map +1 -1
  49. package/dist/languageServerBase.d.ts +8 -3
  50. package/dist/languageServerBase.js +30 -25
  51. package/dist/languageServerBase.js.map +1 -1
  52. package/dist/languageService/codeActionProvider.d.ts +1 -0
  53. package/dist/languageService/codeActionProvider.js +11 -0
  54. package/dist/languageService/codeActionProvider.js.map +1 -1
  55. package/dist/languageService/completionProvider.d.ts +1 -1
  56. package/dist/languageService/completionProvider.js +3 -3
  57. package/dist/languageService/completionProvider.js.map +1 -1
  58. package/dist/localization/localize.d.ts +2 -0
  59. package/dist/localization/localize.js +12 -2
  60. package/dist/localization/localize.js.map +1 -1
  61. package/dist/localization/package.nls.cs.json +718 -0
  62. package/dist/localization/package.nls.de.json +718 -1
  63. package/dist/localization/package.nls.en-us.json +1 -0
  64. package/dist/localization/package.nls.es.json +718 -1
  65. package/dist/localization/package.nls.fr.json +718 -1
  66. package/dist/localization/package.nls.it.json +718 -0
  67. package/dist/localization/package.nls.ja.json +718 -1
  68. package/dist/localization/package.nls.ko.json +718 -0
  69. package/dist/localization/package.nls.pl.json +718 -0
  70. package/dist/localization/package.nls.pt-br.json +718 -0
  71. package/dist/localization/package.nls.qps-ploc.json +718 -0
  72. package/dist/localization/package.nls.ru.json +718 -1
  73. package/dist/localization/package.nls.tr.json +718 -0
  74. package/dist/localization/package.nls.zh-cn.json +718 -1
  75. package/dist/localization/package.nls.zh-tw.json +718 -1
  76. package/dist/parser/parser.d.ts +3 -0
  77. package/dist/parser/parser.js +2 -31
  78. package/dist/parser/parser.js.map +1 -1
  79. package/dist/parser/tokenizer.d.ts +5 -2
  80. package/dist/parser/tokenizer.js +16 -4
  81. package/dist/parser/tokenizer.js.map +1 -1
  82. package/dist/parser/tokenizerTypes.d.ts +2 -2
  83. package/dist/parser/tokenizerTypes.js.map +1 -1
  84. package/dist/pprof/profiler.d.ts +36 -0
  85. package/dist/pprof/profiler.js +64 -0
  86. package/dist/pprof/profiler.js.map +1 -0
  87. package/dist/tests/harness/fourslash/testState.d.ts +6 -4
  88. package/dist/tests/harness/fourslash/testState.js +50 -39
  89. package/dist/tests/harness/fourslash/testState.js.map +1 -1
  90. package/dist/tests/harness/vfs/factory.d.ts +1 -0
  91. package/dist/tests/harness/vfs/factory.js +7 -1
  92. package/dist/tests/harness/vfs/factory.js.map +1 -1
  93. package/dist/tests/harness/vfs/filesystem.d.ts +2 -2
  94. package/dist/tests/harness/vfs/filesystem.js +13 -8
  95. package/dist/tests/harness/vfs/filesystem.js.map +1 -1
  96. package/dist/tests/localizer.test.js +20 -0
  97. package/dist/tests/localizer.test.js.map +1 -1
  98. package/dist/tests/typeEvaluator1.test.js +4 -0
  99. package/dist/tests/typeEvaluator1.test.js.map +1 -1
  100. package/dist/tests/typeEvaluator2.test.js +8 -0
  101. package/dist/tests/typeEvaluator2.test.js.map +1 -1
  102. package/dist/tests/typeEvaluator4.test.js +9 -1
  103. package/dist/tests/typeEvaluator4.test.js.map +1 -1
  104. package/dist/tests/typeEvaluator5.test.js +4 -0
  105. package/dist/tests/typeEvaluator5.test.js.map +1 -1
  106. package/dist/workspaceFactory.js +5 -3
  107. package/dist/workspaceFactory.js.map +1 -1
  108. package/package.json +3 -2
@@ -566,7 +566,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
566
566
  }
567
567
  case 31 /* List */:
568
568
  case 45 /* Set */: {
569
- typeResult = getTypeOfListOrSet(node, inferenceContext);
569
+ typeResult = getTypeOfListOrSet(node, flags, inferenceContext);
570
570
  break;
571
571
  }
572
572
  case 46 /* Slice */: {
@@ -586,7 +586,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
586
586
  break;
587
587
  }
588
588
  case 15 /* Dictionary */: {
589
- typeResult = getTypeOfDictionary(node, inferenceContext);
589
+ typeResult = getTypeOfDictionary(node, flags, inferenceContext);
590
590
  break;
591
591
  }
592
592
  case 30 /* Lambda */: {
@@ -1990,10 +1990,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1990
1990
  if (expectedTypeDiagAddendum) {
1991
1991
  diagAddendum = expectedTypeDiagAddendum;
1992
1992
  }
1993
- addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeAssignmentMismatch().format({
1994
- sourceType: printType(type),
1995
- destType: printType(declaredType),
1996
- }) + diagAddendum.getString(), srcExpression !== null && srcExpression !== void 0 ? srcExpression : nameNode, (_c = (_b = diagAddendum.getEffectiveTextRange()) !== null && _b !== void 0 ? _b : srcExpression) !== null && _c !== void 0 ? _c : nameNode);
1993
+ addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeAssignmentMismatch().format(printSrcDestTypes(type, declaredType)) +
1994
+ diagAddendum.getString(), srcExpression !== null && srcExpression !== void 0 ? srcExpression : nameNode, (_c = (_b = diagAddendum.getEffectiveTextRange()) !== null && _b !== void 0 ? _b : srcExpression) !== null && _c !== void 0 ? _c : nameNode);
1997
1995
  // Replace the assigned type with the (unnarrowed) declared type.
1998
1996
  destType = declaredType;
1999
1997
  }
@@ -3681,6 +3679,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3681
3679
  types_1.ClassType.isSameGenericClass(memberInfo.classType, classType)) {
3682
3680
  setSymbolAccessed(AnalyzerNodeInfo.getFileInfo(errorNode), memberInfo.symbol, errorNode);
3683
3681
  }
3682
+ // Special-case `__init_subclass` and `__class_getitem__` because
3683
+ // these are always treated as class methods even if they're not
3684
+ // decorated as such.
3685
+ if (memberName === '__init_subclass__' || memberName === '__class_getitem__') {
3686
+ if ((0, types_1.isFunction)(type) && !types_1.FunctionType.isClassMethod(type)) {
3687
+ type = types_1.FunctionType.cloneWithNewFlags(type, type.details.flags | 2 /* ClassMethod */);
3688
+ }
3689
+ }
3684
3690
  }
3685
3691
  const descriptorResult = applyDescriptorAccessMethod(type, memberInfo, classType, bindToType, isAccessedThroughObject, flags, errorNode, memberName, usage, diag);
3686
3692
  if (!descriptorResult) {
@@ -4212,7 +4218,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4212
4218
  // We limit type narrowing for index expressions to built-in types that are
4213
4219
  // known to have symmetric __getitem__ and __setitem__ methods (i.e. the value
4214
4220
  // passed to __setitem__ is the same type as the value returned by __getitem__).
4215
- let baseTypeSupportsIndexNarrowing = true;
4221
+ let baseTypeSupportsIndexNarrowing = !(0, types_1.isAny)(baseTypeResult.type);
4216
4222
  mapSubtypesExpandTypeVars(baseTypeResult.type, /* conditionFilter */ undefined, (subtype) => {
4217
4223
  if (!(0, types_1.isClassInstance)(subtype) ||
4218
4224
  !(types_1.ClassType.isBuiltIn(subtype) || types_1.ClassType.isTypedDictClass(subtype))) {
@@ -4971,14 +4977,31 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4971
4977
  const getTypeArgTypeResult = (expr, argIndex) => {
4972
4978
  let typeResult;
4973
4979
  // If it's a custom __class_getitem__, none of the arguments should be
4974
- // treated as types. If it's an Annotated[a, b, c], only the first index
4975
- // should be treated as a type. The others can be regular (non-type) objects.
4976
- if ((options === null || options === void 0 ? void 0 : options.hasCustomClassGetItem) || ((options === null || options === void 0 ? void 0 : options.isAnnotatedClass) && argIndex > 0)) {
4980
+ // treated as types.
4981
+ if (options === null || options === void 0 ? void 0 : options.hasCustomClassGetItem) {
4982
+ adjFlags =
4983
+ 32 /* DisallowParamSpec */ |
4984
+ 64 /* DisallowTypeVarTuple */ |
4985
+ 2 /* DoNotSpecialize */ |
4986
+ 131072 /* DisallowClassVar */;
4977
4987
  typeResult = {
4978
- ...getTypeOfExpression(expr, 32 /* DisallowParamSpec */ |
4988
+ ...getTypeOfExpression(expr, adjFlags),
4989
+ node: expr,
4990
+ };
4991
+ }
4992
+ else if ((options === null || options === void 0 ? void 0 : options.isAnnotatedClass) && argIndex > 0) {
4993
+ // If it's an Annotated[a, b, c], only the first index should be
4994
+ // treated as a type.The others can be regular(non - type) objects.
4995
+ adjFlags =
4996
+ 32 /* DisallowParamSpec */ |
4979
4997
  64 /* DisallowTypeVarTuple */ |
4980
4998
  2 /* DoNotSpecialize */ |
4981
- 131072 /* DisallowClassVar */),
4999
+ 131072 /* DisallowClassVar */;
5000
+ if ((0, analyzerFileInfo_1.isAnnotationEvaluationPostponed)(AnalyzerNodeInfo.getFileInfo(node))) {
5001
+ adjFlags |= 4 /* AllowForwardReferences */;
5002
+ }
5003
+ typeResult = {
5004
+ ...getTypeOfExpression(expr, adjFlags),
4982
5005
  node: expr,
4983
5006
  };
4984
5007
  }
@@ -5073,6 +5096,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5073
5096
  return typeResult;
5074
5097
  }
5075
5098
  function getTypeOfTuple(node, flags, inferenceContext) {
5099
+ var _a;
5100
+ if ((flags & 256 /* ExpectingTypeAnnotation */) !== 0 &&
5101
+ ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) !== 1 /* Argument */) {
5102
+ // This is allowed inside of an index trailer, specifically
5103
+ // to support Tuple[()], which is the documented way to annotate
5104
+ // a zero-length tuple.
5105
+ const diag = new diagnostic_1.DiagnosticAddendum();
5106
+ diag.addMessage(localize_1.Localizer.DiagnosticAddendum.useTupleInstead());
5107
+ addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.tupleInAnnotation() + diag.getString(), node);
5108
+ }
5076
5109
  if ((flags & 128 /* ExpectingInstantiableType */) !== 0 &&
5077
5110
  node.expressions.length === 0 &&
5078
5111
  !inferenceContext) {
@@ -5230,12 +5263,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5230
5263
  function getTypeOfCall(node, flags, inferenceContext) {
5231
5264
  var _a;
5232
5265
  let baseTypeResult;
5266
+ if ((flags & 256 /* ExpectingTypeAnnotation */) !== 0 &&
5267
+ node.leftExpression.nodeType === 38 /* Name */ &&
5268
+ node.leftExpression.value === 'type') {
5269
+ const diag = new diagnostic_1.DiagnosticAddendum();
5270
+ diag.addMessage(localize_1.Localizer.DiagnosticAddendum.useTypeInstead());
5271
+ addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeCallNotAllowed() + diag.getString(), node);
5272
+ }
5233
5273
  // Handle immediate calls of lambdas specially.
5234
5274
  if (node.leftExpression.nodeType === 30 /* Lambda */) {
5235
5275
  baseTypeResult = getTypeOfLambdaForCall(node, inferenceContext);
5236
5276
  }
5237
5277
  else {
5238
- baseTypeResult = getTypeOfExpression(node.leftExpression, 2 /* DoNotSpecialize */);
5278
+ baseTypeResult = getTypeOfExpression(node.leftExpression, 2 /* DoNotSpecialize */ | (flags & 4 /* AllowForwardReferences */));
5239
5279
  }
5240
5280
  const argList = node.arguments.map((arg) => {
5241
5281
  const functionArg = {
@@ -6163,19 +6203,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6163
6203
  case 6 /* OverloadedFunction */: {
6164
6204
  // Handle the 'cast' call as a special case.
6165
6205
  if (expandedSubtype.overloads[0].details.builtInName === 'cast' && argList.length === 2) {
6166
- // Verify that the cast is necessary.
6167
- const castToType = getTypeOfArgumentExpectingType(argList[0]).type;
6168
- const castFromType = getTypeOfArgument(argList[1]).type;
6169
- if (types_1.TypeBase.isInstantiable(castToType) && !(0, types_1.isUnknown)(castToType)) {
6170
- if ((0, types_1.isTypeSame)((0, typeUtils_1.convertToInstance)(castToType), castFromType, {
6171
- ignorePseudoGeneric: true,
6172
- })) {
6173
- addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportUnnecessaryCast, diagnosticRules_1.DiagnosticRule.reportUnnecessaryCast, localize_1.Localizer.Diagnostic.unnecessaryCast().format({
6174
- type: printType(castFromType),
6175
- }), errorNode);
6176
- }
6177
- }
6178
- return (0, typeUtils_1.convertToInstance)(castToType);
6206
+ return evaluateCastCall(argList, errorNode);
6179
6207
  }
6180
6208
  const functionResult = validateOverloadedFunctionArguments(errorNode, argList, { type: expandedSubtype, isIncomplete: callTypeResult.isIncomplete }, typeVarContext, skipUnknownArgCheck, inferenceContext);
6181
6209
  (0, collectionUtils_1.appendArray)(overloadsUsedForCall, functionResult.overloadsUsedForCall);
@@ -6435,6 +6463,22 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6435
6463
  overloadsUsedForCall,
6436
6464
  };
6437
6465
  }
6466
+ // Evaluates the type of the "cast" call.
6467
+ function evaluateCastCall(argList, errorNode) {
6468
+ // Verify that the cast is necessary.
6469
+ const castToType = getTypeOfArgumentExpectingType(argList[0]).type;
6470
+ const castFromType = getTypeOfArgument(argList[1]).type;
6471
+ if (types_1.TypeBase.isInstantiable(castToType) && !(0, types_1.isUnknown)(castToType)) {
6472
+ if ((0, types_1.isTypeSame)((0, typeUtils_1.convertToInstance)(castToType), castFromType, {
6473
+ ignorePseudoGeneric: true,
6474
+ })) {
6475
+ addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportUnnecessaryCast, diagnosticRules_1.DiagnosticRule.reportUnnecessaryCast, localize_1.Localizer.Diagnostic.unnecessaryCast().format({
6476
+ type: printType(castFromType),
6477
+ }), errorNode);
6478
+ }
6479
+ }
6480
+ return (0, typeUtils_1.convertToInstance)(castToType);
6481
+ }
6438
6482
  // Expands any unpacked tuples within an argument list.
6439
6483
  function expandArgList(argList) {
6440
6484
  var _a;
@@ -6530,8 +6574,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6530
6574
  // Does this function define the param spec, or is it an inner
6531
6575
  // function nested within another function that defines the param
6532
6576
  // spec? We need to handle these two cases differently.
6533
- if (varArgListParam.type.scopeId === typeResult.type.details.typeVarScopeId ||
6534
- varArgListParam.type.scopeId === typeResult.type.details.constructorTypeVarScopeId) {
6577
+ const paramSpecScopeId = varArgListParam.type.scopeId;
6578
+ if (paramSpecScopeId === typeResult.type.details.typeVarScopeId ||
6579
+ paramSpecScopeId === typeResult.type.details.constructorTypeVarScopeId) {
6535
6580
  paramSpecArgList = [];
6536
6581
  paramSpecTarget = types_1.TypeVarType.cloneForParamSpecAccess(varArgListParam.type, /* access */ undefined);
6537
6582
  }
@@ -6540,6 +6585,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6540
6585
  }
6541
6586
  }
6542
6587
  }
6588
+ else if (typeResult.type.details.paramSpec) {
6589
+ const paramSpecScopeId = typeResult.type.details.paramSpec.scopeId;
6590
+ if (paramSpecScopeId === typeResult.type.details.typeVarScopeId ||
6591
+ paramSpecScopeId === typeResult.type.details.constructorTypeVarScopeId) {
6592
+ hasParamSpecArgsKwargs = true;
6593
+ paramSpecArgList = [];
6594
+ paramSpecTarget = types_1.TypeVarType.cloneForParamSpecAccess(typeResult.type.details.paramSpec,
6595
+ /* access */ undefined);
6596
+ }
6597
+ }
6543
6598
  // If there are keyword arguments present after a *args argument,
6544
6599
  // the keyword arguments may target one or more parameters that are positional.
6545
6600
  // In this case, we will limit the number of positional parameters so the
@@ -7028,27 +7083,25 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7028
7083
  trySetActive(argList[argIndex], paramDetails.params[paramInfoIndex].param);
7029
7084
  }
7030
7085
  }
7086
+ else if (paramSpecArgList) {
7087
+ paramSpecArgList.push(argList[argIndex]);
7088
+ }
7031
7089
  else if (paramDetails.kwargsIndex !== undefined) {
7032
- if (paramSpecArgList) {
7033
- paramSpecArgList.push(argList[argIndex]);
7034
- }
7035
- else {
7036
- const paramType = paramDetails.params[paramDetails.kwargsIndex].type;
7037
- validateArgTypeParams.push({
7038
- paramCategory: 2 /* KwargsDict */,
7039
- paramType,
7040
- requiresTypeVarMatching: (0, typeUtils_1.requiresSpecialization)(paramType),
7041
- argument: argList[argIndex],
7042
- errorNode: (_h = argList[argIndex].valueExpression) !== null && _h !== void 0 ? _h : errorNode,
7043
- paramName: paramNameValue,
7044
- });
7045
- // Remember that this parameter has already received a value.
7046
- paramMap.set(paramNameValue, {
7047
- argsNeeded: 1,
7048
- argsReceived: 1,
7049
- isPositionalOnly: false,
7050
- });
7051
- }
7090
+ const paramType = paramDetails.params[paramDetails.kwargsIndex].type;
7091
+ validateArgTypeParams.push({
7092
+ paramCategory: 2 /* KwargsDict */,
7093
+ paramType,
7094
+ requiresTypeVarMatching: (0, typeUtils_1.requiresSpecialization)(paramType),
7095
+ argument: argList[argIndex],
7096
+ errorNode: (_h = argList[argIndex].valueExpression) !== null && _h !== void 0 ? _h : errorNode,
7097
+ paramName: paramNameValue,
7098
+ });
7099
+ // Remember that this parameter has already received a value.
7100
+ paramMap.set(paramNameValue, {
7101
+ argsNeeded: 1,
7102
+ argsReceived: 1,
7103
+ isPositionalOnly: false,
7104
+ });
7052
7105
  (0, debug_1.assert)(paramDetails.params[paramDetails.kwargsIndex], 'paramDetails.kwargsIndex params entry is undefined');
7053
7106
  trySetActive(argList[argIndex], paramDetails.params[paramDetails.kwargsIndex].param);
7054
7107
  }
@@ -7058,15 +7111,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7058
7111
  }
7059
7112
  }
7060
7113
  else if (argList[argIndex].argumentCategory === 0 /* Simple */) {
7061
- if (!isDiagnosticSuppressedForNode(errorNode)) {
7062
- const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
7063
- addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, positionParamLimitIndex === 1
7064
- ? localize_1.Localizer.Diagnostic.argPositionalExpectedOne()
7065
- : localize_1.Localizer.Diagnostic.argPositionalExpectedCount().format({
7066
- expected: positionParamLimitIndex,
7067
- }), argList[argIndex].valueExpression || errorNode);
7114
+ if (paramSpecArgList) {
7115
+ paramSpecArgList.push(argList[argIndex]);
7116
+ }
7117
+ else {
7118
+ if (!isDiagnosticSuppressedForNode(errorNode)) {
7119
+ const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
7120
+ addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, positionParamLimitIndex === 1
7121
+ ? localize_1.Localizer.Diagnostic.argPositionalExpectedOne()
7122
+ : localize_1.Localizer.Diagnostic.argPositionalExpectedCount().format({
7123
+ expected: positionParamLimitIndex,
7124
+ }), argList[argIndex].valueExpression || errorNode);
7125
+ }
7126
+ reportedArgError = true;
7068
7127
  }
7069
- reportedArgError = true;
7070
7128
  }
7071
7129
  else if (argList[argIndex].argumentCategory === 1 /* UnpackedList */) {
7072
7130
  // Handle the case where a *args: P.args is passed as an argument to
@@ -7700,7 +7758,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7700
7758
  return false;
7701
7759
  }
7702
7760
  const liveTypeVarScopes = ParseTreeUtils.getTypeVarScopesForNode(errorNode);
7703
- const srcTypeVarContext = new typeVarContext_1.TypeVarContext(paramSpecType.details.typeVarScopeId);
7761
+ const srcTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeIds)(paramSpecType));
7704
7762
  let reportedArgError = false;
7705
7763
  // Build a map of all named parameters.
7706
7764
  const paramMap = new Map();
@@ -8663,7 +8721,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8663
8721
  }
8664
8722
  return returnType;
8665
8723
  }
8666
- function getTypeOfDictionary(node, inferenceContext) {
8724
+ function getTypeOfDictionary(node, flags, inferenceContext) {
8725
+ var _a;
8726
+ if ((flags & 256 /* ExpectingTypeAnnotation */) !== 0 &&
8727
+ ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) !== 1 /* Argument */) {
8728
+ const diag = new diagnostic_1.DiagnosticAddendum();
8729
+ diag.addMessage(localize_1.Localizer.DiagnosticAddendum.useDictInstead());
8730
+ addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.dictInAnnotation() + diag.getString(), node);
8731
+ }
8667
8732
  // If the expected type is a union, analyze for each of the subtypes
8668
8733
  // to find one that matches.
8669
8734
  let effectiveExpectedType = inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType;
@@ -8823,7 +8888,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8823
8888
  let isIncomplete = false;
8824
8889
  // Infer the key and value types if possible.
8825
8890
  node.entries.forEach((entryNode, index) => {
8826
- var _a, _b, _c;
8891
+ var _a;
8827
8892
  let addUnknown = true;
8828
8893
  if (entryNode.nodeType === 17 /* DictionaryKeyEntry */) {
8829
8894
  const keyTypeResult = getTypeOfExpression(entryNode.keyExpression,
@@ -8857,8 +8922,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8857
8922
  /* flags */ undefined, entryInferenceContext);
8858
8923
  }
8859
8924
  if (entryInferenceContext && !valueTypeResult.typeErrors) {
8860
- valueTypeResult.type =
8861
- (_a = inferTypeArgFromExpectedEntryType(entryInferenceContext, [valueTypeResult.type], !isValueTypeInvariant)) !== null && _a !== void 0 ? _a : valueTypeResult.type;
8925
+ const fromExpectedType = inferTypeArgFromExpectedEntryType(entryInferenceContext, [valueTypeResult.type], !isValueTypeInvariant);
8926
+ if (fromExpectedType) {
8927
+ valueTypeResult = { ...valueTypeResult, type: fromExpectedType };
8928
+ }
8862
8929
  }
8863
8930
  if (expectedDiagAddendum && valueTypeResult.expectedTypeDiagAddendum) {
8864
8931
  expectedDiagAddendum.addAddendum(valueTypeResult.expectedTypeDiagAddendum);
@@ -8882,11 +8949,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8882
8949
  }
8883
8950
  }
8884
8951
  const entryInferenceContext = (0, typeUtils_1.makeInferenceContext)(expectedType);
8885
- const unexpandedTypeResult = getTypeOfExpression(entryNode.expandExpression,
8952
+ let unexpandedTypeResult = getTypeOfExpression(entryNode.expandExpression,
8886
8953
  /* flags */ undefined, entryInferenceContext);
8887
8954
  if (entryInferenceContext && !unexpandedTypeResult.typeErrors) {
8888
- unexpandedTypeResult.type =
8889
- (_b = inferTypeArgFromExpectedEntryType(entryInferenceContext, [unexpandedTypeResult.type], !isValueTypeInvariant)) !== null && _b !== void 0 ? _b : unexpandedTypeResult.type;
8955
+ const fromExpectedType = inferTypeArgFromExpectedEntryType(entryInferenceContext, [unexpandedTypeResult.type], !isValueTypeInvariant);
8956
+ if (fromExpectedType) {
8957
+ unexpandedTypeResult = { ...unexpandedTypeResult, type: fromExpectedType };
8958
+ }
8890
8959
  }
8891
8960
  if (unexpandedTypeResult.isIncomplete) {
8892
8961
  isIncomplete = true;
@@ -8942,7 +9011,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8942
9011
  }
8943
9012
  // The result should be a tuple.
8944
9013
  if ((0, types_1.isClassInstance)(dictEntryType) && (0, typeUtils_1.isTupleClass)(dictEntryType)) {
8945
- const typeArgs = (_c = dictEntryType.tupleTypeArguments) === null || _c === void 0 ? void 0 : _c.map((t) => t.type);
9014
+ const typeArgs = (_a = dictEntryType.tupleTypeArguments) === null || _a === void 0 ? void 0 : _a.map((t) => t.type);
8946
9015
  if (typeArgs && typeArgs.length === 2) {
8947
9016
  if (forceStrictInference || index < maxEntriesToUseForInference) {
8948
9017
  keyTypes.push({ node: entryNode, type: typeArgs[0] });
@@ -8961,7 +9030,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8961
9030
  });
8962
9031
  return isIncomplete;
8963
9032
  }
8964
- function getTypeOfListOrSet(node, inferenceContext) {
9033
+ function getTypeOfListOrSet(node, flags, inferenceContext) {
9034
+ var _a;
9035
+ if ((flags & 256 /* ExpectingTypeAnnotation */) !== 0 &&
9036
+ node.nodeType === 31 /* List */ &&
9037
+ ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) !== 1 /* Argument */) {
9038
+ const diag = new diagnostic_1.DiagnosticAddendum();
9039
+ diag.addMessage(localize_1.Localizer.DiagnosticAddendum.useListInstead());
9040
+ addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.listInAnnotation() + diag.getString(), node);
9041
+ }
8965
9042
  // If the expected type is a union, recursively call for each of the subtypes
8966
9043
  // to find one that matches.
8967
9044
  let effectiveExpectedType = inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType;
@@ -12039,6 +12116,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12039
12116
  }
12040
12117
  // Note that the inferred type, once lazily computed, needs to wrap the
12041
12118
  // resulting type in an awaitable.
12119
+ functionType.details.flags |= 1024 /* WrapReturnTypeInAwait */;
12042
12120
  awaitableFunctionType.details.flags |= 1024 /* WrapReturnTypeInAwait */;
12043
12121
  return awaitableFunctionType;
12044
12122
  }
@@ -12525,18 +12603,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12525
12603
  /* isPositiveTest */ false);
12526
12604
  }
12527
12605
  }
12528
- // Determine if the pre-narrowed subject type contains an object.
12529
- let subjectIsObject = false;
12530
- (0, typeUtils_1.doForEachSubtype)(makeTopLevelTypeVarsConcrete(subjectType), (subtype) => {
12531
- if ((0, types_1.isClassInstance)(subtype) && types_1.ClassType.isBuiltIn(subtype, 'object')) {
12532
- subjectIsObject = true;
12533
- }
12534
- });
12535
- // Apply positive narrowing for the current case statement.
12536
- subjectType = (0, patternMatching_1.narrowTypeBasedOnPattern)(evaluatorInterface, subjectType, node.pattern,
12537
- /* isPositiveTest */ true);
12538
- (0, patternMatching_1.assignTypeToPatternTargets)(evaluatorInterface, subjectType, !!subjectTypeResult.isIncomplete, subjectIsObject, node.pattern);
12539
- writeTypeCache(node, { type: subjectType, isIncomplete: !!subjectTypeResult.isIncomplete }, 0 /* None */);
12606
+ const narrowedSubjectType = (0, patternMatching_1.assignTypeToPatternTargets)(evaluatorInterface, subjectType, !!subjectTypeResult.isIncomplete, node.pattern);
12607
+ writeTypeCache(node, { type: narrowedSubjectType, isIncomplete: !!subjectTypeResult.isIncomplete }, 0 /* None */);
12540
12608
  }
12541
12609
  function evaluateTypesForImportFrom(node) {
12542
12610
  if (isTypeCached(node)) {
@@ -14601,6 +14669,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14601
14669
  }
14602
14670
  let typedDecls = symbol.getTypedDeclarations();
14603
14671
  if (typedDecls.length === 0) {
14672
+ // If the symbol has no type declaration but is assigned many times,
14673
+ // treat it as though it has an explicit type annotation of "Unknown".
14674
+ // This will avoid a pathological performance condition for unannotated
14675
+ // code that reassigns the same variable hundreds of times. If the symbol
14676
+ // effectively has an "Any" annotation, it won't be narrowed.
14677
+ if (symbol.getDeclarations().length > maxDeclarationsToUseForInference) {
14678
+ return { type: types_1.UnknownType.create() };
14679
+ }
14604
14680
  // There was no declaration with a defined type.
14605
14681
  return { type: undefined };
14606
14682
  }
@@ -15571,10 +15647,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15571
15647
  destType.details.parameters.length <= 2) {
15572
15648
  return true;
15573
15649
  }
15574
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.typeAssignmentMismatch().format({
15575
- sourceType: printType(srcType),
15576
- destType: printType(destType),
15577
- }));
15650
+ diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.typeAssignmentMismatch().format(printSrcDestTypes(srcType, destType)));
15578
15651
  return false;
15579
15652
  }
15580
15653
  }
@@ -15673,10 +15746,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15673
15746
  if (assignType(destType, instantiableType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
15674
15747
  return true;
15675
15748
  }
15676
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.typeAssignmentMismatch().format({
15677
- sourceType: printType(srcType),
15678
- destType: printType(destType),
15679
- }));
15749
+ diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.typeAssignmentMismatch().format(printSrcDestTypes(srcType, destType)));
15680
15750
  return false;
15681
15751
  }
15682
15752
  }
@@ -15700,10 +15770,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15700
15770
  /* reportErrorsUsingObjType */ false)) {
15701
15771
  return true;
15702
15772
  }
15703
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.typeAssignmentMismatch().format({
15704
- sourceType: printType(srcType),
15705
- destType: printType(destType),
15706
- }));
15773
+ diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.typeAssignmentMismatch().format(printSrcDestTypes(srcType, destType)));
15707
15774
  return false;
15708
15775
  }
15709
15776
  }
@@ -15933,10 +16000,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15933
16000
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.assignToNone());
15934
16001
  return false;
15935
16002
  }
15936
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.typeAssignmentMismatch().format({
15937
- sourceType: printType(srcType),
15938
- destType: printType(destType),
15939
- }));
16003
+ diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.typeAssignmentMismatch().format(printSrcDestTypes(srcType, destType)));
15940
16004
  return false;
15941
16005
  }
15942
16006
  function assignFromUnionType(destType, srcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount) {
@@ -16078,10 +16142,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16078
16142
  }
16079
16143
  }, /* sortSubtypes */ true);
16080
16144
  if (isIncompatible) {
16081
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.typeAssignmentMismatch().format({
16082
- sourceType: printType(srcType),
16083
- destType: printType(destType),
16084
- }));
16145
+ diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.typeAssignmentMismatch().format(printSrcDestTypes(srcType, destType)));
16085
16146
  return false;
16086
16147
  }
16087
16148
  return true;
@@ -16146,10 +16207,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16146
16207
  }
16147
16208
  });
16148
16209
  if (isIncompatible) {
16149
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.typeAssignmentMismatch().format({
16150
- sourceType: printType(srcType),
16151
- destType: printType(destType),
16152
- }));
16210
+ diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.typeAssignmentMismatch().format(printSrcDestTypes(srcType, destType)));
16153
16211
  return false;
16154
16212
  }
16155
16213
  return true;
@@ -16229,10 +16287,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16229
16287
  }
16230
16288
  if (!foundMatch) {
16231
16289
  if (diag && diagAddendum) {
16232
- diag.addMessage(localize_1.Localizer.DiagnosticAddendum.typeAssignmentMismatch().format({
16233
- sourceType: printType(srcType),
16234
- destType: printType(destType),
16235
- }));
16290
+ diag.addMessage(localize_1.Localizer.DiagnosticAddendum.typeAssignmentMismatch().format(printSrcDestTypes(srcType, destType)));
16236
16291
  diag.addAddendum(diagAddendum);
16237
16292
  }
16238
16293
  return false;
@@ -17663,6 +17718,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17663
17718
  const flags = extraFlags ? evaluatorOptions.printTypeFlags | extraFlags : evaluatorOptions.printTypeFlags;
17664
17719
  return TypePrinter.printFunctionParts(type, flags, getFunctionEffectiveReturnType);
17665
17720
  }
17721
+ // Prints two types and determines whether they need to be output in
17722
+ // fully-qualified form for disambiguation.
17723
+ function printSrcDestTypes(srcType, destType) {
17724
+ const simpleSrcType = printType(srcType);
17725
+ const simpleDestType = printType(destType);
17726
+ if (simpleSrcType !== simpleDestType) {
17727
+ return { sourceType: simpleSrcType, destType: simpleDestType };
17728
+ }
17729
+ const fullSrcType = printType(srcType, { useFullyQualifiedNames: true });
17730
+ const fullDestType = printType(destType, { useFullyQualifiedNames: true });
17731
+ if (fullSrcType !== fullDestType) {
17732
+ return { sourceType: fullSrcType, destType: fullDestType };
17733
+ }
17734
+ return { sourceType: simpleSrcType, destType: simpleDestType };
17735
+ }
17666
17736
  function printType(type, options) {
17667
17737
  let flags = evaluatorOptions.printTypeFlags;
17668
17738
  if (options === null || options === void 0 ? void 0 : options.expandTypeAlias) {
@@ -17683,6 +17753,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17683
17753
  if (options === null || options === void 0 ? void 0 : options.omitTypeArgumentsIfUnknown) {
17684
17754
  flags |= 2 /* OmitTypeArgumentsIfUnknown */;
17685
17755
  }
17756
+ if (options === null || options === void 0 ? void 0 : options.useFullyQualifiedNames) {
17757
+ flags |= 4096 /* UseFullyQualifiedNames */;
17758
+ }
17686
17759
  return TypePrinter.printType(type, flags, getFunctionEffectiveReturnType);
17687
17760
  }
17688
17761
  // Calls back into the parser to parse the contents of a string literal.
@@ -17838,6 +17911,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17838
17911
  addDiagnostic,
17839
17912
  addDiagnosticForTextRange,
17840
17913
  printType,
17914
+ printSrcDestTypes,
17841
17915
  printFunctionParts,
17842
17916
  getTypeCacheEntryCount,
17843
17917
  disposeEvaluator,