@zzzen/pyright-internal 1.2.0-dev.20230326 → 1.2.0-dev.20230409

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 (161) hide show
  1. package/dist/analyzer/binder.d.ts +8 -0
  2. package/dist/analyzer/binder.js +46 -1
  3. package/dist/analyzer/binder.js.map +1 -1
  4. package/dist/analyzer/cacheManager.js +1 -1
  5. package/dist/analyzer/checker.js +54 -20
  6. package/dist/analyzer/checker.js.map +1 -1
  7. package/dist/analyzer/constraintSolver.js +4 -1
  8. package/dist/analyzer/constraintSolver.js.map +1 -1
  9. package/dist/analyzer/constructorTransform.js +4 -3
  10. package/dist/analyzer/constructorTransform.js.map +1 -1
  11. package/dist/analyzer/declarationUtils.d.ts +8 -0
  12. package/dist/analyzer/declarationUtils.js +147 -1
  13. package/dist/analyzer/declarationUtils.js.map +1 -1
  14. package/dist/analyzer/importStatementUtils.js +1 -1
  15. package/dist/analyzer/parameterUtils.d.ts +25 -1
  16. package/dist/analyzer/parameterUtils.js +182 -1
  17. package/dist/analyzer/parameterUtils.js.map +1 -1
  18. package/dist/analyzer/patternMatching.js +39 -2
  19. package/dist/analyzer/patternMatching.js.map +1 -1
  20. package/dist/analyzer/program.d.ts +2 -0
  21. package/dist/analyzer/program.js +62 -11
  22. package/dist/analyzer/program.js.map +1 -1
  23. package/dist/analyzer/properties.js +13 -13
  24. package/dist/analyzer/properties.js.map +1 -1
  25. package/dist/analyzer/protocols.js +3 -2
  26. package/dist/analyzer/protocols.js.map +1 -1
  27. package/dist/analyzer/pythonPathUtils.js +1 -1
  28. package/dist/analyzer/regions.js +4 -4
  29. package/dist/analyzer/regions.js.map +1 -1
  30. package/dist/analyzer/service.js +17 -8
  31. package/dist/analyzer/service.js.map +1 -1
  32. package/dist/analyzer/sourceFile.js +2 -2
  33. package/dist/analyzer/sourceFile.js.map +1 -1
  34. package/dist/analyzer/sourceFileInfoUtils.js +1 -1
  35. package/dist/analyzer/sourceMapper.js +1 -1
  36. package/dist/analyzer/sourceMapperUtils.d.ts +0 -8
  37. package/dist/analyzer/sourceMapperUtils.js +18 -25
  38. package/dist/analyzer/sourceMapperUtils.js.map +1 -1
  39. package/dist/analyzer/staticExpressions.js +2 -2
  40. package/dist/analyzer/symbolUtils.js +1 -1
  41. package/dist/analyzer/testWalker.js +3 -0
  42. package/dist/analyzer/testWalker.js.map +1 -1
  43. package/dist/analyzer/tracePrinter.js +1 -1
  44. package/dist/analyzer/typeCacheUtils.js +25 -1
  45. package/dist/analyzer/typeCacheUtils.js.map +1 -1
  46. package/dist/analyzer/typeEvaluator.js +180 -150
  47. package/dist/analyzer/typeEvaluator.js.map +1 -1
  48. package/dist/analyzer/typeEvaluatorTypes.d.ts +3 -3
  49. package/dist/analyzer/typeEvaluatorTypes.js +0 -1
  50. package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
  51. package/dist/analyzer/typeEvaluatorWithTracker.js +3 -5
  52. package/dist/analyzer/typeEvaluatorWithTracker.js.map +1 -1
  53. package/dist/analyzer/typeGuards.js +182 -159
  54. package/dist/analyzer/typeGuards.js.map +1 -1
  55. package/dist/analyzer/typeUtils.d.ts +13 -25
  56. package/dist/analyzer/typeUtils.js +157 -235
  57. package/dist/analyzer/typeUtils.js.map +1 -1
  58. package/dist/analyzer/typeVarContext.js +6 -2
  59. package/dist/analyzer/typeVarContext.js.map +1 -1
  60. package/dist/analyzer/typedDicts.js +42 -7
  61. package/dist/analyzer/typedDicts.js.map +1 -1
  62. package/dist/analyzer/types.d.ts +1 -0
  63. package/dist/analyzer/types.js +10 -0
  64. package/dist/analyzer/types.js.map +1 -1
  65. package/dist/common/configOptions.js +1 -1
  66. package/dist/common/configOptions.js.map +1 -1
  67. package/dist/common/diagnosticSink.js +1 -1
  68. package/dist/common/envVarUtils.js +7 -7
  69. package/dist/common/envVarUtils.js.map +1 -1
  70. package/dist/common/fileBasedCancellationUtils.js +1 -1
  71. package/dist/common/host.js +1 -1
  72. package/dist/common/lspUtils.js +1 -1
  73. package/dist/common/pathConsts.d.ts +1 -0
  74. package/dist/common/pathConsts.js +2 -1
  75. package/dist/common/pathConsts.js.map +1 -1
  76. package/dist/common/positionUtils.d.ts +2 -1
  77. package/dist/common/positionUtils.js +18 -12
  78. package/dist/common/positionUtils.js.map +1 -1
  79. package/dist/common/progressReporter.js +4 -1
  80. package/dist/common/progressReporter.js.map +1 -1
  81. package/dist/common/pythonVersion.js +1 -2
  82. package/dist/common/pythonVersion.js.map +1 -1
  83. package/dist/common/realFileSystem.js +1 -1
  84. package/dist/common/textEditTracker.js +1 -1
  85. package/dist/common/workspaceEditUtils.js +1 -1
  86. package/dist/languageServerBase.js +1 -1
  87. package/dist/languageServerBase.js.map +1 -1
  88. package/dist/languageService/analyzerServiceExecutor.js +2 -2
  89. package/dist/languageService/analyzerServiceExecutor.js.map +1 -1
  90. package/dist/languageService/autoImporter.js +1 -0
  91. package/dist/languageService/autoImporter.js.map +1 -1
  92. package/dist/languageService/callHierarchyProvider.d.ts +7 -3
  93. package/dist/languageService/callHierarchyProvider.js +38 -6
  94. package/dist/languageService/callHierarchyProvider.js.map +1 -1
  95. package/dist/languageService/completionProvider.d.ts +1 -0
  96. package/dist/languageService/completionProvider.js +29 -10
  97. package/dist/languageService/completionProvider.js.map +1 -1
  98. package/dist/languageService/completionProviderUtils.js +2 -2
  99. package/dist/languageService/completionProviderUtils.js.map +1 -1
  100. package/dist/languageService/documentSymbolCollector.js +4 -1
  101. package/dist/languageService/documentSymbolCollector.js.map +1 -1
  102. package/dist/languageService/documentSymbolProvider.js +1 -2
  103. package/dist/languageService/documentSymbolProvider.js.map +1 -1
  104. package/dist/languageService/hoverProvider.d.ts +2 -0
  105. package/dist/languageService/hoverProvider.js +53 -43
  106. package/dist/languageService/hoverProvider.js.map +1 -1
  107. package/dist/languageService/importSorter.js +1 -1
  108. package/dist/languageService/indentationUtils.js +7 -1
  109. package/dist/languageService/indentationUtils.js.map +1 -1
  110. package/dist/languageService/insertionPointUtils.js +2 -1
  111. package/dist/languageService/insertionPointUtils.js.map +1 -1
  112. package/dist/languageService/tooltipUtils.js +2 -2
  113. package/dist/localization/localize.d.ts +0 -3
  114. package/dist/localization/localize.js +0 -1
  115. package/dist/localization/localize.js.map +1 -1
  116. package/dist/localization/package.nls.en-us.json +0 -1
  117. package/dist/pyright.js +1 -2
  118. package/dist/pyright.js.map +1 -1
  119. package/dist/tests/chainedSourceFiles.test.js +27 -0
  120. package/dist/tests/chainedSourceFiles.test.js.map +1 -1
  121. package/dist/tests/checker.test.js +1 -1
  122. package/dist/tests/checker.test.js.map +1 -1
  123. package/dist/tests/fourslash/fourslash.d.ts +5 -0
  124. package/dist/tests/fourslash/showcallhierarchy.incomingCalls.aliasedFunction.fourslash.d.ts +1 -0
  125. package/dist/tests/fourslash/showcallhierarchy.incomingCalls.aliasedFunction.fourslash.js +34 -0
  126. package/dist/tests/fourslash/showcallhierarchy.incomingCalls.aliasedFunction.fourslash.js.map +1 -0
  127. package/dist/tests/fourslash/showcallhierarchy.incomingCalls.aliasedVariable.fourslash.d.ts +1 -0
  128. package/dist/tests/fourslash/showcallhierarchy.incomingCalls.aliasedVariable.fourslash.js +19 -0
  129. package/dist/tests/fourslash/showcallhierarchy.incomingCalls.aliasedVariable.fourslash.js.map +1 -0
  130. package/dist/tests/fourslash/showcallhierarchy.incomingCalls.function.fourslash.d.ts +1 -0
  131. package/dist/tests/fourslash/showcallhierarchy.incomingCalls.function.fourslash.js +39 -0
  132. package/dist/tests/fourslash/showcallhierarchy.incomingCalls.function.fourslash.js.map +1 -0
  133. package/dist/tests/harness/fourslash/testState.d.ts +5 -0
  134. package/dist/tests/harness/fourslash/testState.js +21 -0
  135. package/dist/tests/harness/fourslash/testState.js.map +1 -1
  136. package/dist/tests/indentationUtils.reindent.test.js +19 -0
  137. package/dist/tests/indentationUtils.reindent.test.js.map +1 -1
  138. package/dist/tests/insertionPointUtils.test.js +13 -0
  139. package/dist/tests/insertionPointUtils.test.js.map +1 -1
  140. package/dist/tests/moveSymbol.insertion.test.js +21 -0
  141. package/dist/tests/moveSymbol.insertion.test.js.map +1 -1
  142. package/dist/tests/positionUtils.test.d.ts +1 -0
  143. package/dist/tests/positionUtils.test.js +48 -0
  144. package/dist/tests/positionUtils.test.js.map +1 -0
  145. package/dist/tests/typeEvaluator1.test.js +10 -0
  146. package/dist/tests/typeEvaluator1.test.js.map +1 -1
  147. package/dist/tests/typeEvaluator2.test.js +20 -0
  148. package/dist/tests/typeEvaluator2.test.js.map +1 -1
  149. package/dist/tests/typeEvaluator3.test.js +9 -1
  150. package/dist/tests/typeEvaluator3.test.js.map +1 -1
  151. package/dist/tests/typeEvaluator4.test.js +43 -115
  152. package/dist/tests/typeEvaluator4.test.js.map +1 -1
  153. package/dist/tests/typeEvaluator5.test.js +1 -5
  154. package/dist/tests/typeEvaluator5.test.js.map +1 -1
  155. package/dist/workspaceFactory.d.ts +1 -0
  156. package/dist/workspaceFactory.js +24 -14
  157. package/dist/workspaceFactory.js.map +1 -1
  158. package/package.json +1 -1
  159. package/dist/analyzer/aliasDeclarationUtils.d.ts +0 -9
  160. package/dist/analyzer/aliasDeclarationUtils.js +0 -157
  161. package/dist/analyzer/aliasDeclarationUtils.js.map +0 -1
