@zzzen/pyright-internal 1.2.0-dev.20230129 → 1.2.0-dev.20230212

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 (237) hide show
  1. package/dist/analyzer/backgroundAnalysisProgram.d.ts +3 -3
  2. package/dist/analyzer/backgroundAnalysisProgram.js +4 -2
  3. package/dist/analyzer/backgroundAnalysisProgram.js.map +1 -1
  4. package/dist/analyzer/binder.js +15 -11
  5. package/dist/analyzer/binder.js.map +1 -1
  6. package/dist/analyzer/checker.d.ts +2 -1
  7. package/dist/analyzer/checker.js +28 -21
  8. package/dist/analyzer/checker.js.map +1 -1
  9. package/dist/analyzer/codeFlowEngine.js +3 -2
  10. package/dist/analyzer/codeFlowEngine.js.map +1 -1
  11. package/dist/analyzer/constraintSolver.js +83 -67
  12. package/dist/analyzer/constraintSolver.js.map +1 -1
  13. package/dist/analyzer/dataClasses.js +13 -5
  14. package/dist/analyzer/dataClasses.js.map +1 -1
  15. package/dist/analyzer/declaration.d.ts +2 -0
  16. package/dist/analyzer/declaration.js.map +1 -1
  17. package/dist/analyzer/importResolver.d.ts +1 -1
  18. package/dist/analyzer/importResolver.js +6 -3
  19. package/dist/analyzer/importResolver.js.map +1 -1
  20. package/dist/analyzer/parameterUtils.d.ts +2 -0
  21. package/dist/analyzer/parameterUtils.js +20 -0
  22. package/dist/analyzer/parameterUtils.js.map +1 -0
  23. package/dist/analyzer/parseTreeUtils.d.ts +3 -1
  24. package/dist/analyzer/parseTreeUtils.js +54 -12
  25. package/dist/analyzer/parseTreeUtils.js.map +1 -1
  26. package/dist/analyzer/parseTreeWalker.d.ts +1 -1
  27. package/dist/analyzer/program.d.ts +6 -3
  28. package/dist/analyzer/program.js +78 -19
  29. package/dist/analyzer/program.js.map +1 -1
  30. package/dist/analyzer/service.d.ts +0 -2
  31. package/dist/analyzer/service.js +8 -8
  32. package/dist/analyzer/service.js.map +1 -1
  33. package/dist/analyzer/sourceFile.d.ts +3 -7
  34. package/dist/analyzer/sourceFile.js +3 -19
  35. package/dist/analyzer/sourceFile.js.map +1 -1
  36. package/dist/analyzer/testWalker.js +23 -15
  37. package/dist/analyzer/testWalker.js.map +1 -1
  38. package/dist/analyzer/typeCacheUtils.d.ts +8 -2
  39. package/dist/analyzer/typeCacheUtils.js +4 -4
  40. package/dist/analyzer/typeCacheUtils.js.map +1 -1
  41. package/dist/analyzer/typeEvaluator.js +283 -160
  42. package/dist/analyzer/typeEvaluator.js.map +1 -1
  43. package/dist/analyzer/typeEvaluatorTypes.d.ts +14 -9
  44. package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
  45. package/dist/analyzer/typeGuards.js +0 -14
  46. package/dist/analyzer/typeGuards.js.map +1 -1
  47. package/dist/analyzer/typePrinter.d.ts +2 -1
  48. package/dist/analyzer/typePrinter.js +13 -0
  49. package/dist/analyzer/typePrinter.js.map +1 -1
  50. package/dist/analyzer/typeUtils.d.ts +5 -4
  51. package/dist/analyzer/typeUtils.js +191 -144
  52. package/dist/analyzer/typeUtils.js.map +1 -1
  53. package/dist/analyzer/typeVarContext.d.ts +32 -19
  54. package/dist/analyzer/typeVarContext.js +173 -99
  55. package/dist/analyzer/typeVarContext.js.map +1 -1
  56. package/dist/analyzer/types.d.ts +2 -1
  57. package/dist/analyzer/types.js +1 -0
  58. package/dist/analyzer/types.js.map +1 -1
  59. package/dist/backgroundAnalysisBase.d.ts +1 -3
  60. package/dist/backgroundAnalysisBase.js +2 -3
  61. package/dist/backgroundAnalysisBase.js.map +1 -1
  62. package/dist/backgroundThreadBase.js +5 -1
  63. package/dist/backgroundThreadBase.js.map +1 -1
  64. package/dist/common/envVarUtils.d.ts +1 -1
  65. package/dist/common/envVarUtils.js +26 -16
  66. package/dist/common/envVarUtils.js.map +1 -1
  67. package/dist/common/extensibility.d.ts +44 -6
  68. package/dist/common/extensibility.js +26 -2
  69. package/dist/common/extensibility.js.map +1 -1
  70. package/dist/common/fullAccessHost.d.ts +2 -1
  71. package/dist/common/fullAccessHost.js +22 -0
  72. package/dist/common/fullAccessHost.js.map +1 -1
  73. package/dist/common/host.d.ts +6 -0
  74. package/dist/common/host.js +3 -0
  75. package/dist/common/host.js.map +1 -1
  76. package/dist/common/pathUtils.d.ts +2 -0
  77. package/dist/common/pathUtils.js +17 -3
  78. package/dist/common/pathUtils.js.map +1 -1
  79. package/dist/common/textRangeCollection.d.ts +1 -0
  80. package/dist/common/textRangeCollection.js +54 -20
  81. package/dist/common/textRangeCollection.js.map +1 -1
  82. package/dist/languageServerBase.d.ts +2 -4
  83. package/dist/languageServerBase.js +5 -6
  84. package/dist/languageServerBase.js.map +1 -1
  85. package/dist/languageService/callHierarchyProvider.js +1 -1
  86. package/dist/languageService/callHierarchyProvider.js.map +1 -1
  87. package/dist/languageService/completionProvider.d.ts +0 -1
  88. package/dist/languageService/completionProvider.js +33 -98
  89. package/dist/languageService/completionProvider.js.map +1 -1
  90. package/dist/languageService/completionProviderUtils.d.ts +34 -0
  91. package/dist/languageService/completionProviderUtils.js +102 -0
  92. package/dist/languageService/completionProviderUtils.js.map +1 -0
  93. package/dist/languageService/definitionProvider.d.ts +2 -1
  94. package/dist/languageService/definitionProvider.js +25 -9
  95. package/dist/languageService/definitionProvider.js.map +1 -1
  96. package/dist/languageService/documentSymbolCollector.d.ts +2 -1
  97. package/dist/languageService/documentSymbolCollector.js +27 -3
  98. package/dist/languageService/documentSymbolCollector.js.map +1 -1
  99. package/dist/languageService/documentSymbolProvider.js +1 -1
  100. package/dist/languageService/documentSymbolProvider.js.map +1 -1
  101. package/dist/languageService/hoverProvider.d.ts +1 -0
  102. package/dist/languageService/hoverProvider.js +44 -10
  103. package/dist/languageService/hoverProvider.js.map +1 -1
  104. package/dist/languageService/referencesProvider.d.ts +2 -1
  105. package/dist/languageService/referencesProvider.js +4 -3
  106. package/dist/languageService/referencesProvider.js.map +1 -1
  107. package/dist/languageService/signatureHelpProvider.js +20 -3
  108. package/dist/languageService/signatureHelpProvider.js.map +1 -1
  109. package/dist/languageService/tooltipUtils.d.ts +3 -1
  110. package/dist/languageService/tooltipUtils.js +30 -10
  111. package/dist/languageService/tooltipUtils.js.map +1 -1
  112. package/dist/localization/localize.d.ts +8 -1
  113. package/dist/localization/localize.js +10 -10
  114. package/dist/localization/localize.js.map +1 -1
  115. package/dist/localization/package.nls.en-us.json +3 -3
  116. package/dist/parser/stringTokenUtils.js +10 -0
  117. package/dist/parser/stringTokenUtils.js.map +1 -1
  118. package/dist/pyright.js +17 -9
  119. package/dist/pyright.js.map +1 -1
  120. package/dist/tests/fourslash/completions.autoimport.shadow.fourslash.js +1 -1
  121. package/dist/tests/fourslash/completions.autoimport.shadow.fourslash.js.map +1 -1
  122. package/dist/tests/fourslash/completions.builtinDocstrings.fourslash.js +5 -5
  123. package/dist/tests/fourslash/completions.builtinDocstrings.fourslash.js.map +1 -1
  124. package/dist/tests/fourslash/completions.fourslash.js +2 -2
  125. package/dist/tests/fourslash/completions.fourslash.js.map +1 -1
  126. package/dist/tests/fourslash/completions.inherited.overload.docFromScrWithStub.fourslash.js +1 -1
  127. package/dist/tests/fourslash/completions.inherited.overload.docFromScrWithStub.fourslash.js.map +1 -1
  128. package/dist/tests/fourslash/completions.inherited.overload.docFromStub.fourslash.js +1 -1
  129. package/dist/tests/fourslash/completions.inherited.overload.docFromStub.fourslash.js.map +1 -1
  130. package/dist/tests/fourslash/completions.libCodeAndStub.fourslash.js +1 -1
  131. package/dist/tests/fourslash/completions.libCodeAndStub.fourslash.js.map +1 -1
  132. package/dist/tests/fourslash/completions.libCodeNoStub.fourslash.js +1 -1
  133. package/dist/tests/fourslash/completions.libCodeNoStub.fourslash.js.map +1 -1
  134. package/dist/tests/fourslash/completions.libStub.fourslash.js +1 -1
  135. package/dist/tests/fourslash/completions.libStub.fourslash.js.map +1 -1
  136. package/dist/tests/fourslash/completions.localCode.fourslash.js +2 -2
  137. package/dist/tests/fourslash/completions.localCode.fourslash.js.map +1 -1
  138. package/dist/tests/fourslash/completions.overloads.fourslash.js +1 -1
  139. package/dist/tests/fourslash/completions.overloads.fourslash.js.map +1 -1
  140. package/dist/tests/fourslash/completions.params.fourslash.js +37 -0
  141. package/dist/tests/fourslash/completions.params.fourslash.js.map +1 -1
  142. package/dist/tests/fourslash/completions.plainText.fourslash.js +2 -2
  143. package/dist/tests/fourslash/completions.plainText.fourslash.js.map +1 -1
  144. package/dist/tests/fourslash/completions.self.fourslash.js +2 -2
  145. package/dist/tests/fourslash/completions.self.fourslash.js.map +1 -1
  146. package/dist/tests/fourslash/completions.wildcardimports.fourslash.js +1 -1
  147. package/dist/tests/fourslash/completions.wildcardimports.fourslash.js.map +1 -1
  148. package/dist/tests/fourslash/hover.builtinDocstrings.fourslash.js +7 -7
  149. package/dist/tests/fourslash/hover.builtinDocstrings.fourslash.js.map +1 -1
  150. package/dist/tests/fourslash/hover.class.docString.fourslash.js +1 -1
  151. package/dist/tests/fourslash/hover.class.docString.fourslash.js.map +1 -1
  152. package/dist/tests/fourslash/hover.classNoInit.fourslash.js +1 -1
  153. package/dist/tests/fourslash/hover.classNoInit.fourslash.js.map +1 -1
  154. package/dist/tests/fourslash/hover.docFromSrc.fourslash.js +7 -7
  155. package/dist/tests/fourslash/hover.docFromSrc.fourslash.js.map +1 -1
  156. package/dist/tests/fourslash/hover.docFromSrc.pkg-vs-module1.fourslash.js +1 -1
  157. package/dist/tests/fourslash/hover.docFromSrc.pkg-vs-module1.fourslash.js.map +1 -1
  158. package/dist/tests/fourslash/hover.docFromSrc.pkg-vs-module2.fourslash.js +1 -1
  159. package/dist/tests/fourslash/hover.docFromSrc.pkg-vs-module2.fourslash.js.map +1 -1
  160. package/dist/tests/fourslash/hover.docFromSrc.relativeImport1.fourslash.js +1 -1
  161. package/dist/tests/fourslash/hover.docFromSrc.relativeImport1.fourslash.js.map +1 -1
  162. package/dist/tests/fourslash/hover.docFromSrc.relativeImport2.fourslash.js +1 -1
  163. package/dist/tests/fourslash/hover.docFromSrc.relativeImport2.fourslash.js.map +1 -1
  164. package/dist/tests/fourslash/hover.docFromSrc.relativeImport3.fourslash.js +1 -1
  165. package/dist/tests/fourslash/hover.docFromSrc.relativeImport3.fourslash.js.map +1 -1
  166. package/dist/tests/fourslash/hover.docFromSrc.stubs-package.fourslash.js +2 -2
  167. package/dist/tests/fourslash/hover.docFromSrc.stubs-package.fourslash.js.map +1 -1
  168. package/dist/tests/fourslash/hover.docFromSrc.typeshed.fourslash.js +1 -1
  169. package/dist/tests/fourslash/hover.docFromSrc.typeshed.fourslash.js.map +1 -1
  170. package/dist/tests/fourslash/hover.docstring.links.fourslash.js +1 -1
  171. package/dist/tests/fourslash/hover.docstring.links.fourslash.js.map +1 -1
  172. package/dist/tests/fourslash/hover.docstring.split.fourslash.js +3 -3
  173. package/dist/tests/fourslash/hover.docstring.split.fourslash.js.map +1 -1
  174. package/dist/tests/fourslash/hover.dunderNew.basic.fourslash.js +1 -1
  175. package/dist/tests/fourslash/hover.dunderNew.basic.fourslash.js.map +1 -1
  176. package/dist/tests/fourslash/hover.dunderNew.inheritance.fourslash.js +1 -1
  177. package/dist/tests/fourslash/hover.dunderNew.inheritance.fourslash.js.map +1 -1
  178. package/dist/tests/fourslash/hover.dunderNew.inheritance2.fourslash.js +1 -1
  179. package/dist/tests/fourslash/hover.dunderNew.inheritance2.fourslash.js.map +1 -1
  180. package/dist/tests/fourslash/hover.dunderNew.overloads.fourslash.js +1 -1
  181. package/dist/tests/fourslash/hover.dunderNew.overloads.fourslash.js.map +1 -1
  182. package/dist/tests/fourslash/hover.dunderNew.withInit.fourslash.js +1 -1
  183. package/dist/tests/fourslash/hover.dunderNew.withInit.fourslash.js.map +1 -1
  184. package/dist/tests/fourslash/hover.formatted.fourslash.js +6 -6
  185. package/dist/tests/fourslash/hover.formatted.fourslash.js.map +1 -1
  186. package/dist/tests/fourslash/hover.fourslash.js +1 -1
  187. package/dist/tests/fourslash/hover.fourslash.js.map +1 -1
  188. package/dist/tests/fourslash/hover.inherited.docFromSrc.fourslash.js +6 -6
  189. package/dist/tests/fourslash/hover.inherited.docFromSrc.fourslash.js.map +1 -1
  190. package/dist/tests/fourslash/hover.inherited.docFromSrcWithStub.fourslash.js +5 -5
  191. package/dist/tests/fourslash/hover.inherited.docFromSrcWithStub.fourslash.js.map +1 -1
  192. package/dist/tests/fourslash/hover.inherited.docFromStub.fourslash.js +4 -4
  193. package/dist/tests/fourslash/hover.inherited.docFromStub.fourslash.js.map +1 -1
  194. package/dist/tests/fourslash/hover.inherited.overload.docFromSrcWithStub.fourslash.js +2 -2
  195. package/dist/tests/fourslash/hover.inherited.overload.docFromSrcWithStub.fourslash.js.map +1 -1
  196. package/dist/tests/fourslash/hover.inherited.overload.docFromStub.fourslash.js +2 -2
  197. package/dist/tests/fourslash/hover.inherited.overload.docFromStub.fourslash.js.map +1 -1
  198. package/dist/tests/fourslash/hover.init.fourslash.js +4 -4
  199. package/dist/tests/fourslash/hover.init.fourslash.js.map +1 -1
  200. package/dist/tests/fourslash/hover.libCodeAndStub.fourslash.js +2 -2
  201. package/dist/tests/fourslash/hover.libCodeAndStub.fourslash.js.map +1 -1
  202. package/dist/tests/fourslash/hover.libCodeNoStub.fourslash.js +2 -2
  203. package/dist/tests/fourslash/hover.libCodeNoStub.fourslash.js.map +1 -1
  204. package/dist/tests/fourslash/hover.libStub.fourslash.js +2 -2
  205. package/dist/tests/fourslash/hover.libStub.fourslash.js.map +1 -1
  206. package/dist/tests/fourslash/hover.overloadedFunction.fourslash.js +2 -2
  207. package/dist/tests/fourslash/hover.overloadedFunction.fourslash.js.map +1 -1
  208. package/dist/tests/fourslash/hover.plainText.fourslash.js +1 -1
  209. package/dist/tests/fourslash/hover.plainText.fourslash.js.map +1 -1
  210. package/dist/tests/fourslash/hover.wildcardimports.fourslash.js +1 -1
  211. package/dist/tests/fourslash/hover.wildcardimports.fourslash.js.map +1 -1
  212. package/dist/tests/fourslash/import.multipart.fourslash.js +1 -1
  213. package/dist/tests/fourslash/import.multipart.fourslash.js.map +1 -1
  214. package/dist/tests/fourslash/import.pytyped.typeCheckingBasic.fourslash.js +1 -1
  215. package/dist/tests/fourslash/import.pytyped.typeCheckingBasic.fourslash.js.map +1 -1
  216. package/dist/tests/fourslash/import.pytyped.typeCheckingOff.fourslash.js +1 -1
  217. package/dist/tests/fourslash/import.pytyped.typeCheckingOff.fourslash.js.map +1 -1
  218. package/dist/tests/fourslash/signature.complicated.fourslash.js +31 -1
  219. package/dist/tests/fourslash/signature.complicated.fourslash.js.map +1 -1
  220. package/dist/tests/harness/fourslash/testLanguageService.js +1 -1
  221. package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
  222. package/dist/tests/hoverProvider.test.js +27 -0
  223. package/dist/tests/hoverProvider.test.js.map +1 -1
  224. package/dist/tests/pathUtils.test.js +24 -1
  225. package/dist/tests/pathUtils.test.js.map +1 -1
  226. package/dist/tests/typeEvaluator1.test.js +16 -0
  227. package/dist/tests/typeEvaluator1.test.js.map +1 -1
  228. package/dist/tests/typeEvaluator2.test.js +4 -0
  229. package/dist/tests/typeEvaluator2.test.js.map +1 -1
  230. package/dist/tests/typeEvaluator3.test.js +2 -2
  231. package/dist/tests/typeEvaluator3.test.js.map +1 -1
  232. package/dist/tests/typeEvaluator4.test.js +11 -3
  233. package/dist/tests/typeEvaluator4.test.js.map +1 -1
  234. package/dist/workspaceMap.d.ts +4 -0
  235. package/dist/workspaceMap.js +67 -37
  236. package/dist/workspaceMap.js.map +1 -1
  237. package/package.json +1 -1
