@zzzen/pyright-internal 1.2.0-dev.20230122 → 1.2.0-dev.20230205

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 (244) 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 +16 -12
  5. package/dist/analyzer/binder.js.map +1 -1
  6. package/dist/analyzer/checker.d.ts +3 -1
  7. package/dist/analyzer/checker.js +63 -20
  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 +1 -1
  12. package/dist/analyzer/constraintSolver.js.map +1 -1
  13. package/dist/analyzer/dataClasses.js +4 -3
  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/enums.js +1 -1
  18. package/dist/analyzer/enums.js.map +1 -1
  19. package/dist/analyzer/importResolver.d.ts +1 -1
  20. package/dist/analyzer/importResolver.js +7 -3
  21. package/dist/analyzer/importResolver.js.map +1 -1
  22. package/dist/analyzer/importResult.d.ts +1 -0
  23. package/dist/analyzer/parseTreeUtils.d.ts +2 -1
  24. package/dist/analyzer/parseTreeUtils.js +75 -10
  25. package/dist/analyzer/parseTreeUtils.js.map +1 -1
  26. package/dist/analyzer/patternMatching.js +1 -1
  27. package/dist/analyzer/patternMatching.js.map +1 -1
  28. package/dist/analyzer/program.d.ts +8 -4
  29. package/dist/analyzer/program.js +92 -24
  30. package/dist/analyzer/program.js.map +1 -1
  31. package/dist/analyzer/service.d.ts +0 -2
  32. package/dist/analyzer/service.js +8 -8
  33. package/dist/analyzer/service.js.map +1 -1
  34. package/dist/analyzer/sourceFile.d.ts +4 -8
  35. package/dist/analyzer/sourceFile.js +5 -21
  36. package/dist/analyzer/sourceFile.js.map +1 -1
  37. package/dist/analyzer/typeCacheUtils.d.ts +8 -2
  38. package/dist/analyzer/typeCacheUtils.js +4 -4
  39. package/dist/analyzer/typeCacheUtils.js.map +1 -1
  40. package/dist/analyzer/typeEvaluator.js +247 -110
  41. package/dist/analyzer/typeEvaluator.js.map +1 -1
  42. package/dist/analyzer/typeEvaluatorTypes.d.ts +12 -8
  43. package/dist/analyzer/typeGuards.js +2 -16
  44. package/dist/analyzer/typeGuards.js.map +1 -1
  45. package/dist/analyzer/typeUtils.d.ts +5 -4
  46. package/dist/analyzer/typeUtils.js +41 -14
  47. package/dist/analyzer/typeUtils.js.map +1 -1
  48. package/dist/analyzer/typeVarContext.d.ts +1 -5
  49. package/dist/analyzer/typeVarContext.js +17 -22
  50. package/dist/analyzer/typeVarContext.js.map +1 -1
  51. package/dist/analyzer/typedDicts.js +6 -2
  52. package/dist/analyzer/typedDicts.js.map +1 -1
  53. package/dist/analyzer/types.d.ts +4 -1
  54. package/dist/analyzer/types.js +26 -2
  55. package/dist/analyzer/types.js.map +1 -1
  56. package/dist/backgroundAnalysisBase.d.ts +1 -3
  57. package/dist/backgroundAnalysisBase.js +2 -3
  58. package/dist/backgroundAnalysisBase.js.map +1 -1
  59. package/dist/backgroundThreadBase.js +6 -1
  60. package/dist/backgroundThreadBase.js.map +1 -1
  61. package/dist/common/configOptions.d.ts +5 -0
  62. package/dist/common/configOptions.js +19 -1
  63. package/dist/common/configOptions.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/languageServerBase.d.ts +4 -5
  80. package/dist/languageServerBase.js +5 -6
  81. package/dist/languageServerBase.js.map +1 -1
  82. package/dist/languageService/callHierarchyProvider.js +1 -1
  83. package/dist/languageService/callHierarchyProvider.js.map +1 -1
  84. package/dist/languageService/completionProvider.d.ts +0 -1
  85. package/dist/languageService/completionProvider.js +21 -99
  86. package/dist/languageService/completionProvider.js.map +1 -1
  87. package/dist/languageService/completionProviderUtils.d.ts +34 -0
  88. package/dist/languageService/completionProviderUtils.js +102 -0
  89. package/dist/languageService/completionProviderUtils.js.map +1 -0
  90. package/dist/languageService/definitionProvider.d.ts +2 -1
  91. package/dist/languageService/definitionProvider.js +25 -9
  92. package/dist/languageService/definitionProvider.js.map +1 -1
  93. package/dist/languageService/documentSymbolCollector.d.ts +2 -1
  94. package/dist/languageService/documentSymbolCollector.js +27 -3
  95. package/dist/languageService/documentSymbolCollector.js.map +1 -1
  96. package/dist/languageService/documentSymbolProvider.js +1 -1
  97. package/dist/languageService/documentSymbolProvider.js.map +1 -1
  98. package/dist/languageService/hoverProvider.d.ts +3 -1
  99. package/dist/languageService/hoverProvider.js +51 -37
  100. package/dist/languageService/hoverProvider.js.map +1 -1
  101. package/dist/languageService/referencesProvider.d.ts +2 -1
  102. package/dist/languageService/referencesProvider.js +4 -3
  103. package/dist/languageService/referencesProvider.js.map +1 -1
  104. package/dist/languageService/tooltipUtils.d.ts +7 -1
  105. package/dist/languageService/tooltipUtils.js +81 -4
  106. package/dist/languageService/tooltipUtils.js.map +1 -1
  107. package/dist/localization/localize.d.ts +7 -0
  108. package/dist/localization/localize.js +9 -9
  109. package/dist/localization/localize.js.map +1 -1
  110. package/dist/localization/package.nls.en-us.json +2 -2
  111. package/dist/parser/parseNodes.js +0 -1
  112. package/dist/parser/parseNodes.js.map +1 -1
  113. package/dist/parser/stringTokenUtils.js +10 -0
  114. package/dist/parser/stringTokenUtils.js.map +1 -1
  115. package/dist/pyright.js +17 -9
  116. package/dist/pyright.js.map +1 -1
  117. package/dist/server.js +2 -0
  118. package/dist/server.js.map +1 -1
  119. package/dist/tests/fourslash/completions.autoimport.shadow.fourslash.js +1 -1
  120. package/dist/tests/fourslash/completions.autoimport.shadow.fourslash.js.map +1 -1
  121. package/dist/tests/fourslash/completions.builtinDocstrings.fourslash.js +5 -5
  122. package/dist/tests/fourslash/completions.builtinDocstrings.fourslash.js.map +1 -1
  123. package/dist/tests/fourslash/completions.commitChars.fourslash.js +23 -1
  124. package/dist/tests/fourslash/completions.commitChars.fourslash.js.map +1 -1
  125. package/dist/tests/fourslash/completions.fourslash.js +2 -2
  126. package/dist/tests/fourslash/completions.fourslash.js.map +1 -1
  127. package/dist/tests/fourslash/completions.inherited.overload.docFromScrWithStub.fourslash.js +1 -1
  128. package/dist/tests/fourslash/completions.inherited.overload.docFromScrWithStub.fourslash.js.map +1 -1
  129. package/dist/tests/fourslash/completions.inherited.overload.docFromStub.fourslash.js +1 -1
  130. package/dist/tests/fourslash/completions.inherited.overload.docFromStub.fourslash.js.map +1 -1
  131. package/dist/tests/fourslash/completions.libCodeAndStub.fourslash.js +1 -1
  132. package/dist/tests/fourslash/completions.libCodeAndStub.fourslash.js.map +1 -1
  133. package/dist/tests/fourslash/completions.libCodeNoStub.fourslash.js +1 -1
  134. package/dist/tests/fourslash/completions.libCodeNoStub.fourslash.js.map +1 -1
  135. package/dist/tests/fourslash/completions.libStub.fourslash.js +1 -1
  136. package/dist/tests/fourslash/completions.libStub.fourslash.js.map +1 -1
  137. package/dist/tests/fourslash/completions.localCode.fourslash.js +2 -2
  138. package/dist/tests/fourslash/completions.localCode.fourslash.js.map +1 -1
  139. package/dist/tests/fourslash/completions.overloads.fourslash.js +1 -1
  140. package/dist/tests/fourslash/completions.overloads.fourslash.js.map +1 -1
  141. package/dist/tests/fourslash/completions.plainText.fourslash.js +2 -2
  142. package/dist/tests/fourslash/completions.plainText.fourslash.js.map +1 -1
  143. package/dist/tests/fourslash/completions.self.fourslash.js +2 -2
  144. package/dist/tests/fourslash/completions.self.fourslash.js.map +1 -1
  145. package/dist/tests/fourslash/completions.wildcardimports.fourslash.js +1 -1
  146. package/dist/tests/fourslash/completions.wildcardimports.fourslash.js.map +1 -1
  147. package/dist/tests/fourslash/findDefinitions.namespaceImport.fourslash.js +2 -2
  148. package/dist/tests/fourslash/findDefinitions.namespaceImport.fourslash.js.map +1 -1
  149. package/dist/tests/fourslash/hover.builtinDocstrings.fourslash.js +7 -7
  150. package/dist/tests/fourslash/hover.builtinDocstrings.fourslash.js.map +1 -1
  151. package/dist/tests/fourslash/hover.class.docString.fourslash.js +1 -1
  152. package/dist/tests/fourslash/hover.class.docString.fourslash.js.map +1 -1
  153. package/dist/tests/fourslash/hover.classNoInit.fourslash.js +1 -1
  154. package/dist/tests/fourslash/hover.classNoInit.fourslash.js.map +1 -1
  155. package/dist/tests/fourslash/hover.docFromSrc.fourslash.js +7 -7
  156. package/dist/tests/fourslash/hover.docFromSrc.fourslash.js.map +1 -1
  157. package/dist/tests/fourslash/hover.docFromSrc.pkg-vs-module1.fourslash.js +1 -1
  158. package/dist/tests/fourslash/hover.docFromSrc.pkg-vs-module1.fourslash.js.map +1 -1
  159. package/dist/tests/fourslash/hover.docFromSrc.pkg-vs-module2.fourslash.js +1 -1
  160. package/dist/tests/fourslash/hover.docFromSrc.pkg-vs-module2.fourslash.js.map +1 -1
  161. package/dist/tests/fourslash/hover.docFromSrc.relativeImport1.fourslash.js +1 -1
  162. package/dist/tests/fourslash/hover.docFromSrc.relativeImport1.fourslash.js.map +1 -1
  163. package/dist/tests/fourslash/hover.docFromSrc.relativeImport2.fourslash.js +1 -1
  164. package/dist/tests/fourslash/hover.docFromSrc.relativeImport2.fourslash.js.map +1 -1
  165. package/dist/tests/fourslash/hover.docFromSrc.relativeImport3.fourslash.js +1 -1
  166. package/dist/tests/fourslash/hover.docFromSrc.relativeImport3.fourslash.js.map +1 -1
  167. package/dist/tests/fourslash/hover.docFromSrc.stubs-package.fourslash.js +2 -2
  168. package/dist/tests/fourslash/hover.docFromSrc.stubs-package.fourslash.js.map +1 -1
  169. package/dist/tests/fourslash/hover.docFromSrc.typeshed.fourslash.js +1 -1
  170. package/dist/tests/fourslash/hover.docFromSrc.typeshed.fourslash.js.map +1 -1
  171. package/dist/tests/fourslash/hover.docstring.links.fourslash.js +1 -1
  172. package/dist/tests/fourslash/hover.docstring.links.fourslash.js.map +1 -1
  173. package/dist/tests/fourslash/hover.docstring.split.fourslash.js +3 -3
  174. package/dist/tests/fourslash/hover.docstring.split.fourslash.js.map +1 -1
  175. package/dist/tests/fourslash/hover.dunderNew.basic.fourslash.js +1 -1
  176. package/dist/tests/fourslash/hover.dunderNew.basic.fourslash.js.map +1 -1
  177. package/dist/tests/fourslash/hover.dunderNew.inheritance.fourslash.js +1 -1
  178. package/dist/tests/fourslash/hover.dunderNew.inheritance.fourslash.js.map +1 -1
  179. package/dist/tests/fourslash/hover.dunderNew.inheritance2.fourslash.js +1 -1
  180. package/dist/tests/fourslash/hover.dunderNew.inheritance2.fourslash.js.map +1 -1
  181. package/dist/tests/fourslash/hover.dunderNew.overloads.fourslash.js +1 -1
  182. package/dist/tests/fourslash/hover.dunderNew.overloads.fourslash.js.map +1 -1
  183. package/dist/tests/fourslash/hover.dunderNew.withInit.fourslash.js +1 -1
  184. package/dist/tests/fourslash/hover.dunderNew.withInit.fourslash.js.map +1 -1
  185. package/dist/tests/fourslash/hover.formatted.fourslash.d.ts +1 -0
  186. package/dist/tests/fourslash/hover.formatted.fourslash.js +45 -0
  187. package/dist/tests/fourslash/hover.formatted.fourslash.js.map +1 -0
  188. package/dist/tests/fourslash/hover.fourslash.js +1 -1
  189. package/dist/tests/fourslash/hover.fourslash.js.map +1 -1
  190. package/dist/tests/fourslash/hover.inherited.docFromSrc.fourslash.js +6 -6
  191. package/dist/tests/fourslash/hover.inherited.docFromSrc.fourslash.js.map +1 -1
  192. package/dist/tests/fourslash/hover.inherited.docFromSrcWithStub.fourslash.js +5 -5
  193. package/dist/tests/fourslash/hover.inherited.docFromSrcWithStub.fourslash.js.map +1 -1
  194. package/dist/tests/fourslash/hover.inherited.docFromStub.fourslash.js +4 -4
  195. package/dist/tests/fourslash/hover.inherited.docFromStub.fourslash.js.map +1 -1
  196. package/dist/tests/fourslash/hover.inherited.overload.docFromSrcWithStub.fourslash.js +2 -2
  197. package/dist/tests/fourslash/hover.inherited.overload.docFromSrcWithStub.fourslash.js.map +1 -1
  198. package/dist/tests/fourslash/hover.inherited.overload.docFromStub.fourslash.js +2 -2
  199. package/dist/tests/fourslash/hover.inherited.overload.docFromStub.fourslash.js.map +1 -1
  200. package/dist/tests/fourslash/hover.init.fourslash.js +4 -4
  201. package/dist/tests/fourslash/hover.init.fourslash.js.map +1 -1
  202. package/dist/tests/fourslash/hover.libCodeAndStub.fourslash.js +2 -2
  203. package/dist/tests/fourslash/hover.libCodeAndStub.fourslash.js.map +1 -1
  204. package/dist/tests/fourslash/hover.libCodeNoStub.fourslash.js +2 -2
  205. package/dist/tests/fourslash/hover.libCodeNoStub.fourslash.js.map +1 -1
  206. package/dist/tests/fourslash/hover.libStub.fourslash.js +2 -2
  207. package/dist/tests/fourslash/hover.libStub.fourslash.js.map +1 -1
  208. package/dist/tests/fourslash/hover.overloadedFunction.fourslash.js +2 -2
  209. package/dist/tests/fourslash/hover.overloadedFunction.fourslash.js.map +1 -1
  210. package/dist/tests/fourslash/hover.plainText.fourslash.js +1 -1
  211. package/dist/tests/fourslash/hover.plainText.fourslash.js.map +1 -1
  212. package/dist/tests/fourslash/hover.wildcardimports.fourslash.js +1 -1
  213. package/dist/tests/fourslash/hover.wildcardimports.fourslash.js.map +1 -1
  214. package/dist/tests/fourslash/import.multipart.fourslash.js +1 -1
  215. package/dist/tests/fourslash/import.multipart.fourslash.js.map +1 -1
  216. package/dist/tests/fourslash/import.pytyped.typeCheckingBasic.fourslash.js +1 -1
  217. package/dist/tests/fourslash/import.pytyped.typeCheckingBasic.fourslash.js.map +1 -1
  218. package/dist/tests/fourslash/import.pytyped.typeCheckingOff.fourslash.js +1 -1
  219. package/dist/tests/fourslash/import.pytyped.typeCheckingOff.fourslash.js.map +1 -1
  220. package/dist/tests/harness/fourslash/testLanguageService.js +2 -1
  221. package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
  222. package/dist/tests/harness/fourslash/testState.d.ts +0 -10
  223. package/dist/tests/harness/fourslash/testState.js +15 -68
  224. package/dist/tests/harness/fourslash/testState.js.map +1 -1
  225. package/dist/tests/harness/fourslash/testStateUtils.d.ts +12 -0
  226. package/dist/tests/harness/fourslash/testStateUtils.js +98 -0
  227. package/dist/tests/harness/fourslash/testStateUtils.js.map +1 -0
  228. package/dist/tests/pathUtils.test.js +24 -1
  229. package/dist/tests/pathUtils.test.js.map +1 -1
  230. package/dist/tests/signatureHelp.test.d.ts +1 -0
  231. package/dist/tests/signatureHelp.test.js +73 -0
  232. package/dist/tests/signatureHelp.test.js.map +1 -0
  233. package/dist/tests/typeEvaluator1.test.js +16 -0
  234. package/dist/tests/typeEvaluator1.test.js.map +1 -1
  235. package/dist/tests/typeEvaluator2.test.js +8 -0
  236. package/dist/tests/typeEvaluator2.test.js.map +1 -1
  237. package/dist/tests/typeEvaluator3.test.js +5 -1
  238. package/dist/tests/typeEvaluator3.test.js.map +1 -1
  239. package/dist/tests/typeEvaluator4.test.js +15 -1
  240. package/dist/tests/typeEvaluator4.test.js.map +1 -1
  241. package/dist/workspaceMap.d.ts +4 -0
  242. package/dist/workspaceMap.js +67 -37
  243. package/dist/workspaceMap.js.map +1 -1
  244. package/package.json +1 -1