@@ -46,7 +46,6 @@ const textRange_1 = require("../common/textRange");
46
46
  const localize_1 = require("../localization/localize");
47
47
  const parseNodes_1 = require("../parser/parseNodes");
48
48
  const parser_1 = require("../parser/parser");
49
- const DeclarationUtils = __importStar(require("./aliasDeclarationUtils"));
50
49
  const analyzerFileInfo_1 = require("./analyzerFileInfo");
51
50
  const AnalyzerNodeInfo = __importStar(require("./analyzerNodeInfo"));
52
51
  const codeFlowEngine_1 = require("./codeFlowEngine");
@@ -58,6 +57,7 @@ const declarationUtils_1 = require("./declarationUtils");
58
57
  const enums_1 = require("./enums");
59
58
  const functionTransform_1 = require("./functionTransform");
60
59
  const namedTuples_1 = require("./namedTuples");
60
+ const parameterUtils_1 = require("./parameterUtils");
61
61
  const ParseTreeUtils = __importStar(require("./parseTreeUtils"));
62
62
  const patternMatching_1 = require("./patternMatching");
63
63
  const properties_1 = require("./properties");
@@ -254,6 +254,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
254
254
  let dictClassType;
255
255
  let typedDictClassType;
256
256
  let typedDictPrivateClassType;
257
+ let mappingType;
257
258
  let printExpressionSpaceCount = 0;
258
259
  let incompleteGenerationCount = 0;
259
260
  const returnTypeInferenceContextStack = [];
@@ -503,6 +504,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
503
504
  dictClassType = getBuiltInType(node, 'dict');
504
505
  typedDictClassType = getTypingType(node, 'TypedDict');
505
506
  typedDictPrivateClassType = getTypingType(node, '_TypedDict');
507
+ mappingType = getTypeshedType(node, 'SupportsKeysAndGetItem');
508
+ if (!mappingType) {
509
+ // Fall back on 'Mapping' if 'SupportsKeysAndGetItem' is not available.
510
+ mappingType = getTypingType(node, 'Mapping');
511
+ }
506
512
  }
507
513
  }
508
514
  function getTypeOfExpression(node, flags = 0 /* None */, inferenceContext) {
@@ -930,7 +936,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
930
936
  if (types_1.ClassType.isBuiltIn(subtype, 'LiteralString')) {
931
937
  // Handle "LiteralString" specially.
932
938
  if (strClassType && (0, types_1.isInstantiableClass)(strClassType)) {
933
- return types_1.ClassType.cloneAsInstance(strClassType);
939
+ let strInstance = types_1.ClassType.cloneAsInstance(strClassType);
940
+ if (subtype.condition) {
941
+ strInstance = types_1.TypeBase.cloneForCondition(strInstance, (0, typeUtils_1.getTypeCondition)(subtype));
942
+ }
943
+ return strInstance;
934
944
  }
935
945
  }
936
946
  }
@@ -2153,7 +2163,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2153
2163
  }
2154
2164
  }
2155
2165
  }
2156
- const setTypeResult = getTypeOfMemberAccessWithBaseType(target, baseTypeResult, { method: 'set', setType: type, setErrorNode: srcExpr, setExpectedTypeDiag: expectedTypeDiagAddendum }, 0 /* None */);
2166
+ const setTypeResult = getTypeOfMemberAccessWithBaseType(target, baseTypeResult, {
2167
+ method: 'set',
2168
+ setType: { type, isIncomplete: isTypeIncomplete },
2169
+ setErrorNode: srcExpr,
2170
+ setExpectedTypeDiag: expectedTypeDiagAddendum,
2171
+ }, 0 /* None */);
2157
2172
  if (setTypeResult.isAsymmetricDescriptor) {
2158
2173
  setAsymmetricDescriptorAssignment(target);
2159
2174
  }
@@ -2263,11 +2278,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2263
2278
  const sourceEntryTypes = tupleType.tupleTypeArguments.map((t) => (0, typeUtils_1.addConditionToType)(t.type, (0, typeUtils_1.getTypeCondition)(subtype)));
2264
2279
  const unboundedIndex = tupleType.tupleTypeArguments.findIndex((t) => t.isUnbounded);