@@ -254,6 +254,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
254
254
  let dictClassType;
255
255
  let typedDictClassType;
256
256
  let printExpressionSpaceCount = 0;
257
+ let incompleteGenerationCount = 0;
257
258
  const returnTypeInferenceContextStack = [];
258
259
  let returnTypeInferenceTypeCache;
259
260
  function runWithCancellationToken(token, callback) {
@@ -333,14 +334,23 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
333
334
  const typeCacheToUse = returnTypeInferenceTypeCache && isNodeInReturnTypeInferenceContext(node)
334
335
  ? returnTypeInferenceTypeCache
335
336
  : typeCache;
336
- typeCacheToUse.set(node.id, { typeResult, flags });
337
+ if (!typeResult.isIncomplete) {
338
+ incompleteGenerationCount++;
339
+ }
340
+ else {
341
+ const oldValue = typeCacheToUse.get(node.id);
342
+ if (oldValue !== undefined && !(0, types_1.isTypeSame)(typeResult.type, oldValue.typeResult.type)) {
343
+ incompleteGenerationCount++;
344
+ }
345
+ }
346
+ typeCacheToUse.set(node.id, { typeResult, flags, incompleteGenerationCount: incompleteGenerationCount });
337
347
  // If the entry is located within a part of the parse tree that is currently being
338
348
  // "speculatively" evaluated, track it so we delete the cached entry when we leave
339
349
  // this speculative context.
340
350
  if (speculativeTypeTracker.isSpeculative(node)) {
341
351
  speculativeTypeTracker.trackEntry(typeCacheToUse, node.id);
342
- if (allowSpeculativeCaching && !typeResult.isIncomplete) {
343
- speculativeTypeTracker.addSpeculativeType(node, typeResult, inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType);
352
+ if (allowSpeculativeCaching) {
353
+ speculativeTypeTracker.addSpeculativeType(node, typeResult, incompleteGenerationCount, inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType);
344
354
  }
345
355
  }
346
356
  }
@@ -494,7 +504,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
494
504
  var _a, _b;
495
505
  // Is this type already cached?
496
506
  const cacheEntry = readTypeCacheEntry(node);
497
- if (cacheEntry && !cacheEntry.typeResult.isIncomplete) {
507
+ if (cacheEntry &&
508
+ (!cacheEntry.typeResult.isIncomplete || cacheEntry.incompleteGenerationCount === incompleteGenerationCount)) {
498
509
  if (printExpressionTypes) {
499
510
  console.log(`${getPrintExpressionTypesSpaces()}${ParseTreeUtils.printExpression(node)} (${getLineNum(node)}): Cached ${printType(cacheEntry.typeResult.type)} ${cacheEntry.typeResult.typeErrors ? ' Errors' : ''}`);
500
511
  }
@@ -502,12 +513,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
502
513
  }
503
514
  else {
504
515
  // Is it cached in the speculative type cache?
505
- const cachedTypeResult = speculativeTypeTracker.getSpeculativeType(node, inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType);
506
- if (cachedTypeResult) {
516
+ const cacheEntry = speculativeTypeTracker.getSpeculativeType(node, inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType);
517
+ if (cacheEntry &&
518
+ (!cacheEntry.typeResult.isIncomplete ||
519
+ cacheEntry.incompleteGenerationCount === incompleteGenerationCount)) {
507
520
  if (printExpressionTypes) {
508
- console.log(`${getPrintExpressionTypesSpaces()}${ParseTreeUtils.printExpression(node)} (${getLineNum(node)}): Speculative ${printType(cachedTypeResult.type)}`);
521
+ console.log(`${getPrintExpressionTypesSpaces()}${ParseTreeUtils.printExpression(node)} (${getLineNum(node)}): Speculative ${printType(cacheEntry.typeResult.type)}`);
509
522
  }
510
- return cachedTypeResult;
523
+ return cacheEntry.typeResult;
511
524
  }
512
525
  }
513
526
  if (printExpressionTypes) {
@@ -614,16 +627,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
614
627
  }
615
628
  case 3 /* Assignment */: {
616
629
  typeResult = getTypeOfExpression(node.rightExpression);
617
- assignTypeToExpression(node.leftExpression, typeResult.type,
618
- /* isTypeIncomplete */ false, node.rightExpression,
630
+ assignTypeToExpression(node.leftExpression, typeResult.type, !!typeResult.isIncomplete, node.rightExpression,
619
631
  /* ignoreEmptyContainers */ true,
620
632
  /* allowAssignmentToFinalVar */ true);
621
633
  break;
622
634
  }
623
635
  case 4 /* AssignmentExpression */: {
624
636
  typeResult = getTypeOfExpression(node.rightExpression);
625
- assignTypeToExpression(node.name, typeResult.type,
626
- /* isTypeIncomplete */ false, node.rightExpression,
637
+ assignTypeToExpression(node.name, typeResult.type, !!typeResult.isIncomplete, node.rightExpression,
627
638
  /* ignoreEmptyContainers */ true);
628
639
  break;
629
640
  }
@@ -1218,6 +1229,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1218
1229
  if (types_1.ClassType.isBuiltIn(concreteSubtype, 'bool')) {
1219
1230
  return types_1.ClassType.cloneWithLiteral(concreteSubtype, /* value */ false);
1220
1231
  }
1232
+ // If the object is an int, str or bytes, narrow to a literal type.
1233
+ // This is slightly unsafe in that someone could subclass `int`, `str`
1234
+ // or `bytes` and override the `__bool__` method to change its behavior,
1235
+ // but this is extremely unlikely (and ill advised).
1236
+ if (types_1.ClassType.isBuiltIn(concreteSubtype, 'int')) {
1237
+ return types_1.ClassType.cloneWithLiteral(concreteSubtype, /* value */ 0);
1238
+ }
1239
+ else if (types_1.ClassType.isBuiltIn(concreteSubtype, ['str', 'bytes'])) {
1240
+ return types_1.ClassType.cloneWithLiteral(concreteSubtype, /* value */ '');
1241
+ }
1221
1242
  }
1222
1243
  // If it's possible for the type to be falsy, include it.
1223
1244
  if (canBeFalsy(subtype)) {
@@ -1389,7 +1410,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1389
1410
  function addOneFunctionToSignature(type) {
1390
1411
  let callResult;
1391
1412
  useSpeculativeMode(callNode, () => {
1392
- callResult = validateFunctionArguments(exprNode, argList, type, new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(type)),
1413
+ callResult = validateFunctionArguments(exprNode, argList, { type }, new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(type)),
1393
1414
  /* skipUnknownArgCheck */ true);
1394
1415
  });
1395
1416
  signatures.push({
@@ -1425,16 +1446,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1425
1446
  (0, types_1.isFunction)(methodType) &&
1426
1447
  methodType.details.fullName === 'builtins.object.__init__';
1427
1448
  const isSkipConstructor = !!methodType && (0, types_1.isFunction)(methodType) && types_1.FunctionType.isSkipConstructorCheck(methodType);
1428
- // If there was no `__init__` or the only `__init__` that was found
1429
- // was form the `object` class, see if we can find a better `__new__`
1430
- // method.
1431
- if (!methodType ||
1432
- isObjectInit ||
1433
- isSkipConstructor ||
1434
- (methodType &&
1435
- (0, types_1.isFunction)(methodType) &&
1436
- (types_1.FunctionType.hasDefaultParameters(methodType) ||
1437
- methodType.details.parameters.length === 0))) {
1449
+ const isDefaultParams = methodType && (0, types_1.isFunction)(methodType) && types_1.FunctionType.hasDefaultParameters(methodType);
1450
+ // If there was no `__init__` or the only `__init__` that was found was from
1451
+ // the `object` class or accepts only default parameters(* args, ** kwargs),
1452
+ // see if we can find a better signature from the `__new__` method.
1453
+ if (!methodType || isObjectInit || isSkipConstructor || isDefaultParams) {
1438
1454
  const constructorType = getBoundMethod(subtype, '__new__',
1439
1455
  /* recursionCount */ undefined,
1440
1456
  /* treatConstructorAsClassMember */ true);
@@ -2741,7 +2757,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2741
2757
  if (methodType) {
2742
2758
  if ((0, types_1.isOverloadedFunction)(methodType)) {
2743
2759
  if (errorNode) {
2744
- const bestOverload = getBestOverloadForArguments(errorNode, methodType, argList);
2760
+ const bestOverload = getBestOverloadForArguments(errorNode, { type: methodType, isIncomplete: memberTypeResult.isIncomplete }, argList);
2745
2761
  if (bestOverload) {
2746
2762
  return getFunctionEffectiveReturnType(bestOverload);
2747
2763
  }
@@ -2941,11 +2957,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2941
2957
  // Handles the case where a variable or parameter is defined in an outer
2942
2958
  // scope and captured by an inner scope (either a function or a lambda).
2943
2959
  function getCodeFlowTypeForCapturedVariable(node, symbolWithScope, effectiveType) {
2944
- // This function applies only to variables and parameters, not to other
2960
+ // This function applies only to variables, parameters, and imports, not to other
2945
2961
  // types of symbols.
2946
2962
  if (!symbolWithScope.symbol
2947
2963
  .getDeclarations()
2948
- .every((decl) => decl.type === 1 /* Variable */ || decl.type === 2 /* Parameter */)) {
2964
+ .every((decl) => decl.type === 1 /* Variable */ ||
2965
+ decl.type === 2 /* Parameter */ ||
2966
+ decl.type === 8 /* Alias */)) {
2949
2967
  return undefined;
2950
2968
  }
2951
2969
  // If the symbol is a variable captured by an inner function
@@ -2972,6 +2990,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2972
2990
  if (decl.type === 2 /* Parameter */) {
2973
2991
  return true;
2974
2992
  }
2993
+ // Assume alias declarations are also always safe to narrow.
2994
+ if (decl.type === 8 /* Alias */) {
2995
+ return true;
2996
+ }
2975
2997
  const declCodeFlowNode = AnalyzerNodeInfo.getFlowNode(decl.node);
2976
2998
  if (!declCodeFlowNode) {
2977
2999
  return false;
@@ -3349,7 +3371,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3349
3371
  const getTypeOfNoneBase = (subtype) => {
3350
3372
  if (noneType && (0, types_1.isInstantiableClass)(noneType)) {
3351
3373
  if (types_1.TypeBase.isInstance(subtype)) {
3352
- return getTypeOfObjectMember(node.memberName, noneType, memberName, usage, diag);
3374
+ return getTypeOfObjectMember(node.memberName, types_1.ClassType.cloneAsInstance(noneType), memberName, usage, diag);
3353
3375
  }
3354
3376
  else {
3355
3377
  return getTypeOfClassMember(node.memberName, noneType, memberName, usage, diag);
@@ -4429,15 +4451,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4429
4451
  if (!diag.isEmpty()) {
4430
4452
  addError(localize_1.Localizer.Diagnostic.typeNotSpecializable().format({ type: printType(baseType) }) + diag.getString(), node);
4431
4453
  }
4454
+ const primarySignatureContext = typeVarContext.getPrimarySignature();
4432
4455
  const aliasTypeArgs = [];
4433
4456
  (_b = baseType.typeAliasInfo.typeParameters) === null || _b === void 0 ? void 0 : _b.forEach((typeParam) => {
4434
4457
  let typeVarType;
4435
4458
  if ((0, types_1.isParamSpec)(typeParam)) {
4436
- const paramSpecType = typeVarContext.getParamSpecType(typeParam);
4459
+ const paramSpecType = primarySignatureContext.getParamSpecType(typeParam);
4437
4460
  typeVarType = paramSpecType ? (0, typeUtils_1.convertParamSpecValueToType)(paramSpecType) : types_1.UnknownType.create();
4438
4461
  }
4439
4462
  else {
4440
- typeVarType = typeVarContext.getTypeVarType(typeParam);
4463
+ typeVarType = primarySignatureContext.getTypeVarType(typeParam);
4441
4464
  }
4442
4465
  aliasTypeArgs.push(typeVarType || types_1.UnknownType.create());
4443
4466
  });
@@ -5412,17 +5435,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5412
5435
  // (one for each argument) will be undefined. On subsequent calls, this
5413
5436
  // list will grow to include union expansions.
5414
5437
  function validateOverloadsWithExpandedTypes(errorNode, expandedArgTypes, argParamMatches, typeVarContext, skipUnknownArgCheck, inferenceContext) {
5415
- var _a;
5438
+ var _a, _b;
5416
5439
  const returnTypes = [];
5417
5440
  const matchedOverloads = [];
5418
5441
  let isTypeIncomplete = false;
5419
- const overloadsUsedForCall = [];
5442
+ let overloadsUsedForCall = [];
5420
5443
  let isDefinitiveMatchFound = false;
5421
5444
  for (let expandedTypesIndex = 0; expandedTypesIndex < expandedArgTypes.length; expandedTypesIndex++) {
5422
5445
  let matchedOverload;
5423
5446
  const argTypeOverride = expandedArgTypes[expandedTypesIndex];
5424
5447
  const hasArgTypeOverride = argTypeOverride.some((a) => a !== undefined);
5425
- const possibleMatchResults = [];
5448
+ let possibleMatchResults = [];
5426
5449
  isDefinitiveMatchFound = false;
5427
5450
  for (let overloadIndex = 0; overloadIndex < argParamMatches.length; overloadIndex++) {
5428
5451
  const overload = argParamMatches[overloadIndex].overload;
@@ -5459,13 +5482,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5459
5482
  if (!callResult.argumentErrors && callResult.returnType) {
5460
5483
  overloadsUsedForCall.push(overload);
5461
5484
  matchedOverload = overload;
5462
- matchedOverloads.push({
5485
+ const matchedOverloadInfo = {
5463
5486
  overload: matchedOverload,
5464
5487
  matchResults,
5465
5488
  typeVarContext: effectiveTypeVarContext,
5466
- });
5489
+ returnType: callResult.returnType,
5490
+ argResults: (_b = callResult.argResults) !== null && _b !== void 0 ? _b : [],
5491
+ };
5492
+ matchedOverloads.push(matchedOverloadInfo);
5467
5493
  if (callResult.isArgumentAnyOrUnknown) {
5468
- possibleMatchResults.push(callResult.returnType);
5494
+ possibleMatchResults.push(matchedOverloadInfo);
5469
5495
  }
5470
5496
  else {
5471
5497
  returnTypes.push(callResult.returnType);
@@ -5480,27 +5506,35 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5480
5506
  // Unknown, but include the "possible types" to allow for completion
5481
5507
  // suggestions.
5482
5508
  if (!isDefinitiveMatchFound) {
5483
- // Eliminate any return types that are subsumed by other return types.
5484
- let dedupedMatchResults = [];
5485
- possibleMatchResults.forEach((subtype) => {
5486
- let isSubtypeSubsumed = false;
5487
- for (let dedupedIndex = 0; dedupedIndex < dedupedMatchResults.length; dedupedIndex++) {
5488
- if (assignType(dedupedMatchResults[dedupedIndex], subtype)) {
5489
- isSubtypeSubsumed = true;
5490
- break;
5509
+ possibleMatchResults = filterOverloadMatchesForAnyArgs(possibleMatchResults);
5510
+ // Did the filtering produce a single result? If so, we're done.
5511
+ if (possibleMatchResults.length === 1) {
5512
+ overloadsUsedForCall = [possibleMatchResults[0].overload];
5513
+ returnTypes.push(possibleMatchResults[0].returnType);
5514
+ }
5515
+ else {
5516
+ // Eliminate any return types that are subsumed by other return types.
5517
+ let dedupedMatchResults = [];
5518
+ possibleMatchResults.forEach((result) => {
5519
+ let isSubtypeSubsumed = false;
5520
+ for (let dedupedIndex = 0; dedupedIndex < dedupedMatchResults.length; dedupedIndex++) {
5521
+ if (assignType(dedupedMatchResults[dedupedIndex], result.returnType)) {
5522
+ isSubtypeSubsumed = true;
5523
+ break;
5524
+ }
5525
+ else if (assignType(result.returnType, dedupedMatchResults[dedupedIndex])) {
5526
+ dedupedMatchResults[dedupedIndex] = types_1.NeverType.createNever();
5527
+ break;
5528
+ }
5491
5529
  }
5492
- else if (assignType(subtype, dedupedMatchResults[dedupedIndex])) {
5493
- dedupedMatchResults[dedupedIndex] = types_1.NeverType.createNever();
5494
- break;
5530
+ if (!isSubtypeSubsumed) {
5531
+ dedupedMatchResults.push(result.returnType);
5495
5532
  }
5496
- }
5497
- if (!isSubtypeSubsumed) {
5498
- dedupedMatchResults.push(subtype);
5499
- }
5500
- });
5501
- dedupedMatchResults = dedupedMatchResults.filter((t) => !(0, types_1.isNever)(t));
5502
- const combinedTypes = (0, types_1.combineTypes)(dedupedMatchResults);
5503
- returnTypes.push(dedupedMatchResults.length > 1 ? types_1.UnknownType.createPossibleType(combinedTypes) : combinedTypes);
5533
+ });
5534
+ dedupedMatchResults = dedupedMatchResults.filter((t) => !(0, types_1.isNever)(t));
5535
+ const combinedTypes = (0, types_1.combineTypes)(dedupedMatchResults);
5536
+ returnTypes.push(dedupedMatchResults.length > 1 ? types_1.UnknownType.createPossibleType(combinedTypes) : combinedTypes);
5537
+ }
5504
5538
  }
5505
5539
  if (!matchedOverload) {
5506
5540
  return { argumentErrors: true, isTypeIncomplete, overloadsUsedForCall };
@@ -5531,13 +5565,41 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5531
5565
  overloadsUsedForCall,
5532
5566
  };
5533
5567
  }
5534
- function getBestOverloadForArguments(errorNode, type, argList) {
5568
+ // This function determines whether multiple incompatible overloads match
5569
+ // due to an Any or Unknown argument type.
5570
+ function filterOverloadMatchesForAnyArgs(matches) {
5571
+ if (matches.length < 2) {
5572
+ return matches;
5573
+ }
5574
+ // If all of the return types match, select the first one.
5575
+ if ((0, typeUtils_1.areTypesSame)(matches.map((match) => match.returnType), { treatAnySameAsUnknown: true })) {
5576
+ return [matches[0]];
5577
+ }
5578
+ const firstArgResults = matches[0].argResults;
5579
+ if (!firstArgResults) {
5580
+ return matches;
5581
+ }
5582
+ for (let i = 0; i < firstArgResults.length; i++) {
5583
+ // If the arg is Any or Unknown, see if the corresponding
5584
+ // parameter types differ in any way.
5585
+ if ((0, types_1.isAnyOrUnknown)(firstArgResults[i].argType)) {
5586
+ const paramTypes = matches.map((match) => i < match.matchResults.argParams.length
5587
+ ? match.matchResults.argParams[i].paramType
5588
+ : types_1.UnknownType.create());
5589
+ if (!(0, typeUtils_1.areTypesSame)(paramTypes, { treatAnySameAsUnknown: true })) {
5590
+ return matches;
5591
+ }
5592
+ }
5593
+ }
5594
+ return [matches[0]];
5595
+ }
5596
+ function getBestOverloadForArguments(errorNode, typeResult, argList) {
5535
5597
  let overloadIndex = 0;
5536
5598
  let matches = [];
5537
5599
  // Create a list of potential overload matches based on arguments.
5538
- types_1.OverloadedFunctionType.getOverloads(type).forEach((overload) => {
5600
+ types_1.OverloadedFunctionType.getOverloads(typeResult.type).forEach((overload) => {
5539
5601
  useSpeculativeMode(errorNode, () => {
5540
- const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, overload, overloadIndex);
5602
+ const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, { type: overload, isIncomplete: typeResult.isIncomplete }, overloadIndex);
5541
5603
  if (!matchResults.argumentErrors) {
5542
5604
  matches.push(matchResults);
5543
5605
  }
@@ -5568,7 +5630,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5568
5630
  return a.overloadIndex - b.overloadIndex;
5569
5631
  });
5570
5632
  }
5571
- function validateOverloadedFunctionArguments(errorNode, argList, type, typeVarContext, skipUnknownArgCheck, inferenceContext) {
5633
+ function validateOverloadedFunctionArguments(errorNode, argList, typeResult, typeVarContext, skipUnknownArgCheck, inferenceContext) {
5572
5634
  let filteredMatchResults = [];
5573
5635
  let contextFreeArgTypes;
5574
5636
  // Start by evaluating the types of the arguments without any expected
@@ -5578,11 +5640,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5578
5640
  // cache or record any diagnostics at this stage.
5579
5641
  useSpeculativeMode(errorNode, () => {
5580
5642
  let overloadIndex = 0;
5581
- types_1.OverloadedFunctionType.getOverloads(type).forEach((overload) => {
5643
+ types_1.OverloadedFunctionType.getOverloads(typeResult.type).forEach((overload) => {
5582
5644
  // Consider only the functions that have the @overload decorator,
5583
5645
  // not the final function that omits the overload. This is the
5584
5646
  // intended behavior according to PEP 484.
5585
- const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, overload, overloadIndex);
5647
+ const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, { type: overload, isIncomplete: typeResult.isIncomplete }, overloadIndex);
5586
5648
  if (!matchResults.argumentErrors) {
5587
5649
  filteredMatchResults.push(matchResults);
5588
5650
  }
@@ -5596,7 +5658,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5596
5658
  // Skip the error message if we're in speculative mode because it's very
5597
5659
  // expensive, and we're going to suppress the diagnostic anyway.
5598
5660
  if (!isDiagnosticSuppressedForNode(errorNode)) {
5599
- const functionName = type.overloads[0].details.name || '<anonymous function>';
5661
+ const functionName = typeResult.type.overloads[0].details.name || '<anonymous function>';
5600
5662
  const diagAddendum = new diagnostic_1.DiagnosticAddendum();
5601
5663
  const argTypes = argList.map((t) => printType(getTypeOfArgument(t).type));
5602
5664
  diagAddendum.addMessage(localize_1.Localizer.DiagnosticAddendum.argumentTypes().format({ types: argTypes.join(', ') }));
@@ -5624,7 +5686,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5624
5686
  return evaluateUsingLastMatchingOverload(/* skipUnknownArgCheck */ false);
5625
5687
  }
5626
5688
  let expandedArgTypes = [argList.map((arg) => undefined)];
5627
- let isTypeIncomplete = false;
5689
+ let isTypeIncomplete = !!typeResult.isIncomplete;
5628
5690
  while (true) {
5629
5691
  const callResult = validateOverloadsWithExpandedTypes(errorNode, expandedArgTypes, filteredMatchResults, typeVarContext, skipUnknownArgCheck, inferenceContext);
5630
5692
  if (callResult.isTypeIncomplete) {
@@ -6085,7 +6147,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6085
6147
  effectiveTypeVarContext.addSolveForScope(types_1.WildcardTypeVarScopeId);
6086
6148
  }
6087
6149
  }
6088
- const functionResult = validateFunctionArguments(errorNode, argList, expandedSubtype, effectiveTypeVarContext, skipUnknownArgCheck, inferenceContext);
6150
+ const functionResult = validateFunctionArguments(errorNode, argList, { type: expandedSubtype, isIncomplete: callTypeResult.isIncomplete }, effectiveTypeVarContext, skipUnknownArgCheck, inferenceContext);
6089
6151
  if (functionResult.isTypeIncomplete) {
6090
6152
  isTypeIncomplete = true;
6091
6153
  }
@@ -6134,7 +6196,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6134
6196
  }
6135
6197
  return (0, typeUtils_1.convertToInstance)(castToType);
6136
6198
  }
6137
- const functionResult = validateOverloadedFunctionArguments(errorNode, argList, expandedSubtype, typeVarContext, skipUnknownArgCheck, inferenceContext);
6199
+ const functionResult = validateOverloadedFunctionArguments(errorNode, argList, { type: expandedSubtype, isIncomplete: callTypeResult.isIncomplete }, typeVarContext, skipUnknownArgCheck, inferenceContext);
6138
6200
  overloadsUsedForCall.push(...functionResult.overloadsUsedForCall);
6139
6201
  if (functionResult.isTypeIncomplete) {
6140
6202
  isTypeIncomplete = true;
@@ -6411,13 +6473,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6411
6473
  // function. This matching is done based on positions and keywords. Type evaluation and
6412
6474
  // validation is left to the caller.
6413
6475
  // This logic is based on PEP 3102: https://www.python.org/dev/peps/pep-3102/
6414
- function matchFunctionArgumentsToParameters(errorNode, argList, type, overloadIndex) {
6476
+ function matchFunctionArgumentsToParameters(errorNode, argList, typeResult, overloadIndex) {
6415
6477
  var _a, _b, _c, _d, _e;
6416
- const paramDetails = (0, typeUtils_1.getParameterListDetails)(type);
6478
+ const paramDetails = (0, typeUtils_1.getParameterListDetails)(typeResult.type);
6417
6479
  let argIndex = 0;
6418
6480
  let matchedUnpackedListOfUnknownLength = false;
6419
6481
  let reportedArgError = false;
6420
- let isTypeIncomplete = false;
6482
+ let isTypeIncomplete = !!typeResult.isIncomplete;
6421
6483
  let isVariadicTypeVarFullyMatched = false;
6422
6484
  // Expand any unpacked tuples in the arg list.
6423
6485
  argList = expandArgList(argList);
@@ -6457,8 +6519,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6457
6519
  // Does this function define the param spec, or is it an inner
6458
6520
  // function nested within another function that defines the param
6459
6521
  // spec? We need to handle these two cases differently.
6460
- if (varArgListParam.type.scopeId === type.details.typeVarScopeId ||
6461
- varArgListParam.type.scopeId === type.details.constructorTypeVarScopeId) {
6522
+ if (varArgListParam.type.scopeId === typeResult.type.details.typeVarScopeId ||
6523
+ varArgListParam.type.scopeId === typeResult.type.details.constructorTypeVarScopeId) {
6462
6524
  paramSpecArgList = [];
6463
6525
  paramSpecTarget = types_1.TypeVarType.cloneForParamSpecAccess(varArgListParam.type, /* access */ undefined);
6464
6526
  }
@@ -6516,7 +6578,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6516
6578
  const remainingArgCount = positionalArgCount - argIndex;
6517
6579
  const remainingParamCount = positionParamLimitIndex - paramIndex - 1;
6518
6580
  if (paramIndex >= positionParamLimitIndex) {
6519
- if (!type.details.paramSpec) {
6581
+ if (!typeResult.type.details.paramSpec) {
6520
6582
  let tooManyPositionals = false;
6521
6583
  if (foundUnpackedListArg && argList[argIndex].argumentCategory === 1 /* UnpackedList */) {
6522
6584
  // If this is an unpacked iterable, we will conservatively assume that it
@@ -6562,7 +6624,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6562
6624
  // with a ParamSpec and a Concatenate operator. PEP 612 indicates that
6563
6625
  // all positional parameters specified in the Concatenate must be
6564
6626
  // filled explicitly.
6565
- if (type.details.paramSpec && paramIndex < positionParamLimitIndex) {
6627
+ if (typeResult.type.details.paramSpec && paramIndex < positionParamLimitIndex) {
6566
6628
  addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, positionParamLimitIndex === 1
6567
6629
  ? localize_1.Localizer.Diagnostic.argPositionalExpectedOne()
6568
6630
  : localize_1.Localizer.Diagnostic.argPositionalExpectedCount().format({
@@ -6848,10 +6910,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6848
6910
  }
6849
6911
  else if ((0, types_1.isParamSpec)(argType) && argType.paramSpecAccess === 'kwargs') {
6850
6912
  unpackedDictionaryArgType = types_1.AnyType.create();
6851
- if (type.details.paramSpec) {
6913
+ if (typeResult.type.details.paramSpec) {
6852
6914
  validateArgTypeParams.push({
6853
6915
  paramCategory: 2 /* VarArgDictionary */,
6854
- paramType: type.details.paramSpec,
6916
+ paramType: typeResult.type.details.paramSpec,
6855
6917
  requiresTypeVarMatching: false,
6856
6918
  argument: argList[argIndex],
6857
6919
  errorNode: argList[argIndex].valueExpression || errorNode,
@@ -6967,7 +7029,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6967
7029
  else if (argList[argIndex].argumentCategory === 1 /* UnpackedList */) {
6968
7030
  // Handle the case where a *args: P.args is passed as an argument to
6969
7031
  // a function that accepts a ParamSpec.
6970
- if (type.details.paramSpec) {
7032
+ if (typeResult.type.details.paramSpec) {
6971
7033
  const argTypeResult = getTypeOfArgument(argList[argIndex]);
6972
7034
  const argType = argTypeResult.type;
6973
7035
  if (argTypeResult.isIncomplete) {
@@ -6976,7 +7038,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6976
7038
  if ((0, types_1.isParamSpec)(argType) && argType.paramSpecAccess === 'args') {
6977
7039
  validateArgTypeParams.push({
6978
7040
  paramCategory: 1 /* VarArgList */,
6979
- paramType: type.details.paramSpec,
7041
+ paramType: typeResult.type.details.paramSpec,
6980
7042
  requiresTypeVarMatching: false,
6981
7043
  argument: argList[argIndex],
6982
7044
  errorNode: argList[argIndex].valueExpression || errorNode,
@@ -7023,7 +7085,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7023
7085
  // but have not yet received them. If we received a dictionary argument
7024
7086
  // (i.e. an arg starting with a "**"), we will assume that all parameters
7025
7087
  // are matched.
7026
- if (!unpackedDictionaryArgType && !types_1.FunctionType.isDefaultParameterCheckDisabled(type)) {
7088
+ if (!unpackedDictionaryArgType && !types_1.FunctionType.isDefaultParameterCheckDisabled(typeResult.type)) {
7027
7089
  const unassignedParams = [...paramMap.keys()].filter((name) => {
7028
7090
  const entry = paramMap.get(name);
7029
7091
  return !entry || entry.argsReceived < entry.argsNeeded;
@@ -7147,12 +7209,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7147
7209
  relevance--;
7148
7210
  }
7149
7211
  // Special-case the builtin isinstance and issubclass functions.
7150
- if (['isinstance', 'issubclass'].some((name) => name === type.details.builtInName) &&
7212
+ if (['isinstance', 'issubclass'].some((name) => name === typeResult.type.details.builtInName) &&
7151
7213
  validateArgTypeParams.length === 2) {
7152
7214
  validateArgTypeParams[1].expectingType = true;
7153
7215
  }
7154
7216
  return {
7155
- overload: type,
7217
+ overload: typeResult.type,
7156
7218
  overloadIndex,
7157
7219
  argumentErrors: reportedArgError,
7158
7220
  isTypeIncomplete,
@@ -7294,7 +7356,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7294
7356
  // Set useNarrowBoundOnly to true the first time through
7295
7357
  // the loop if we're going to go through the loop multiple
7296
7358
  // times.
7297
- const argResult = validateArgType(argParam, typeVarContext, type, skipUnknownArgCheck,
7359
+ const argResult = validateArgType(argParam, typeVarContext, { type, isIncomplete: matchResults.isTypeIncomplete }, skipUnknownArgCheck,
7298
7360
  /* skipOverloadArg */ i === 0,
7299
7361
  /* useNarrowBoundOnly */ passCount > 1 && i === 0, typeCondition);
7300
7362
  if (argResult.isTypeIncomplete) {
@@ -7317,11 +7379,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7317
7379
  let sawParamSpecArgs = false;
7318
7380
  let sawParamSpecKwargs = false;
7319
7381
  let condition = [];
7382
+ const argResults = [];
7320
7383
  matchResults.argParams.forEach((argParam) => {
7321
7384
  var _a;
7322
- const argResult = validateArgType(argParam, typeVarContext, type, skipUnknownArgCheck,
7385
+ const argResult = validateArgType(argParam, typeVarContext, { type, isIncomplete: matchResults.isTypeIncomplete }, skipUnknownArgCheck,
7323
7386
  /* skipOverloadArg */ false,
7324
7387
  /* useNarrowBoundOnly */ false, typeCondition);
7388
+ argResults.push(argResult);
7325
7389
  if (!argResult.isCompatible) {
7326
7390
  argumentErrors = true;
7327
7391
  }
@@ -7432,6 +7496,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7432
7496
  }
7433
7497
  return {
7434
7498
  argumentErrors,
7499
+ argResults,
7435
7500
  isArgumentAnyOrUnknown,
7436
7501
  returnType: specializedReturnType,
7437
7502
  isTypeIncomplete,
@@ -7457,8 +7522,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7457
7522
  // Tries to assign the call arguments to the function parameter
7458
7523
  // list and reports any mismatches in types or counts. Returns the
7459
7524
  // specialized return type of the call.
7460
- function validateFunctionArguments(errorNode, argList, type, typeVarContext, skipUnknownArgCheck = false, inferenceContext) {
7461
- const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, type, 0);
7525
+ function validateFunctionArguments(errorNode, argList, typeResult, typeVarContext, skipUnknownArgCheck = false, inferenceContext) {
7526
+ const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, typeResult, 0);
7462
7527
  if (matchResults.argumentErrors) {
7463
7528
  // Evaluate types of all args. This will ensure that referenced symbols are
7464
7529
  // not reported as unaccessed.
@@ -7478,8 +7543,30 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7478
7543
  // Determines whether the specified argument list satisfies the function
7479
7544
  // signature bound to the specified ParamSpec. Return value indicates success.
7480
7545
  function validateFunctionArgumentsForParamSpec(errorNode, argList, paramSpec, destTypeVarContext, conditionFilter) {
7546
+ const signatureContexts = destTypeVarContext.getSignatureContexts();
7547
+ // Handle the common case where there is only one signature context.
7548
+ if (signatureContexts.length === 1) {
7549
+ return validateFunctionArgumentsForParamSpecSignature(errorNode, argList, paramSpec, signatureContexts[0], conditionFilter);
7550
+ }
7551
+ const filteredSignatureContexts = [];
7552
+ signatureContexts.forEach((context) => {
7553
+ // Use speculative mode to avoid emitting errors or caching types.
7554
+ useSpeculativeMode(errorNode, () => {
7555
+ if (validateFunctionArgumentsForParamSpecSignature(errorNode, argList, paramSpec, context, conditionFilter)) {
7556
+ filteredSignatureContexts.push(context);
7557
+ }
7558
+ });
7559
+ });
7560
+ // Copy back any compatible signature contexts if any were compatible.
7561
+ if (filteredSignatureContexts.length > 0) {
7562
+ destTypeVarContext.copySignatureContexts(filteredSignatureContexts);
7563
+ }
7564
+ // Evaluate non-speculatively to produce a final result and cache types.
7565
+ return validateFunctionArgumentsForParamSpecSignature(errorNode, argList, paramSpec, filteredSignatureContexts.length > 0 ? filteredSignatureContexts[0] : signatureContexts[0], conditionFilter);
7566
+ }
7567
+ function validateFunctionArgumentsForParamSpecSignature(errorNode, argList, paramSpec, typeVarContext, conditionFilter) {
7481
7568
  var _a;
7482
- const paramSpecType = destTypeVarContext.getParamSpecType(paramSpec);
7569
+ const paramSpecType = typeVarContext.getParamSpecType(paramSpec);
7483
7570
  if (!paramSpecType) {
7484
7571
  addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.paramSpecNotBound().format({ type: printType(paramSpec) }), ((_a = argList[0]) === null || _a === void 0 ? void 0 : _a.valueExpression) || errorNode);
7485
7572
  return false;
@@ -7541,7 +7628,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7541
7628
  positionalIndex++;
7542
7629
  }
7543
7630
  if (paramType) {
7544
- if (!validateArgType({
7631
+ const argResult = validateArgType({
7545
7632
  paramCategory: 0 /* Simple */,
7546
7633
  paramType,
7547
7634
  requiresTypeVarMatching: false,
@@ -7551,7 +7638,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7551
7638
  /* functionType */ undefined,
7552
7639
  /* skipUnknownArgCheck */ false,
7553
7640
  /* skipOverloadArg */ false,
7554
- /* useNarrowBoundOnly */ false, conditionFilter)) {
7641
+ /* useNarrowBoundOnly */ false, conditionFilter);
7642
+ if (!argResult.isCompatible) {
7555
7643
  reportedArgError = true;
7556
7644
  }
7557
7645
  }
@@ -7578,17 +7666,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7578
7666
  }
7579
7667
  }
7580
7668
  if (!reportedArgError) {
7581
- destTypeVarContext.applySourceContextTypeVars(srcTypeVarContext);
7669
+ typeVarContext.applySourceContextTypeVars(srcTypeVarContext);
7582
7670
  }
7583
7671
  return !reportedArgError;
7584
7672
  }
7585
- function validateArgType(argParam, typeVarContext, functionType, skipUnknownCheck, skipOverloadArg, useNarrowBoundOnly, conditionFilter) {
7673
+ function validateArgType(argParam, typeVarContext, typeResult, skipUnknownCheck, skipOverloadArg, useNarrowBoundOnly, conditionFilter) {
7586
7674
  var _a;
7587
7675
  let argType;
7588
7676
  let expectedTypeDiag;
7589
- let isTypeIncomplete = false;
7677
+ let isTypeIncomplete = !!(typeResult === null || typeResult === void 0 ? void 0 : typeResult.isIncomplete);
7590
7678
  let isCompatible = true;
7591
- const functionName = functionType === null || functionType === void 0 ? void 0 : functionType.details.name;
7679
+ const functionName = typeResult === null || typeResult === void 0 ? void 0 : typeResult.type.details.name;
7592
7680
  if (argParam.argument.valueExpression) {
7593
7681
  // If the param type is a "bare" TypeVar, don't use it as an expected
7594
7682
  // type. This causes problems for cases where the the call expression
@@ -7598,7 +7686,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7598
7686
  // a wide bound on a TypeVar (if a narrow bound has not yet been established)
7599
7687
  // will unnecessarily constrain the expected type.
7600
7688
  let expectedType;
7601
- if (!(0, types_1.isTypeVar)(argParam.paramType) || argParam.paramType.scopeId !== (functionType === null || functionType === void 0 ? void 0 : functionType.details.typeVarScopeId)) {
7689
+ if (!(0, types_1.isTypeVar)(argParam.paramType) ||
7690
+ argParam.paramType.scopeId !== (typeResult === null || typeResult === void 0 ? void 0 : typeResult.type.details.typeVarScopeId)) {
7602
7691
  expectedType = (0, typeUtils_1.applySolvedTypeVars)(argParam.paramType, typeVarContext, { useNarrowBoundOnly });
7603
7692
  }
7604
7693
  // If the expected type is unknown, don't use an expected type. Instead,
@@ -7616,7 +7705,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7616
7705
  32 /* DisallowParamSpec */ |
7617
7706
  64 /* DisallowTypeVarTuple */
7618
7707
  : 0 /* None */;
7619
- const exprTypeResult = getTypeOfExpression(argParam.argument.valueExpression, flags, (0, typeUtils_1.makeInferenceContext)(expectedType, typeVarContext));
7708
+ const exprTypeResult = getTypeOfExpression(argParam.argument.valueExpression, flags, (0, typeUtils_1.makeInferenceContext)(expectedType, typeVarContext, !!(typeResult === null || typeResult === void 0 ? void 0 : typeResult.isIncomplete)));
7620
7709
  argType = exprTypeResult.type;
7621
7710
  if (exprTypeResult.isIncomplete) {
7622
7711
  isTypeIncomplete = true;
@@ -8870,6 +8959,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8870
8959
  /* typeVarContext */ undefined,
8871
8960
  /* skipUnknownArgCheck */ true, inferenceContext);
8872
8961
  });
8962
+ // If there were errors with the expected type, try
8963
+ // to evaluate without the expected type.
8964
+ if (callResult.argumentErrors && inferenceContext) {
8965
+ useSpeculativeMode(errorNode, () => {
8966
+ callResult = validateCallArguments(errorNode, functionArgs, { type: magicMethodType },
8967
+ /* typeVarContext */ undefined,
8968
+ /* skipUnknownArgCheck */ true);
8969
+ });
8970
+ }
8873
8971
  if (callResult.argumentErrors) {
8874
8972
  magicMethodSupported = false;
8875
8973
  }
@@ -9496,7 +9594,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9496
9594
  return { type: returnedType || types_1.UnknownType.create() };
9497
9595
  }
9498
9596
  function getTypeOfLambda(node, inferenceContext) {
9499
- let isIncomplete = false;
9597
+ let isIncomplete = !!(inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.isTypeIncomplete);
9500
9598
  const functionType = types_1.FunctionType.createInstance('', '', '', 131072 /* PartiallyEvaluated */);
9501
9599
  functionType.details.typeVarScopeId = getScopeIdForNode(node);
9502
9600
  // Pre-cache the incomplete function type in case the evaluation of the
@@ -9601,7 +9699,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9601
9699
  isIncomplete = true;
9602
9700
  }
9603
9701
  };
9604
- if (speculativeTypeTracker.isSpeculative(node)) {
9702
+ if (speculativeTypeTracker.isSpeculative(node) || (inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.isTypeIncomplete)) {
9605
9703
  // We need to set allowCacheRetention to false because we don't want to
9606
9704
  // cache the type of the lambda return expression because it depends on
9607
9705
  // the parameter types that we set above, and the speculative type cache
@@ -10699,6 +10797,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
10699
10797
  if (isDeclaredTypeAlias(node.leftExpression)) {
10700
10798
  flags |=
10701
10799
  128 /* ExpectingType */ |
10800
+ 256 /* ExpectingTypeAnnotation */ |
10702
10801
  8 /* EvaluateStringLiteralAsType */ |
10703
10802
  32 /* DisallowParamSpec */ |
10704
10803
  64 /* DisallowTypeVarTuple */ |
@@ -10997,14 +11096,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
10997
11096
  }
10998
11097
  node.arguments.forEach((arg) => {
10999
11098
  // Ignore unpacked arguments.
11000
- if (arg.argumentCategory !== 0 /* Simple */) {
11099
+ if (arg.argumentCategory === 2 /* UnpackedDictionary */) {
11001
11100
  // Evaluate the expression's type so symbols are marked accessed
11002
11101
  // and errors are reported.
11003
11102
  getTypeOfExpression(arg.valueExpression);
11004
11103
  return;
11005
11104
  }
11006
11105
  if (!arg.name) {
11007
- let argType = getTypeOfExpression(arg.valueExpression, exprFlags).type;
11106
+ let argType;
11107
+ if (arg.argumentCategory === 1 /* UnpackedList */) {
11108
+ getTypeOfExpression(arg.valueExpression);
11109
+ argType = types_1.UnknownType.create();
11110
+ }
11111
+ else {
11112
+ argType = getTypeOfExpression(arg.valueExpression, exprFlags).type;
11113
+ }
11008
11114
  // In some stub files, classes are conditionally defined (e.g. based
11009
11115
  // on platform type). We'll assume that the conditional logic is correct
11010
11116
  // and strip off the "unbound" union.
@@ -11350,24 +11456,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11350
11456
  if (!skipSynthesizedInit) {
11351
11457
  const initSymbol = (0, typeUtils_1.lookUpClassMember)(classType, '__init__', 2 /* SkipBaseClasses */);
11352
11458
  if (initSymbol) {
11353
- const initSymbolType = getTypeOfMember(initSymbol);
11354
- if ((0, types_1.isFunction)(initSymbolType)) {
11355
- if (!types_1.FunctionType.isSynthesizedMethod(initSymbolType)) {
11356
- hasExistingInitMethod = true;
11357
- }
11358
- }
11359
- else {
11360
- hasExistingInitMethod = true;
11361
- }
11459
+ hasExistingInitMethod = true;
11362
11460
  }
11363
11461
  }
11364
11462
  let skipSynthesizeHash = false;
11365
11463
  const hashSymbol = (0, typeUtils_1.lookUpClassMember)(classType, '__hash__', 2 /* SkipBaseClasses */);
11366
11464
  if (hashSymbol) {
11367
- const hashSymbolType = getTypeOfMember(hashSymbol);
11368
- if ((0, types_1.isFunction)(hashSymbolType) && !types_1.FunctionType.isSynthesizedMethod(hashSymbolType)) {
11369
- skipSynthesizeHash = true;
11370
- }
11465
+ skipSynthesizeHash = true;
11371
11466
  }
11372
11467
  (0, dataClasses_1.synthesizeDataClassMethods)(evaluatorInterface, node, classType, skipSynthesizedInit, hasExistingInitMethod, skipSynthesizeHash);
11373
11468
  }
@@ -11750,7 +11845,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11750
11845
  argument: arg,
11751
11846
  errorNode: (_b = arg.valueExpression) !== null && _b !== void 0 ? _b : errorNode,
11752
11847
  };
11753
- validateArgType(argParam, new typeVarContext_1.TypeVarContext(), newMethodType,
11848
+ validateArgType(argParam, new typeVarContext_1.TypeVarContext(), { type: newMethodType },
11754
11849
  /* skipUnknownCheck */ true,
11755
11850
  /* skipOverloadArg */ true,
11756
11851
  /* useNarrowBoundOnly */ false,
@@ -13177,6 +13272,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
13177
13272
  getTypeOfClass(node.parent);
13178
13273
  return;
13179
13274
  }
13275
+ if (node.parent.nodeType === 23 /* ImportFromAs */) {
13276
+ evaluateTypesForImportFromAs(node.parent);
13277
+ return;
13278
+ }
13279
+ if (node.parent.nodeType === 21 /* ImportAs */) {
13280
+ evaluateTypesForImportAs(node.parent);
13281
+ return;
13282
+ }
13180
13283
  if (node.parent.nodeType === 77 /* TypeAlias */ && node.parent.name === node) {
13181
13284
  getTypeOfTypeAlias(node.parent);
13182
13285
  return;
@@ -14683,9 +14786,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14683
14786
  })) === null || _a === void 0 ? void 0 : _a.type;
14684
14787
  }
14685
14788
  if (resolvedDecl.type === 1 /* Variable */ && resolvedDecl.inferredTypeSource) {
14789
+ const isTypeAlias = (0, declarationUtils_1.isExplicitTypeAliasDeclaration)(resolvedDecl) || isPossibleTypeAliasOrTypedDict(resolvedDecl);
14686
14790
  // If this is a type alias, evaluate types for the entire assignment
14687
14791
  // statement rather than just the RHS of the assignment.
14688
- const typeSource = resolvedDecl.typeAliasName && resolvedDecl.inferredTypeSource.parent
14792
+ const typeSource = isTypeAlias && resolvedDecl.inferredTypeSource.parent
14689
14793
  ? resolvedDecl.inferredTypeSource.parent
14690
14794
  : resolvedDecl.inferredTypeSource;
14691
14795
  let inferredType = (_b = evaluateTypeForSubnode(resolvedDecl.node, () => {
@@ -14703,7 +14807,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14703
14807
  inferredType = enumMemberType;
14704
14808
  }
14705
14809
  }
14706
- if (inferredType && resolvedDecl.typeAliasName) {
14810
+ if (inferredType && isTypeAlias && resolvedDecl.typeAliasName) {
14707
14811
  // If this was a speculative type alias, it becomes a real type alias only
14708
14812
  // in the event that its inferred type is instantiable or explicitly Any
14709
14813
  // (but not an ellipsis).
@@ -14879,7 +14983,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14879
14983
  }
14880
14984
  let sawExplicitTypeAlias = false;
14881
14985
  decls.forEach((decl, index) => {
14882
- var _a, _b;
14986
+ var _a, _b, _c;
14883
14987
  let considerDecl = declIndexToConsider === undefined || index === declIndexToConsider;
14884
14988
  // If we have already seen an explicit type alias, do not consider
14885
14989
  // additional decls. This can happen if multiple TypeAlias declarations
@@ -14901,6 +15005,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14901
15005
  }
14902
15006
  }
14903
15007
  if (considerDecl) {
15008
+ const resolvedDecl = (_a = resolveAliasDeclaration(decl,
15009
+ /* resolveLocalNames */ true,
15010
+ /* allowExternallyHiddenAccess */ AnalyzerNodeInfo.getFileInfo(decl.node).isStubFile)) !== null && _a !== void 0 ? _a : decl;
14904
15011
  const isExplicitTypeAlias = (0, declarationUtils_1.isExplicitTypeAliasDeclaration)(decl);
14905
15012
  const isTypeAlias = isExplicitTypeAlias || isPossibleTypeAliasOrTypedDict(decl);
14906
15013
  if (isExplicitTypeAlias) {
@@ -14909,15 +15016,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14909
15016
  // If this is a type alias, evaluate it outside of the recursive symbol
14910
15017
  // resolution check so we can evaluate the full assignment statement.
14911
15018
  if (isTypeAlias &&
14912
- decl.type === 1 /* Variable */ &&
14913
- ((_b = (_a = decl.inferredTypeSource) === null || _a === void 0 ? void 0 : _a.parent) === null || _b === void 0 ? void 0 : _b.nodeType) === 3 /* Assignment */) {
14914
- evaluateTypesForAssignmentStatement(decl.inferredTypeSource.parent);
14915
- if (decl.typeAliasAnnotation) {
15019
+ resolvedDecl.type === 1 /* Variable */ &&
15020
+ ((_c = (_b = resolvedDecl.inferredTypeSource) === null || _b === void 0 ? void 0 : _b.parent) === null || _c === void 0 ? void 0 : _c.nodeType) === 3 /* Assignment */) {
15021
+ evaluateTypesForAssignmentStatement(resolvedDecl.inferredTypeSource.parent);
15022
+ if (resolvedDecl.typeAliasAnnotation) {
14916
15023
  // Mark "TypeAlias" declaration as accessed.
14917
- getTypeOfAnnotation(decl.typeAliasAnnotation, {
15024
+ getTypeOfAnnotation(resolvedDecl.typeAliasAnnotation, {
14918
15025
  isVariableAnnotation: true,
14919
- allowFinal: ParseTreeUtils.isFinalAllowedForAssignmentTarget(decl.node),
14920
- allowClassVar: ParseTreeUtils.isClassVarAllowedForAssignmentTarget(decl.node),
15026
+ allowFinal: ParseTreeUtils.isFinalAllowedForAssignmentTarget(resolvedDecl.node),
15027
+ allowClassVar: ParseTreeUtils.isClassVarAllowedForAssignmentTarget(resolvedDecl.node),
14921
15028
  });
14922
15029
  }
14923
15030
  }
@@ -14928,14 +15035,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14928
15035
  isIncomplete = true;
14929
15036
  }
14930
15037
  if (type) {
14931
- if (decl.type === 1 /* Variable */) {
14932
- includesVariableDecl = true;
14933
- let isConstant = decl.type === 1 /* Variable */ && !!decl.isConstant;
15038
+ if (resolvedDecl.type === 1 /* Variable */) {
15039
+ // Exempt typing.pyi, which uses variables to define some
15040
+ // special forms like Any.
15041
+ const fileInfo = AnalyzerNodeInfo.getFileInfo(resolvedDecl.node);
15042
+ if (!fileInfo.isTypingStubFile) {
15043
+ includesVariableDecl = true;
15044
+ }
15045
+ let isConstant = resolvedDecl.type === 1 /* Variable */ && !!resolvedDecl.isConstant;
14934
15046
  // Treat enum values declared within an enum class as though they are const even
14935
15047
  // though they may not be named as such.
14936
15048
  if ((0, types_1.isClassInstance)(type) &&
14937
15049
  types_1.ClassType.isEnumClass(type) &&
14938
- (0, enums_1.isDeclInEnumClass)(evaluatorInterface, decl)) {
15050
+ (0, enums_1.isDeclInEnumClass)(evaluatorInterface, resolvedDecl)) {
14939
15051
  isConstant = true;
14940
15052
  }
14941
15053
  // If the symbol is constant, we can retain the literal
@@ -14960,12 +15072,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14960
15072
  }
14961
15073
  }
14962
15074
  else {
14963
- // If this resolves to a class decl, we can use a partially-evaluated
14964
- // version of the class type.
14965
- const resolvedDecl = resolveAliasDeclaration(decl,
14966
- /* resolveLocalNames */ true,
14967
- /* allowExternallyHiddenAccess */ AnalyzerNodeInfo.getFileInfo(decl.node).isStubFile);
14968
- if ((resolvedDecl === null || resolvedDecl === void 0 ? void 0 : resolvedDecl.type) === 6 /* Class */) {
15075
+ if (resolvedDecl.type === 6 /* Class */) {
14969
15076
  const classTypeInfo = getTypeOfClass(resolvedDecl.node);
14970
15077
  if (classTypeInfo === null || classTypeInfo === void 0 ? void 0 : classTypeInfo.decoratedType) {
14971
15078
  typesToCombine.push(classTypeInfo.decoratedType);
@@ -15868,7 +15975,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15868
15975
  srcType.details.isSynthesizedSelf &&
15869
15976
  srcType.details.boundType &&
15870
15977
  destType.details.isSynthesizedSelf &&
15871
- destType.details.boundType) {
15978
+ destType.details.boundType &&
15979
+ types_1.TypeBase.isInstance(srcType) === types_1.TypeBase.isInstance(destType)) {
15872
15980
  if ((flags & 2 /* ReverseTypeVarMatching */) === 0 && destTypeVarContext) {
15873
15981
  (0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, destType, srcType, diag, destTypeVarContext, originalFlags, recursionCount);
15874
15982
  }
@@ -16183,7 +16291,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16183
16291
  }
16184
16292
  }
16185
16293
  if ((0, types_1.isFunction)(destType)) {
16186
- let srcFunction;
16187
16294
  let concreteSrcType = makeTopLevelTypeVarsConcrete(srcType);
16188
16295
  if ((0, types_1.isClassInstance)(concreteSrcType)) {
16189
16296
  const boundMethod = getBoundMethod(concreteSrcType, '__call__', recursionCount);
@@ -16198,33 +16305,45 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16198
16305
  concreteSrcType = constructor;
16199
16306
  }
16200
16307
  }
16308
+ if ((0, types_1.isAnyOrUnknown)(concreteSrcType)) {
16309
+ return (flags & 16 /* OverloadOverlapCheck */) === 0;
16310
+ }
16201
16311
  if ((0, types_1.isOverloadedFunction)(concreteSrcType)) {
16202
- // Overloads are not compatible with ParamSpec.
16203
- if (destType.details.paramSpec) {
16204
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.paramSpecOverload());
16205
- return false;
16206
- }
16207
- // Find first overloaded function that matches the parameters.
16208
- // We don't want to pollute the current typeVarContext, so we'll
16209
- // make a copy of the existing one if it's specified.
16312
+ // Find all of the overloaded functions that match the parameters.
16210
16313
  const overloads = types_1.OverloadedFunctionType.getOverloads(concreteSrcType);
16211
- const overloadIndex = overloads.findIndex((overload) => {
16212
- return assignType(destType, overload, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext === null || destTypeVarContext === void 0 ? void 0 : destTypeVarContext.clone(), srcTypeVarContext === null || srcTypeVarContext === void 0 ? void 0 : srcTypeVarContext.clone(), flags, recursionCount);
16314
+ const filteredOverloads = [];
16315
+ const destTypeVarSignatures = [];
16316
+ const srcTypeVarSignatures = [];
16317
+ overloads.forEach((overload) => {
16318
+ var _a;
16319
+ const overloadScopeId = (_a = (0, typeUtils_1.getTypeVarScopeId)(overload)) !== null && _a !== void 0 ? _a : '';
16320
+ const destTypeVarContextClone = destTypeVarContext === null || destTypeVarContext === void 0 ? void 0 : destTypeVarContext.cloneWithSignatureSource(overloadScopeId);
16321
+ const srcTypeVarContextClone = srcTypeVarContext === null || srcTypeVarContext === void 0 ? void 0 : srcTypeVarContext.cloneWithSignatureSource(overloadScopeId);
16322
+ if (assignType(destType, overload,
16323
+ /* diag */ undefined, destTypeVarContextClone, srcTypeVarContextClone, flags, recursionCount)) {
16324
+ filteredOverloads.push(overload);
16325
+ if (destTypeVarContextClone) {
16326
+ destTypeVarSignatures.push(...destTypeVarContextClone.getSignatureContexts());
16327
+ }
16328
+ if (srcTypeVarContextClone) {
16329
+ srcTypeVarSignatures.push(...srcTypeVarContextClone.getSignatureContexts());
16330
+ }
16331
+ }
16213
16332
  });
16214
- if (overloadIndex < 0) {
16333
+ if (filteredOverloads.length === 0) {
16215
16334
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.noOverloadAssignable().format({ type: printType(destType) }));
16216
16335
  return false;
16217
16336
  }
16218
- srcFunction = overloads[overloadIndex];
16219
- }
16220
- else if ((0, types_1.isFunction)(concreteSrcType)) {
16221
- srcFunction = concreteSrcType;
16222
- }
16223
- else if ((0, types_1.isAnyOrUnknown)(concreteSrcType)) {
16224
- return (flags & 16 /* OverloadOverlapCheck */) === 0;
16337
+ if (destTypeVarContext) {
16338
+ destTypeVarContext.copySignatureContexts(destTypeVarSignatures);
16339
+ }
16340
+ if (srcTypeVarContext) {
16341
+ srcTypeVarContext.copySignatureContexts(srcTypeVarSignatures);
16342
+ }
16343
+ return true;
16225
16344
  }
16226
- if (srcFunction) {
16227
- if (assignFunction(destType, srcFunction, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext !== null && destTypeVarContext !== void 0 ? destTypeVarContext : new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(destType)), srcTypeVarContext !== null && srcTypeVarContext !== void 0 ? srcTypeVarContext : new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(srcFunction)), flags, recursionCount)) {
16345
+ if ((0, types_1.isFunction)(concreteSrcType)) {
16346
+ if (assignFunction(destType, concreteSrcType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext !== null && destTypeVarContext !== void 0 ? destTypeVarContext : new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(destType)), srcTypeVarContext !== null && srcTypeVarContext !== void 0 ? srcTypeVarContext : new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(concreteSrcType)), flags, recursionCount)) {
16228
16347
  return true;
16229
16348
  }
16230
16349
  }
@@ -16265,10 +16384,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16265
16384
  }
16266
16385
  return true;
16267
16386
  }
16268
- if ((0, types_1.isClassInstance)(destType) && types_1.ClassType.isBuiltIn(destType, 'object')) {
16269
- if ((flags & 1 /* EnforceInvariance */) === 0) {
16270
- // All types (including None, Module, OverloadedFunction) derive from object.
16271
- return true;
16387
+ if ((0, types_1.isClass)(destType) && types_1.ClassType.isBuiltIn(destType, 'object')) {
16388
+ if (((0, types_1.isInstantiableClass)(destType) && types_1.TypeBase.isInstantiable(srcType)) || (0, types_1.isClassInstance)(destType)) {
16389
+ if ((flags & 1 /* EnforceInvariance */) === 0) {
16390
+ // All types (including None, Module, OverloadedFunction) derive from object.
16391
+ return true;
16392
+ }
16272
16393
  }
16273
16394
  }
16274
16395
  // Are we trying to assign None to a protocol?
@@ -17189,8 +17310,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17189
17310
  const effectiveSrcTypeVarContext = (flags & 2 /* ReverseTypeVarMatching */) === 0 ? srcTypeVarContext : destTypeVarContext;
17190
17311
  // If the target function was generic and we solved some of the type variables
17191
17312
  // in that generic type, assign them back to the destination typeVar.
17192
- effectiveSrcTypeVarContext.getTypeVars().forEach((typeVarEntry) => {
17193
- assignType(typeVarEntry.typeVar, effectiveSrcTypeVarContext.getTypeVarType(typeVarEntry.typeVar),
17313
+ const typeVarSignatureContext = effectiveSrcTypeVarContext.getPrimarySignature();
17314
+ typeVarSignatureContext.getTypeVars().forEach((typeVarEntry) => {
17315
+ assignType(typeVarEntry.typeVar, typeVarSignatureContext.getTypeVarType(typeVarEntry.typeVar),
17194
17316
  /* diag */ undefined, destTypeVarContext, srcTypeVarContext, 0 /* Default */, recursionCount);
17195
17317
  });
17196
17318
  // Are we assigning to a function with a ParamSpec?
@@ -17345,7 +17467,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17345
17467
  let replacedTypeArg = false;
17346
17468
  const newTypeArgs = assignedType.typeArguments.map((typeArg, index) => {
17347
17469
  const typeParam = assignedType.details.typeParameters[index];
17348
- const expectedTypeArgType = typeVarContext.getTypeVarType(typeParam);
17470
+ const expectedTypeArgType = typeVarContext.getPrimarySignature().getTypeVarType(typeParam);
17349
17471
  if (expectedTypeArgType) {
17350
17472
  if ((0, types_1.isAny)(expectedTypeArgType) || (0, types_1.isAnyOrUnknown)(typeArg)) {
17351
17473
  replacedTypeArg = true;
@@ -17945,8 +18067,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17945
18067
  function printObjectTypeForClass(type) {
17946
18068
  return TypePrinter.printObjectTypeForClass(type, evaluatorOptions.printTypeFlags, getFunctionEffectiveReturnType);
17947
18069
  }
17948
- function printFunctionParts(type) {
17949
- return TypePrinter.printFunctionParts(type, evaluatorOptions.printTypeFlags, getFunctionEffectiveReturnType);
18070
+ function printFunctionParts(type, extraFlags) {
18071
+ const flags = extraFlags ? evaluatorOptions.printTypeFlags | extraFlags : evaluatorOptions.printTypeFlags;
18072
+ return TypePrinter.printFunctionParts(type, flags, getFunctionEffectiveReturnType);
17950
18073
  }
17951
18074
  function printType(type, options) {
17952
18075
  let flags = evaluatorOptions.printTypeFlags;