@@ -205,6 +205,10 @@ const maxOverloadUnionExpansionCount = 64;
205
205
  // Maximum number of recursive function return type inference attempts
206
206
  // that can be concurrently pending before we give up.
207
207
  const maxInferFunctionReturnRecursionCount = 12;
208
+ // In certain loops, it's possible to construct arbitrarily-deep containers
209
+ // (tuples, lists, sets, or dicts) which can lead to infinite type analysis.
210
+ // This limits the depth.
211
+ const maxInferredContainerDepth = 8;
208
212
  // Maximum recursion amount when comparing two recursive type aliases.
209
213
  // Increasing this can greatly increase the time required to evaluate
210
214
  // two recursive type aliases that have the same definition. Decreasing
@@ -250,6 +254,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
250
254
  let dictClassType;
251
255
  let typedDictClassType;
252
256
  let printExpressionSpaceCount = 0;
257
+ let incompleteGenerationCount = 0;
253
258
  const returnTypeInferenceContextStack = [];
254
259
  let returnTypeInferenceTypeCache;
255
260
  function runWithCancellationToken(token, callback) {
@@ -329,14 +334,23 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
329
334
  const typeCacheToUse = returnTypeInferenceTypeCache && isNodeInReturnTypeInferenceContext(node)
330
335
  ? returnTypeInferenceTypeCache
331
336
  : typeCache;
332
- 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 });
333
347
  // If the entry is located within a part of the parse tree that is currently being