2265
2280
  if (unboundedIndex >= 0) {
2266
- if (sourceEntryTypes.length > targetTypes.length) {
2267
- // Splice out the unbounded since it might be zero length.
2268
- sourceEntryTypes.splice(unboundedIndex, 1);
2269
- }
2270
- else if (sourceEntryTypes.length < targetTypes.length) {
2281
+ if (sourceEntryTypes.length < targetTypes.length) {
2271
2282
  const typeToReplicate = sourceEntryTypes.length > 0 ? sourceEntryTypes[unboundedIndex] : types_1.AnyType.create();
2272
2283
  // Add elements to make the count match the target count.
2273
2284
  while (sourceEntryTypes.length < targetTypes.length) {
@@ -2340,7 +2351,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2340
2351
  // used as type arguments in other types) with their concrete form.
2341
2352
  // If conditionFilter is specified and the TypeVar is a constrained
2342
2353
  // TypeVar, only the conditions that match the filter will be included.
2343
- function makeTopLevelTypeVarsConcrete(type, conditionFilter) {
2354
+ function makeTopLevelTypeVarsConcrete(type, makeParamSpecsConcrete = false, conditionFilter) {
2344
2355
  return (0, typeUtils_1.mapSubtypes)(type, (subtype) => {
2345
2356
  if ((0, types_1.isParamSpec)(subtype)) {
2346
2357
  if (subtype.paramSpecAccess === 'args') {
@@ -2365,6 +2376,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2365
2376
  return types_1.UnknownType.create();
2366
2377
  }
2367
2378
  }
2379
+ // If this is a function that contains only a ParamSpec (no additional
2380
+ // parameters), convert it to a concrete type of (*args: Any, **kwargs: Any).
2381
+ if (makeParamSpecsConcrete &&
2382
+ (0, types_1.isFunction)(subtype) &&
2383
+ subtype.details.parameters.length === 0 &&
2384
+ subtype.details.paramSpec) {
2385
+ const concreteFunction = types_1.FunctionType.createInstance('', '', '', 64 /* SynthesizedMethod */ | 32768 /* SkipArgsKwargsCompatibilityCheck */);
2386
+ types_1.FunctionType.addDefaultParameters(concreteFunction);
2387
+ return types_1.FunctionType.cloneForParamSpec(subtype, concreteFunction);
2388
+ }
2368
2389
  // If this is a TypeVarTuple *Ts, convert it to an unpacked tuple
2369
2390
  // *tuple[*Ts].
2370
2391
  if ((0, types_1.isVariadicTypeVar)(subtype)) {
@@ -2557,7 +2578,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2557
2578
  const baseTypeResult = getTypeOfExpression(target.baseExpression, 2 /* DoNotSpecialize */);
2558
2579
  getTypeOfIndexWithBaseType(target, baseTypeResult, {
2559
2580
  method: 'set',
2560
- setType: type,
2581
+ setType: { type, isIncomplete: isTypeIncomplete },
2561
2582
  setErrorNode: srcExpr,
2562
2583
  setExpectedTypeDiag: expectedTypeDiagAddendum,
2563
2584
  }, 0 /* None */);
@@ -3770,12 +3791,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3770
3791
  type = descriptorResult.type;
3771
3792
  if (usage.method === 'set' && usage.setType) {
3772
3793
  // Verify that the assigned type is compatible.
3773
- if (!assignType(type, usage.setType, diag === null || diag === void 0 ? void 0 : diag.createAddendum())) {
3774
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.memberAssignment().format({
3775
- type: printType(usage.setType),
3776
- name: memberName,
3777
- classType: printObjectTypeForClass(classType),
3778
- }));
3794
+ if (!assignType(type, usage.setType.type, diag === null || diag === void 0 ? void 0 : diag.createAddendum())) {
3795
+ if (!usage.setType.isIncomplete) {
3796
+ diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.memberAssignment().format({
3797
+ type: printType(usage.setType.type),
3798
+ name: memberName,
3799
+ classType: printObjectTypeForClass(classType),
3800
+ }));
3801
+ }
3779
3802
  return undefined;
3780
3803
  }
3781
3804
  if ((0, types_1.isInstantiableClass)(memberInfo.classType) &&
@@ -3825,7 +3848,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3825
3848
  let isTypeValid = true;
3826
3849
  let isAsymmetricDescriptor = false;
3827
3850
  type = (0, typeUtils_1.mapSubtypes)(type, (subtype) => {
3828
- var _a;
3851
+ var _a, _b, _c;
3829
3852
  const concreteSubtype = makeTopLevelTypeVarsConcrete(subtype);
3830
3853
  const isClassMember = !memberInfo || memberInfo.isClassMember;
3831
3854
  if ((0, types_1.isClass)(concreteSubtype) && isClassMember) {
@@ -3910,7 +3933,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3910
3933
  // Provide "value" argument.
3911
3934
  argList.push({
3912
3935
  argumentCategory: 0 /* Simple */,
3913
- typeResult: { type: (_a = usage.setType) !== null && _a !== void 0 ? _a : types_1.UnknownType.create() },
3936
+ typeResult: {
3937
+ type: (_b = (_a = usage.setType) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : types_1.UnknownType.create(),
3938
+ isIncomplete: !!((_c = usage.setType) === null || _c === void 0 ? void 0 : _c.isIncomplete),
3939
+ },
3914
3940
  });
3915
3941
  }
3916
3942
  if (types_1.ClassType.isPropertyClass(lookupClass) &&
@@ -3980,11 +4006,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3980
4006
  if (usage.method === 'set') {
3981
4007
  if (usage.setType &&
3982
4008
  (0, types_1.isFunction)(boundMethodType) &&
3983
- boundMethodType.details.parameters.length >= 2) {
4009
+ boundMethodType.details.parameters.length >= 2 &&
4010
+ !usage.setType.isIncomplete) {
3984
4011
  const setterType = types_1.FunctionType.getEffectiveParameterType(boundMethodType, 1);
3985
4012
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.typeIncompatible().format({
3986
4013
  destType: printType(setterType),
3987
- sourceType: printType(usage.setType),
4014
+ sourceType: printType(usage.setType.type),
3988
4015
  }));
3989
4016
  }
3990
4017
  else if ((0, types_1.isOverloadedFunction)(boundMethodType)) {
@@ -4154,7 +4181,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4154
4181
  }
4155
4182
  // Applies the __getattr__, __setattr__ or __delattr__ method if present.
4156
4183
  function applyAttributeAccessOverride(classType, errorNode, usage, memberName) {
4157
- var _a, _b, _c;
4184
+ var _a, _b, _c, _d, _e;
4158
4185
  const getAttributeAccessMember = (name) => {
4159
4186
  var _a;
4160
4187
  // See if the class has a "__getattribute__" or "__getattr__" method.
@@ -4194,7 +4221,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4194
4221
  argList.push({
4195
4222
  // Provide "value" argument.
4196
4223
  argumentCategory: 0 /* Simple */,
4197
- typeResult: { type: (_b = usage.setType) !== null && _b !== void 0 ? _b : types_1.UnknownType.create() },
4224
+ typeResult: {
4225
+ type: (_c = (_b = usage.setType) === null || _b === void 0 ? void 0 : _b.type) !== null && _c !== void 0 ? _c : types_1.UnknownType.create(),
4226
+ isIncomplete: !!((_d = usage.setType) === null || _d === void 0 ? void 0 : _d.isIncomplete),
4227
+ },
4198
4228
  });
4199
4229
  }
4200
4230
  if ((0, types_1.isFunction)(accessMemberType) || (0, types_1.isOverloadedFunction)(accessMemberType)) {
@@ -4203,7 +4233,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4203
4233
  const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(boundMethodType));
4204
4234
  const callResult = validateCallArguments(errorNode, argList, { type: boundMethodType }, typeVarContext,
4205
4235
  /* skipUnknownArgCheck */ true);
4206
- return (_c = callResult.returnType) !== null && _c !== void 0 ? _c : types_1.UnknownType.create();
4236
+ return (_e = callResult.returnType) !== null && _e !== void 0 ? _e : types_1.UnknownType.create();
4207
4237
  }
4208
4238
  }
4209
4239
  }
@@ -4783,7 +4813,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4783
4813
  }
4784
4814
  }
4785
4815
  function getTypeOfIndexedObjectOrClass(node, baseType, usage) {
4786
- var _a, _b, _c;
4816
+ var _a, _b, _c, _d, _e, _f;
4787
4817
  // Handle index operations for TypedDict classes specially.
4788
4818
  if ((0, types_1.isClassInstance)(baseType) && types_1.ClassType.isTypedDictClass(baseType)) {
4789
4819
  const typeFromTypedDict = (0, typedDicts_1.getTypeOfIndexedTypedDict)(evaluatorInterface, node, baseType, usage);
@@ -4924,15 +4954,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4924
4954
  },
4925
4955
  ];
4926
4956
  if (usage.method === 'set') {
4927
- let setType = usage.setType || types_1.AnyType.create();
4957
+ let setType = (_d = (_c = usage.setType) === null || _c === void 0 ? void 0 : _c.type) !== null && _d !== void 0 ? _d : types_1.AnyType.create();
4928
4958
  // Expand constrained type variables.
4929
4959
  if ((0, types_1.isTypeVar)(setType) && setType.details.constraints.length > 0) {
4930
4960
  const conditionFilter = (0, types_1.isClassInstance)(baseType) ? baseType.condition : undefined;
4931
- setType = makeTopLevelTypeVarsConcrete(setType, conditionFilter);
4961
+ setType = makeTopLevelTypeVarsConcrete(setType,
4962
+ /* makeParamSpecsConcrete */ undefined, conditionFilter);
4932
4963
  }
4933
4964
  argList.push({
4934
4965
  argumentCategory: 0 /* Simple */,
4935
- typeResult: { type: setType, isIncomplete: isPositionalIndexTypeIncomplete },
4966
+ typeResult: {
4967
+ type: setType,
4968
+ isIncomplete: !!((_e = usage.setType) === null || _e === void 0 ? void 0 : _e.isIncomplete),
4969
+ },
4936
4970
  });
4937
4971
  }
4938
4972
  keywordArgs.forEach((arg) => {
@@ -4981,7 +5015,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4981
5015
  }
4982
5016
  callResult = validateCallArguments(node, argList, { type: itemMethodType });
4983
5017
  return {
4984
- type: (_c = callResult.returnType) !== null && _c !== void 0 ? _c : types_1.UnknownType.create(),
5018
+ type: (_f = callResult.returnType) !== null && _f !== void 0 ? _f : types_1.UnknownType.create(),
4985
5019
  isIncomplete: !!callResult.isTypeIncomplete,
4986
5020
  };
4987
5021
  }
@@ -5999,7 +6033,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5999
6033
  // one or more analyzes with no errors, use those results.
6000
6034
  if (inferenceContext) {
6001
6035
  const expectedCallResult = validateConstructorMethodWithExpectedType(errorNode, argList, type, skipUnknownArgCheck, inferenceContext, initMethodType);
6002
- if (expectedCallResult) {
6036
+ if (expectedCallResult && !expectedCallResult.argumentErrors) {
6003
6037
  returnType = expectedCallResult.returnType;
6004
6038
  if (expectedCallResult.isTypeIncomplete) {
6005
6039
  isTypeIncomplete = true;
@@ -6061,12 +6095,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6061
6095
  }
6062
6096
  if (constructorMethodInfo && !skipConstructorCheck(constructorMethodInfo.type)) {
6063
6097
  const constructorMethodType = constructorMethodInfo.type;
6098
+ let newReturnType;
6064
6099
  // If there is an expected type that was not applied above when
6065
6100
  // handling the __init__ method, try to apply it with the __new__ method.
6066
6101
  if (inferenceContext && !returnType) {
6067
6102
  const expectedCallResult = validateConstructorMethodWithExpectedType(errorNode, argList, type, skipUnknownArgCheck, inferenceContext, constructorMethodType);
6068
- if (expectedCallResult) {
6069
- returnType = expectedCallResult.returnType;
6103
+ if (expectedCallResult && !expectedCallResult.argumentErrors) {
6104
+ newReturnType = expectedCallResult.returnType;
6105
+ returnType = newReturnType;
6070
6106
  if (expectedCallResult.isTypeIncomplete) {
6071
6107
  isTypeIncomplete = true;
6072
6108
  }
@@ -6096,8 +6132,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6096
6132
  if (callResult.argumentErrors) {
6097
6133
  reportedErrors = true;
6098
6134
  }
6099
- else {
6100
- let newReturnType = callResult.returnType;
6135
+ else if (!newReturnType) {
6136
+ newReturnType = callResult.returnType;
6101
6137
  // If the constructor returned an object whose type matches the class of
6102
6138
  // the original type being constructed, use the return type in case it was
6103
6139
  // specialized. If it doesn't match, we'll fall back on the assumption that
@@ -6704,7 +6740,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6704
6740
  // This logic is based on PEP 3102: https://www.python.org/dev/peps/pep-3102/
6705
6741
  function matchFunctionArgumentsToParameters(errorNode, argList, typeResult, overloadIndex) {
6706
6742
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
6707
- const paramDetails = (0, typeUtils_1.getParameterListDetails)(typeResult.type);
6743
+ const paramDetails = (0, parameterUtils_1.getParameterListDetails)(typeResult.type);
6708
6744
  let argIndex = 0;
6709
6745
  let matchedUnpackedListOfUnknownLength = false;
6710
6746
  let reportedArgError = false;
@@ -6720,7 +6756,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6720
6756
  paramMap.set(param.name, {
6721
6757
  argsNeeded: param.category === 0 /* Simple */ && !param.hasDefault ? 1 : 0,
6722
6758
  argsReceived: 0,
6723
- isPositionalOnly: paramInfo.source === typeUtils_1.ParameterSource.PositionOnly,
6759
+ isPositionalOnly: paramInfo.source === parameterUtils_1.ParameterSource.PositionOnly,
6724
6760
  });
6725
6761
  }
6726
6762
  });
@@ -7162,10 +7198,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7162
7198
  }
7163
7199
  }
7164
7200
  else {
7165
- let mappingType = getTypeshedType(errorNode, 'SupportsKeysAndGetItem');
7166
- if (!mappingType) {
7167
- mappingType = getTypingType(errorNode, 'Mapping');
7168
- }
7169
7201
  const strObjType = getBuiltInObject(errorNode, 'str');
7170
7202
  if (mappingType &&
7171
7203
  (0, types_1.isInstantiableClass)(mappingType) &&
@@ -7600,28 +7632,30 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7600
7632
  // where more than two passes are needed.
7601
7633
  let passCount = Math.min(typeVarMatchingCount, 2);
7602
7634
  for (let i = 0; i < passCount; i++) {
7635
+ const signatureTracker = new typeUtils_1.UniqueSignatureTracker();
7603
7636
  useSpeculativeMode(errorNode, () => {
7604
7637
  matchResults.argParams.forEach((argParam) => {
7605
- if (argParam.requiresTypeVarMatching) {
7606
- // Populate the typeVarContext for the argument. If the argument
7607
- // is an overload function, skip it during the first pass
7608
- // because the selection of the proper overload may depend
7609
- // on type arguments supplied by other function arguments.
7610
- // Set useNarrowBoundOnly to true the first time through
7611
- // the loop if we're going to go through the loop multiple
7612
- // times.
7613
- const argResult = validateArgType(argParam, typeVarContext, { type, isIncomplete: matchResults.isTypeIncomplete }, skipUnknownArgCheck,
7614
- /* skipOverloadArg */ i === 0,
7615
- /* useNarrowBoundOnly */ passCount > 1 && i === 0, typeCondition);
7616
- if (argResult.isTypeIncomplete) {
7617
- isTypeIncomplete = true;
7618
- }
7619
- // If we skipped a overload arg during the first pass,
7620
- // add another pass to ensure that we handle all of the
7621
- // type variables.
7622
- if (i === 0 && argResult.skippedOverloadArg) {
7623
- passCount++;
7624
- }
7638
+ if (!argParam.requiresTypeVarMatching) {
7639
+ return;
7640
+ }
7641
+ // Populate the typeVarContext for the argument. If the argument
7642
+ // is an overload function, skip it during the first pass
7643
+ // because the selection of the proper overload may depend
7644
+ // on type arguments supplied by other function arguments.
7645
+ // Set useNarrowBoundOnly to true the first time through
7646
+ // the loop if we're going to go through the loop multiple
7647
+ // times.
7648
+ const argResult = validateArgType(argParam, typeVarContext, signatureTracker, { type, isIncomplete: matchResults.isTypeIncomplete }, skipUnknownArgCheck,
7649
+ /* skipOverloadArg */ i === 0,
7650
+ /* useNarrowBoundOnly */ passCount > 1 && i === 0, typeCondition);
7651
+ if (argResult.isTypeIncomplete) {
7652
+ isTypeIncomplete = true;
7653
+ }
7654
+ // If we skipped a overload arg during the first pass,
7655
+ // add another pass to ensure that we handle all of the
7656
+ // type variables.
7657
+ if (i === 0 && argResult.skippedOverloadArg) {
7658
+ passCount++;
7625
7659
  }
7626
7660
  });
7627
7661
  });
@@ -7634,9 +7668,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7634
7668
  let sawParamSpecKwargs = false;
7635
7669
  let condition = [];
7636
7670
  const argResults = [];
7671
+ const signatureTracker = new typeUtils_1.UniqueSignatureTracker();
7637
7672
  matchResults.argParams.forEach((argParam) => {
7638
7673
  var _a;
7639
- const argResult = validateArgType(argParam, typeVarContext, { type, isIncomplete: matchResults.isTypeIncomplete }, skipUnknownArgCheck,
7674
+ const argResult = validateArgType(argParam, typeVarContext, signatureTracker, { type, isIncomplete: matchResults.isTypeIncomplete }, skipUnknownArgCheck,
7640
7675
  /* skipOverloadArg */ false,
7641
7676
  /* useNarrowBoundOnly */ false, typeCondition);
7642
7677
  argResults.push(argResult);
@@ -7859,6 +7894,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7859
7894
  }
7860
7895
  const argsParam = paramSpecParams.find((paramInfo) => paramInfo.category === 1 /* VarArgList */);
7861
7896
  const kwargsParam = paramSpecParams.find((paramInfo) => paramInfo.category === 2 /* VarArgDictionary */);
7897
+ const signatureTracker = new typeUtils_1.UniqueSignatureTracker();
7862
7898
  argList.forEach((arg) => {
7863
7899
  var _a;
7864
7900
  if (arg.argumentCategory === 0 /* Simple */) {
@@ -7905,7 +7941,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7905
7941
  requiresTypeVarMatching: false,
7906
7942
  argument: arg,
7907
7943
  errorNode: arg.valueExpression || errorNode,
7908
- }, srcTypeVarContext,
7944
+ }, srcTypeVarContext, signatureTracker,
7909
7945
  /* functionType */ undefined,
7910
7946
  /* skipUnknownArgCheck */ false,
7911
7947
  /* skipOverloadArg */ false,
@@ -7941,7 +7977,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7941
7977
  }
7942
7978
  return !reportedArgError;
7943
7979
  }
7944
- function validateArgType(argParam, typeVarContext, typeResult, skipUnknownCheck, skipOverloadArg, useNarrowBoundOnly, conditionFilter) {
7980
+ function validateArgType(argParam, typeVarContext, signatureTracker, typeResult, skipUnknownCheck, skipOverloadArg, useNarrowBoundOnly, conditionFilter) {
7945
7981
  var _a;
7946
7982
  let argType;
7947
7983
  let expectedTypeDiag;
@@ -8014,6 +8050,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8014
8050
  }
8015
8051
  }
8016
8052
  }
8053
+ // If the type includes multiple instances of a generic function
8054
+ // signature, force the type arguments for the duplicates to have
8055
+ // unique names.
8056
+ argType = (0, typeUtils_1.ensureFunctionSignaturesAreUnique)(argType, signatureTracker);
8017
8057
  // If we're assigning to a var arg dictionary with a TypeVar type,
8018
8058
  // strip literals before performing the assignment. This is used in
8019
8059
  // places like a dict constructor.
@@ -9483,13 +9523,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9483
9523
  addUnknown = false;
9484
9524
  }
9485
9525
  else if (entryNode.nodeType === 16 /* DictionaryExpandEntry */) {
9486
- // Verify that the type supports the `keys` and `__getitem__` methods.
9487
- // This protocol is defined in the _typeshed stub. If we can't find
9488
- // it there, fall back on typing.Mapping.
9489
- let mappingType = getTypeshedType(node, 'SupportsKeysAndGetItem');
9490
- if (!mappingType) {
9491
- mappingType = getTypingType(node, 'Mapping');
9492
- }
9493
9526
  let expectedType;
9494
9527
  if (expectedKeyType && expectedValueType) {
9495
9528
  if (mappingType && (0, types_1.isInstantiableClass)(mappingType)) {
@@ -9521,30 +9554,28 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9521
9554
  addUnknown = false;
9522
9555
  }
9523
9556
  }
9524
- else {
9525
- if (mappingType && (0, types_1.isInstantiableClass)(mappingType)) {
9526
- const mappingTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(mappingType));
9527
- // Self-specialize the class.
9528
- mappingType = types_1.ClassType.cloneForSpecialization(mappingType, mappingType.details.typeParameters,
9529
- /* isTypeArgumentExplicit */ true);
9530
- if (assignType(types_1.ClassType.cloneAsInstance(mappingType), unexpandedType,
9531
- /* diag */ undefined, mappingTypeVarContext,
9532
- /* srcTypeVarContext */ undefined, 128 /* RetainLiteralsForTypeVar */)) {
9533
- const specializedMapping = (0, typeUtils_1.applySolvedTypeVars)(mappingType, mappingTypeVarContext);
9534
- const typeArgs = specializedMapping.typeArguments;
9535
- if (typeArgs && typeArgs.length >= 2) {
9536
- if (forceStrictInference || index < maxEntriesToUseForInference) {
9537
- keyTypes.push({ node: entryNode, type: typeArgs[0] });
9538
- valueTypes.push({ node: entryNode, type: typeArgs[1] });
9539
- }
9540
- addUnknown = false;
9557
+ else if (mappingType && (0, types_1.isInstantiableClass)(mappingType)) {
9558
+ const mappingTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(mappingType));
9559
+ // Self-specialize the class.
9560
+ mappingType = types_1.ClassType.cloneForSpecialization(mappingType, mappingType.details.typeParameters,
9561
+ /* isTypeArgumentExplicit */ true);
9562
+ if (assignType(types_1.ClassType.cloneAsInstance(mappingType), unexpandedType,
9563
+ /* diag */ undefined, mappingTypeVarContext,
9564
+ /* srcTypeVarContext */ undefined, 128 /* RetainLiteralsForTypeVar */)) {
9565
+ const specializedMapping = (0, typeUtils_1.applySolvedTypeVars)(mappingType, mappingTypeVarContext);
9566
+ const typeArgs = specializedMapping.typeArguments;
9567
+ if (typeArgs && typeArgs.length >= 2) {
9568
+ if (forceStrictInference || index < maxEntriesToUseForInference) {
9569
+ keyTypes.push({ node: entryNode, type: typeArgs[0] });
9570
+ valueTypes.push({ node: entryNode, type: typeArgs[1] });
9541
9571
  }
9542
- }
9543
- else {
9544
- const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
9545
- addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.dictUnpackIsNotMapping(), entryNode);
9572
+ addUnknown = false;
9546
9573
  }
9547
9574
  }
9575
+ else {
9576
+ const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
9577
+ addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.dictUnpackIsNotMapping(), entryNode);
9578
+ }
9548
9579
  }
9549
9580
  }
9550
9581
  else if (entryNode.nodeType === 32 /* ListComprehension */) {
@@ -11615,7 +11646,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11615
11646
  }
11616
11647
  // The scope for this class becomes the "fields" for the corresponding type.
11617
11648
  const innerScope = ScopeUtils.getScopeForNode(node.suite);
11618
- classType.details.fields = (innerScope === null || innerScope === void 0 ? void 0 : innerScope.symbolTable) || new Map();
11649
+ classType.details.fields = (innerScope === null || innerScope === void 0 ? void 0 : innerScope.symbolTable)
11650
+ ? new Map(innerScope.symbolTable)
11651
+ : new Map();
11619
11652
  // Determine whether the class's instance variables are constrained
11620
11653
  // to those defined by __slots__. We need to do this prior to dataclass
11621
11654
  // processing because dataclasses can implicitly add to the slots
@@ -12115,7 +12148,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12115
12148
  if (newMethodMember) {
12116
12149
  const newMethodType = getTypeOfMember(newMethodMember);
12117
12150
  if ((0, types_1.isFunction)(newMethodType)) {
12118
- const paramListDetails = (0, typeUtils_1.getParameterListDetails)(newMethodType);
12151
+ const paramListDetails = (0, parameterUtils_1.getParameterListDetails)(newMethodType);
12119
12152
  if (paramListDetails.firstKeywordOnlyIndex !== undefined) {
12120
12153
  // Build a map of the keyword-only parameters.
12121
12154
  const paramMap = new Map();
@@ -12127,6 +12160,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12127
12160
  }
12128
12161
  argList.forEach((arg) => {
12129
12162
  var _a, _b, _c;
12163
+ const signatureTracker = new typeUtils_1.UniqueSignatureTracker();
12130
12164
  if (arg.argumentCategory === 0 /* Simple */ && arg.name) {
12131
12165
  const paramIndex = (_a = paramMap.get(arg.name.value)) !== null && _a !== void 0 ? _a : paramListDetails.kwargsIndex;
12132
12166
  if (paramIndex !== undefined) {
@@ -12138,7 +12172,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12138
12172
  argument: arg,
12139
12173
  errorNode: (_b = arg.valueExpression) !== null && _b !== void 0 ? _b : errorNode,
12140
12174
  };
12141
- validateArgType(argParam, new typeVarContext_1.TypeVarContext(), { type: newMethodType },
12175
+ validateArgType(argParam, new typeVarContext_1.TypeVarContext(), signatureTracker, { type: newMethodType },
12142
12176
  /* skipUnknownCheck */ true,
12143
12177
  /* skipOverloadArg */ true,
12144
12178
  /* useNarrowBoundOnly */ false,
@@ -13269,9 +13303,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
13269
13303
  }
13270
13304
  return getExceptionType(subType, node.typeExpression);
13271
13305
  });
13272
- // If this is an except group, wrap the exception type in an ExceptionGroup.
13306
+ // If this is an except group, wrap the exception type in an BaseExceptionGroup.
13273
13307
  if (node.isExceptGroup) {
13274
- targetType = getBuiltInObject(node, 'ExceptionGroup', [targetType]);
13308
+ targetType = getBuiltInObject(node, 'BaseExceptionGroup', [targetType]);
13275
13309
  }
13276
13310
  if (node.name) {
13277
13311
  assignTypeToExpression(node.name, targetType, /* isIncomplete */ false, node.name);
@@ -15260,10 +15294,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15260
15294
  // resolves aliases through local renames ("as" clauses found in import statements).
15261
15295
  function resolveAliasDeclaration(declaration, resolveLocalNames, allowExternallyHiddenAccess = false) {
15262
15296
  var _a;
15263
- return (_a = DeclarationUtils.resolveAliasDeclaration(importLookup, declaration, resolveLocalNames, allowExternallyHiddenAccess)) === null || _a === void 0 ? void 0 : _a.declaration;
15297
+ return (_a = (0, declarationUtils_1.resolveAliasDeclaration)(importLookup, declaration, resolveLocalNames, allowExternallyHiddenAccess)) === null || _a === void 0 ? void 0 : _a.declaration;
15264
15298
  }
15265
15299
  function resolveAliasDeclarationWithInfo(declaration, resolveLocalNames, allowExternallyHiddenAccess = false) {
15266
- return DeclarationUtils.resolveAliasDeclaration(importLookup, declaration, resolveLocalNames, allowExternallyHiddenAccess);
15300
+ return (0, declarationUtils_1.resolveAliasDeclaration)(importLookup, declaration, resolveLocalNames, allowExternallyHiddenAccess);
15267
15301
  }
15268
15302
  // Returns the type of the symbol. If the type is explicitly declared, that type
15269
15303
  // is returned. If not, the type is inferred from assignments to the symbol. All
@@ -15463,33 +15497,31 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15463
15497
  }
15464
15498
  }
15465
15499
  });
15500
+ // How many times have we already attempted to evaluate this declaration already?
15501
+ const evaluationAttempts = ((_b = (_a = cacheEntries === null || cacheEntries === void 0 ? void 0 : cacheEntries.get(effectiveTypeCacheKey)) === null || _a === void 0 ? void 0 : _a.evaluationAttempts) !== null && _b !== void 0 ? _b : 0) + 1;
15502
+ let resultType;
15466
15503
  if (typesToCombine.length > 0) {
15467
- // How many times have we already attempted to evaluate this declaration already?
15468
- const evaluationAttempts = ((_b = (_a = cacheEntries === null || cacheEntries === void 0 ? void 0 : cacheEntries.get(effectiveTypeCacheKey)) === null || _a === void 0 ? void 0 : _a.evaluationAttempts) !== null && _b !== void 0 ? _b : 0) + 1;
15469
15504
  // Ignore the pending evaluation flag if we've already attempted the
15470
15505
  // type evaluation many times because this probably means there's a
15471
15506
  // cyclical dependency that cannot be broken.
15472
15507
  isIncomplete = sawPendingEvaluation && evaluationAttempts < maxEffectiveTypeEvaluationAttempts;
15473
- const result = {
15474
- type: (0, types_1.combineTypes)(typesToCombine),
15475
- isIncomplete,
15476
- includesVariableDecl,
15477
- includesIllegalTypeAliasDecl: !decls.every((decl) => isPossibleTypeAliasDeclaration(decl)),
15478
- isRecursiveDefinition: false,
15479
- evaluationAttempts,
15480
- };
15481
- if (!includesSpeculativeResult) {
15482
- addToEffectiveTypeCache(result);
15483
- }
15484
- return result;
15508
+ resultType = (0, types_1.combineTypes)(typesToCombine);
15485
15509
  }
15486
- return {
15487
- type: types_1.UnboundType.create(),
15510
+ else {
15511
+ resultType = types_1.UnboundType.create();
15512
+ }
15513
+ const result = {
15514
+ type: resultType,
15488
15515
  isIncomplete,
15489
15516
  includesVariableDecl,
15490
15517
  includesIllegalTypeAliasDecl: !decls.every((decl) => isPossibleTypeAliasDeclaration(decl)),
15491
15518
  isRecursiveDefinition: false,
15519
+ evaluationAttempts,
15492
15520
  };
15521
+ if (!includesSpeculativeResult) {
15522
+ addToEffectiveTypeCache(result);
15523
+ }
15524
+ return result;
15493
15525
  function addToEffectiveTypeCache(result) {
15494
15526
  // Add the entry to the cache so we don't need to compute it next time.
15495
15527
  if (!cacheEntries) {
@@ -15610,6 +15642,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15610
15642
  if (types_1.FunctionType.isStubDefinition(type)) {
15611
15643
  return types_1.UnknownType.create();
15612
15644
  }
15645
+ // Don't infer the return type for an overloaded function (unless it's synthesized,
15646
+ // which is needed for proper operation of the __get__ method in properties).
15647
+ if (types_1.FunctionType.isOverloaded(type) && !types_1.FunctionType.isSynthesizedMethod(type)) {
15648
+ return types_1.UnknownType.create();
15649
+ }
15613
15650
  // If the return type has already been lazily evaluated,
15614
15651
  // don't bother computing it again.
15615
15652
  if (type.inferredReturnType) {
@@ -16020,7 +16057,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16020
16057
  });
16021
16058
  return isAssignable;
16022
16059
  }
16023
- function assignTupleTypeArgs(destType, srcType, diag, typeVarContext, flags, recursionCount) {
16060
+ function assignTupleTypeArgs(destType, srcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount) {
16024
16061
  var _a, _b;
16025
16062
  const destTypeArgs = [...((_a = destType.tupleTypeArguments) !== null && _a !== void 0 ? _a : [])];
16026
16063
  const srcTypeArgs = [...((_b = srcType.tupleTypeArguments) !== null && _b !== void 0 ? _b : [])];
@@ -16074,8 +16111,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16074
16111
  if (srcTypeArgs.length === destTypeArgs.length) {
16075
16112
  for (let argIndex = 0; argIndex < srcTypeArgs.length; argIndex++) {
16076
16113
  const entryDiag = diag === null || diag === void 0 ? void 0 : diag.createAddendum();
16077
- if (!assignType(destTypeArgs[argIndex].type, srcTypeArgs[argIndex].type, entryDiag === null || entryDiag === void 0 ? void 0 : entryDiag.createAddendum(), typeVarContext,
16078
- /* srcTypeVarContext */ undefined, flags, recursionCount)) {
16114
+ if (!assignType(destTypeArgs[argIndex].type, srcTypeArgs[argIndex].type, entryDiag === null || entryDiag === void 0 ? void 0 : entryDiag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
16079
16115
  if (entryDiag) {
16080
16116
  entryDiag.addMessage(localize_1.Localizer.DiagnosticAddendum.tupleEntryTypeMismatch().format({
16081
16117
  entry: argIndex + 1,
@@ -16086,17 +16122,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16086
16122
  }
16087
16123
  }
16088
16124
  else {
16089
- if (srcUnboundedIndex >= 0) {
16090
- // PEP 646 allows an indeterminate tuple type to be assigned to
16091
- // a determinate tuple type if it's associated with a TypeVarTuple.
16092
- if (!destType.isUnpacked) {
16093
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.tupleSizeMismatchIndeterminate().format({
16094
- expected: destTypeArgs.length,
16095
- }));
16096
- return false;
16097
- }
16098
- }
16099
- else {
16125
+ if (srcUnboundedIndex < 0) {
16100
16126
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.tupleSizeMismatch().format({
16101
16127
  expected: destTypeArgs.length,
16102
16128
  received: srcTypeArgs.length,
@@ -16144,7 +16170,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16144
16170
  // Handle built-in types that support arbitrary numbers
16145
16171
  // of type parameters like Tuple.
16146
16172
  if (ancestorIndex === 0 && destType.tupleTypeArguments && curSrcType.tupleTypeArguments) {
16147
- return assignTupleTypeArgs(destType, curSrcType, diag, curDestTypeVarContext, flags, recursionCount);
16173
+ return assignTupleTypeArgs(destType, curSrcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount);
16148
16174
  }
16149
16175
  // If there are no type parameters on this class, we're done.
16150
16176
  const ancestorTypeParams = types_1.ClassType.getTypeParameters(ancestorType);
@@ -16219,6 +16245,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16219
16245
  destTypeArgs = destType.typeArguments;
16220
16246
  srcTypeArgs = srcType.typeArguments;
16221
16247
  }
16248
+ let isCompatible = true;
16222
16249
  if (srcTypeArgs) {
16223
16250
  for (let srcArgIndex = 0; srcArgIndex < srcTypeArgs.length; srcArgIndex++) {
16224
16251
  const srcTypeArg = srcTypeArgs[srcArgIndex];
@@ -16243,7 +16270,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16243
16270
  diag.addAddendum(assignmentDiag);
16244
16271
  }
16245
16272
  }
16246
- return false;
16273
+ isCompatible = false;
16247
16274
  }
16248
16275
  }
16249
16276
  else if (types_1.TypeVarType.getVariance(destTypeParam) === 4 /* Contravariant */) {
@@ -16255,7 +16282,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16255
16282
  }));
16256
16283
  childDiag.addAddendum(assignmentDiag);
16257
16284
  }
16258
- return false;
16285
+ isCompatible = false;
16259
16286
  }
16260
16287
  }
16261
16288
  else {
@@ -16270,13 +16297,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16270
16297
  }));
16271
16298
  childDiag.addAddendum(assignmentDiag);
16272
16299
  }
16273
- return false;
16300
+ isCompatible = false;
16274
16301
  }
16275
16302
  }
16276
16303
  }
16277
16304
  }
16278
16305
  }
16279
- return true;
16306
+ return isCompatible;
16280
16307
  }
16281
16308
  // Determines if the source type can be assigned to the dest type.
16282
16309
  // If typeVarContext is provided, type variables within the destType are
@@ -16357,7 +16384,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16357
16384
  // Before performing any other checks, see if the dest type is a
16358
16385
  // TypeVar that we are attempting to match.
16359
16386
  if ((0, types_1.isTypeVar)(destType)) {
16360
- if ((0, types_1.isTypeSame)(destType, srcType)) {
16387
+ if ((0, typeUtils_1.isTypeVarSame)(destType, srcType)) {
16361
16388
  if (destType.scopeId && (destTypeVarContext === null || destTypeVarContext === void 0 ? void 0 : destTypeVarContext.hasSolveForScope(destType.scopeId))) {
16362
16389
  return (0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, destType, srcType, diag, destTypeVarContext, flags, recursionCount);
16363
16390
  }
@@ -16484,6 +16511,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16484
16511
  }
16485
16512
  }
16486
16513
  if ((0, types_1.isNever)(srcType)) {
16514
+ if ((flags & 1 /* EnforceInvariance */) !== 0) {
16515
+ return (0, types_1.isNever)(destType);
16516
+ }
16487
16517
  const targetTypeVarContext = (flags & 2 /* ReverseTypeVarMatching */) === 0 ? destTypeVarContext : srcTypeVarContext;
16488
16518
  if (targetTypeVarContext) {
16489
16519
  (0, typeUtils_1.setTypeArgumentsRecursive)(destType, types_1.UnknownType.create(), targetTypeVarContext, recursionCount);
@@ -16665,9 +16695,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16665
16695
  if (destCallbackType) {
16666
16696
  return assignType(destCallbackType, concreteSrcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount);
16667
16697
  }
16668
- // All functions are objects, so try to assign as an object.
16669
- if (objectType && (0, types_1.isClassInstance)(objectType)) {
16670
- return assignType(destType, objectType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount);
16698
+ // All functions are considered instances of "builtins.function".
16699
+ if (functionObj && (0, types_1.isClassInstance)(functionObj)) {
16700
+ return assignType(destType, functionObj, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount);
16671
16701
  }
16672
16702
  }
16673
16703
  else if ((0, types_1.isModule)(concreteSrcType)) {
@@ -17384,7 +17414,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17384
17414
  if (srcDetails.params.length < destDetails.argsIndex) {
17385
17415
  return;
17386
17416
  }
17387
- let srcLastToPackIndex = srcDetails.params.findIndex((p, i) => i >= destDetails.argsIndex && p.source === typeUtils_1.ParameterSource.KeywordOnly);
17417
+ let srcLastToPackIndex = srcDetails.params.findIndex((p, i) => i >= destDetails.argsIndex && p.source === parameterUtils_1.ParameterSource.KeywordOnly);
17388
17418
  if (srcLastToPackIndex < 0) {
17389
17419
  srcLastToPackIndex = srcDetails.params.length;
17390
17420
  }
@@ -17433,7 +17463,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17433
17463
  },
17434
17464
  type: srcPositionalsType,
17435
17465
  index: -1,
17436
- source: typeUtils_1.ParameterSource.PositionOnly,
17466
+ source: parameterUtils_1.ParameterSource.PositionOnly,
17437
17467
  },
17438
17468
  ...srcDetails.params.slice(destDetails.argsIndex + srcPositionalsToPack.length, srcDetails.params.length),
17439
17469
  ];
@@ -17441,9 +17471,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17441
17471
  srcDetails.argsIndex = argsIndex >= 0 ? argsIndex : undefined;
17442
17472
  const kwargsIndex = srcDetails.params.findIndex((param) => param.param.category === 2 /* VarArgDictionary */);
17443
17473
  srcDetails.kwargsIndex = kwargsIndex >= 0 ? kwargsIndex : undefined;
17444
- const firstKeywordOnlyIndex = srcDetails.params.findIndex((param) => param.source === typeUtils_1.ParameterSource.KeywordOnly);
17474
+ const firstKeywordOnlyIndex = srcDetails.params.findIndex((param) => param.source === parameterUtils_1.ParameterSource.KeywordOnly);
17445
17475
  srcDetails.firstKeywordOnlyIndex = firstKeywordOnlyIndex >= 0 ? firstKeywordOnlyIndex : undefined;
17446
- srcDetails.positionOnlyParamCount = Math.max(0, srcDetails.params.findIndex((p) => p.source !== typeUtils_1.ParameterSource.PositionOnly ||
17476
+ srcDetails.positionOnlyParamCount = Math.max(0, srcDetails.params.findIndex((p) => p.source !== parameterUtils_1.ParameterSource.PositionOnly ||
17447
17477
  p.param.category !== 0 /* Simple */ ||
17448
17478
  p.param.hasDefault));
17449
17479
  }
@@ -17455,8 +17485,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17455
17485
  flags &= ~32 /* SkipFunctionReturnTypeCheck */;
17456
17486
  destType = (0, typeUtils_1.removeParamSpecVariadicsFromFunction)(destType);
17457
17487
  srcType = (0, typeUtils_1.removeParamSpecVariadicsFromFunction)(srcType);
17458
- const destParamDetails = (0, typeUtils_1.getParameterListDetails)(destType);
17459
- const srcParamDetails = (0, typeUtils_1.getParameterListDetails)(srcType);
17488
+ const destParamDetails = (0, parameterUtils_1.getParameterListDetails)(destType);
17489
+ const srcParamDetails = (0, parameterUtils_1.getParameterListDetails)(srcType);
17460
17490
  adjustSourceParamDetailsForDestVariadic(srcParamDetails, destParamDetails);
17461
17491
  const targetIncludesParamSpec = (flags & 2 /* ReverseTypeVarMatching */) !== 0
17462
17492
  ? !!srcType.details.paramSpec
@@ -17475,7 +17505,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17475
17505
  const destParamName = (_e = destParam.param.name) !== null && _e !== void 0 ? _e : '';
17476
17506
  const srcParamName = (_f = srcParam.param.name) !== null && _f !== void 0 ? _f : '';
17477
17507
  if (destParamName && !(0, symbolNameUtils_1.isPrivateOrProtectedName)(destParamName) && !(0, symbolNameUtils_1.isPrivateOrProtectedName)(srcParamName)) {
17478
- const isDestPositionalOnly = destParam.source === typeUtils_1.ParameterSource.PositionOnly;
17508
+ const isDestPositionalOnly = destParam.source === parameterUtils_1.ParameterSource.PositionOnly;
17479
17509
  if (!isDestPositionalOnly &&
17480
17510
  destParam.param.category !== 1 /* VarArgList */ &&
17481
17511
  srcParam.param.category !== 1 /* VarArgList */ &&
@@ -17570,7 +17600,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17570
17600
  if (!assignFunctionParameter(destParamType, srcArgsType, paramIndex, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
17571
17601
  canAssign = false;
17572
17602
  }
17573
- if (destParamDetails.params[paramIndex].source !== typeUtils_1.ParameterSource.PositionOnly &&
17603
+ if (destParamDetails.params[paramIndex].source !== parameterUtils_1.ParameterSource.PositionOnly &&
17574
17604
  srcParamDetails.kwargsIndex === undefined) {
17575
17605
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.namedParamMissingInSource().format({
17576
17606
  name: (_g = destParamDetails.params[paramIndex].param.name) !== null && _g !== void 0 ? _g : '',
@@ -18017,8 +18047,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
18017
18047
  }
18018
18048
  function validateOverrideMethodInternal(baseMethod, overrideMethod, diag, enforceParamNames) {
18019
18049
  var _a, _b;
18020
- const baseParamDetails = (0, typeUtils_1.getParameterListDetails)(baseMethod);
18021
- const overrideParamDetails = (0, typeUtils_1.getParameterListDetails)(overrideMethod);
18050
+ const baseParamDetails = (0, parameterUtils_1.getParameterListDetails)(baseMethod);
18051
+ const overrideParamDetails = (0, parameterUtils_1.getParameterListDetails)(overrideMethod);
18022
18052
  let canOverride = true;
18023
18053
  // Verify that we're not overriding a static, class or instance method with
18024
18054
  // an incompatible type.
@@ -18097,12 +18127,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
18097
18127
  const overrideParam = overrideParamDetails.params[i].param;
18098
18128
  if (i >= baseParamDetails.positionOnlyParamCount &&
18099
18129
  !(0, symbolNameUtils_1.isPrivateOrProtectedName)(baseParam.name || '') &&
18100
- baseParamDetails.params[i].source !== typeUtils_1.ParameterSource.PositionOnly &&
18130
+ baseParamDetails.params[i].source !== parameterUtils_1.ParameterSource.PositionOnly &&
18101
18131
  baseParam.category === 0 /* Simple */ &&
18102
18132
  baseParam.name !== overrideParam.name) {
18103
18133
  if (overrideParam.category === 0 /* Simple */) {
18104
18134
  if (enforceParamNames) {
18105
- if (overrideParamDetails.params[i].source === typeUtils_1.ParameterSource.PositionOnly) {
18135
+ if (overrideParamDetails.params[i].source === parameterUtils_1.ParameterSource.PositionOnly) {
18106
18136
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNamePositionOnly().format({
18107
18137
  index: i + 1,
18108
18138
  baseName: baseParam.name || '*',
@@ -18174,9 +18204,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
18174
18204
  }
18175
18205
  }
18176
18206
  // Now check any keyword-only parameters.
18177
- const baseKwOnlyParams = baseParamDetails.params.filter((paramInfo) => paramInfo.source === typeUtils_1.ParameterSource.KeywordOnly &&
18207
+ const baseKwOnlyParams = baseParamDetails.params.filter((paramInfo) => paramInfo.source === parameterUtils_1.ParameterSource.KeywordOnly &&
18178
18208
  paramInfo.param.category === 0 /* Simple */);
18179
- const overrideWkOnlyParams = overrideParamDetails.params.filter((paramInfo) => paramInfo.source === typeUtils_1.ParameterSource.KeywordOnly &&
18209
+ const overrideWkOnlyParams = overrideParamDetails.params.filter((paramInfo) => paramInfo.source === parameterUtils_1.ParameterSource.KeywordOnly &&
18180
18210
  paramInfo.param.category === 0 /* Simple */);
18181
18211
  baseKwOnlyParams.forEach((paramInfo) => {
18182
18212
  var _a, _b, _c;