334
348
  // "speculatively" evaluated, track it so we delete the cached entry when we leave
335
349
  // this speculative context.
336
350
  if (speculativeTypeTracker.isSpeculative(node)) {
337
351
  speculativeTypeTracker.trackEntry(typeCacheToUse, node.id);
338
- if (allowSpeculativeCaching && !typeResult.isIncomplete) {
339
- 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);
340
354
  }
341
355
  }
342
356
  }
@@ -490,7 +504,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
490
504
  var _a, _b;
491
505
  // Is this type already cached?
492
506
  const cacheEntry = readTypeCacheEntry(node);
493
- if (cacheEntry && !cacheEntry.typeResult.isIncomplete) {
507
+ if (cacheEntry &&
508
+ (!cacheEntry.typeResult.isIncomplete || cacheEntry.incompleteGenerationCount === incompleteGenerationCount)) {
494
509
  if (printExpressionTypes) {
495
510
  console.log(`${getPrintExpressionTypesSpaces()}${ParseTreeUtils.printExpression(node)} (${getLineNum(node)}): Cached ${printType(cacheEntry.typeResult.type)} ${cacheEntry.typeResult.typeErrors ? ' Errors' : ''}`);
496
511
  }
@@ -498,12 +513,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
498
513
  }
499
514
  else {
500
515
  // Is it cached in the speculative type cache?
501
- const cachedTypeResult = speculativeTypeTracker.getSpeculativeType(node, inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType);
502
- 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)) {
503
520
  if (printExpressionTypes) {
504
- 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)}`);
505
522
  }
506
- return cachedTypeResult;
523
+ return cacheEntry.typeResult;
507
524
  }
508
525
  }
509
526
  if (printExpressionTypes) {
@@ -610,16 +627,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
610
627
  }
611
628
  case 3 /* Assignment */: {
612
629
  typeResult = getTypeOfExpression(node.rightExpression);
613
- assignTypeToExpression(node.leftExpression, typeResult.type,
614
- /* isTypeIncomplete */ false, node.rightExpression,
630
+ assignTypeToExpression(node.leftExpression, typeResult.type, !!typeResult.isIncomplete, node.rightExpression,
615
631
  /* ignoreEmptyContainers */ true,
616
632
  /* allowAssignmentToFinalVar */ true);
617
633
  break;
618
634
  }
619
635
  case 4 /* AssignmentExpression */: {
620
636
  typeResult = getTypeOfExpression(node.rightExpression);
621
- assignTypeToExpression(node.name, typeResult.type,
622
- /* isTypeIncomplete */ false, node.rightExpression,
637
+ assignTypeToExpression(node.name, typeResult.type, !!typeResult.isIncomplete, node.rightExpression,
623
638
  /* ignoreEmptyContainers */ true);
624
639
  break;
625
640
  }
@@ -1214,6 +1229,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1214
1229
  if (types_1.ClassType.isBuiltIn(concreteSubtype, 'bool')) {
1215
1230
  return types_1.ClassType.cloneWithLiteral(concreteSubtype, /* value */ false);
1216
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
+ }
1217
1242
  }
1218
1243
  // If it's possible for the type to be falsy, include it.
1219
1244
  if (canBeFalsy(subtype)) {
@@ -1385,7 +1410,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1385
1410
  function addOneFunctionToSignature(type) {
1386
1411
  let callResult;
1387
1412
  useSpeculativeMode(callNode, () => {
1388
- 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)),
1389
1414
  /* skipUnknownArgCheck */ true);
1390
1415
  });
1391
1416
  signatures.push({
@@ -2737,7 +2762,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2737
2762
  if (methodType) {
2738
2763
  if ((0, types_1.isOverloadedFunction)(methodType)) {
2739
2764
  if (errorNode) {
2740
- const bestOverload = getBestOverloadForArguments(errorNode, methodType, argList);
2765
+ const bestOverload = getBestOverloadForArguments(errorNode, { type: methodType, isIncomplete: memberTypeResult.isIncomplete }, argList);
2741
2766
  if (bestOverload) {
2742
2767
  return getFunctionEffectiveReturnType(bestOverload);
2743
2768
  }
@@ -2937,11 +2962,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2937
2962
  // Handles the case where a variable or parameter is defined in an outer
2938
2963
  // scope and captured by an inner scope (either a function or a lambda).
2939
2964
  function getCodeFlowTypeForCapturedVariable(node, symbolWithScope, effectiveType) {
2940
- // This function applies only to variables and parameters, not to other
2965
+ // This function applies only to variables, parameters, and imports, not to other
2941
2966
  // types of symbols.
2942
2967
  if (!symbolWithScope.symbol
2943
2968
  .getDeclarations()
2944
- .every((decl) => decl.type === 1 /* Variable */ || decl.type === 2 /* Parameter */)) {
2969
+ .every((decl) => decl.type === 1 /* Variable */ ||
2970
+ decl.type === 2 /* Parameter */ ||
2971
+ decl.type === 8 /* Alias */)) {
2945
2972
  return undefined;
2946
2973
  }
2947
2974
  // If the symbol is a variable captured by an inner function
@@ -2968,6 +2995,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2968
2995
  if (decl.type === 2 /* Parameter */) {
2969
2996
  return true;
2970
2997
  }
2998
+ // Assume alias declarations are also always safe to narrow.
2999
+ if (decl.type === 8 /* Alias */) {
3000
+ return true;
3001
+ }
2971
3002
  const declCodeFlowNode = AnalyzerNodeInfo.getFlowNode(decl.node);
2972
3003
  if (!declCodeFlowNode) {
2973
3004
  return false;
@@ -3345,7 +3376,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3345
3376
  const getTypeOfNoneBase = (subtype) => {
3346
3377
  if (noneType && (0, types_1.isInstantiableClass)(noneType)) {
3347
3378
  if (types_1.TypeBase.isInstance(subtype)) {
3348
- return getTypeOfObjectMember(node.memberName, noneType, memberName, usage, diag);
3379
+ return getTypeOfObjectMember(node.memberName, types_1.ClassType.cloneAsInstance(noneType), memberName, usage, diag);
3349
3380
  }
3350
3381
  else {
3351
3382
  return getTypeOfClassMember(node.memberName, noneType, memberName, usage, diag);
@@ -5001,12 +5032,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5001
5032
  return { type: types_1.UnknownType.create() };
5002
5033
  }
5003
5034
  const type = (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClassType, buildTupleTypesList(entryTypeResults)));
5004
- // In certain loops, it's possible to construct arbitrarily-deep tuples
5005
- // which can lead to infinite type analysis. Prevent this by detecting
5006
- // the condition.
5007
5035
  if (isIncomplete) {
5008
- const maxInferredTupleDepth = 8;
5009
- if ((0, typeUtils_1.getTupleDepth)(type) > maxInferredTupleDepth) {
5036
+ if ((0, typeUtils_1.getContainerDepth)(type) > maxInferredContainerDepth) {
5010
5037
  return { type: types_1.UnknownType.create() };
5011
5038
  }
5012
5039
  }
@@ -5412,17 +5439,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5412
5439
  // (one for each argument) will be undefined. On subsequent calls, this
5413
5440
  // list will grow to include union expansions.
5414
5441
  function validateOverloadsWithExpandedTypes(errorNode, expandedArgTypes, argParamMatches, typeVarContext, skipUnknownArgCheck, inferenceContext) {
5415
- var _a;
5442
+ var _a, _b;
5416
5443
  const returnTypes = [];
5417
5444
  const matchedOverloads = [];
5418
5445
  let isTypeIncomplete = false;
5419
- const overloadsUsedForCall = [];
5446
+ let overloadsUsedForCall = [];
5420
5447
  let isDefinitiveMatchFound = false;
5421
5448
  for (let expandedTypesIndex = 0; expandedTypesIndex < expandedArgTypes.length; expandedTypesIndex++) {
5422
5449
  let matchedOverload;
5423
5450
  const argTypeOverride = expandedArgTypes[expandedTypesIndex];
5424
5451
  const hasArgTypeOverride = argTypeOverride.some((a) => a !== undefined);
5425
- const possibleMatchResults = [];
5452
+ let possibleMatchResults = [];
5426
5453
  isDefinitiveMatchFound = false;
5427
5454
  for (let overloadIndex = 0; overloadIndex < argParamMatches.length; overloadIndex++) {
5428
5455
  const overload = argParamMatches[overloadIndex].overload;
@@ -5459,13 +5486,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5459
5486
  if (!callResult.argumentErrors && callResult.returnType) {
5460
5487
  overloadsUsedForCall.push(overload);
5461
5488
  matchedOverload = overload;
5462
- matchedOverloads.push({
5489
+ const matchedOverloadInfo = {
5463
5490
  overload: matchedOverload,
5464
5491
  matchResults,
5465
5492
  typeVarContext: effectiveTypeVarContext,
5466
- });
5493
+ returnType: callResult.returnType,
5494
+ argResults: (_b = callResult.argResults) !== null && _b !== void 0 ? _b : [],
5495
+ };
5496
+ matchedOverloads.push(matchedOverloadInfo);
5467
5497
  if (callResult.isArgumentAnyOrUnknown) {
5468
- possibleMatchResults.push(callResult.returnType);
5498
+ possibleMatchResults.push(matchedOverloadInfo);
5469
5499
  }
5470
5500
  else {
5471
5501
  returnTypes.push(callResult.returnType);
@@ -5480,27 +5510,35 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5480
5510
  // Unknown, but include the "possible types" to allow for completion
5481
5511
  // suggestions.
5482
5512
  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;
5513
+ possibleMatchResults = filterOverloadMatchesForAnyArgs(possibleMatchResults);
5514
+ // Did the filtering produce a single result? If so, we're done.
5515
+ if (possibleMatchResults.length === 1) {
5516
+ overloadsUsedForCall = [possibleMatchResults[0].overload];
5517
+ returnTypes.push(possibleMatchResults[0].returnType);
5518
+ }
5519
+ else {
5520
+ // Eliminate any return types that are subsumed by other return types.
5521
+ let dedupedMatchResults = [];
5522
+ possibleMatchResults.forEach((result) => {
5523
+ let isSubtypeSubsumed = false;
5524
+ for (let dedupedIndex = 0; dedupedIndex < dedupedMatchResults.length; dedupedIndex++) {
5525
+ if (assignType(dedupedMatchResults[dedupedIndex], result.returnType)) {
5526
+ isSubtypeSubsumed = true;
5527
+ break;
5528
+ }
5529
+ else if (assignType(result.returnType, dedupedMatchResults[dedupedIndex])) {
5530
+ dedupedMatchResults[dedupedIndex] = types_1.NeverType.createNever();
5531
+ break;
5532
+ }
5491
5533
  }
5492
- else if (assignType(subtype, dedupedMatchResults[dedupedIndex])) {
5493
- dedupedMatchResults[dedupedIndex] = types_1.NeverType.createNever();
5494
- break;
5534
+ if (!isSubtypeSubsumed) {
5535
+ dedupedMatchResults.push(result.returnType);
5495
5536
  }
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);
5537
+ });
5538
+ dedupedMatchResults = dedupedMatchResults.filter((t) => !(0, types_1.isNever)(t));
5539
+ const combinedTypes = (0, types_1.combineTypes)(dedupedMatchResults);
5540
+ returnTypes.push(dedupedMatchResults.length > 1 ? types_1.UnknownType.createPossibleType(combinedTypes) : combinedTypes);
5541
+ }
5504
5542
  }
5505
5543
  if (!matchedOverload) {
5506
5544
  return { argumentErrors: true, isTypeIncomplete, overloadsUsedForCall };
@@ -5531,13 +5569,41 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5531
5569
  overloadsUsedForCall,
5532
5570
  };
5533
5571
  }
5534
- function getBestOverloadForArguments(errorNode, type, argList) {
5572
+ // This function determines whether multiple incompatible overloads match
5573
+ // due to an Any or Unknown argument type.
5574
+ function filterOverloadMatchesForAnyArgs(matches) {
5575
+ if (matches.length < 2) {
5576
+ return matches;
5577
+ }
5578
+ // If all of the return types match, select the first one.
5579
+ if ((0, typeUtils_1.areTypesSame)(matches.map((match) => match.returnType), { treatAnySameAsUnknown: true })) {
5580
+ return [matches[0]];
5581
+ }
5582
+ const firstArgResults = matches[0].argResults;
5583
+ if (!firstArgResults) {
5584
+ return matches;
5585
+ }
5586
+ for (let i = 0; i < firstArgResults.length; i++) {
5587
+ // If the arg is Any or Unknown, see if the corresponding
5588
+ // parameter types differ in any way.
5589
+ if ((0, types_1.isAnyOrUnknown)(firstArgResults[i].argType)) {
5590
+ const paramTypes = matches.map((match) => i < match.matchResults.argParams.length
5591
+ ? match.matchResults.argParams[i].paramType
5592
+ : types_1.UnknownType.create());
5593
+ if (!(0, typeUtils_1.areTypesSame)(paramTypes, { treatAnySameAsUnknown: true })) {
5594
+ return matches;
5595
+ }
5596
+ }
5597
+ }
5598
+ return [matches[0]];
5599
+ }
5600
+ function getBestOverloadForArguments(errorNode, typeResult, argList) {
5535
5601
  let overloadIndex = 0;
5536
5602
  let matches = [];
5537
5603
  // Create a list of potential overload matches based on arguments.
5538
- types_1.OverloadedFunctionType.getOverloads(type).forEach((overload) => {
5604
+ types_1.OverloadedFunctionType.getOverloads(typeResult.type).forEach((overload) => {
5539
5605
  useSpeculativeMode(errorNode, () => {
5540
- const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, overload, overloadIndex);
5606
+ const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, { type: overload, isIncomplete: typeResult.isIncomplete }, overloadIndex);
5541
5607
  if (!matchResults.argumentErrors) {
5542
5608
  matches.push(matchResults);
5543
5609
  }
@@ -5568,7 +5634,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5568
5634
  return a.overloadIndex - b.overloadIndex;
5569
5635
  });
5570
5636
  }
5571
- function validateOverloadedFunctionArguments(errorNode, argList, type, typeVarContext, skipUnknownArgCheck, inferenceContext) {
5637
+ function validateOverloadedFunctionArguments(errorNode, argList, typeResult, typeVarContext, skipUnknownArgCheck, inferenceContext) {
5572
5638
  let filteredMatchResults = [];
5573
5639
  let contextFreeArgTypes;
5574
5640
  // Start by evaluating the types of the arguments without any expected
@@ -5578,11 +5644,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5578
5644
  // cache or record any diagnostics at this stage.
5579
5645
  useSpeculativeMode(errorNode, () => {
5580
5646
  let overloadIndex = 0;
5581
- types_1.OverloadedFunctionType.getOverloads(type).forEach((overload) => {
5647
+ types_1.OverloadedFunctionType.getOverloads(typeResult.type).forEach((overload) => {
5582
5648
  // Consider only the functions that have the @overload decorator,
5583
5649
  // not the final function that omits the overload. This is the
5584
5650
  // intended behavior according to PEP 484.
5585
- const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, overload, overloadIndex);
5651
+ const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, { type: overload, isIncomplete: typeResult.isIncomplete }, overloadIndex);
5586
5652
  if (!matchResults.argumentErrors) {
5587
5653
  filteredMatchResults.push(matchResults);
5588
5654
  }
@@ -5596,7 +5662,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5596
5662
  // Skip the error message if we're in speculative mode because it's very
5597
5663
  // expensive, and we're going to suppress the diagnostic anyway.
5598
5664
  if (!isDiagnosticSuppressedForNode(errorNode)) {
5599
- const functionName = type.overloads[0].details.name || '<anonymous function>';
5665
+ const functionName = typeResult.type.overloads[0].details.name || '<anonymous function>';
5600
5666
  const diagAddendum = new diagnostic_1.DiagnosticAddendum();
5601
5667
  const argTypes = argList.map((t) => printType(getTypeOfArgument(t).type));
5602
5668
  diagAddendum.addMessage(localize_1.Localizer.DiagnosticAddendum.argumentTypes().format({ types: argTypes.join(', ') }));
@@ -5624,7 +5690,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5624
5690
  return evaluateUsingLastMatchingOverload(/* skipUnknownArgCheck */ false);
5625
5691
  }
5626
5692
  let expandedArgTypes = [argList.map((arg) => undefined)];
5627
- let isTypeIncomplete = false;
5693
+ let isTypeIncomplete = !!typeResult.isIncomplete;
5628
5694
  while (true) {
5629
5695
  const callResult = validateOverloadsWithExpandedTypes(errorNode, expandedArgTypes, filteredMatchResults, typeVarContext, skipUnknownArgCheck, inferenceContext);
5630
5696
  if (callResult.isTypeIncomplete) {
@@ -6085,7 +6151,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6085
6151
  effectiveTypeVarContext.addSolveForScope(types_1.WildcardTypeVarScopeId);
6086
6152
  }
6087
6153
  }
6088
- const functionResult = validateFunctionArguments(errorNode, argList, expandedSubtype, effectiveTypeVarContext, skipUnknownArgCheck, inferenceContext);
6154
+ const functionResult = validateFunctionArguments(errorNode, argList, { type: expandedSubtype, isIncomplete: callTypeResult.isIncomplete }, effectiveTypeVarContext, skipUnknownArgCheck, inferenceContext);
6089
6155
  if (functionResult.isTypeIncomplete) {
6090
6156
  isTypeIncomplete = true;
6091
6157
  }
@@ -6134,7 +6200,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6134
6200
  }
6135
6201
  return (0, typeUtils_1.convertToInstance)(castToType);
6136
6202
  }
6137
- const functionResult = validateOverloadedFunctionArguments(errorNode, argList, expandedSubtype, typeVarContext, skipUnknownArgCheck, inferenceContext);
6203
+ const functionResult = validateOverloadedFunctionArguments(errorNode, argList, { type: expandedSubtype, isIncomplete: callTypeResult.isIncomplete }, typeVarContext, skipUnknownArgCheck, inferenceContext);
6138
6204
  overloadsUsedForCall.push(...functionResult.overloadsUsedForCall);
6139
6205
  if (functionResult.isTypeIncomplete) {
6140
6206
  isTypeIncomplete = true;
@@ -6411,13 +6477,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6411
6477
  // function. This matching is done based on positions and keywords. Type evaluation and
6412
6478
  // validation is left to the caller.
6413
6479
  // This logic is based on PEP 3102: https://www.python.org/dev/peps/pep-3102/
6414
- function matchFunctionArgumentsToParameters(errorNode, argList, type, overloadIndex) {
6480
+ function matchFunctionArgumentsToParameters(errorNode, argList, typeResult, overloadIndex) {
6415
6481
  var _a, _b, _c, _d, _e;
6416
- const paramDetails = (0, typeUtils_1.getParameterListDetails)(type);
6482
+ const paramDetails = (0, typeUtils_1.getParameterListDetails)(typeResult.type);
6417
6483
  let argIndex = 0;
6418
6484
  let matchedUnpackedListOfUnknownLength = false;
6419
6485
  let reportedArgError = false;
6420
- let isTypeIncomplete = false;
6486
+ let isTypeIncomplete = !!typeResult.isIncomplete;
6421
6487
  let isVariadicTypeVarFullyMatched = false;
6422
6488
  // Expand any unpacked tuples in the arg list.
6423
6489
  argList = expandArgList(argList);
@@ -6457,8 +6523,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6457
6523
  // Does this function define the param spec, or is it an inner
6458
6524
  // function nested within another function that defines the param
6459
6525
  // spec? We need to handle these two cases differently.
6460
- if (varArgListParam.type.scopeId === type.details.typeVarScopeId ||
6461
- varArgListParam.type.scopeId === type.details.constructorTypeVarScopeId) {
6526
+ if (varArgListParam.type.scopeId === typeResult.type.details.typeVarScopeId ||
6527
+ varArgListParam.type.scopeId === typeResult.type.details.constructorTypeVarScopeId) {
6462
6528
  paramSpecArgList = [];
6463
6529
  paramSpecTarget = types_1.TypeVarType.cloneForParamSpecAccess(varArgListParam.type, /* access */ undefined);
6464
6530
  }
@@ -6516,7 +6582,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6516
6582
  const remainingArgCount = positionalArgCount - argIndex;
6517
6583
  const remainingParamCount = positionParamLimitIndex - paramIndex - 1;
6518
6584
  if (paramIndex >= positionParamLimitIndex) {
6519
- if (!type.details.paramSpec) {
6585
+ if (!typeResult.type.details.paramSpec) {
6520
6586
  let tooManyPositionals = false;
6521
6587
  if (foundUnpackedListArg && argList[argIndex].argumentCategory === 1 /* UnpackedList */) {
6522
6588
  // If this is an unpacked iterable, we will conservatively assume that it
@@ -6562,7 +6628,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6562
6628
  // with a ParamSpec and a Concatenate operator. PEP 612 indicates that
6563
6629
  // all positional parameters specified in the Concatenate must be
6564
6630
  // filled explicitly.
6565
- if (type.details.paramSpec && paramIndex < positionParamLimitIndex) {
6631
+ if (typeResult.type.details.paramSpec && paramIndex < positionParamLimitIndex) {
6566
6632
  addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, positionParamLimitIndex === 1
6567
6633
  ? localize_1.Localizer.Diagnostic.argPositionalExpectedOne()
6568
6634
  : localize_1.Localizer.Diagnostic.argPositionalExpectedCount().format({
@@ -6848,10 +6914,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6848
6914
  }
6849
6915
  else if ((0, types_1.isParamSpec)(argType) && argType.paramSpecAccess === 'kwargs') {
6850
6916
  unpackedDictionaryArgType = types_1.AnyType.create();
6851
- if (type.details.paramSpec) {
6917
+ if (typeResult.type.details.paramSpec) {
6852
6918
  validateArgTypeParams.push({
6853
6919
  paramCategory: 2 /* VarArgDictionary */,
6854
- paramType: type.details.paramSpec,
6920
+ paramType: typeResult.type.details.paramSpec,
6855
6921
  requiresTypeVarMatching: false,
6856
6922
  argument: argList[argIndex],
6857
6923
  errorNode: argList[argIndex].valueExpression || errorNode,
@@ -6967,7 +7033,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6967
7033
  else if (argList[argIndex].argumentCategory === 1 /* UnpackedList */) {
6968
7034
  // Handle the case where a *args: P.args is passed as an argument to
6969
7035
  // a function that accepts a ParamSpec.
6970
- if (type.details.paramSpec) {
7036
+ if (typeResult.type.details.paramSpec) {
6971
7037
  const argTypeResult = getTypeOfArgument(argList[argIndex]);
6972
7038
  const argType = argTypeResult.type;
6973
7039
  if (argTypeResult.isIncomplete) {
@@ -6976,7 +7042,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6976
7042
  if ((0, types_1.isParamSpec)(argType) && argType.paramSpecAccess === 'args') {
6977
7043
  validateArgTypeParams.push({
6978
7044
  paramCategory: 1 /* VarArgList */,
6979
- paramType: type.details.paramSpec,
7045
+ paramType: typeResult.type.details.paramSpec,
6980
7046
  requiresTypeVarMatching: false,
6981
7047
  argument: argList[argIndex],
6982
7048
  errorNode: argList[argIndex].valueExpression || errorNode,
@@ -7023,7 +7089,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7023
7089
  // but have not yet received them. If we received a dictionary argument
7024
7090
  // (i.e. an arg starting with a "**"), we will assume that all parameters
7025
7091
  // are matched.
7026
- if (!unpackedDictionaryArgType && !types_1.FunctionType.isDefaultParameterCheckDisabled(type)) {
7092
+ if (!unpackedDictionaryArgType && !types_1.FunctionType.isDefaultParameterCheckDisabled(typeResult.type)) {
7027
7093
  const unassignedParams = [...paramMap.keys()].filter((name) => {
7028
7094
  const entry = paramMap.get(name);
7029
7095
  return !entry || entry.argsReceived < entry.argsNeeded;
@@ -7147,12 +7213,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7147
7213
  relevance--;
7148
7214
  }
7149
7215
  // Special-case the builtin isinstance and issubclass functions.
7150
- if (['isinstance', 'issubclass'].some((name) => name === type.details.builtInName) &&
7216
+ if (['isinstance', 'issubclass'].some((name) => name === typeResult.type.details.builtInName) &&
7151
7217
  validateArgTypeParams.length === 2) {
7152
7218
  validateArgTypeParams[1].expectingType = true;
7153
7219
  }
7154
7220
  return {
7155
- overload: type,
7221
+ overload: typeResult.type,
7156
7222
  overloadIndex,
7157
7223
  argumentErrors: reportedArgError,
7158
7224
  isTypeIncomplete,
@@ -7294,7 +7360,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7294
7360
  // Set useNarrowBoundOnly to true the first time through
7295
7361
  // the loop if we're going to go through the loop multiple
7296
7362
  // times.
7297
- const argResult = validateArgType(argParam, typeVarContext, type, skipUnknownArgCheck,
7363
+ const argResult = validateArgType(argParam, typeVarContext, { type, isIncomplete: matchResults.isTypeIncomplete }, skipUnknownArgCheck,
7298
7364
  /* skipOverloadArg */ i === 0,
7299
7365
  /* useNarrowBoundOnly */ passCount > 1 && i === 0, typeCondition);
7300
7366
  if (argResult.isTypeIncomplete) {
@@ -7317,11 +7383,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7317
7383
  let sawParamSpecArgs = false;
7318
7384
  let sawParamSpecKwargs = false;
7319
7385
  let condition = [];
7386
+ const argResults = [];
7320
7387
  matchResults.argParams.forEach((argParam) => {
7321
7388
  var _a;
7322
- const argResult = validateArgType(argParam, typeVarContext, type, skipUnknownArgCheck,
7389
+ const argResult = validateArgType(argParam, typeVarContext, { type, isIncomplete: matchResults.isTypeIncomplete }, skipUnknownArgCheck,
7323
7390
  /* skipOverloadArg */ false,
7324
7391
  /* useNarrowBoundOnly */ false, typeCondition);
7392
+ argResults.push(argResult);
7325
7393
  if (!argResult.isCompatible) {
7326
7394
  argumentErrors = true;
7327
7395
  }
@@ -7432,6 +7500,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7432
7500
  }
7433
7501
  return {
7434
7502
  argumentErrors,
7503
+ argResults,
7435
7504
  isArgumentAnyOrUnknown,
7436
7505
  returnType: specializedReturnType,
7437
7506
  isTypeIncomplete,
@@ -7457,8 +7526,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7457
7526
  // Tries to assign the call arguments to the function parameter
7458
7527
  // list and reports any mismatches in types or counts. Returns the
7459
7528
  // specialized return type of the call.
7460
- function validateFunctionArguments(errorNode, argList, type, typeVarContext, skipUnknownArgCheck = false, inferenceContext) {
7461
- const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, type, 0);
7529
+ function validateFunctionArguments(errorNode, argList, typeResult, typeVarContext, skipUnknownArgCheck = false, inferenceContext) {
7530
+ const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, typeResult, 0);
7462
7531
  if (matchResults.argumentErrors) {
7463
7532
  // Evaluate types of all args. This will ensure that referenced symbols are
7464
7533
  // not reported as unaccessed.
@@ -7582,13 +7651,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7582
7651
  }
7583
7652
  return !reportedArgError;
7584
7653
  }
7585
- function validateArgType(argParam, typeVarContext, functionType, skipUnknownCheck, skipOverloadArg, useNarrowBoundOnly, conditionFilter) {
7654
+ function validateArgType(argParam, typeVarContext, typeResult, skipUnknownCheck, skipOverloadArg, useNarrowBoundOnly, conditionFilter) {
7586
7655
  var _a;
7587
7656
  let argType;
7588
7657
  let expectedTypeDiag;
7589
- let isTypeIncomplete = false;
7658
+ let isTypeIncomplete = !!(typeResult === null || typeResult === void 0 ? void 0 : typeResult.isIncomplete);
7590
7659
  let isCompatible = true;
7591
- const functionName = functionType === null || functionType === void 0 ? void 0 : functionType.details.name;
7660
+ const functionName = typeResult === null || typeResult === void 0 ? void 0 : typeResult.type.details.name;
7592
7661
  if (argParam.argument.valueExpression) {
7593
7662
  // If the param type is a "bare" TypeVar, don't use it as an expected
7594
7663
  // type. This causes problems for cases where the the call expression
@@ -7598,7 +7667,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7598
7667
  // a wide bound on a TypeVar (if a narrow bound has not yet been established)
7599
7668
  // will unnecessarily constrain the expected type.
7600
7669
  let expectedType;
7601
- if (!(0, types_1.isTypeVar)(argParam.paramType) || argParam.paramType.scopeId !== (functionType === null || functionType === void 0 ? void 0 : functionType.details.typeVarScopeId)) {
7670
+ if (!(0, types_1.isTypeVar)(argParam.paramType) ||
7671
+ argParam.paramType.scopeId !== (typeResult === null || typeResult === void 0 ? void 0 : typeResult.type.details.typeVarScopeId)) {
7602
7672
  expectedType = (0, typeUtils_1.applySolvedTypeVars)(argParam.paramType, typeVarContext, { useNarrowBoundOnly });
7603
7673
  }
7604
7674
  // If the expected type is unknown, don't use an expected type. Instead,
@@ -7616,7 +7686,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7616
7686
  32 /* DisallowParamSpec */ |
7617
7687
  64 /* DisallowTypeVarTuple */
7618
7688
  : 0 /* None */;
7619
- const exprTypeResult = getTypeOfExpression(argParam.argument.valueExpression, flags, (0, typeUtils_1.makeInferenceContext)(expectedType, typeVarContext));
7689
+ const exprTypeResult = getTypeOfExpression(argParam.argument.valueExpression, flags, (0, typeUtils_1.makeInferenceContext)(expectedType, typeVarContext, !!(typeResult === null || typeResult === void 0 ? void 0 : typeResult.isIncomplete)));
7620
7690
  argType = exprTypeResult.type;
7621
7691
  if (exprTypeResult.isIncomplete) {
7622
7692
  isTypeIncomplete = true;
@@ -8870,6 +8940,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8870
8940
  /* typeVarContext */ undefined,
8871
8941
  /* skipUnknownArgCheck */ true, inferenceContext);
8872
8942
  });
8943
+ // If there were errors with the expected type, try
8944
+ // to evaluate without the expected type.
8945
+ if (callResult.argumentErrors && inferenceContext) {
8946
+ useSpeculativeMode(errorNode, () => {
8947
+ callResult = validateCallArguments(errorNode, functionArgs, { type: magicMethodType },
8948
+ /* typeVarContext */ undefined,
8949
+ /* skipUnknownArgCheck */ true);
8950
+ });
8951
+ }
8873
8952
  if (callResult.argumentErrors) {
8874
8953
  magicMethodSupported = false;
8875
8954
  }
@@ -9064,6 +9143,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9064
9143
  /* includeSubclasses */ undefined,
9065
9144
  /* TupleTypeArguments */ undefined, isEmptyContainer))
9066
9145
  : types_1.UnknownType.create();
9146
+ if (isIncomplete) {
9147
+ if ((0, typeUtils_1.getContainerDepth)(type) > maxInferredContainerDepth) {
9148
+ return { type: types_1.UnknownType.create() };
9149
+ }
9150
+ }
9067
9151
  return { type, isIncomplete };
9068
9152
  }
9069
9153
  function getKeyAndValueTypesFromDictionary(node, keyTypes, valueTypes, forceStrictInference, expectedKeyType, expectedValueType, expectedTypedDictEntries, expectedDiagAddendum) {
@@ -9346,6 +9430,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9346
9430
  /* includeSubclasses */ undefined,
9347
9431
  /* TupleTypeArguments */ undefined, isEmptyContainer))
9348
9432
  : types_1.UnknownType.create();
9433
+ if (isIncomplete) {
9434
+ if ((0, typeUtils_1.getContainerDepth)(type) > maxInferredContainerDepth) {
9435
+ return { type: types_1.UnknownType.create() };
9436
+ }
9437
+ }
9349
9438
  return { type, isIncomplete, typeErrors };
9350
9439
  }
9351
9440
  function verifySetEntryOrDictKeyIsHashable(entry, type, isDictKey) {
@@ -9486,7 +9575,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9486
9575
  return { type: returnedType || types_1.UnknownType.create() };
9487
9576
  }
9488
9577
  function getTypeOfLambda(node, inferenceContext) {
9489
- let isIncomplete = false;
9578
+ let isIncomplete = !!(inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.isTypeIncomplete);
9490
9579
  const functionType = types_1.FunctionType.createInstance('', '', '', 131072 /* PartiallyEvaluated */);
9491
9580
  functionType.details.typeVarScopeId = getScopeIdForNode(node);
9492
9581
  // Pre-cache the incomplete function type in case the evaluation of the
@@ -9591,7 +9680,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9591
9680
  isIncomplete = true;
9592
9681
  }
9593
9682
  };
9594
- if (speculativeTypeTracker.isSpeculative(node)) {
9683
+ if (speculativeTypeTracker.isSpeculative(node) || (inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.isTypeIncomplete)) {
9595
9684
  // We need to set allowCacheRetention to false because we don't want to
9596
9685
  // cache the type of the lambda return expression because it depends on
9597
9686
  // the parameter types that we set above, and the speculative type cache
@@ -10987,14 +11076,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
10987
11076
  }
10988
11077
  node.arguments.forEach((arg) => {
10989
11078
  // Ignore unpacked arguments.
10990
- if (arg.argumentCategory !== 0 /* Simple */) {
11079
+ if (arg.argumentCategory === 2 /* UnpackedDictionary */) {
10991
11080
  // Evaluate the expression's type so symbols are marked accessed
10992
11081
  // and errors are reported.
10993
11082
  getTypeOfExpression(arg.valueExpression);
10994
11083
  return;
10995
11084
  }
10996
11085
  if (!arg.name) {
10997
- let argType = getTypeOfExpression(arg.valueExpression, exprFlags).type;
11086
+ let argType;
11087
+ if (arg.argumentCategory === 1 /* UnpackedList */) {
11088
+ getTypeOfExpression(arg.valueExpression);
11089
+ argType = types_1.UnknownType.create();
11090
+ }
11091
+ else {
11092
+ argType = getTypeOfExpression(arg.valueExpression, exprFlags).type;
11093
+ }
10998
11094
  // In some stub files, classes are conditionally defined (e.g. based
10999
11095
  // on platform type). We'll assume that the conditional logic is correct
11000
11096
  // and strip off the "unbound" union.
@@ -11740,7 +11836,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11740
11836
  argument: arg,
11741
11837
  errorNode: (_b = arg.valueExpression) !== null && _b !== void 0 ? _b : errorNode,
11742
11838
  };
11743
- validateArgType(argParam, new typeVarContext_1.TypeVarContext(), newMethodType,
11839
+ validateArgType(argParam, new typeVarContext_1.TypeVarContext(), { type: newMethodType },
11744
11840
  /* skipUnknownCheck */ true,
11745
11841
  /* skipOverloadArg */ true,
11746
11842
  /* useNarrowBoundOnly */ false,
@@ -13167,6 +13263,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
13167
13263
  getTypeOfClass(node.parent);
13168
13264
  return;
13169
13265
  }
13266
+ if (node.parent.nodeType === 23 /* ImportFromAs */) {
13267
+ evaluateTypesForImportFromAs(node.parent);
13268
+ return;
13269
+ }
13270
+ if (node.parent.nodeType === 21 /* ImportAs */) {
13271
+ evaluateTypesForImportAs(node.parent);
13272
+ return;
13273
+ }
13170
13274
  if (node.parent.nodeType === 77 /* TypeAlias */ && node.parent.name === node) {
13171
13275
  getTypeOfTypeAlias(node.parent);
13172
13276
  return;
@@ -14673,9 +14777,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14673
14777
  })) === null || _a === void 0 ? void 0 : _a.type;
14674
14778
  }
14675
14779
  if (resolvedDecl.type === 1 /* Variable */ && resolvedDecl.inferredTypeSource) {
14780
+ const isTypeAlias = (0, declarationUtils_1.isExplicitTypeAliasDeclaration)(resolvedDecl) || isPossibleTypeAliasOrTypedDict(resolvedDecl);
14676
14781
  // If this is a type alias, evaluate types for the entire assignment
14677
14782
  // statement rather than just the RHS of the assignment.
14678
- const typeSource = resolvedDecl.typeAliasName && resolvedDecl.inferredTypeSource.parent
14783
+ const typeSource = isTypeAlias && resolvedDecl.inferredTypeSource.parent
14679
14784
  ? resolvedDecl.inferredTypeSource.parent
14680
14785
  : resolvedDecl.inferredTypeSource;
14681
14786
  let inferredType = (_b = evaluateTypeForSubnode(resolvedDecl.node, () => {
@@ -14693,7 +14798,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14693
14798
  inferredType = enumMemberType;
14694
14799
  }
14695
14800
  }
14696
- if (inferredType && resolvedDecl.typeAliasName) {
14801
+ if (inferredType && isTypeAlias && resolvedDecl.typeAliasName) {
14697
14802
  // If this was a speculative type alias, it becomes a real type alias only
14698
14803
  // in the event that its inferred type is instantiable or explicitly Any
14699
14804
  // (but not an ellipsis).
@@ -14856,9 +14961,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14856
14961
  }
14857
14962
  });
14858
14963
  }
14964
+ else {
14965
+ // Handle the case where there are multiple imports — one of them in
14966
+ // a try block and one or more in except blocks. In this case, we'll
14967
+ // use the one in the try block rather than the excepts.
14968
+ if (decls.length > 1 && decls.every((decl) => decl.type === 8 /* Alias */)) {
14969
+ const nonExceptDecls = decls.filter((decl) => decl.type === 8 /* Alias */ && !decl.isInExceptSuite);
14970
+ if (nonExceptDecls.length === 1) {
14971
+ declIndexToConsider = decls.findIndex((decl) => decl === nonExceptDecls[0]);
14972
+ }
14973
+ }
14974
+ }
14859
14975
  let sawExplicitTypeAlias = false;
14860
14976
  decls.forEach((decl, index) => {
14861
- var _a, _b;
14977
+ var _a, _b, _c;
14862
14978
  let considerDecl = declIndexToConsider === undefined || index === declIndexToConsider;
14863
14979
  // If we have already seen an explicit type alias, do not consider
14864
14980
  // additional decls. This can happen if multiple TypeAlias declarations
@@ -14880,6 +14996,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14880
14996
  }
14881
14997
  }
14882
14998
  if (considerDecl) {
14999
+ const resolvedDecl = (_a = resolveAliasDeclaration(decl,
15000
+ /* resolveLocalNames */ true,
15001
+ /* allowExternallyHiddenAccess */ AnalyzerNodeInfo.getFileInfo(decl.node).isStubFile)) !== null && _a !== void 0 ? _a : decl;
14883
15002
  const isExplicitTypeAlias = (0, declarationUtils_1.isExplicitTypeAliasDeclaration)(decl);
14884
15003
  const isTypeAlias = isExplicitTypeAlias || isPossibleTypeAliasOrTypedDict(decl);
14885
15004
  if (isExplicitTypeAlias) {
@@ -14888,15 +15007,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14888
15007
  // If this is a type alias, evaluate it outside of the recursive symbol
14889
15008
  // resolution check so we can evaluate the full assignment statement.
14890
15009
  if (isTypeAlias &&
14891
- decl.type === 1 /* Variable */ &&
14892
- ((_b = (_a = decl.inferredTypeSource) === null || _a === void 0 ? void 0 : _a.parent) === null || _b === void 0 ? void 0 : _b.nodeType) === 3 /* Assignment */) {
14893
- evaluateTypesForAssignmentStatement(decl.inferredTypeSource.parent);
14894
- if (decl.typeAliasAnnotation) {
15010
+ resolvedDecl.type === 1 /* Variable */ &&
15011
+ ((_c = (_b = resolvedDecl.inferredTypeSource) === null || _b === void 0 ? void 0 : _b.parent) === null || _c === void 0 ? void 0 : _c.nodeType) === 3 /* Assignment */) {
15012
+ evaluateTypesForAssignmentStatement(resolvedDecl.inferredTypeSource.parent);
15013
+ if (resolvedDecl.typeAliasAnnotation) {
14895
15014
  // Mark "TypeAlias" declaration as accessed.
14896
- getTypeOfAnnotation(decl.typeAliasAnnotation, {
15015
+ getTypeOfAnnotation(resolvedDecl.typeAliasAnnotation, {
14897
15016
  isVariableAnnotation: true,
14898
- allowFinal: ParseTreeUtils.isFinalAllowedForAssignmentTarget(decl.node),
14899
- allowClassVar: ParseTreeUtils.isClassVarAllowedForAssignmentTarget(decl.node),
15017
+ allowFinal: ParseTreeUtils.isFinalAllowedForAssignmentTarget(resolvedDecl.node),
15018
+ allowClassVar: ParseTreeUtils.isClassVarAllowedForAssignmentTarget(resolvedDecl.node),
14900
15019
  });
14901
15020
  }
14902
15021
  }
@@ -14907,14 +15026,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14907
15026
  isIncomplete = true;
14908
15027
  }
14909
15028
  if (type) {
14910
- if (decl.type === 1 /* Variable */) {
14911
- includesVariableDecl = true;
14912
- let isConstant = decl.type === 1 /* Variable */ && !!decl.isConstant;
15029
+ if (resolvedDecl.type === 1 /* Variable */) {
15030
+ // Exempt typing.pyi, which uses variables to define some
15031
+ // special forms like Any.
15032
+ const fileInfo = AnalyzerNodeInfo.getFileInfo(resolvedDecl.node);
15033
+ if (!fileInfo.isTypingStubFile) {
15034
+ includesVariableDecl = true;
15035
+ }
15036
+ let isConstant = resolvedDecl.type === 1 /* Variable */ && !!resolvedDecl.isConstant;
14913
15037
  // Treat enum values declared within an enum class as though they are const even
14914
15038
  // though they may not be named as such.
14915
15039
  if ((0, types_1.isClassInstance)(type) &&
14916
15040
  types_1.ClassType.isEnumClass(type) &&
14917
- (0, enums_1.isDeclInEnumClass)(evaluatorInterface, decl)) {
15041
+ (0, enums_1.isDeclInEnumClass)(evaluatorInterface, resolvedDecl)) {
14918
15042
  isConstant = true;
14919
15043
  }
14920
15044
  // If the symbol is constant, we can retain the literal
@@ -14939,12 +15063,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14939
15063
  }
14940
15064
  }
14941
15065
  else {
14942
- // If this resolves to a class decl, we can use a partially-evaluated
14943
- // version of the class type.
14944
- const resolvedDecl = resolveAliasDeclaration(decl,
14945
- /* resolveLocalNames */ true,
14946
- /* allowExternallyHiddenAccess */ AnalyzerNodeInfo.getFileInfo(decl.node).isStubFile);
14947
- if ((resolvedDecl === null || resolvedDecl === void 0 ? void 0 : resolvedDecl.type) === 6 /* Class */) {
15066
+ if (resolvedDecl.type === 6 /* Class */) {
14948
15067
  const classTypeInfo = getTypeOfClass(resolvedDecl.node);
14949
15068
  if (classTypeInfo === null || classTypeInfo === void 0 ? void 0 : classTypeInfo.decoratedType) {
14950
15069
  typesToCombine.push(classTypeInfo.decoratedType);
@@ -16211,7 +16330,23 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16211
16330
  if ((0, types_1.isOverloadedFunction)(destType)) {
16212
16331
  const overloadDiag = diag === null || diag === void 0 ? void 0 : diag.createAddendum();
16213
16332
  // All overloads in the dest must be assignable.
16214
- const isAssignable = types_1.OverloadedFunctionType.getOverloads(destType).every((destOverload) => {
16333
+ const destOverloads = types_1.OverloadedFunctionType.getOverloads(destType);
16334
+ // If the source is also an overload with the same number of overloads,
16335
+ // there's a good chance that there's a one-to-one mapping. Try this
16336
+ // first before using an n^2 algorithm.
16337
+ if ((0, types_1.isOverloadedFunction)(srcType)) {
16338
+ const srcOverloads = types_1.OverloadedFunctionType.getOverloads(srcType);
16339
+ if (destOverloads.length === srcOverloads.length) {
16340
+ if (destOverloads.every((destOverload, index) => {
16341
+ const srcOverload = srcOverloads[index];
16342
+ return assignType(destOverload, srcOverload,
16343
+ /* diag */ undefined, destTypeVarContext !== null && destTypeVarContext !== void 0 ? destTypeVarContext : new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(destOverload)), srcTypeVarContext, flags, recursionCount);
16344
+ })) {
16345
+ return true;
16346
+ }
16347
+ }
16348
+ }
16349
+ const isAssignable = destOverloads.every((destOverload) => {
16215
16350
  if (destTypeVarContext) {
16216
16351
  destTypeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeId)(destOverload));
16217
16352
  }
@@ -16228,10 +16363,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16228
16363
  }
16229
16364
  return true;
16230
16365
  }
16231
- if ((0, types_1.isClassInstance)(destType) && types_1.ClassType.isBuiltIn(destType, 'object')) {
16232
- if ((flags & 1 /* EnforceInvariance */) === 0) {
16233
- // All types (including None, Module, OverloadedFunction) derive from object.
16234
- return true;
16366
+ if ((0, types_1.isClass)(destType) && types_1.ClassType.isBuiltIn(destType, 'object')) {
16367
+ if (((0, types_1.isInstantiableClass)(destType) && types_1.TypeBase.isInstantiable(srcType)) || (0, types_1.isClassInstance)(destType)) {
16368
+ if ((flags & 1 /* EnforceInvariance */) === 0) {
16369
+ // All types (including None, Module, OverloadedFunction) derive from object.
16370
+ return true;
16371
+ }
16235
16372
  }
16236
16373
  }
16237
16374
  // Are we trying to assign None to a protocol?