@zzzen/pyright-internal 1.2.0-dev.20221009 → 1.2.0-dev.20221127

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 (338) hide show
  1. package/dist/analyzer/backgroundAnalysisProgram.d.ts +10 -10
  2. package/dist/analyzer/backgroundAnalysisProgram.js +21 -54
  3. package/dist/analyzer/backgroundAnalysisProgram.js.map +1 -1
  4. package/dist/analyzer/binder.js +43 -32
  5. package/dist/analyzer/binder.js.map +1 -1
  6. package/dist/analyzer/cacheManager.d.ts +7 -7
  7. package/dist/analyzer/cacheManager.js +17 -15
  8. package/dist/analyzer/cacheManager.js.map +1 -1
  9. package/dist/analyzer/checker.d.ts +16 -3
  10. package/dist/analyzer/checker.js +295 -143
  11. package/dist/analyzer/checker.js.map +1 -1
  12. package/dist/analyzer/codeFlowEngine.d.ts +2 -2
  13. package/dist/analyzer/codeFlowEngine.js +85 -88
  14. package/dist/analyzer/codeFlowEngine.js.map +1 -1
  15. package/dist/analyzer/codeFlowTypes.d.ts +1 -0
  16. package/dist/analyzer/codeFlowTypes.js +3 -1
  17. package/dist/analyzer/codeFlowTypes.js.map +1 -1
  18. package/dist/analyzer/constraintSolver.js +1 -1
  19. package/dist/analyzer/constraintSolver.js.map +1 -1
  20. package/dist/analyzer/dataClasses.d.ts +3 -3
  21. package/dist/analyzer/dataClasses.js +77 -57
  22. package/dist/analyzer/dataClasses.js.map +1 -1
  23. package/dist/analyzer/declaration.js.map +1 -1
  24. package/dist/analyzer/declarationUtils.d.ts +1 -1
  25. package/dist/analyzer/declarationUtils.js +6 -4
  26. package/dist/analyzer/declarationUtils.js.map +1 -1
  27. package/dist/analyzer/docStringConversion.js +4 -3
  28. package/dist/analyzer/docStringConversion.js.map +1 -1
  29. package/dist/analyzer/importResolver.d.ts +4 -0
  30. package/dist/analyzer/importResolver.js +53 -10
  31. package/dist/analyzer/importResolver.js.map +1 -1
  32. package/dist/analyzer/importResult.d.ts +1 -0
  33. package/dist/analyzer/namedTuples.js +1 -1
  34. package/dist/analyzer/namedTuples.js.map +1 -1
  35. package/dist/analyzer/packageTypeVerifier.d.ts +2 -1
  36. package/dist/analyzer/packageTypeVerifier.js +16 -10
  37. package/dist/analyzer/packageTypeVerifier.js.map +1 -1
  38. package/dist/analyzer/parseTreeUtils.d.ts +2 -1
  39. package/dist/analyzer/parseTreeUtils.js +38 -3
  40. package/dist/analyzer/parseTreeUtils.js.map +1 -1
  41. package/dist/analyzer/parseTreeWalker.d.ts +86 -79
  42. package/dist/analyzer/parseTreeWalker.js +384 -201
  43. package/dist/analyzer/parseTreeWalker.js.map +1 -1
  44. package/dist/analyzer/program.d.ts +9 -9
  45. package/dist/analyzer/program.js +90 -86
  46. package/dist/analyzer/program.js.map +1 -1
  47. package/dist/analyzer/properties.js +10 -3
  48. package/dist/analyzer/properties.js.map +1 -1
  49. package/dist/analyzer/protocols.js +1 -1
  50. package/dist/analyzer/protocols.js.map +1 -1
  51. package/dist/analyzer/regions.d.ts +11 -0
  52. package/dist/analyzer/regions.js +57 -0
  53. package/dist/analyzer/regions.js.map +1 -0
  54. package/dist/analyzer/service.d.ts +11 -6
  55. package/dist/analyzer/service.js +69 -30
  56. package/dist/analyzer/service.js.map +1 -1
  57. package/dist/analyzer/sourceFile.d.ts +5 -2
  58. package/dist/analyzer/sourceFile.js +21 -8
  59. package/dist/analyzer/sourceFile.js.map +1 -1
  60. package/dist/analyzer/sourceFileInfoUtils.d.ts +1 -1
  61. package/dist/analyzer/sourceFileInfoUtils.js +1 -1
  62. package/dist/analyzer/sourceFileInfoUtils.js.map +1 -1
  63. package/dist/analyzer/sourceMapper.d.ts +11 -3
  64. package/dist/analyzer/sourceMapper.js +61 -14
  65. package/dist/analyzer/sourceMapper.js.map +1 -1
  66. package/dist/analyzer/sourceMapperUtils.d.ts +10 -0
  67. package/dist/analyzer/sourceMapperUtils.js +57 -0
  68. package/dist/analyzer/sourceMapperUtils.js.map +1 -0
  69. package/dist/analyzer/staticExpressions.js +19 -9
  70. package/dist/analyzer/staticExpressions.js.map +1 -1
  71. package/dist/analyzer/symbolUtils.d.ts +1 -0
  72. package/dist/analyzer/symbolUtils.js +5 -1
  73. package/dist/analyzer/symbolUtils.js.map +1 -1
  74. package/dist/analyzer/typeEvaluator.js +654 -258
  75. package/dist/analyzer/typeEvaluator.js.map +1 -1
  76. package/dist/analyzer/typeEvaluatorTypes.d.ts +15 -4
  77. package/dist/analyzer/typeGuards.js +9 -0
  78. package/dist/analyzer/typeGuards.js.map +1 -1
  79. package/dist/analyzer/typePrinter.d.ts +3 -1
  80. package/dist/analyzer/typePrinter.js +135 -26
  81. package/dist/analyzer/typePrinter.js.map +1 -1
  82. package/dist/analyzer/typeStubWriter.js +5 -1
  83. package/dist/analyzer/typeStubWriter.js.map +1 -1
  84. package/dist/analyzer/typeUtils.d.ts +4 -2
  85. package/dist/analyzer/typeUtils.js +112 -25
  86. package/dist/analyzer/typeUtils.js.map +1 -1
  87. package/dist/analyzer/typedDicts.js +8 -6
  88. package/dist/analyzer/typedDicts.js.map +1 -1
  89. package/dist/analyzer/types.d.ts +8 -5
  90. package/dist/analyzer/types.js +49 -20
  91. package/dist/analyzer/types.js.map +1 -1
  92. package/dist/backgroundAnalysisBase.d.ts +6 -4
  93. package/dist/backgroundAnalysisBase.js +30 -8
  94. package/dist/backgroundAnalysisBase.js.map +1 -1
  95. package/dist/backgroundThreadBase.d.ts +2 -1
  96. package/dist/backgroundThreadBase.js +4 -0
  97. package/dist/backgroundThreadBase.js.map +1 -1
  98. package/dist/commands/createTypeStub.js +3 -1
  99. package/dist/commands/createTypeStub.js.map +1 -1
  100. package/dist/common/configOptions.d.ts +1 -0
  101. package/dist/common/configOptions.js +4 -0
  102. package/dist/common/configOptions.js.map +1 -1
  103. package/dist/common/core.d.ts +2 -0
  104. package/dist/common/core.js +24 -3
  105. package/dist/common/core.js.map +1 -1
  106. package/dist/common/diagnostic.d.ts +8 -0
  107. package/dist/common/diagnostic.js +5 -1
  108. package/dist/common/diagnostic.js.map +1 -1
  109. package/dist/common/diagnosticRules.d.ts +2 -1
  110. package/dist/common/diagnosticRules.js +1 -0
  111. package/dist/common/diagnosticRules.js.map +1 -1
  112. package/dist/common/fileSystem.d.ts +1 -0
  113. package/dist/common/fileSystem.js.map +1 -1
  114. package/dist/common/pathUtils.d.ts +1 -0
  115. package/dist/common/pathUtils.js +13 -3
  116. package/dist/common/pathUtils.js.map +1 -1
  117. package/dist/common/pythonVersion.d.ts +1 -1
  118. package/dist/common/pythonVersion.js +1 -1
  119. package/dist/common/realFileSystem.js +12 -3
  120. package/dist/common/realFileSystem.js.map +1 -1
  121. package/dist/common/workspaceEditUtils.d.ts +6 -1
  122. package/dist/common/workspaceEditUtils.js +72 -1
  123. package/dist/common/workspaceEditUtils.js.map +1 -1
  124. package/dist/languageServerBase.d.ts +9 -5
  125. package/dist/languageServerBase.js +35 -21
  126. package/dist/languageServerBase.js.map +1 -1
  127. package/dist/languageService/analyzerServiceExecutor.d.ts +6 -2
  128. package/dist/languageService/analyzerServiceExecutor.js +7 -4
  129. package/dist/languageService/analyzerServiceExecutor.js.map +1 -1
  130. package/dist/languageService/autoImporter.js +2 -1
  131. package/dist/languageService/autoImporter.js.map +1 -1
  132. package/dist/languageService/codeActionProvider.js +30 -0
  133. package/dist/languageService/codeActionProvider.js.map +1 -1
  134. package/dist/languageService/completionProvider.d.ts +1 -0
  135. package/dist/languageService/completionProvider.js +66 -28
  136. package/dist/languageService/completionProvider.js.map +1 -1
  137. package/dist/languageService/definitionProvider.d.ts +2 -0
  138. package/dist/languageService/definitionProvider.js +3 -0
  139. package/dist/languageService/definitionProvider.js.map +1 -1
  140. package/dist/languageService/documentSymbolCollector.js +7 -3
  141. package/dist/languageService/documentSymbolCollector.js.map +1 -1
  142. package/dist/languageService/documentSymbolProvider.js +1 -1
  143. package/dist/languageService/documentSymbolProvider.js.map +1 -1
  144. package/dist/languageService/hoverProvider.d.ts +1 -1
  145. package/dist/languageService/hoverProvider.js +73 -38
  146. package/dist/languageService/hoverProvider.js.map +1 -1
  147. package/dist/languageService/referencesProvider.js +2 -1
  148. package/dist/languageService/referencesProvider.js.map +1 -1
  149. package/dist/languageService/signatureHelpProvider.js +1 -2
  150. package/dist/languageService/signatureHelpProvider.js.map +1 -1
  151. package/dist/languageService/tooltipUtils.js +30 -19
  152. package/dist/languageService/tooltipUtils.js.map +1 -1
  153. package/dist/localization/localize.d.ts +33 -4
  154. package/dist/localization/localize.js +22 -5
  155. package/dist/localization/localize.js.map +1 -1
  156. package/dist/localization/package.nls.en-us.json +20 -3
  157. package/dist/parser/parseNodes.d.ts +2 -1
  158. package/dist/parser/parseNodes.js +6 -1
  159. package/dist/parser/parseNodes.js.map +1 -1
  160. package/dist/parser/parser.js +19 -13
  161. package/dist/parser/parser.js.map +1 -1
  162. package/dist/parser/tokenizer.js +2 -1
  163. package/dist/parser/tokenizer.js.map +1 -1
  164. package/dist/pyright.js +4 -4
  165. package/dist/pyright.js.map +1 -1
  166. package/dist/pyrightFileSystem.d.ts +1 -0
  167. package/dist/pyrightFileSystem.js +3 -0
  168. package/dist/pyrightFileSystem.js.map +1 -1
  169. package/dist/readonlyAugmentedFileSystem.d.ts +1 -0
  170. package/dist/readonlyAugmentedFileSystem.js +3 -0
  171. package/dist/readonlyAugmentedFileSystem.js.map +1 -1
  172. package/dist/server.d.ts +1 -1
  173. package/dist/server.js +1 -1
  174. package/dist/server.js.map +1 -1
  175. package/dist/tests/checker.test.js +25 -2
  176. package/dist/tests/checker.test.js.map +1 -1
  177. package/dist/tests/config.test.js +11 -0
  178. package/dist/tests/config.test.js.map +1 -1
  179. package/dist/tests/diagnostics.test.d.ts +1 -0
  180. package/dist/tests/diagnostics.test.js +37 -0
  181. package/dist/tests/diagnostics.test.js.map +1 -0
  182. package/dist/tests/docStringConversion.test.js +25 -0
  183. package/dist/tests/docStringConversion.test.js.map +1 -1
  184. package/dist/tests/fourslash/completions.autoimport.shadow.fourslash.js +1 -1
  185. package/dist/tests/fourslash/completions.autoimport.shadow.fourslash.js.map +1 -1
  186. package/dist/tests/fourslash/completions.builtinDocstrings.fourslash.js +5 -5
  187. package/dist/tests/fourslash/completions.builtinDocstrings.fourslash.js.map +1 -1
  188. package/dist/tests/fourslash/completions.classVariable.fourslash.js +28 -6
  189. package/dist/tests/fourslash/completions.classVariable.fourslash.js.map +1 -1
  190. package/dist/tests/fourslash/{signature.paramspec.fourslash.d.ts → completions.dunderNew.Inheritance.fourslash.d.ts} +0 -0
  191. package/dist/tests/fourslash/completions.dunderNew.Inheritance.fourslash.js +29 -0
  192. package/dist/tests/fourslash/completions.dunderNew.Inheritance.fourslash.js.map +1 -0
  193. package/dist/tests/fourslash/completions.dunderNew.fourslash.d.ts +1 -0
  194. package/dist/tests/fourslash/completions.dunderNew.fourslash.js +20 -0
  195. package/dist/tests/fourslash/completions.dunderNew.fourslash.js.map +1 -0
  196. package/dist/tests/fourslash/completions.fourslash.js +2 -2
  197. package/dist/tests/fourslash/completions.fourslash.js.map +1 -1
  198. package/dist/tests/fourslash/completions.libCodeAndStub.fourslash.js +1 -1
  199. package/dist/tests/fourslash/completions.libCodeAndStub.fourslash.js.map +1 -1
  200. package/dist/tests/fourslash/completions.libCodeNoStub.fourslash.js +1 -1
  201. package/dist/tests/fourslash/completions.libCodeNoStub.fourslash.js.map +1 -1
  202. package/dist/tests/fourslash/completions.libStub.fourslash.js +1 -1
  203. package/dist/tests/fourslash/completions.libStub.fourslash.js.map +1 -1
  204. package/dist/tests/fourslash/completions.localCode.fourslash.js +2 -2
  205. package/dist/tests/fourslash/completions.localCode.fourslash.js.map +1 -1
  206. package/dist/tests/fourslash/completions.plainText.fourslash.js +2 -2
  207. package/dist/tests/fourslash/completions.plainText.fourslash.js.map +1 -1
  208. package/dist/tests/fourslash/completions.self.fourslash.js +2 -2
  209. package/dist/tests/fourslash/completions.self.fourslash.js.map +1 -1
  210. package/dist/tests/fourslash/completions.wildcardimports.fourslash.js +1 -1
  211. package/dist/tests/fourslash/completions.wildcardimports.fourslash.js.map +1 -1
  212. package/dist/tests/fourslash/findDefinitions.builtinClass.fourslash.js +8 -6
  213. package/dist/tests/fourslash/findDefinitions.builtinClass.fourslash.js.map +1 -1
  214. package/dist/tests/fourslash/findDefinitions.namespaceImport.fourslash.js +2 -2
  215. package/dist/tests/fourslash/findDefinitions.namespaceImport.fourslash.js.map +1 -1
  216. package/dist/tests/fourslash/findDefinitions.namespaceImportWithInit.fourslash.d.ts +1 -0
  217. package/dist/tests/fourslash/findDefinitions.namespaceImportWithInit.fourslash.js +32 -0
  218. package/dist/tests/fourslash/findDefinitions.namespaceImportWithInit.fourslash.js.map +1 -0
  219. package/dist/tests/fourslash/fourslash.d.ts +2 -1
  220. package/dist/tests/fourslash/hover.builtinDocstrings.fourslash.js +2 -2
  221. package/dist/tests/fourslash/hover.builtinDocstrings.fourslash.js.map +1 -1
  222. package/dist/tests/fourslash/hover.docFromSrc.fourslash.js +4 -4
  223. package/dist/tests/fourslash/hover.docFromSrc.fourslash.js.map +1 -1
  224. package/dist/tests/fourslash/hover.docFromSrc.pkg-vs-module1.fourslash.js +1 -1
  225. package/dist/tests/fourslash/hover.docFromSrc.pkg-vs-module1.fourslash.js.map +1 -1
  226. package/dist/tests/fourslash/hover.docFromSrc.pkg-vs-module2.fourslash.js +1 -1
  227. package/dist/tests/fourslash/hover.docFromSrc.pkg-vs-module2.fourslash.js.map +1 -1
  228. package/dist/tests/fourslash/hover.docFromSrc.relativeImport1.fourslash.js +1 -1
  229. package/dist/tests/fourslash/hover.docFromSrc.relativeImport1.fourslash.js.map +1 -1
  230. package/dist/tests/fourslash/hover.docFromSrc.relativeImport2.fourslash.js +1 -1
  231. package/dist/tests/fourslash/hover.docFromSrc.relativeImport2.fourslash.js.map +1 -1
  232. package/dist/tests/fourslash/hover.docFromSrc.relativeImport3.fourslash.js +1 -1
  233. package/dist/tests/fourslash/hover.docFromSrc.relativeImport3.fourslash.js.map +1 -1
  234. package/dist/tests/fourslash/hover.docFromSrc.stubs-package.fourslash.js +2 -2
  235. package/dist/tests/fourslash/hover.docFromSrc.stubs-package.fourslash.js.map +1 -1
  236. package/dist/tests/fourslash/hover.docFromSrc.typeshed.fourslash.js +1 -1
  237. package/dist/tests/fourslash/hover.docFromSrc.typeshed.fourslash.js.map +1 -1
  238. package/dist/tests/fourslash/hover.docstring.alias.fourslash.d.ts +1 -0
  239. package/dist/tests/fourslash/hover.docstring.alias.fourslash.js +24 -0
  240. package/dist/tests/fourslash/hover.docstring.alias.fourslash.js.map +1 -0
  241. package/dist/tests/fourslash/hover.docstring.links.fourslash.js +1 -1
  242. package/dist/tests/fourslash/hover.docstring.links.fourslash.js.map +1 -1
  243. package/dist/tests/fourslash/hover.docstring.split.fourslash.js +3 -3
  244. package/dist/tests/fourslash/hover.docstring.split.fourslash.js.map +1 -1
  245. package/dist/tests/fourslash/hover.dunderNew.basic.fourslash.d.ts +1 -0
  246. package/dist/tests/fourslash/hover.dunderNew.basic.fourslash.js +13 -0
  247. package/dist/tests/fourslash/hover.dunderNew.basic.fourslash.js.map +1 -0
  248. package/dist/tests/fourslash/hover.dunderNew.inheritance.fourslash.d.ts +1 -0
  249. package/dist/tests/fourslash/hover.dunderNew.inheritance.fourslash.js +15 -0
  250. package/dist/tests/fourslash/hover.dunderNew.inheritance.fourslash.js.map +1 -0
  251. package/dist/tests/fourslash/hover.dunderNew.inheritance2.fourslash.d.ts +1 -0
  252. package/dist/tests/fourslash/hover.dunderNew.inheritance2.fourslash.js +21 -0
  253. package/dist/tests/fourslash/hover.dunderNew.inheritance2.fourslash.js.map +1 -0
  254. package/dist/tests/fourslash/hover.dunderNew.overloads.fourslash.d.ts +1 -0
  255. package/dist/tests/fourslash/hover.dunderNew.overloads.fourslash.js +17 -0
  256. package/dist/tests/fourslash/hover.dunderNew.overloads.fourslash.js.map +1 -0
  257. package/dist/tests/fourslash/hover.dunderNew.withInit.fourslash.d.ts +1 -0
  258. package/dist/tests/fourslash/hover.dunderNew.withInit.fourslash.js +15 -0
  259. package/dist/tests/fourslash/hover.dunderNew.withInit.fourslash.js.map +1 -0
  260. package/dist/tests/fourslash/hover.fourslash.js +1 -1
  261. package/dist/tests/fourslash/hover.fourslash.js.map +1 -1
  262. package/dist/tests/fourslash/hover.inherited.docFromSrc.fourslash.js +3 -3
  263. package/dist/tests/fourslash/hover.inherited.docFromSrc.fourslash.js.map +1 -1
  264. package/dist/tests/fourslash/hover.inherited.docFromSrcWithStub.fourslash.js +2 -2
  265. package/dist/tests/fourslash/hover.inherited.docFromSrcWithStub.fourslash.js.map +1 -1
  266. package/dist/tests/fourslash/hover.inherited.docFromStub.fourslash.js +2 -2
  267. package/dist/tests/fourslash/hover.inherited.docFromStub.fourslash.js.map +1 -1
  268. package/dist/tests/fourslash/hover.init.fourslash.js +1 -1
  269. package/dist/tests/fourslash/hover.init.fourslash.js.map +1 -1
  270. package/dist/tests/fourslash/hover.libCodeAndStub.fourslash.js +1 -1
  271. package/dist/tests/fourslash/hover.libCodeAndStub.fourslash.js.map +1 -1
  272. package/dist/tests/fourslash/hover.libCodeNoStub.fourslash.js +1 -1
  273. package/dist/tests/fourslash/hover.libCodeNoStub.fourslash.js.map +1 -1
  274. package/dist/tests/fourslash/hover.libStub.fourslash.js +1 -1
  275. package/dist/tests/fourslash/hover.libStub.fourslash.js.map +1 -1
  276. package/dist/tests/fourslash/hover.plainText.fourslash.js +1 -1
  277. package/dist/tests/fourslash/hover.plainText.fourslash.js.map +1 -1
  278. package/dist/tests/fourslash/hover.wildcardimports.fourslash.js +1 -1
  279. package/dist/tests/fourslash/hover.wildcardimports.fourslash.js.map +1 -1
  280. package/dist/tests/fourslash/import.pytyped.typeCheckingBasic.fourslash.js +1 -1
  281. package/dist/tests/fourslash/import.pytyped.typeCheckingBasic.fourslash.js.map +1 -1
  282. package/dist/tests/fourslash/import.pytyped.typeCheckingOff.fourslash.js +1 -1
  283. package/dist/tests/fourslash/import.pytyped.typeCheckingOff.fourslash.js.map +1 -1
  284. package/dist/tests/fourslash/shadowedImports.fourslash.d.ts +1 -0
  285. package/dist/tests/fourslash/shadowedImports.fourslash.js +75 -0
  286. package/dist/tests/fourslash/shadowedImports.fourslash.js.map +1 -0
  287. package/dist/tests/fourslash/signature.dunderNew.fourslash.d.ts +1 -0
  288. package/dist/tests/fourslash/signature.dunderNew.fourslash.js +24 -0
  289. package/dist/tests/fourslash/signature.dunderNew.fourslash.js.map +1 -0
  290. package/dist/tests/harness/fourslash/runner.js +1 -0
  291. package/dist/tests/harness/fourslash/runner.js.map +1 -1
  292. package/dist/tests/harness/fourslash/testLanguageService.d.ts +3 -1
  293. package/dist/tests/harness/fourslash/testLanguageService.js +4 -2
  294. package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
  295. package/dist/tests/harness/fourslash/testState.d.ts +8 -7
  296. package/dist/tests/harness/fourslash/testState.js +80 -161
  297. package/dist/tests/harness/fourslash/testState.js.map +1 -1
  298. package/dist/tests/harness/fourslash/workspaceEditTestUtils.d.ts +16 -0
  299. package/dist/tests/harness/fourslash/workspaceEditTestUtils.js +159 -0
  300. package/dist/tests/harness/fourslash/workspaceEditTestUtils.js.map +1 -0
  301. package/dist/tests/harness/vfs/filesystem.d.ts +1 -0
  302. package/dist/tests/harness/vfs/filesystem.js +3 -0
  303. package/dist/tests/harness/vfs/filesystem.js.map +1 -1
  304. package/dist/tests/ipythonMode.test.js +39 -0
  305. package/dist/tests/ipythonMode.test.js.map +1 -1
  306. package/dist/tests/logger.test.js +3 -1
  307. package/dist/tests/logger.test.js.map +1 -1
  308. package/dist/tests/pathUtils.test.js +7 -0
  309. package/dist/tests/pathUtils.test.js.map +1 -1
  310. package/dist/tests/sourceFile.test.js +34 -1
  311. package/dist/tests/sourceFile.test.js.map +1 -1
  312. package/dist/tests/sourceMapperUtils.test.d.ts +1 -0
  313. package/dist/tests/sourceMapperUtils.test.js +138 -0
  314. package/dist/tests/sourceMapperUtils.test.js.map +1 -0
  315. package/dist/tests/tokenizer.test.js +6 -2
  316. package/dist/tests/tokenizer.test.js.map +1 -1
  317. package/dist/tests/typeEvaluator1.test.js +16 -6
  318. package/dist/tests/typeEvaluator1.test.js.map +1 -1
  319. package/dist/tests/typeEvaluator2.test.js +19 -3
  320. package/dist/tests/typeEvaluator2.test.js.map +1 -1
  321. package/dist/tests/typeEvaluator3.test.js +44 -10
  322. package/dist/tests/typeEvaluator3.test.js.map +1 -1
  323. package/dist/tests/typeEvaluator4.test.js +11 -3
  324. package/dist/tests/typeEvaluator4.test.js.map +1 -1
  325. package/dist/tests/typeEvaluator5.test.js +48 -0
  326. package/dist/tests/typeEvaluator5.test.js.map +1 -1
  327. package/dist/tests/typePrinter.test.d.ts +1 -0
  328. package/dist/tests/typePrinter.test.js +148 -0
  329. package/dist/tests/typePrinter.test.js.map +1 -0
  330. package/dist/tests/workspaceEditUtils.test.d.ts +1 -0
  331. package/dist/tests/workspaceEditUtils.test.js +167 -0
  332. package/dist/tests/workspaceEditUtils.test.js.map +1 -0
  333. package/dist/workspaceMap.d.ts +2 -0
  334. package/dist/workspaceMap.js +45 -15
  335. package/dist/workspaceMap.js.map +1 -1
  336. package/package.json +3 -3
  337. package/dist/tests/fourslash/signature.paramspec.fourslash.js +0 -30
  338. package/dist/tests/fourslash/signature.paramspec.fourslash.js.map +0 -1
@@ -677,9 +677,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
677
677
  }
678
678
  if (reportExpectingTypeErrors && !typeResult.isIncomplete) {
679
679
  if (flags & 128 /* TypeVarTupleDisallowed */) {
680
- if ((0, types_1.isTypeVar)(typeResult.type) &&
681
- typeResult.type.details.isVariadic &&
682
- !typeResult.type.isVariadicInUnion) {
680
+ if ((0, types_1.isVariadicTypeVar)(typeResult.type) && !typeResult.type.isVariadicInUnion) {
683
681
  addError(localize_1.Localizer.Diagnostic.typeVarTupleContext(), node);
684
682
  typeResult.type = types_1.UnknownType.create();
685
683
  }
@@ -691,6 +689,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
691
689
  if (!isEmptyVariadic) {
692
690
  addExpectedClassDiagnostic(typeResult.type, node);
693
691
  typeResult.type = types_1.UnknownType.create();
692
+ typeResult.typeErrors = true;
694
693
  }
695
694
  }
696
695
  }
@@ -779,8 +778,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
779
778
  typeResult = { type: types_1.ClassType.cloneForUnpacked(iterType) };
780
779
  }
781
780
  else {
782
- const type = (_a = getTypeOfIterator(iterType, /* isAsync */ false, node)) !== null && _a !== void 0 ? _a : types_1.UnknownType.create(!!iterTypeResult.isIncomplete);
783
- typeResult = { type, unpackedType: iterType, isIncomplete: iterTypeResult.isIncomplete };
781
+ const iteratorTypeResult = (_a = getTypeOfIterator(iterTypeResult, /* isAsync */ false, node)) !== null && _a !== void 0 ? _a : {
782
+ type: types_1.UnknownType.create(!!iterTypeResult.isIncomplete),
783
+ isIncomplete: iterTypeResult.isIncomplete,
784
+ };
785
+ typeResult = {
786
+ type: iteratorTypeResult.type,
787
+ unpackedType: iterType,
788
+ isIncomplete: iteratorTypeResult.isIncomplete,
789
+ };
784
790
  }
785
791
  }
786
792
  return typeResult;
@@ -869,17 +875,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
869
875
  // the resulting formatted string is also LiteralString.
870
876
  node.expressions.forEach((expr) => {
871
877
  const exprType = getTypeOfExpression(expr).type;
872
- if (!(0, types_1.isClassInstance)(exprType)) {
878
+ (0, typeUtils_1.doForEachSubtype)(exprType, (exprSubtype) => {
879
+ if (!(0, types_1.isClassInstance)(exprSubtype)) {
880
+ isLiteralString = false;
881
+ return;
882
+ }
883
+ if (types_1.ClassType.isBuiltIn(exprSubtype, 'LiteralString')) {
884
+ return;
885
+ }
886
+ if (types_1.ClassType.isBuiltIn(exprSubtype, 'str') && exprSubtype.literalValue !== undefined) {
887
+ return;
888
+ }
873
889
  isLiteralString = false;
874
- return;
875
- }
876
- if (types_1.ClassType.isBuiltIn(exprType, 'LiteralString')) {
877
- return;
878
- }
879
- if (types_1.ClassType.isBuiltIn(exprType, 'str') && exprType.literalValue !== undefined) {
880
- return;
881
- }
882
- isLiteralString = false;
890
+ });
883
891
  });
884
892
  if (!isBytes && isLiteralString) {
885
893
  const literalStringType = getTypingType(node, 'LiteralString');
@@ -1092,6 +1100,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1092
1100
  if ((0, typeUtils_1.isTupleClass)(type) && type.tupleTypeArguments) {
1093
1101
  return (0, typeUtils_1.isUnboundedTupleClass)(type) || type.tupleTypeArguments.length === 0;
1094
1102
  }
1103
+ // Handle subclasses of tuple, such as NamedTuple.
1104
+ const tupleBaseClass = type.details.mro.find((mroClass) => !(0, types_1.isClass)(mroClass) || (0, typeUtils_1.isTupleClass)(mroClass));
1105
+ if (tupleBaseClass && (0, types_1.isClass)(tupleBaseClass) && tupleBaseClass.tupleTypeArguments) {
1106
+ return (0, typeUtils_1.isUnboundedTupleClass)(tupleBaseClass) || tupleBaseClass.tupleTypeArguments.length === 0;
1107
+ }
1095
1108
  // Check for Literal[False] and Literal[True].
1096
1109
  if (types_1.ClassType.isBuiltIn(type, 'bool') && type.literalValue !== undefined) {
1097
1110
  return type.literalValue === false;
@@ -1402,8 +1415,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1402
1415
  case 7 /* Class */: {
1403
1416
  if (types_1.TypeBase.isInstantiable(subtype)) {
1404
1417
  let methodType;
1405
- // Try to get the __init__ method first because it typically has
1406
- // more type information than __new__.
1418
+ // Try to get the `__init__` method first because it typically has more
1419
+ // type information than `__new__`.
1407
1420
  methodType = getBoundMethod(subtype, '__init__');
1408
1421
  // Is this the __init__ method provided by the object class?
1409
1422
  const isObjectInit = !!methodType &&
@@ -1413,7 +1426,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1413
1426
  // If there was no `__init__` or the only `__init__` that was found
1414
1427
  // was form the `object` class, see if we can find a better `__new__`
1415
1428
  // method.
1416
- if (!methodType || isObjectInit || isSkipConstructor) {
1429
+ if (!methodType ||
1430
+ isObjectInit ||
1431
+ isSkipConstructor ||
1432
+ (methodType &&
1433
+ (0, types_1.isFunction)(methodType) &&
1434
+ (types_1.FunctionType.hasDefaultParameters(methodType) ||
1435
+ methodType.details.parameters.length === 0))) {
1417
1436
  const constructorType = getBoundMethod(subtype, '__new__',
1418
1437
  /* recursionCount */ undefined,
1419
1438
  /* treatConstructorAsClassMember */ true);
@@ -1615,14 +1634,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1615
1634
  }
1616
1635
  // Validates that the type is an iterator and returns the iterated type
1617
1636
  // (i.e. the type returned from the '__next__' or '__anext__' method).
1618
- function getTypeOfIterator(type, isAsync, errorNode) {
1637
+ function getTypeOfIterator(typeResult, isAsync, errorNode) {
1619
1638
  const iterMethodName = isAsync ? '__aiter__' : '__iter__';
1620
1639
  const nextMethodName = isAsync ? '__anext__' : '__next__';
1621
1640
  let isValidIterator = true;
1622
- type = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(type);
1641
+ let type = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(typeResult.type);
1623
1642
  type = makeTopLevelTypeVarsConcrete(type);
1624
1643
  if ((0, typeUtils_1.isOptionalType)(type)) {
1625
- if (errorNode) {
1644
+ if (errorNode && !typeResult.isIncomplete) {
1626
1645
  addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportOptionalIterable, diagnosticRules_1.DiagnosticRule.reportOptionalIterable, localize_1.Localizer.Diagnostic.noneNotIterable(), errorNode);
1627
1646
  }
1628
1647
  type = (0, types_1.removeNoneFromUnion)(type);
@@ -1677,7 +1696,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1677
1696
  return subtype;
1678
1697
  }
1679
1698
  if ((0, types_1.isClassInstance)(subtype)) {
1680
- const nextReturnType = getSpecializedReturnType(subtype, nextMethodName, [], errorNode);
1699
+ let nextReturnType = getSpecializedReturnType(subtype, nextMethodName, [], errorNode);
1681
1700
  if (!nextReturnType) {
1682
1701
  iterReturnTypeDiag.addMessage(localize_1.Localizer.Diagnostic.methodNotDefinedOnType().format({
1683
1702
  name: nextMethodName,
@@ -1685,6 +1704,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1685
1704
  }));
1686
1705
  }
1687
1706
  else {
1707
+ // Convert any unpacked TypeVarTuples into object instances. We don't
1708
+ // know anything more about them.
1709
+ nextReturnType = (0, typeUtils_1.mapSubtypes)(nextReturnType, (returnSubtype) => {
1710
+ if ((0, types_1.isTypeVar)(returnSubtype) && (0, types_1.isUnpackedVariadicTypeVar)(returnSubtype)) {
1711
+ return objectType !== null && objectType !== void 0 ? objectType : types_1.UnknownType.create();
1712
+ }
1713
+ return returnSubtype;
1714
+ });
1688
1715
  if (!isAsync) {
1689
1716
  return nextReturnType;
1690
1717
  }
@@ -1704,21 +1731,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1704
1731
  diag.addAddendum(iterReturnTypeDiag);
1705
1732
  }
1706
1733
  }
1707
- if (errorNode) {
1734
+ if (errorNode && !typeResult.isIncomplete) {
1708
1735
  addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeNotIterable().format({ type: printType(subtype) }) + diag.getString(), errorNode);
1709
1736
  }
1710
1737
  isValidIterator = false;
1711
1738
  return undefined;
1712
1739
  });
1713
- return isValidIterator ? iterableType : undefined;
1740
+ return isValidIterator ? { type: iterableType, isIncomplete: typeResult.isIncomplete } : undefined;
1714
1741
  }
1715
1742
  // Validates that the type is an iterable and returns the iterable type argument.
1716
- function getTypeOfIterable(type, isAsync, errorNode) {
1743
+ function getTypeOfIterable(typeResult, isAsync, errorNode) {
1717
1744
  const iterMethodName = isAsync ? '__aiter__' : '__iter__';
1718
1745
  let isValidIterable = true;
1719
- type = makeTopLevelTypeVarsConcrete(type);
1746
+ let type = makeTopLevelTypeVarsConcrete(typeResult.type);
1720
1747
  if ((0, typeUtils_1.isOptionalType)(type)) {
1721
- if (errorNode) {
1748
+ if (errorNode && !typeResult.isIncomplete) {
1722
1749
  addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportOptionalIterable, diagnosticRules_1.DiagnosticRule.reportOptionalIterable, localize_1.Localizer.Diagnostic.noneNotIterable(), errorNode);
1723
1750
  }
1724
1751
  type = (0, types_1.removeNoneFromUnion)(type);
@@ -1747,7 +1774,47 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1747
1774
  isValidIterable = false;
1748
1775
  return undefined;
1749
1776
  });
1750
- return isValidIterable ? iterableType : undefined;
1777
+ return isValidIterable ? { type: iterableType, isIncomplete: typeResult.isIncomplete } : undefined;
1778
+ }
1779
+ function isTypeHashable(type) {
1780
+ let isTypeHashable = true;
1781
+ (0, typeUtils_1.doForEachSubtype)(makeTopLevelTypeVarsConcrete(type), (subtype) => {
1782
+ if ((0, types_1.isClassInstance)(subtype)) {
1783
+ // Assume the class is hashable.
1784
+ let isObjectHashable = true;
1785
+ // Have we already computed and cached the hashability?
1786
+ if (subtype.details.isInstanceHashable !== undefined) {
1787
+ isObjectHashable = subtype.details.isInstanceHashable;
1788
+ }
1789
+ else {
1790
+ const hashMember = (0, typeUtils_1.lookUpObjectMember)(subtype, '__hash__', 4 /* SkipObjectBaseClass */);
1791
+ if (hashMember && hashMember.isTypeDeclared) {
1792
+ const decls = hashMember.symbol.getTypedDeclarations();
1793
+ const synthesizedType = hashMember.symbol.getSynthesizedType();
1794
+ // Handle the case where the type is synthesized (used for
1795
+ // dataclasses).
1796
+ if (synthesizedType) {
1797
+ isObjectHashable = !(0, types_1.isNoneInstance)(synthesizedType);
1798
+ }
1799
+ else {
1800
+ // Assume that if '__hash__' is declared as a variable, it is
1801
+ // not hashable. If it's declared as a function, it is. We'll
1802
+ // skip evaluating its full type because that's not needed in
1803
+ // this case.
1804
+ if (decls.every((decl) => decl.type === 1 /* Variable */)) {
1805
+ isObjectHashable = false;
1806
+ }
1807
+ }
1808
+ }
1809
+ // Cache the hashability for next time.
1810
+ subtype.details.isInstanceHashable = isObjectHashable;
1811
+ }
1812
+ if (!isObjectHashable) {
1813
+ isTypeHashable = false;
1814
+ }
1815
+ }
1816
+ });
1817
+ return isTypeHashable;
1751
1818
  }
1752
1819
  function getTypedDictClassType() {
1753
1820
  return typedDictClassType;
@@ -1834,10 +1901,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1834
1901
  const codeFlowResult = analyzer.getTypeFromCodeFlow(flowNode,
1835
1902
  /* reference */ undefined,
1836
1903
  /* targetSymbolId */ undefined,
1837
- /* initialType */ types_1.UnboundType.create(), {
1904
+ /* typeAtStart */ types_1.UnboundType.create(), {
1838
1905
  skipNoReturnCallAnalysis: true,
1839
1906
  });
1840
- return codeFlowResult.type !== undefined;
1907
+ return codeFlowResult.type !== undefined && !(0, types_1.isNever)(codeFlowResult.type);
1841
1908
  }
1842
1909
  // Determines whether there is a code flow path from sourceNode to sinkNode.
1843
1910
  function isFlowPathBetweenNodes(sourceNode, sinkNode, allowSelf = true) {
@@ -2158,6 +2225,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2158
2225
  type = makeTopLevelTypeVarsConcrete(type);
2159
2226
  const diagAddendum = new diagnostic_1.DiagnosticAddendum();
2160
2227
  (0, typeUtils_1.doForEachSubtype)(type, (subtype) => {
2228
+ var _a, _b;
2161
2229
  // Is this subtype a tuple?
2162
2230
  const tupleType = (0, typeUtils_1.getSpecializedTupleType)(subtype);
2163
2231
  if (tupleType && tupleType.tupleTypeArguments) {
@@ -2214,7 +2282,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2214
2282
  else {
2215
2283
  // The assigned expression isn't a tuple, so it had better
2216
2284
  // be some iterable type.
2217
- const iterableType = getTypeOfIterator(subtype, /* isAsync */ false, srcExpr) || types_1.UnknownType.create();
2285
+ const iterableType = (_b = (_a = getTypeOfIterator({ type: subtype, isIncomplete: isTypeIncomplete }, /* isAsync */ false, srcExpr)) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : types_1.UnknownType.create();
2218
2286
  for (let index = 0; index < targetExpressions.length; index++) {
2219
2287
  targetTypes[index].push((0, typeUtils_1.addConditionToType)(iterableType, (0, typeUtils_1.getTypeCondition)(subtype)));
2220
2288
  }
@@ -2266,9 +2334,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2266
2334
  return types_1.UnknownType.create();
2267
2335
  }
2268
2336
  }
2337
+ // If this is a TypeVarTuple *Ts, convert it to an unpacked tuple
2338
+ // *tuple[*Ts].
2269
2339
  if ((0, types_1.isVariadicTypeVar)(subtype)) {
2270
2340
  if (tupleClassType && (0, types_1.isInstantiableClass)(tupleClassType)) {
2271
- return (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClassType, [],
2341
+ return (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClassType, [{ type: subtype, isUnbounded: false }],
2272
2342
  /* isTypeArgumentExplicit */ true,
2273
2343
  /* isUnpackedTuple */ true));
2274
2344
  }
@@ -2533,7 +2603,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2533
2603
  if (!(0, typeUtils_1.derivesFromClassRecursive)(concreteSubtype, baseExceptionType,
2534
2604
  /* ignoreUnknown */ false)) {
2535
2605
  diagAddendum.addMessage(localize_1.Localizer.Diagnostic.exceptionTypeIncorrect().format({
2536
- type: printType(subtype, /* expandTypeAlias */ false),
2606
+ type: printType(subtype),
2537
2607
  }));
2538
2608
  }
2539
2609
  else {
@@ -2545,7 +2615,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2545
2615
  });
2546
2616
  if (callResult && callResult.argumentErrors) {
2547
2617
  diagAddendum.addMessage(localize_1.Localizer.Diagnostic.exceptionTypeNotInstantiable().format({
2548
- type: printType(subtype, /* expandTypeAlias */ false),
2618
+ type: printType(subtype),
2549
2619
  }));
2550
2620
  }
2551
2621
  }
@@ -2554,13 +2624,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2554
2624
  if (!(0, typeUtils_1.derivesFromClassRecursive)(types_1.ClassType.cloneAsInstantiable(concreteSubtype), baseExceptionType,
2555
2625
  /* ignoreUnknown */ false)) {
2556
2626
  diagAddendum.addMessage(localize_1.Localizer.Diagnostic.exceptionTypeIncorrect().format({
2557
- type: printType(subtype, /* expandTypeAlias */ false),
2627
+ type: printType(subtype),
2558
2628
  }));
2559
2629
  }
2560
2630
  }
2561
2631
  else {
2562
2632
  diagAddendum.addMessage(localize_1.Localizer.Diagnostic.exceptionTypeIncorrect().format({
2563
- type: printType(subtype, /* expandTypeAlias */ false),
2633
+ type: printType(subtype),
2564
2634
  }));
2565
2635
  }
2566
2636
  }
@@ -2642,7 +2712,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2642
2712
  if (!classMember) {
2643
2713
  return undefined;
2644
2714
  }
2645
- const memberType = getTypeOfMember(classMember);
2715
+ const memberTypeResult = getTypeOfMemberInternal(classMember, objType);
2716
+ if (!memberTypeResult) {
2717
+ return undefined;
2718
+ }
2719
+ const memberType = memberTypeResult.type;
2646
2720
  if ((0, types_1.isAnyOrUnknown)(memberType)) {
2647
2721
  return memberType;
2648
2722
  }
@@ -2684,6 +2758,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2684
2758
  };
2685
2759
  }
2686
2760
  }
2761
+ // Does this name refer to a PEP 695-style type parameter?
2687
2762
  const typeParamSymbol = AnalyzerNodeInfo.getTypeParameterSymbol(node);
2688
2763
  if (typeParamSymbol) {
2689
2764
  symbol = typeParamSymbol;
@@ -2693,7 +2768,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2693
2768
  else {
2694
2769
  // Look for the scope that contains the value definition and
2695
2770
  // see if it has a declared type.
2696
- const symbolWithScope = lookUpSymbolRecursive(node, name, !allowForwardReferences, allowForwardReferences && (flags & 1024 /* ExpectingTypeAnnotation */) !== 0);
2771
+ let symbolWithScope = lookUpSymbolRecursive(node, name, !allowForwardReferences, allowForwardReferences && (flags & 1024 /* ExpectingTypeAnnotation */) !== 0);
2772
+ if (!symbolWithScope) {
2773
+ // If the node is part of a "from X import Y as Z" statement and the node
2774
+ // is the "Y" (non-aliased) name, we need to look up the alias symbol
2775
+ // since the non-aliased name is not in the symbol table.
2776
+ const alias = getAliasFromImport(node);
2777
+ if (alias) {
2778
+ symbolWithScope = lookUpSymbolRecursive(alias, alias.value, !allowForwardReferences, allowForwardReferences && (flags & 1024 /* ExpectingTypeAnnotation */) !== 0);
2779
+ }
2780
+ }
2697
2781
  if (symbolWithScope) {
2698
2782
  let useCodeFlowAnalysis = !allowForwardReferences;
2699
2783
  // If the symbol is implicitly imported from the builtin
@@ -2723,9 +2807,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2723
2807
  // If the symbol is declared outside of our execution scope, use its effective
2724
2808
  // type. If it's declared inside our execution scope, it generally starts
2725
2809
  // as unbound at the start of the code flow.
2726
- const typeAtStart = symbolWithScope.isBeyondExecutionScope || !symbol.isInitiallyUnbound()
2727
- ? effectiveType
2728
- : types_1.UnboundType.create();
2810
+ let typeAtStart = effectiveType;
2811
+ if (!symbolWithScope.isBeyondExecutionScope && symbol.isInitiallyUnbound()) {
2812
+ typeAtStart = types_1.UnboundType.create();
2813
+ // Is this a module-level scope? If so, see if it's an alias of a builtin.
2814
+ if (symbolWithScope.scope.type === 3 /* Module */) {
2815
+ (0, debug_1.assert)(symbolWithScope.scope.parent);
2816
+ const builtInSymbol = symbolWithScope.scope.parent.lookUpSymbol(name);
2817
+ if (builtInSymbol) {
2818
+ const builtInEffectiveType = getEffectiveTypeOfSymbolForUsage(builtInSymbol);
2819
+ typeAtStart = builtInEffectiveType.type;
2820
+ }
2821
+ }
2822
+ }
2729
2823
  const codeFlowTypeResult = getFlowTypeOfReference(node, symbol.id, typeAtStart,
2730
2824
  /* startNode */ undefined, {
2731
2825
  skipConditionalNarrowing: (flags & 1024 /* ExpectingTypeAnnotation */) !== 0,
@@ -2793,6 +2887,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2793
2887
  }
2794
2888
  if ((0, types_1.isTypeVar)(type) &&
2795
2889
  !type.details.isParamSpec &&
2890
+ !type.isVariadicInUnion &&
2796
2891
  (flags & 64 /* ExpectingType */) === 0 &&
2797
2892
  type.details.name === name) {
2798
2893
  // Handle the special case of a PEP 604 union. These can appear within
@@ -2956,7 +3051,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2956
3051
  }
2957
3052
  // If this type var is variadic, the name refers to the packed form. It
2958
3053
  // must be unpacked in most contexts.
2959
- if (type.isVariadicUnpacked) {
3054
+ if ((0, types_1.isUnpackedVariadicTypeVar)(type)) {
2960
3055
  type = types_1.TypeVarType.cloneForPacked(type);
2961
3056
  }
2962
3057
  return type;
@@ -2983,11 +3078,24 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2983
3078
  type.typeAliasInfo.typeParameters &&
2984
3079
  type.typeAliasInfo.typeParameters.length > 0 &&
2985
3080
  !type.typeAliasInfo.typeArguments) {
2986
- addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportMissingTypeArgument, diagnosticRules_1.DiagnosticRule.reportMissingTypeArgument, localize_1.Localizer.Diagnostic.typeArgsMissingForAlias().format({
2987
- name: type.typeAliasInfo.name,
2988
- }), node);
2989
- type = types_1.TypeBase.cloneForTypeAlias((0, typeUtils_1.applySolvedTypeVars)(type, new typeVarContext_1.TypeVarContext(type.typeAliasInfo.typeVarScopeId),
2990
- /* unknownIfNotFound */ true), type.typeAliasInfo.name, type.typeAliasInfo.fullName, type.typeAliasInfo.typeVarScopeId, type.typeAliasInfo.typeParameters, type.typeAliasInfo.typeParameters.map((param) => types_1.UnknownType.create()));
3081
+ let reportMissingTypeArguments = false;
3082
+ const defaultTypeArgs = [];
3083
+ type.typeAliasInfo.typeParameters.forEach((param) => {
3084
+ if (param.details.defaultType) {
3085
+ defaultTypeArgs.push(param.details.defaultType);
3086
+ }
3087
+ else {
3088
+ defaultTypeArgs.push(types_1.UnknownType.create());
3089
+ reportMissingTypeArguments = true;
3090
+ }
3091
+ });
3092
+ const typeVarContext = (0, typeUtils_1.buildTypeVarContext)(type.typeAliasInfo.typeParameters, defaultTypeArgs, type.typeAliasInfo.typeVarScopeId);
3093
+ if (reportMissingTypeArguments) {
3094
+ addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportMissingTypeArgument, diagnosticRules_1.DiagnosticRule.reportMissingTypeArgument, localize_1.Localizer.Diagnostic.typeArgsMissingForAlias().format({
3095
+ name: type.typeAliasInfo.name,
3096
+ }), node);
3097
+ }
3098
+ type = types_1.TypeBase.cloneForTypeAlias((0, typeUtils_1.applySolvedTypeVars)(type, typeVarContext, /* unknownIfNotFound */ true), type.typeAliasInfo.name, type.typeAliasInfo.fullName, type.typeAliasInfo.typeVarScopeId, type.typeAliasInfo.typeParameters, defaultTypeArgs);
2991
3099
  }
2992
3100
  }
2993
3101
  return type;
@@ -3131,9 +3239,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3131
3239
  writeTypeCache(node.memberName, typeResult.type, flags, /* isIncomplete */ true);
3132
3240
  // If the type is initially unbound, see if there's a parent class that
3133
3241
  // potentially initialized the value.
3134
- let initialType = typeResult.type;
3135
- let isInitialTypeIncomplete = !!typeResult.isIncomplete;
3136
- if ((0, types_1.isUnbound)(initialType)) {
3242
+ let typeAtStart = typeResult.type;
3243
+ let isTypeAtStartIncomplete = !!typeResult.isIncomplete;
3244
+ if ((0, types_1.isUnbound)(typeAtStart)) {
3137
3245
  const baseType = makeTopLevelTypeVarsConcrete(baseTypeResult.type);
3138
3246
  let classMemberInfo;
3139
3247
  if ((0, types_1.isInstantiableClass)(baseType)) {
@@ -3143,14 +3251,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3143
3251
  classMemberInfo = (0, typeUtils_1.lookUpObjectMember)(baseType, node.memberName.value, 1 /* SkipOriginalClass */);
3144
3252
  }
3145
3253
  if (classMemberInfo) {
3146
- initialType = getTypeOfMember(classMemberInfo);
3147
- isInitialTypeIncomplete = false;
3254
+ typeAtStart = getTypeOfMember(classMemberInfo);
3255
+ isTypeAtStartIncomplete = false;
3148
3256
  }
3149
3257
  }
3150
3258
  // See if we can refine the type based on code flow analysis.
3151
- const codeFlowTypeResult = getFlowTypeOfReference(node, symbol_1.indeterminateSymbolId, initialType,
3259
+ const codeFlowTypeResult = getFlowTypeOfReference(node, symbol_1.indeterminateSymbolId, typeAtStart,
3152
3260
  /* startNode */ undefined, {
3153
- isInitialTypeIncomplete,
3261
+ isTypeAtStartIncomplete,
3154
3262
  skipConditionalNarrowing: (flags & 1024 /* ExpectingTypeAnnotation */) !== 0,
3155
3263
  });
3156
3264
  if (codeFlowTypeResult.type) {
@@ -4051,7 +4159,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4051
4159
  // See if we can refine the type based on code flow analysis.
4052
4160
  const codeFlowTypeResult = getFlowTypeOfReference(node, symbol_1.indeterminateSymbolId, indexTypeResult.type,
4053
4161
  /* startNode */ undefined, {
4054
- isInitialTypeIncomplete: !!baseTypeResult.isIncomplete || !!indexTypeResult.isIncomplete,
4162
+ isTypeAtStartIncomplete: !!baseTypeResult.isIncomplete || !!indexTypeResult.isIncomplete,
4055
4163
  skipConditionalNarrowing: (flags & 1024 /* ExpectingTypeAnnotation */) !== 0,
4056
4164
  });
4057
4165
  if (codeFlowTypeResult.type) {
@@ -4080,6 +4188,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4080
4188
  return indexTypeResult;
4081
4189
  }
4082
4190
  function adjustTypeArgumentsForVariadicTypeVar(typeArgs, typeParameters, errorNode) {
4191
+ var _a;
4083
4192
  const variadicIndex = typeParameters.findIndex((param) => (0, types_1.isVariadicTypeVar)(param));
4084
4193
  // Do we need to adjust the type arguments to map to a variadic type
4085
4194
  // param at the end of the list?
@@ -4127,7 +4236,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4127
4236
  // Add an empty tuple that maps to the TypeVarTuple type parameter.
4128
4237
  typeArgs.push({
4129
4238
  node: errorNode,
4130
- type: (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClassType, [],
4239
+ type: (_a = typeParameters[variadicIndex].details.defaultType) !== null && _a !== void 0 ? _a : (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClassType, [],
4131
4240
  /* isTypeArgumentExplicit */ true,
4132
4241
  /* isUnpackedTuple */ true)),
4133
4242
  });
@@ -4180,7 +4289,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4180
4289
  ];
4181
4290
  }
4182
4291
  }
4183
- if (typeArgs.length > typeParameters.length && !typeParameters.some((typeVar) => typeVar.details.isVariadic)) {
4292
+ if (typeArgs.length > typeParameters.length &&
4293
+ !typeParameters.some((typeVar) => typeVar.details.isVariadic && !typeVar.isVariadicInUnion)) {
4184
4294
  addError(localize_1.Localizer.Diagnostic.typeArgsTooMany().format({
4185
4295
  name: printType(baseType),
4186
4296
  expected: typeParameters.length,
@@ -4196,6 +4306,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4196
4306
  const typeVarContext = new typeVarContext_1.TypeVarContext(baseType.typeAliasInfo.typeVarScopeId);
4197
4307
  const diag = new diagnostic_1.DiagnosticAddendum();
4198
4308
  typeParameters.forEach((param, index) => {
4309
+ var _a;
4199
4310
  if (param.details.isParamSpec && index < typeArgs.length) {
4200
4311
  const typeArgType = typeArgs[index].type;
4201
4312
  if (typeArgs[index].typeList) {
@@ -4258,7 +4369,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4258
4369
  if (index < typeArgs.length && typeArgs[index].typeList) {
4259
4370
  addError(localize_1.Localizer.Diagnostic.typeArgListNotAllowed(), typeArgs[index].node);
4260
4371
  }
4261
- const typeArgType = index < typeArgs.length ? (0, typeUtils_1.convertToInstance)(typeArgs[index].type) : types_1.UnknownType.create();
4372
+ const typeArgType = index < typeArgs.length
4373
+ ? (0, typeUtils_1.convertToInstance)(typeArgs[index].type)
4374
+ : (_a = param.details.defaultType) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
4262
4375
  (0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, param, typeArgType, diag, typeVarContext, 128 /* RetainLiteralsForTypeVar */);
4263
4376
  }
4264
4377
  });
@@ -4312,7 +4425,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4312
4425
  // See if the class has a custom metaclass that supports __getitem__, etc.
4313
4426
  if (concreteSubtype.details.effectiveMetaclass &&
4314
4427
  (0, types_1.isInstantiableClass)(concreteSubtype.details.effectiveMetaclass) &&
4315
- !types_1.ClassType.isBuiltIn(concreteSubtype.details.effectiveMetaclass, 'type')) {
4428
+ !types_1.ClassType.isBuiltIn(concreteSubtype.details.effectiveMetaclass, ['type', '_InitVarMeta'])) {
4316
4429
  const itemMethodType = getTypeOfClassMember(node, concreteSubtype, getIndexAccessMagicMethodName(usage),
4317
4430
  /* usage */ undefined,
4318
4431
  /* diag */ undefined, 64 /* SkipAttributeAccessOverride */ | 32 /* ConsiderMetaclassOnly */);
@@ -4370,7 +4483,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4370
4483
  }
4371
4484
  if (concreteSubtype.typeArguments) {
4372
4485
  addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.classAlreadySpecialized().format({
4373
- type: printType((0, typeUtils_1.convertToInstance)(concreteSubtype), /* expandTypeAlias */ true),
4486
+ type: printType((0, typeUtils_1.convertToInstance)(concreteSubtype), { expandTypeAlias: true }),
4374
4487
  }), node.baseExpression);
4375
4488
  return concreteSubtype;
4376
4489
  }
@@ -4552,12 +4665,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4552
4665
  }
4553
4666
  });
4554
4667
  unpackedListArgs.forEach((arg) => {
4668
+ var _a, _b;
4555
4669
  const typeResult = getTypeOfExpression(arg.valueExpression);
4556
- const exprType = typeResult.type;
4557
4670
  if (typeResult.isIncomplete) {
4558
4671
  isPositionalIndexTypeIncomplete = true;
4559
4672
  }
4560
- const iterableType = getTypeOfIterator(exprType, /* isAsync */ false, arg.valueExpression) || types_1.UnknownType.create();
4673
+ const iterableType = (_b = (_a = getTypeOfIterator(typeResult, /* isAsync */ false, arg.valueExpression)) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : types_1.UnknownType.create();
4561
4674
  tupleEntries.push(iterableType);
4562
4675
  });
4563
4676
  positionalIndexType = makeTupleObject(tupleEntries, unpackedListArgs.length > 0);
@@ -4640,7 +4753,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4640
4753
  adjFlags &= ~(2 /* DoNotSpecialize */ |
4641
4754
  32 /* ParamSpecDisallowed */ |
4642
4755
  128 /* TypeVarTupleDisallowed */ |
4643
- 1048576 /* RequiredAllowed */);
4756
+ 1048576 /* RequiredAllowed */ |
4757
+ 16384 /* EnforceTypeVarVarianceConsistency */);
4644
4758
  if (!isAnnotatedClass) {
4645
4759
  adjFlags |= 131072 /* ClassVarDisallowed */ | 16 /* FinalDisallowed */;
4646
4760
  }
@@ -5036,7 +5150,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5036
5150
  const typeResult = getTypeOfExpression(arg0Value, /* flags */ undefined, expectedType);
5037
5151
  const type = typeResult.type;
5038
5152
  const exprString = ParseTreeUtils.printExpression(arg0Value);
5039
- const typeString = printType(type, /* expandTypeAlias */ true);
5153
+ const typeString = printType(type, { expandTypeAlias: true });
5040
5154
  if (expectedText !== undefined) {
5041
5155
  if (expectedText !== typeString) {
5042
5156
  addError(localize_1.Localizer.Diagnostic.revealTypeExpectedTextMismatch().format({
@@ -5076,7 +5190,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5076
5190
  const typeOfSymbol = getEffectiveTypeOfSymbol(symbol);
5077
5191
  infoMessages.push(localize_1.Localizer.DiagnosticAddendum.typeOfSymbol().format({
5078
5192
  name,
5079
- type: printType(typeOfSymbol, /* expandTypeAlias */ true),
5193
+ type: printType(typeOfSymbol, { expandTypeAlias: true }),
5080
5194
  }));
5081
5195
  }
5082
5196
  });
@@ -5811,7 +5925,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5811
5925
  const exprNode = errorNode.nodeType === 9 /* Call */ ? errorNode.leftExpression : errorNode;
5812
5926
  addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeNotCallable().format({
5813
5927
  expression: ParseTreeUtils.printExpression(exprNode),
5814
- type: printType(callTypeResult.type, /* expandTypeAlias */ true),
5928
+ type: printType(callTypeResult.type, { expandTypeAlias: true }),
5815
5929
  }), exprNode);
5816
5930
  return { returnType: types_1.UnknownType.create(), argumentErrors: true };
5817
5931
  }
@@ -6076,7 +6190,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6076
6190
  }
6077
6191
  else {
6078
6192
  const memberType = (_d = getTypeOfObjectMember(errorNode, expandedSubtype, '__call__')) === null || _d === void 0 ? void 0 : _d.type;
6079
- if (memberType && ((0, types_1.isFunction)(memberType) || (0, types_1.isOverloadedFunction)(memberType))) {
6193
+ if (memberType) {
6080
6194
  const functionResult = validateCallArguments(errorNode, argList, { type: memberType }, typeVarContext, skipUnknownArgCheck, expectedType, recursionCount);
6081
6195
  if (functionResult.argumentErrors) {
6082
6196
  argumentErrors = true;
@@ -6129,18 +6243,64 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6129
6243
  specializedInitSelfType,
6130
6244
  };
6131
6245
  }
6246
+ // Expands any unpacked tuples within an argument list.
6247
+ function expandArgList(argList) {
6248
+ var _a;
6249
+ const expandedArgList = [];
6250
+ for (const arg of argList) {
6251
+ if (arg.argumentCategory === 1 /* UnpackedList */) {
6252
+ const argType = getTypeOfArgument(arg).type;
6253
+ // If this is a tuple with specified element types, use those
6254
+ // specified types rather than using the more generic iterator
6255
+ // type which will be a union of all element types.
6256
+ const combinedArgType = (0, typeUtils_1.combineSameSizedTuples)(makeTopLevelTypeVarsConcrete(argType), tupleClassType);
6257
+ if ((0, types_1.isClassInstance)(combinedArgType) && (0, typeUtils_1.isTupleClass)(combinedArgType)) {
6258
+ const tupleTypeArgs = (_a = combinedArgType.tupleTypeArguments) !== null && _a !== void 0 ? _a : [];
6259
+ if (tupleTypeArgs.length !== 1) {
6260
+ for (const tupleTypeArg of tupleTypeArgs) {
6261
+ if (tupleTypeArg.isUnbounded) {
6262
+ expandedArgList.push({
6263
+ ...arg,
6264
+ argumentCategory: 1 /* UnpackedList */,
6265
+ valueExpression: undefined,
6266
+ typeResult: {
6267
+ type: (0, typeUtils_1.specializeTupleClass)(combinedArgType, [tupleTypeArg]),
6268
+ },
6269
+ });
6270
+ }
6271
+ else {
6272
+ expandedArgList.push({
6273
+ ...arg,
6274
+ argumentCategory: 0 /* Simple */,
6275
+ valueExpression: undefined,
6276
+ typeResult: {
6277
+ type: tupleTypeArg.type,
6278
+ },
6279
+ });
6280
+ }
6281
+ }
6282
+ continue;
6283
+ }
6284
+ }
6285
+ }
6286
+ expandedArgList.push(arg);
6287
+ }
6288
+ return expandedArgList;
6289
+ }
6132
6290
  // Matches the arguments passed to a function to the corresponding parameters in that
6133
6291
  // function. This matching is done based on positions and keywords. Type evaluation and
6134
6292
  // validation is left to the caller.
6135
6293
  // This logic is based on PEP 3102: https://www.python.org/dev/peps/pep-3102/
6136
6294
  function matchFunctionArgumentsToParameters(errorNode, argList, type, overloadIndex) {
6137
- var _a;
6295
+ var _a, _b, _c, _d, _e;
6138
6296
  const paramDetails = (0, typeUtils_1.getParameterListDetails)(type);
6139
6297
  let argIndex = 0;
6140
6298
  let matchedUnpackedListOfUnknownLength = false;
6141
6299
  let reportedArgError = false;
6142
6300
  let isTypeIncomplete = false;
6143
6301
  let isVariadicTypeVarFullyMatched = false;
6302
+ // Expand any unpacked tuples in the arg list.
6303
+ argList = expandArgList(argList);
6144
6304
  // Build a map of parameters by name.
6145
6305
  const paramMap = new Map();
6146
6306
  paramDetails.params.forEach((paramInfo) => {
@@ -6224,24 +6384,44 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6224
6384
  activeParam = param;
6225
6385
  }
6226
6386
  }
6227
- let foundUnpackedListArg = argList.find((arg) => arg.argumentCategory === 1 /* UnpackedList */) !== undefined;
6387
+ const foundUnpackedListArg = argList.find((arg) => arg.argumentCategory === 1 /* UnpackedList */) !== undefined;
6228
6388
  // Map the positional args to parameters.
6229
6389
  let paramIndex = 0;
6230
- let unpackedArgIndex = 0;
6231
6390
  while (argIndex < positionalArgCount) {
6232
6391
  if (argIndex < positionalOnlyLimitIndex && argList[argIndex].name) {
6233
6392
  const fileInfo = AnalyzerNodeInfo.getFileInfo(argList[argIndex].name);
6234
6393
  addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.argPositional(), argList[argIndex].name);
6235
6394
  reportedArgError = true;
6236
6395
  }
6396
+ const remainingArgCount = positionalArgCount - argIndex;
6397
+ const remainingParamCount = positionParamLimitIndex - paramIndex - 1;
6237
6398
  if (paramIndex >= positionParamLimitIndex) {
6238
- if (!foundUnpackedListArg || argList[argIndex].argumentCategory !== 1 /* UnpackedList */) {
6239
- addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, positionParamLimitIndex === 1
6240
- ? localize_1.Localizer.Diagnostic.argPositionalExpectedOne()
6241
- : localize_1.Localizer.Diagnostic.argPositionalExpectedCount().format({
6242
- expected: positionParamLimitIndex,
6243
- }), argList[argIndex].valueExpression || errorNode);
6244
- reportedArgError = true;
6399
+ if (!type.details.paramSpec) {
6400
+ let tooManyPositionals = false;
6401
+ if (foundUnpackedListArg && argList[argIndex].argumentCategory === 1 /* UnpackedList */) {
6402
+ // If this is an unpacked iterable, we will conservatively assume that it
6403
+ // might have zero iterations unless we can tell from its type that it
6404
+ // definitely has at least one iterable value.
6405
+ const argType = getTypeOfArgument(argList[argIndex]).type;
6406
+ if ((0, types_1.isClassInstance)(argType) &&
6407
+ (0, typeUtils_1.isTupleClass)(argType) &&
6408
+ !(0, typeUtils_1.isUnboundedTupleClass)(argType) &&
6409
+ argType.tupleTypeArguments !== undefined &&
6410
+ argType.tupleTypeArguments.length > 0) {
6411
+ tooManyPositionals = true;
6412
+ }
6413
+ }
6414
+ else {
6415
+ tooManyPositionals = true;
6416
+ }
6417
+ if (tooManyPositionals) {
6418
+ addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, positionParamLimitIndex === 1
6419
+ ? localize_1.Localizer.Diagnostic.argPositionalExpectedOne()
6420
+ : localize_1.Localizer.Diagnostic.argPositionalExpectedCount().format({
6421
+ expected: positionParamLimitIndex,
6422
+ }), (_b = argList[argIndex].valueExpression) !== null && _b !== void 0 ? _b : errorNode);
6423
+ reportedArgError = true;
6424
+ }
6245
6425
  }
6246
6426
  break;
6247
6427
  }
@@ -6250,15 +6430,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6250
6430
  }
6251
6431
  (0, debug_1.assert)(paramDetails.params[paramIndex], 'paramIndex params entry is undefined');
6252
6432
  const paramType = paramDetails.params[paramIndex].type;
6433
+ const paramName = paramDetails.params[paramIndex].param.name;
6434
+ const isParamVariadic = paramDetails.params[paramIndex].param.category === 1 /* VarArgList */ &&
6435
+ (0, types_1.isVariadicTypeVar)(paramType);
6253
6436
  if (argList[argIndex].argumentCategory === 1 /* UnpackedList */) {
6254
- if (!argList[argIndex].valueExpression) {
6255
- break;
6256
- }
6257
- const isParamVariadic = paramDetails.params[paramIndex].param.category === 1 /* VarArgList */ &&
6258
- (0, types_1.isVariadicTypeVar)(paramType);
6259
6437
  let isArgCompatibleWithVariadic = false;
6260
6438
  const argTypeResult = getTypeOfArgument(argList[argIndex]);
6261
- const argType = argTypeResult.type;
6262
6439
  let listElementType;
6263
6440
  let advanceToNextArg = false;
6264
6441
  // Handle the case where *args is being passed to a function defined
@@ -6270,32 +6447,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6270
6447
  ? localize_1.Localizer.Diagnostic.argPositionalExpectedOne()
6271
6448
  : localize_1.Localizer.Diagnostic.argPositionalExpectedCount().format({
6272
6449
  expected: positionParamLimitIndex,
6273
- }), argList[argIndex].valueExpression || errorNode);
6450
+ }), (_c = argList[argIndex].valueExpression) !== null && _c !== void 0 ? _c : errorNode);
6274
6451
  reportedArgError = true;
6275
6452
  }
6276
- // If this is a tuple with specified element types, use those
6277
- // specified types rather than using the more generic iterator
6278
- // type which will be a union of all element types.
6279
- const combinedTupleType = (0, typeUtils_1.combineSameSizedTuples)(makeTopLevelTypeVarsConcrete(argType), tupleClassType);
6280
- if (!isParamVariadic &&
6281
- combinedTupleType &&
6282
- (0, types_1.isClassInstance)(combinedTupleType) &&
6283
- combinedTupleType.tupleTypeArguments &&
6284
- combinedTupleType.tupleTypeArguments.length > 0 &&
6285
- unpackedArgIndex < combinedTupleType.tupleTypeArguments.length) {
6286
- listElementType = combinedTupleType.tupleTypeArguments[unpackedArgIndex].type;
6287
- // Determine if there are any more unpacked list arguments after
6288
- // this one. If not, we'll clear this flag because this unpacked
6289
- // list arg is bounded in length.
6290
- foundUnpackedListArg =
6291
- argList.find((arg, index) => index > argIndex && arg.argumentCategory === 1 /* UnpackedList */) !== undefined;
6292
- unpackedArgIndex++;
6293
- if (unpackedArgIndex >= combinedTupleType.tupleTypeArguments.length) {
6294
- unpackedArgIndex = 0;
6295
- advanceToNextArg = true;
6296
- }
6297
- }
6298
- else if (isParamVariadic && (0, types_1.isVariadicTypeVar)(argType)) {
6453
+ const argType = argTypeResult.type;
6454
+ if (isParamVariadic && (0, types_1.isUnpackedVariadicTypeVar)(argType)) {
6299
6455
  // Allow an unpacked variadic type variable to satisfy an
6300
6456
  // unpacked variadic type variable.
6301
6457
  listElementType = argType;
@@ -6307,7 +6463,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6307
6463
  (0, typeUtils_1.isTupleClass)(argType) &&
6308
6464
  argType.tupleTypeArguments &&
6309
6465
  argType.tupleTypeArguments.length === 1 &&
6310
- (0, types_1.isVariadicTypeVar)(argType.tupleTypeArguments[0].type)) {
6466
+ (0, types_1.isUnpackedVariadicTypeVar)(argType.tupleTypeArguments[0].type)) {
6311
6467
  // Handle the case where an unpacked variadic type var has
6312
6468
  // been packaged into a tuple.
6313
6469
  listElementType = argType.tupleTypeArguments[0].type;
@@ -6315,13 +6471,25 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6315
6471
  advanceToNextArg = true;
6316
6472
  isVariadicTypeVarFullyMatched = true;
6317
6473
  }
6474
+ else if (isParamVariadic && (0, types_1.isClassInstance)(argType) && (0, typeUtils_1.isTupleClass)(argType)) {
6475
+ // Handle the case where an unpacked tuple argument is
6476
+ // matched to a TypeVarTuple parameter.
6477
+ isArgCompatibleWithVariadic = true;
6478
+ advanceToNextArg = true;
6479
+ // Determine whether we should treat the variadic type as fully matched.
6480
+ // This depends on how many args and unmatched parameters exist.
6481
+ if (remainingArgCount < remainingParamCount) {
6482
+ isVariadicTypeVarFullyMatched = true;
6483
+ }
6484
+ listElementType = types_1.ClassType.cloneForUnpacked(argType);
6485
+ }
6318
6486
  else if ((0, types_1.isParamSpec)(argType) && argType.paramSpecAccess === 'args') {
6319
6487
  listElementType = undefined;
6320
6488
  }
6321
6489
  else {
6322
6490
  listElementType =
6323
- getTypeOfIterator(argType, /* isAsync */ false, argList[argIndex].valueExpression) ||
6324
- types_1.UnknownType.create();
6491
+ (_e = (_d = getTypeOfIterator({ type: argType, isIncomplete: argTypeResult.isIncomplete },
6492
+ /* isAsync */ false, argList[argIndex].valueExpression)) === null || _d === void 0 ? void 0 : _d.type) !== null && _e !== void 0 ? _e : types_1.UnknownType.create();
6325
6493
  if (paramDetails.params[paramIndex].param.category !== 1 /* VarArgList */) {
6326
6494
  matchedUnpackedListOfUnknownLength = true;
6327
6495
  }
@@ -6335,7 +6503,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6335
6503
  if (funcArg && argTypeResult.isIncomplete) {
6336
6504
  isTypeIncomplete = true;
6337
6505
  }
6338
- const paramName = paramDetails.params[paramIndex].param.name;
6339
6506
  // It's not allowed to use unpacked arguments with a variadic *args
6340
6507
  // parameter unless the argument is a variadic arg as well.
6341
6508
  if (isParamVariadic && !isArgCompatibleWithVariadic) {
@@ -6355,6 +6522,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6355
6522
  errorNode: argList[argIndex].valueExpression || errorNode,
6356
6523
  paramName,
6357
6524
  isParamNameSynthesized: paramDetails.params[paramIndex].param.isNameSynthesized,
6525
+ mapsToVarArgList: isParamVariadic && remainingArgCount > remainingParamCount,
6358
6526
  });
6359
6527
  }
6360
6528
  }
@@ -6392,8 +6560,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6392
6560
  paramCategory = (0, types_1.isVariadicTypeVar)(effectiveParamType)
6393
6561
  ? 1 /* VarArgList */
6394
6562
  : 0 /* Simple */;
6395
- const remainingArgCount = positionalArgCount - argIndex;
6396
- const remainingParamCount = positionParamLimitIndex - paramIndex - 1;
6397
6563
  if (remainingArgCount <= remainingParamCount) {
6398
6564
  if (remainingArgCount < remainingParamCount) {
6399
6565
  // Have we run out of arguments and still have parameters left to fill?
@@ -6796,7 +6962,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6796
6962
  !isVariadicTypeVarFullyMatched) {
6797
6963
  const paramType = paramDetails.params[paramDetails.argsIndex].type;
6798
6964
  const variadicArgs = validateArgTypeParams.filter((argParam) => argParam.mapsToVarArgList);
6799
- if ((0, types_1.isTypeVar)(paramType) && paramType.details.isVariadic) {
6965
+ if ((0, types_1.isVariadicTypeVar)(paramType) && !paramType.isVariadicInUnion) {
6800
6966
  if (tupleClassType && (0, types_1.isInstantiableClass)(tupleClassType)) {
6801
6967
  const tupleTypeArgs = variadicArgs.map((argParam) => {
6802
6968
  var _a;
@@ -6816,9 +6982,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6816
6982
  isUnbounded: argParam.argument.argumentCategory === 1 /* UnpackedList */,
6817
6983
  };
6818
6984
  });
6819
- const specializedTuple = types_1.ClassType.cloneAsInstance((0, typeUtils_1.specializeTupleClass)(tupleClassType, tupleTypeArgs,
6820
- /* isTypeArgumentExplicit */ true,
6821
- /* isUnpackedTuple */ true));
6985
+ let specializedTuple;
6986
+ if (tupleTypeArgs.length === 1 &&
6987
+ !tupleTypeArgs[0].isUnbounded &&
6988
+ ((0, types_1.isUnpackedClass)(tupleTypeArgs[0].type) || (0, types_1.isVariadicTypeVar)(tupleTypeArgs[0].type))) {
6989
+ // If there is a single unpacked tuple or unpacked variadic type variable
6990
+ // (including an unpacked TypeVarTuple union) within this tuple,
6991
+ // simplify the type.
6992
+ specializedTuple = tupleTypeArgs[0].type;
6993
+ }
6994
+ else {
6995
+ specializedTuple = types_1.ClassType.cloneAsInstance((0, typeUtils_1.specializeTupleClass)(tupleClassType, tupleTypeArgs,
6996
+ /* isTypeArgumentExplicit */ true,
6997
+ /* isUnpackedTuple */ true));
6998
+ }
6822
6999
  const combinedArg = {
6823
7000
  paramCategory: 1 /* VarArgList */,
6824
7001
  paramType,
@@ -7500,7 +7677,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7500
7677
  if (!suppressPartialUnknown) {
7501
7678
  const diagAddendum = getDiagAddendum();
7502
7679
  diagAddendum.addMessage(localize_1.Localizer.DiagnosticAddendum.argumentType().format({
7503
- type: printType(simplifiedType, /* expandTypeAlias */ true),
7680
+ type: printType(simplifiedType, { expandTypeAlias: true }),
7504
7681
  }));
7505
7682
  addDiagnostic(fileInfo.diagnosticRuleSet.reportUnknownArgumentType, diagnosticRules_1.DiagnosticRule.reportUnknownArgumentType, localize_1.Localizer.Diagnostic.argTypePartiallyUnknown() + diagAddendum.getString(), argParam.errorNode);
7506
7683
  }
@@ -7510,9 +7687,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7510
7687
  return { isCompatible, argType, isTypeIncomplete, condition };
7511
7688
  }
7512
7689
  function createTypeVarType(errorNode, argList) {
7513
- var _a, _b, _c, _d, _e;
7690
+ var _a, _b, _c, _d, _e, _f, _g;
7514
7691
  let typeVarName = '';
7515
7692
  let firstConstraintArg;
7693
+ let defaultValueNode;
7516
7694
  if (argList.length === 0) {
7517
7695
  addError(localize_1.Localizer.Diagnostic.typeVarFirstArg(), errorNode);
7518
7696
  return undefined;
@@ -7526,10 +7704,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7526
7704
  }
7527
7705
  const typeVar = types_1.TypeVarType.createInstantiable(typeVarName, /* isParamSpec */ false);
7528
7706
  // Parse the remaining parameters.
7707
+ const paramNameMap = new Map();
7529
7708
  for (let i = 1; i < argList.length; i++) {
7530
7709
  const paramNameNode = argList[i].name;
7531
7710
  const paramName = paramNameNode ? paramNameNode.value : undefined;
7532
- const paramNameMap = new Map();
7533
7711
  if (paramName) {
7534
7712
  if (paramNameMap.get(paramName)) {
7535
7713
  addError(localize_1.Localizer.Diagnostic.duplicateParam().format({ name: paramName }), argList[i].valueExpression || errorNode);
@@ -7541,14 +7719,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7541
7719
  else {
7542
7720
  const argType = (_b = (_a = argList[i].typeResult) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : getTypeOfExpressionExpectingType(argList[i].valueExpression).type;
7543
7721
  if ((0, typeUtils_1.requiresSpecialization)(argType, /* ignorePseudoGeneric */ true)) {
7544
- addError(localize_1.Localizer.Diagnostic.typeVarGeneric(), argList[i].valueExpression || errorNode);
7722
+ addError(localize_1.Localizer.Diagnostic.typeVarBoundGeneric(), argList[i].valueExpression || errorNode);
7545
7723
  }
7546
7724
  typeVar.details.boundType = (0, typeUtils_1.convertToInstance)(argType);
7547
7725
  }
7548
7726
  }
7549
7727
  else if (paramName === 'covariant') {
7550
7728
  if (argList[i].valueExpression && getBooleanValue(argList[i].valueExpression)) {
7551
- if (typeVar.details.declaredVariance === 4 /* Contravariant */) {
7729
+ if (typeVar.details.declaredVariance === 4 /* Contravariant */ ||
7730
+ typeVar.details.declaredVariance === 0 /* Auto */) {
7552
7731
  addError(localize_1.Localizer.Diagnostic.typeVarVariance(), argList[i].valueExpression);
7553
7732
  }
7554
7733
  else {
@@ -7558,7 +7737,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7558
7737
  }
7559
7738
  else if (paramName === 'contravariant') {
7560
7739
  if (argList[i].valueExpression && getBooleanValue(argList[i].valueExpression)) {
7561
- if (typeVar.details.declaredVariance === 3 /* Covariant */) {
7740
+ if (typeVar.details.declaredVariance === 3 /* Covariant */ ||
7741
+ typeVar.details.declaredVariance === 0 /* Auto */) {
7562
7742
  addError(localize_1.Localizer.Diagnostic.typeVarVariance(), argList[i].valueExpression);
7563
7743
  }
7564
7744
  else {
@@ -7566,8 +7746,24 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7566
7746
  }
7567
7747
  }
7568
7748
  }
7749
+ else if (paramName === 'infer_variance') {
7750
+ if (argList[i].valueExpression && getBooleanValue(argList[i].valueExpression)) {
7751
+ if (typeVar.details.declaredVariance === 3 /* Covariant */ ||
7752
+ typeVar.details.declaredVariance === 4 /* Contravariant */) {
7753
+ addError(localize_1.Localizer.Diagnostic.typeVarVariance(), argList[i].valueExpression);
7754
+ }
7755
+ else {
7756
+ typeVar.details.declaredVariance = 0 /* Auto */;
7757
+ }
7758
+ }
7759
+ }
7760
+ else if (paramName === 'default') {
7761
+ defaultValueNode = argList[i].valueExpression;
7762
+ const argType = (_d = (_c = argList[i].typeResult) === null || _c === void 0 ? void 0 : _c.type) !== null && _d !== void 0 ? _d : getTypeOfExpressionExpectingType(argList[i].valueExpression).type;
7763
+ typeVar.details.defaultType = (0, typeUtils_1.convertToInstance)(argType);
7764
+ }
7569
7765
  else {
7570
- addError(localize_1.Localizer.Diagnostic.typeVarUnknownParam().format({ name: paramName }), ((_c = argList[i].node) === null || _c === void 0 ? void 0 : _c.name) || argList[i].valueExpression || errorNode);
7766
+ addError(localize_1.Localizer.Diagnostic.typeVarUnknownParam().format({ name: paramName }), ((_e = argList[i].node) === null || _e === void 0 ? void 0 : _e.name) || argList[i].valueExpression || errorNode);
7571
7767
  }
7572
7768
  paramNameMap.set(paramName, paramName);
7573
7769
  }
@@ -7576,9 +7772,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7576
7772
  addError(localize_1.Localizer.Diagnostic.typeVarBoundAndConstrained(), argList[i].valueExpression || errorNode);
7577
7773
  }
7578
7774
  else {
7579
- const argType = (_e = (_d = argList[i].typeResult) === null || _d === void 0 ? void 0 : _d.type) !== null && _e !== void 0 ? _e : getTypeOfExpressionExpectingType(argList[i].valueExpression).type;
7775
+ const argType = (_g = (_f = argList[i].typeResult) === null || _f === void 0 ? void 0 : _f.type) !== null && _g !== void 0 ? _g : getTypeOfExpressionExpectingType(argList[i].valueExpression).type;
7580
7776
  if ((0, typeUtils_1.requiresSpecialization)(argType, /* ignorePseudoGeneric */ true)) {
7581
- addError(localize_1.Localizer.Diagnostic.typeVarGeneric(), argList[i].valueExpression || errorNode);
7777
+ addError(localize_1.Localizer.Diagnostic.typeVarConstraintGeneric(), argList[i].valueExpression || errorNode);
7582
7778
  }
7583
7779
  types_1.TypeVarType.addConstraint(typeVar, (0, typeUtils_1.convertToInstance)(argType));
7584
7780
  if (firstConstraintArg === undefined) {
@@ -7590,6 +7786,23 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7590
7786
  if (typeVar.details.constraints.length === 1 && firstConstraintArg) {
7591
7787
  addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeVarSingleConstraint(), firstConstraintArg.valueExpression || errorNode);
7592
7788
  }
7789
+ // If a default is provided, make sure it is compatible with the bound
7790
+ // or constraint.
7791
+ if (typeVar.details.defaultType && defaultValueNode) {
7792
+ const typeVarContext = new typeVarContext_1.TypeVarContext(types_1.WildcardTypeVarScopeId);
7793
+ const concreteDefaultType = (0, typeUtils_1.applySolvedTypeVars)(typeVar.details.defaultType, typeVarContext,
7794
+ /* unknownIfNotFound */ true);
7795
+ if (typeVar.details.boundType) {
7796
+ if (!assignType(typeVar.details.boundType, concreteDefaultType)) {
7797
+ addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeVarDefaultBoundMismatch(), defaultValueNode);
7798
+ }
7799
+ }
7800
+ else if (typeVar.details.constraints.length > 0) {
7801
+ if (!typeVar.details.constraints.some((constraint) => (0, types_1.isTypeSame)(constraint, concreteDefaultType))) {
7802
+ addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeVarDefaultConstraintMismatch(), defaultValueNode);
7803
+ }
7804
+ }
7805
+ }
7593
7806
  return typeVar;
7594
7807
  }
7595
7808
  function createTypeVarTupleType(errorNode, argList) {
@@ -7610,12 +7823,33 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7610
7823
  typeVar.details.isVariadic = true;
7611
7824
  // Parse the remaining parameters.
7612
7825
  for (let i = 1; i < argList.length; i++) {
7613
- addError(localize_1.Localizer.Diagnostic.typeVarUnknownParam().format({ name: ((_a = argList[i].name) === null || _a === void 0 ? void 0 : _a.value) || '?' }), ((_b = argList[i].node) === null || _b === void 0 ? void 0 : _b.name) || argList[i].valueExpression || errorNode);
7826
+ const paramNameNode = argList[i].name;
7827
+ const paramName = paramNameNode ? paramNameNode.value : undefined;
7828
+ if (paramName) {
7829
+ if (paramName === 'default') {
7830
+ const expr = argList[i].valueExpression;
7831
+ if (expr) {
7832
+ typeVar.details.defaultType = getTypeVarTupleDefaultType(expr);
7833
+ }
7834
+ }
7835
+ else {
7836
+ addError(localize_1.Localizer.Diagnostic.typeVarTupleUnknownParam().format({ name: ((_a = argList[i].name) === null || _a === void 0 ? void 0 : _a.value) || '?' }), ((_b = argList[i].node) === null || _b === void 0 ? void 0 : _b.name) || argList[i].valueExpression || errorNode);
7837
+ }
7838
+ }
7614
7839
  }
7615
7840
  return typeVar;
7616
7841
  }
7842
+ function getTypeVarTupleDefaultType(node) {
7843
+ const argType = getTypeOfExpressionExpectingType(node, { allowUnpackedTuple: true }).type;
7844
+ const isUnpackedTuple = (0, types_1.isClass)(argType) && (0, typeUtils_1.isTupleClass)(argType) && argType.isUnpacked;
7845
+ const isUnpackedTypeVarTuple = (0, types_1.isUnpackedVariadicTypeVar)(argType);
7846
+ if (!isUnpackedTuple && !isUnpackedTypeVarTuple) {
7847
+ addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeVarTupleDefaultNotUnpacked(), node);
7848
+ return undefined;
7849
+ }
7850
+ return (0, typeUtils_1.convertToInstance)(argType);
7851
+ }
7617
7852
  function createParamSpecType(errorNode, argList) {
7618
- var _a, _b;
7619
7853
  if (argList.length === 0) {
7620
7854
  addError(localize_1.Localizer.Diagnostic.paramSpecFirstArg(), errorNode);
7621
7855
  return undefined;
@@ -7631,8 +7865,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7631
7865
  const paramSpec = types_1.TypeVarType.createInstantiable(paramSpecName, /* isParamSpec */ true);
7632
7866
  // Parse the remaining parameters.
7633
7867
  for (let i = 1; i < argList.length; i++) {
7634
- if ((_a = argList[i].name) === null || _a === void 0 ? void 0 : _a.value) {
7635
- addError(localize_1.Localizer.Diagnostic.paramSpecUnknownParam().format({ name: argList[i].name.value }), ((_b = argList[i].node) === null || _b === void 0 ? void 0 : _b.name) || argList[i].valueExpression || errorNode);
7868
+ const paramNameNode = argList[i].name;
7869
+ const paramName = paramNameNode ? paramNameNode.value : undefined;
7870
+ if (paramName) {
7871
+ if (paramName === 'default') {
7872
+ const expr = argList[i].valueExpression;
7873
+ if (expr) {
7874
+ paramSpec.details.defaultType = getParamSpecDefaultType(expr);
7875
+ }
7876
+ }
7877
+ else {
7878
+ addError(localize_1.Localizer.Diagnostic.paramSpecUnknownParam().format({ name: paramName }), paramNameNode || argList[i].valueExpression || errorNode);
7879
+ }
7636
7880
  }
7637
7881
  else {
7638
7882
  addError(localize_1.Localizer.Diagnostic.paramSpecUnknownArg(), argList[i].valueExpression || errorNode);
@@ -7641,6 +7885,42 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7641
7885
  }
7642
7886
  return paramSpec;
7643
7887
  }
7888
+ function getParamSpecDefaultType(node) {
7889
+ const functionType = types_1.FunctionType.createSynthesizedInstance('', 32768 /* SkipArgsKwargsCompatibilityCheck */ | 65536 /* ParamSpecValue */);
7890
+ types_1.TypeBase.setSpecialForm(functionType);
7891
+ if (node.nodeType === 18 /* Ellipsis */) {
7892
+ types_1.FunctionType.addDefaultParameters(functionType);
7893
+ return functionType;
7894
+ }
7895
+ if (node.nodeType === 52 /* Tuple */) {
7896
+ node.expressions.forEach((paramExpr, index) => {
7897
+ const typeResult = getTypeOfExpressionExpectingType(paramExpr);
7898
+ types_1.FunctionType.addParameter(functionType, {
7899
+ category: 0 /* Simple */,
7900
+ name: `__p${index}`,
7901
+ isNameSynthesized: true,
7902
+ hasDeclaredType: true,
7903
+ type: (0, typeUtils_1.convertToInstance)(typeResult.type),
7904
+ });
7905
+ });
7906
+ // Update the type cache so we don't attempt to re-evaluate this node.
7907
+ // The type doesn't matter, so use Any.
7908
+ writeTypeCache(node, types_1.AnyType.create(), /* flags */ undefined, /* isIncomplete */ false);
7909
+ return functionType;
7910
+ }
7911
+ else {
7912
+ const typeResult = getTypeOfExpressionExpectingType(node, { allowParamSpec: true });
7913
+ if (typeResult.typeErrors) {
7914
+ return undefined;
7915
+ }
7916
+ if ((0, types_1.isParamSpec)(typeResult.type)) {
7917
+ functionType.details.paramSpec = typeResult.type;
7918
+ return functionType;
7919
+ }
7920
+ }
7921
+ addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.paramSpecDefaultNotTuple(), node);
7922
+ return undefined;
7923
+ }
7644
7924
  function getBooleanValue(node) {
7645
7925
  if (node.nodeType === 11 /* Constant */) {
7646
7926
  if (node.constType === 15 /* False */) {
@@ -8166,6 +8446,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8166
8446
  type = mapSubtypesExpandTypeVars(rightType,
8167
8447
  /* conditionFilter */ undefined, (rightSubtypeExpanded, rightSubtypeUnexpanded) => {
8168
8448
  return mapSubtypesExpandTypeVars(concreteLeftType, (0, typeUtils_1.getTypeCondition)(rightSubtypeExpanded), (leftSubtype) => {
8449
+ var _a;
8169
8450
  if ((0, types_1.isAnyOrUnknown)(leftSubtype) || (0, types_1.isAnyOrUnknown)(rightSubtypeUnexpanded)) {
8170
8451
  return (0, typeUtils_1.preserveUnknown)(leftSubtype, rightSubtypeExpanded);
8171
8452
  }
@@ -8174,9 +8455,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8174
8455
  if (!returnType) {
8175
8456
  // If __contains__ was not supported, fall back
8176
8457
  // on an iterable.
8177
- const iteratorType = getTypeOfIterator(rightSubtypeExpanded,
8458
+ const iteratorType = (_a = getTypeOfIterator({ type: rightSubtypeExpanded, isIncomplete: rightTypeResult.isIncomplete },
8178
8459
  /* isAsync */ false,
8179
- /* errorNode */ undefined);
8460
+ /* errorNode */ undefined)) === null || _a === void 0 ? void 0 : _a.type;
8180
8461
  if (iteratorType && assignType(iteratorType, leftSubtype)) {
8181
8462
  returnType = getBuiltInObject(errorNode, 'bool');
8182
8463
  }
@@ -8609,6 +8890,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8609
8890
  isIncomplete = true;
8610
8891
  }
8611
8892
  const keyType = keyTypeResult.type;
8893
+ if (!keyTypeResult.isIncomplete && !keyTypeResult.typeErrors) {
8894
+ verifySetEntryOrDictKeyIsHashable(entryNode.keyExpression, keyType, /* isDictKey */ true);
8895
+ }
8612
8896
  let valueTypeResult;
8613
8897
  if (expectedTypedDictEntries &&
8614
8898
  (0, types_1.isClassInstance)(keyType) &&
@@ -8754,6 +9038,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8754
9038
  expectedType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(expectedType);
8755
9039
  let isIncomplete = false;
8756
9040
  let typeErrors = false;
9041
+ const verifyHashable = node.nodeType === 45 /* Set */;
8757
9042
  if (!(0, types_1.isClassInstance)(expectedType)) {
8758
9043
  return undefined;
8759
9044
  }
@@ -8790,6 +9075,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8790
9075
  if (entryTypeResult.expectedTypeDiagAddendum) {
8791
9076
  expectedTypeDiagAddendum.addAddendum(entryTypeResult.expectedTypeDiagAddendum);
8792
9077
  }
9078
+ if (verifyHashable && !entryTypeResult.isIncomplete && !entryTypeResult.typeErrors) {
9079
+ verifySetEntryOrDictKeyIsHashable(entry, entryTypeResult.type, /* isDictKey */ false);
9080
+ }
8793
9081
  });
8794
9082
  const isExpectedTypeListOrSet = (0, types_1.isClassInstance)(expectedType) && types_1.ClassType.isBuiltIn(expectedType, builtInClassName);
8795
9083
  const specializedEntryType = inferTypeArgFromExpectedType(expectedEntryType, entryTypes,
@@ -8803,6 +9091,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8803
9091
  // Attempts to infer the type of a list or set statement with no "expected type".
8804
9092
  function getTypeOfListOrSetInferred(node, hasExpectedType) {
8805
9093
  const builtInClassName = node.nodeType === 31 /* List */ ? 'list' : 'set';
9094
+ const verifyHashable = node.nodeType === 45 /* Set */;
8806
9095
  let isEmptyContainer = false;
8807
9096
  let isIncomplete = false;
8808
9097
  let typeErrors = false;
@@ -8825,6 +9114,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8825
9114
  if (index < maxEntriesToUseForInference) {
8826
9115
  entryTypes.push(entryTypeResult.type);
8827
9116
  }
9117
+ if (verifyHashable && !entryTypeResult.isIncomplete && !entryTypeResult.typeErrors) {
9118
+ verifySetEntryOrDictKeyIsHashable(entry, entryTypeResult.type, /* isDictKey */ false);
9119
+ }
8828
9120
  });
8829
9121
  entryTypes = entryTypes.map((t) => stripLiteralValue(t));
8830
9122
  let inferredEntryType = hasExpectedType ? types_1.AnyType.create() : types_1.UnknownType.create();
@@ -8856,6 +9148,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8856
9148
  : types_1.UnknownType.create();
8857
9149
  return { type, isIncomplete, typeErrors };
8858
9150
  }
9151
+ function verifySetEntryOrDictKeyIsHashable(entry, type, isDictKey) {
9152
+ // Verify that the type is hashable.
9153
+ if (!isTypeHashable(type)) {
9154
+ const fileInfo = AnalyzerNodeInfo.getFileInfo(entry);
9155
+ const diag = new diagnostic_1.DiagnosticAddendum();
9156
+ diag.addMessage(localize_1.Localizer.DiagnosticAddendum.unhashableType().format({ type: printType(type) }));
9157
+ const message = isDictKey
9158
+ ? localize_1.Localizer.Diagnostic.unhashableDictKey()
9159
+ : localize_1.Localizer.Diagnostic.unhashableSetEntry();
9160
+ addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, message + diag.getString(), entry);
9161
+ }
9162
+ }
8859
9163
  function inferTypeArgFromExpectedType(expectedType, entryTypes, isNarrowable) {
8860
9164
  let targetTypeVar;
8861
9165
  let useSynthesizedTypeVar = false;
@@ -8956,8 +9260,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8956
9260
  return { type: sentType || types_1.UnknownType.create(), isIncomplete };
8957
9261
  }
8958
9262
  function getTypeOfYieldFrom(node) {
8959
- var _a;
8960
- const yieldFromType = getTypeOfExpression(node.expression).type;
9263
+ var _a, _b;
9264
+ const yieldFromTypeResult = getTypeOfExpression(node.expression);
9265
+ const yieldFromType = yieldFromTypeResult.type;
8961
9266
  let generatorTypeArgs = (0, typeUtils_1.getGeneratorTypeArgs)(yieldFromType);
8962
9267
  let returnedType;
8963
9268
  // Is the expression a Generator type?
@@ -8969,7 +9274,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8969
9274
  returnedType = types_1.UnknownType.create();
8970
9275
  }
8971
9276
  else {
8972
- const iterableType = (_a = getTypeOfIterable(yieldFromType, /* isAsync */ false, node)) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
9277
+ const iterableType = (_b = (_a = getTypeOfIterable(yieldFromTypeResult, /* isAsync */ false, node)) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : types_1.UnknownType.create();
8973
9278
  // Does the iterable return a Generator?
8974
9279
  generatorTypeArgs = (0, typeUtils_1.getGeneratorTypeArgs)(iterableType);
8975
9280
  if (generatorTypeArgs) {
@@ -9006,9 +9311,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9006
9311
  // Remove any expected subtypes that don't satisfy the minimum
9007
9312
  // parameter count requirement.
9008
9313
  expectedFunctionTypes = expectedFunctionTypes.filter((functionType) => {
9009
- const params = types_1.FunctionType.getFunctionParameters(functionType);
9010
- const functionParamCount = params.filter((param) => !param.hasDefault).length;
9011
- const hasVarArgs = params.some((param) => param.category !== 0 /* Simple */);
9314
+ const functionParamCount = functionType.details.parameters.filter((param) => !!param.name && !param.hasDefault).length;
9315
+ const hasVarArgs = functionType.details.parameters.some((param) => !!param.name && param.category !== 0 /* Simple */);
9012
9316
  return (hasVarArgs ||
9013
9317
  (functionParamCount >= minLambdaParamCount && functionParamCount <= maxLambdaParamCount));
9014
9318
  });
@@ -9099,6 +9403,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9099
9403
  return { type: functionType, isIncomplete };
9100
9404
  }
9101
9405
  function getTypeOfListComprehension(node, expectedType) {
9406
+ var _a;
9102
9407
  let isIncomplete = false;
9103
9408
  let typeErrors = false;
9104
9409
  let isAsync = node.forIfNodes.some((comp) => {
@@ -9112,7 +9417,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9112
9417
  }
9113
9418
  let expectedElementType;
9114
9419
  if (expectedType) {
9115
- expectedElementType = getTypeOfIterator(expectedType, isAsync, /* errorNode */ undefined);
9420
+ expectedElementType = (_a = getTypeOfIterator({ type: expectedType }, isAsync, /* errorNode */ undefined)) === null || _a === void 0 ? void 0 : _a.type;
9116
9421
  }
9117
9422
  const elementTypeResult = getElementTypeFromListComprehension(node, expectedElementType);
9118
9423
  if (elementTypeResult.isIncomplete) {
@@ -9160,7 +9465,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9160
9465
  const diagAddendum = new diagnostic_1.DiagnosticAddendum();
9161
9466
  diagAddendum.addMessage(localize_1.Localizer.DiagnosticAddendum.typeOfSymbol().format({
9162
9467
  name: nameValue,
9163
- type: printType(simplifiedType, /* expandTypeAlias */ true),
9468
+ type: printType(simplifiedType, { expandTypeAlias: true }),
9164
9469
  }));
9165
9470
  addDiagnostic(diagLevel, rule, localize_1.Localizer.Diagnostic.typePartiallyUnknown().format({ name: nameValue }) + diagAddendum.getString(), errorNode);
9166
9471
  }
@@ -9175,9 +9480,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9175
9480
  isIncomplete = true;
9176
9481
  }
9177
9482
  const iterableType = stripLiteralValue(iterableTypeResult.type);
9178
- const itemType = (_a = getTypeOfIterator(iterableType, !!node.isAsync, node.iterableExpression)) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
9483
+ const itemTypeResult = (_a = getTypeOfIterator({ type: iterableType, isIncomplete: iterableTypeResult.isIncomplete }, !!node.isAsync, node.iterableExpression)) !== null && _a !== void 0 ? _a : { type: types_1.UnknownType.create(), isIncomplete: iterableTypeResult.isIncomplete };
9179
9484
  const targetExpr = node.targetExpression;
9180
- assignTypeToExpression(targetExpr, itemType, !!iterableTypeResult.isIncomplete, node.iterableExpression);
9485
+ assignTypeToExpression(targetExpr, itemTypeResult.type, !!itemTypeResult.isIncomplete, node.iterableExpression);
9181
9486
  }
9182
9487
  else {
9183
9488
  (0, debug_1.assert)(node.nodeType === 34 /* ListComprehensionIf */);
@@ -9907,7 +10212,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9907
10212
  else {
9908
10213
  // If this is an unpacked TypeVar, note that it is in a union so we can differentiate
9909
10214
  // between Unpack[Vs] and Union[Unpack[Vs]].
9910
- if ((0, types_1.isTypeVar)(typeArgType) && (0, types_1.isVariadicTypeVar)(typeArgType) && typeArgType.isVariadicUnpacked) {
10215
+ if ((0, types_1.isTypeVar)(typeArgType) && (0, types_1.isUnpackedVariadicTypeVar)(typeArgType)) {
9911
10216
  typeArgType = types_1.TypeVarType.cloneForUnpacked(typeArgType, /* isInUnion */ true);
9912
10217
  }
9913
10218
  types.push(typeArgType);
@@ -10201,7 +10506,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
10201
10506
  /* honorCodeFlow */ false);
10202
10507
  if (symbolWithScope) {
10203
10508
  const decls = symbolWithScope.symbol.getDeclarations();
10204
- if (decls.length === 1 && (0, declarationUtils_1.isPossibleTypeAliasDeclaration)(decls[0])) {
10509
+ if (decls.length === 1 && isPossibleTypeAliasOrTypedDict(decls[0])) {
10205
10510
  typeAliasNameNode = node.leftExpression;
10206
10511
  isSpeculativeTypeAlias = true;
10207
10512
  }
@@ -10296,6 +10601,33 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
10296
10601
  /* allowAssignmentToFinalVar */ true, expectedTypeDiagAddendum);
10297
10602
  writeTypeCache(node, rightHandType, 0 /* None */, isIncomplete);
10298
10603
  }
10604
+ function isPossibleTypeAliasOrTypedDict(decl) {
10605
+ var _a;
10606
+ if ((0, declarationUtils_1.isPossibleTypeAliasDeclaration)(decl)) {
10607
+ return true;
10608
+ }
10609
+ if (decl.type === 1 /* Variable */ &&
10610
+ decl.node.parent &&
10611
+ decl.node.parent.nodeType === 3 /* Assignment */ &&
10612
+ ((_a = decl.node.parent.rightExpression) === null || _a === void 0 ? void 0 : _a.nodeType) === 9 /* Call */) {
10613
+ const callLeftNode = decl.node.parent.rightExpression.leftExpression;
10614
+ // Use a simple heuristic to determine whether this is potentially
10615
+ // a call to the TypedDict call. This avoids the expensive (and potentially
10616
+ // recursive) call to getTypeOfExpression in cases where it's not needed.
10617
+ if ((callLeftNode.nodeType === 38 /* Name */ && callLeftNode.value) === 'TypedDict' ||
10618
+ (callLeftNode.nodeType === 35 /* MemberAccess */ &&
10619
+ callLeftNode.memberName.value === 'TypedDict' &&
10620
+ callLeftNode.leftExpression.nodeType === 38 /* Name */)) {
10621
+ // See if this is a call to TypedDict. We want to support
10622
+ // recursive type references in a TypedDict call.
10623
+ const callType = getTypeOfExpression(callLeftNode, 2 /* DoNotSpecialize */).type;
10624
+ if ((0, types_1.isInstantiableClass)(callType) && types_1.ClassType.isBuiltIn(callType, 'TypedDict')) {
10625
+ return true;
10626
+ }
10627
+ }
10628
+ }
10629
+ return false;
10630
+ }
10299
10631
  // Evaluates the type of a type alias (i.e. "type") statement. This code
10300
10632
  // path does not handle traditional type aliases, which are treated as
10301
10633
  // variables since they use normal variable assignment syntax.
@@ -10765,7 +11097,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
10765
11097
  }
10766
11098
  if (dataClassBehaviors) {
10767
11099
  (0, dataClasses_1.applyDataClassDefaultBehaviors)(classType, dataClassBehaviors);
10768
- (0, dataClasses_1.applyDataClassClassBehaviorOverrides)(evaluatorInterface, classType, initSubclassArgs);
11100
+ (0, dataClasses_1.applyDataClassClassBehaviorOverrides)(evaluatorInterface, node.name, classType, initSubclassArgs);
10769
11101
  }
10770
11102
  // Run any class hooks that depend on this class.
10771
11103
  runClassTypeHooks(classType);
@@ -11002,7 +11334,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11002
11334
  if ((0, types_1.isOverloadedFunction)(decoratorType)) {
11003
11335
  const dataclassBehaviors = (0, dataClasses_1.getDataclassDecoratorBehaviors)(decoratorType);
11004
11336
  if (dataclassBehaviors) {
11005
- (0, dataClasses_1.applyDataClassDecorator)(evaluatorInterface, originalClassType, dataclassBehaviors,
11337
+ (0, dataClasses_1.applyDataClassDecorator)(evaluatorInterface, decoratorNode, originalClassType, dataclassBehaviors,
11006
11338
  /* callNode */ undefined);
11007
11339
  return inputClassType;
11008
11340
  }
@@ -11035,7 +11367,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11035
11367
  dataclassBehaviors = (0, dataClasses_1.getDataclassDecoratorBehaviors)(decoratorType);
11036
11368
  }
11037
11369
  if (dataclassBehaviors) {
11038
- (0, dataClasses_1.applyDataClassDecorator)(evaluatorInterface, originalClassType, dataclassBehaviors, callNode);
11370
+ (0, dataClasses_1.applyDataClassDecorator)(evaluatorInterface, decoratorNode, originalClassType, dataclassBehaviors, callNode);
11039
11371
  return inputClassType;
11040
11372
  }
11041
11373
  }
@@ -11589,9 +11921,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11589
11921
  if (paramValueExpr) {
11590
11922
  const defaultValueType = getTypeOfExpression(paramValueExpr, 1 /* ConvertEllipsisToAny */).type;
11591
11923
  let inferredParamType;
11592
- if ((0, types_1.isNoneInstance)(defaultValueType)) {
11593
- // Infer Optional[Unknown] in this case.
11594
- inferredParamType = (0, types_1.combineTypes)([types_1.NoneType.createInstance(), types_1.UnknownType.create()]);
11924
+ // Is the default value a "None" or an instance of some private class (one
11925
+ // whose name starts with an underscore)? If so, we will assume that the
11926
+ // value is a singleton sentinel. The actual supported type is going to be
11927
+ // a union of this type and Unknown.
11928
+ if ((0, types_1.isNoneInstance)(defaultValueType) ||
11929
+ ((0, types_1.isClassInstance)(defaultValueType) && (0, symbolNameUtils_1.isPrivateOrProtectedName)(defaultValueType.details.name))) {
11930
+ inferredParamType = (0, types_1.combineTypes)([defaultValueType, types_1.UnknownType.create()]);
11595
11931
  }
11596
11932
  else {
11597
11933
  // Do not infer certain types like tuple because it's likely to be
@@ -11683,6 +12019,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11683
12019
  else if (decoratorType.details.builtInName === 'final') {
11684
12020
  flags |= 8192 /* Final */;
11685
12021
  }
12022
+ else if (decoratorType.details.builtInName === 'override') {
12023
+ flags |= 262144 /* Overridden */;
12024
+ }
11686
12025
  }
11687
12026
  else if ((0, types_1.isInstantiableClass)(decoratorType)) {
11688
12027
  if (types_1.ClassType.isBuiltIn(decoratorType, 'staticmethod')) {
@@ -12009,18 +12348,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12009
12348
  let useAwaitableGenerator = false;
12010
12349
  if (functionDecl.yieldStatements) {
12011
12350
  functionDecl.yieldStatements.forEach((yieldNode) => {
12351
+ var _a;
12012
12352
  if (isNodeReachable(yieldNode)) {
12013
12353
  if (yieldNode.nodeType === 61 /* YieldFrom */) {
12014
- const iteratorType = getTypeOfExpression(yieldNode.expression).type;
12015
- if ((0, types_1.isClassInstance)(iteratorType) &&
12016
- types_1.ClassType.isBuiltIn(iteratorType, 'Coroutine')) {
12354
+ const iteratorTypeResult = getTypeOfExpression(yieldNode.expression);
12355
+ if ((0, types_1.isClassInstance)(iteratorTypeResult.type) &&
12356
+ types_1.ClassType.isBuiltIn(iteratorTypeResult.type, 'Coroutine')) {
12017
12357
  // Handle old-style (pre-await) Coroutines.
12018
12358
  inferredYieldTypes.push();
12019
12359
  useAwaitableGenerator = true;
12020
12360
  }
12021
12361
  else {
12022
- const yieldType = getTypeOfIterator(iteratorType,
12023
- /* isAsync */ false, yieldNode);
12362
+ const yieldType = (_a = getTypeOfIterator(iteratorTypeResult,
12363
+ /* isAsync */ false, yieldNode)) === null || _a === void 0 ? void 0 : _a.type;
12024
12364
  inferredYieldTypes.push(yieldType !== null && yieldType !== void 0 ? yieldType : types_1.UnknownType.create());
12025
12365
  }
12026
12366
  }
@@ -12093,12 +12433,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12093
12433
  return true;
12094
12434
  }
12095
12435
  function evaluateTypesForForStatement(node) {
12096
- var _a;
12436
+ var _a, _b;
12097
12437
  if (readTypeCache(node, 0 /* None */)) {
12098
12438
  return;
12099
12439
  }
12100
12440
  const iteratorTypeResult = getTypeOfExpression(node.iterableExpression);
12101
- const iteratedType = (_a = getTypeOfIterator(iteratorTypeResult.type, !!node.isAsync, node.iterableExpression)) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
12441
+ const iteratedType = (_b = (_a = getTypeOfIterator(iteratorTypeResult, !!node.isAsync, node.iterableExpression)) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : types_1.UnknownType.create();
12102
12442
  assignTypeToExpression(node.targetExpression, iteratedType, !!iteratorTypeResult.isIncomplete, node.targetExpression);
12103
12443
  writeTypeCache(node, iteratedType, 0 /* None */, !!iteratorTypeResult.isIncomplete);
12104
12444
  }
@@ -12108,9 +12448,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12108
12448
  if (readTypeCache(node, 0 /* None */)) {
12109
12449
  return;
12110
12450
  }
12111
- const exceptionTypes = getTypeOfExpression(node.typeExpression).type;
12451
+ const exceptionTypeResult = getTypeOfExpression(node.typeExpression);
12452
+ const exceptionTypes = exceptionTypeResult.type;
12112
12453
  function getExceptionType(exceptionType, errorNode) {
12113
- var _a;
12454
+ var _a, _b;
12114
12455
  exceptionType = makeTopLevelTypeVarsConcrete(exceptionType);
12115
12456
  if ((0, types_1.isAnyOrUnknown)(exceptionType)) {
12116
12457
  return exceptionType;
@@ -12119,7 +12460,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12119
12460
  return types_1.ClassType.cloneAsInstance(exceptionType);
12120
12461
  }
12121
12462
  if ((0, types_1.isClassInstance)(exceptionType)) {
12122
- const iterableType = (_a = getTypeOfIterator(exceptionType, /* isAsync */ false, errorNode)) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
12463
+ const iterableType = (_b = (_a = getTypeOfIterator({ type: exceptionType, isIncomplete: exceptionTypeResult.isIncomplete },
12464
+ /* isAsync */ false, errorNode)) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : types_1.UnknownType.create();
12123
12465
  return (0, typeUtils_1.mapSubtypes)(iterableType, (subtype) => {
12124
12466
  if ((0, types_1.isAnyOrUnknown)(subtype)) {
12125
12467
  return subtype;
@@ -12165,32 +12507,24 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12165
12507
  // Verify that the target has an __enter__ or __aenter__ method defined.
12166
12508
  const enterMethodName = isAsync ? '__aenter__' : '__enter__';
12167
12509
  const scopedType = (0, typeUtils_1.mapSubtypes)(exprType, (subtype) => {
12168
- var _a;
12169
12510
  subtype = makeTopLevelTypeVarsConcrete(subtype);
12170
12511
  if ((0, types_1.isAnyOrUnknown)(subtype)) {
12171
12512
  return subtype;
12172
12513
  }
12173
- const diag = new diagnostic_1.DiagnosticAddendum();
12174
12514
  const additionalHelp = new diagnostic_1.DiagnosticAddendum();
12175
- if ((0, types_1.isClassInstance)(subtype)) {
12176
- const enterType = (_a = getTypeOfObjectMember(node.expression, subtype, enterMethodName, { method: 'get' }, diag)) === null || _a === void 0 ? void 0 : _a.type;
12515
+ if ((0, types_1.isClass)(subtype)) {
12516
+ let enterType = getTypeOfMagicMethodReturn(subtype, [], enterMethodName, node.expression,
12517
+ /* expectedType */ undefined);
12177
12518
  if (enterType) {
12178
- let memberReturnType;
12179
- if ((0, types_1.isFunction)(enterType)) {
12180
- memberReturnType = getFunctionEffectiveReturnType(enterType);
12181
- }
12182
- else {
12183
- memberReturnType = types_1.UnknownType.create();
12184
- }
12185
12519
  // For "async while", an implicit "await" is performed.
12186
12520
  if (isAsync) {
12187
- memberReturnType = getTypeOfAwaitable(memberReturnType, node.expression);
12521
+ enterType = getTypeOfAwaitable(enterType, node.expression);
12188
12522
  }
12189
- return memberReturnType;
12523
+ return enterType;
12190
12524
  }
12191
12525
  if (!isAsync) {
12192
- const memberType = getTypeOfObjectMember(node.expression, subtype, '__aenter__', { method: 'get' }, diag);
12193
- if (memberType) {
12526
+ if (getTypeOfMagicMethodReturn(subtype, [], '__aenter__', node.expression,
12527
+ /* expectedType */ undefined)) {
12194
12528
  additionalHelp.addMessage(localize_1.Localizer.DiagnosticAddendum.asyncHelp());
12195
12529
  }
12196
12530
  }
@@ -12207,9 +12541,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12207
12541
  if ((0, types_1.isAnyOrUnknown)(subtype)) {
12208
12542
  return;
12209
12543
  }
12210
- const diag = new diagnostic_1.DiagnosticAddendum();
12211
- if ((0, types_1.isClassInstance)(subtype)) {
12212
- const exitType = getTypeOfObjectMember(node.expression, subtype, exitMethodName, { method: 'get' }, diag);
12544
+ if ((0, types_1.isClass)(subtype)) {
12545
+ const anyArg = { type: types_1.AnyType.create() };
12546
+ const exitType = getTypeOfMagicMethodReturn(subtype, [anyArg, anyArg, anyArg], exitMethodName, node.expression,
12547
+ /* expectedType */ undefined);
12213
12548
  if (exitType) {
12214
12549
  return;
12215
12550
  }
@@ -12521,6 +12856,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12521
12856
  }
12522
12857
  getTypeOfAnnotation(annotationNode, {
12523
12858
  isVariableAnnotation: ((_a = annotationNode.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 54 /* TypeAnnotation */,
12859
+ allowUnpackedTuple: annotationParent.nodeType === 41 /* Parameter */ &&
12860
+ annotationParent.category === 1 /* VarArgList */,
12861
+ allowUnpackedTypedDict: annotationParent.nodeType === 41 /* Parameter */ &&
12862
+ annotationParent.category === 2 /* VarArgDictionary */,
12524
12863
  });
12525
12864
  return;
12526
12865
  }
@@ -12581,6 +12920,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12581
12920
  break;
12582
12921
  }
12583
12922
  }
12923
+ else if (parent.nodeType === 48 /* StringList */ && nodeToEvaluate === parent.typeAnnotation) {
12924
+ // Forward-declared type annotation expressions need to be be evaluated
12925
+ // in context so they have the appropriate flags set. Most of these cases
12926
+ // will have been detected above when calling getParentAnnotationNode,
12927
+ // but TypeAlias expressions are not handled there.
12928
+ nodeToEvaluate = parent;
12929
+ continue;
12930
+ }
12584
12931
  else {
12585
12932
  // Check for expression types that are always contextual.
12586
12933
  if (nodeToEvaluate.nodeType !== 15 /* Dictionary */ &&
@@ -12896,17 +13243,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12896
13243
  }
12897
13244
  // Attempts to determine the type of the reference expression at the
12898
13245
  // point in the code. If the code flow analysis has nothing to say
12899
- // about that expression, it return undefined. Normally flow analysis
12900
- // starts from the reference node, but startNode can be specified to
12901
- // override this in a few special cases (functions and lambdas) to
12902
- // support analysis of captured variables.
12903
- function getFlowTypeOfReference(reference, targetSymbolId, initialType, startNode, options) {
13246
+ // about that expression, it returns un undefined type. Normally
13247
+ // flow analysis starts from the reference node, but startNode can be
13248
+ // specified to override this in a few special cases (functions and
13249
+ // lambdas) to support analysis of captured variables.
13250
+ function getFlowTypeOfReference(reference, targetSymbolId, typeAtStart, startNode, options) {
12904
13251
  var _a;
12905
13252
  // See if this execution scope requires code flow for this reference expression.
12906
13253
  const referenceKey = (0, codeFlowTypes_1.createKeyForReference)(reference);
12907
13254
  const executionNode = ParseTreeUtils.getExecutionScopeNode((_a = startNode === null || startNode === void 0 ? void 0 : startNode.parent) !== null && _a !== void 0 ? _a : reference);
12908
13255
  const codeFlowExpressions = AnalyzerNodeInfo.getCodeFlowExpressions(executionNode);
12909
- if (!codeFlowExpressions || !codeFlowExpressions.has(referenceKey)) {
13256
+ if (!codeFlowExpressions ||
13257
+ (!codeFlowExpressions.has(referenceKey) && !codeFlowExpressions.has(codeFlowTypes_1.wildcardImportReferenceKey))) {
12910
13258
  return { type: undefined, isIncomplete: false };
12911
13259
  }
12912
13260
  if (checkCodeFlowTooComplex(reference)) {
@@ -12928,7 +13276,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12928
13276
  if (flowNode === undefined) {
12929
13277
  return { type: undefined, isIncomplete: false };
12930
13278
  }
12931
- return analyzer.getTypeFromCodeFlow(flowNode, reference, targetSymbolId, initialType, options);
13279
+ return analyzer.getTypeFromCodeFlow(flowNode, reference, targetSymbolId, typeAtStart, options);
12932
13280
  }
12933
13281
  // Specializes the specified (potentially generic) class type using
12934
13282
  // the specified type arguments, reporting errors as appropriate.
@@ -13061,6 +13409,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
13061
13409
  }
13062
13410
  const variadicTypeParamIndex = typeParameters.findIndex((param) => (0, types_1.isVariadicTypeVar)(param));
13063
13411
  if (typeArgs) {
13412
+ let minTypeArgCount = typeParameters.length;
13413
+ const firstNonDefaultParam = typeParameters.findIndex((param) => !!param.details.defaultType);
13414
+ if (firstNonDefaultParam >= 0) {
13415
+ minTypeArgCount = firstNonDefaultParam;
13416
+ }
13064
13417
  if (typeArgCount > typeParameters.length) {
13065
13418
  if (!types_1.ClassType.isPartiallyEvaluated(classType) && !types_1.ClassType.isTupleClass(classType)) {
13066
13419
  const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
@@ -13079,11 +13432,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
13079
13432
  typeArgCount = typeParameters.length;
13080
13433
  }
13081
13434
  }
13082
- else if (typeArgCount < typeParameters.length) {
13435
+ else if (typeArgCount < minTypeArgCount) {
13083
13436
  const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
13084
13437
  addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeArgsTooFew().format({
13085
13438
  name: classType.aliasName || classType.details.name,
13086
- expected: typeParameters.length,
13439
+ expected: minTypeArgCount,
13087
13440
  received: typeArgCount,
13088
13441
  }), typeArgs.length > 0 ? typeArgs[0].node.parent : errorNode);
13089
13442
  }
@@ -13141,6 +13494,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
13141
13494
  }
13142
13495
  }
13143
13496
  fullTypeParams.forEach((typeParam, index) => {
13497
+ var _a;
13144
13498
  if (typeArgs && index < typeArgs.length) {
13145
13499
  if (typeParam.details.isParamSpec) {
13146
13500
  const typeArg = typeArgs[index];
@@ -13192,7 +13546,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
13192
13546
  typeArgTypes.push((0, typeUtils_1.convertToInstance)(typeArgs[index].type));
13193
13547
  return;
13194
13548
  }
13195
- typeArgTypes.push(types_1.UnknownType.create());
13549
+ typeArgTypes.push((_a = typeParam.details.defaultType) !== null && _a !== void 0 ? _a : types_1.UnknownType.create());
13196
13550
  });
13197
13551
  typeArgTypes = typeArgTypes.map((typeArgType, index) => {
13198
13552
  if (index < typeArgCount) {
@@ -13201,19 +13555,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
13201
13555
  // Determine if the variance must match.
13202
13556
  if (adjustedTypeArgType && (flags & 16384 /* EnforceTypeVarVarianceConsistency */) !== 0) {
13203
13557
  const destType = typeParameters[index];
13204
- if ((0, types_1.isTypeVar)(adjustedTypeArgType) &&
13205
- !adjustedTypeArgType.details.isParamSpec &&
13206
- !adjustedTypeArgType.details.isVariadic &&
13207
- destType.details.declaredVariance !== 0 /* Auto */ &&
13208
- adjustedTypeArgType.details.declaredVariance !== 0 /* Auto */) {
13209
- if (adjustedTypeArgType.details.declaredVariance !== 2 /* Invariant */ &&
13210
- adjustedTypeArgType.details.declaredVariance !== destType.details.declaredVariance) {
13211
- diag.addMessage(localize_1.Localizer.DiagnosticAddendum.varianceMismatch().format({
13212
- typeVarName: printType(adjustedTypeArgType),
13213
- className: classType.details.name,
13214
- }));
13215
- adjustedTypeArgType = undefined;
13216
- }
13558
+ const declaredVariance = destType.details.declaredVariance;
13559
+ if (!(0, typeUtils_1.isVarianceOfTypeArgumentCompatible)(adjustedTypeArgType, declaredVariance)) {
13560
+ diag.addMessage(localize_1.Localizer.DiagnosticAddendum.varianceMismatch().format({
13561
+ typeVarName: printType(adjustedTypeArgType),
13562
+ className: classType.details.name,
13563
+ }));
13564
+ adjustedTypeArgType = undefined;
13217
13565
  }
13218
13566
  }
13219
13567
  if (adjustedTypeArgType) {
@@ -13265,11 +13613,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
13265
13613
  // be a value expression from which we can retrieve the type.
13266
13614
  return getTypeOfExpressionExpectingType(arg.valueExpression);
13267
13615
  }
13268
- function getTypeOfExpressionExpectingType(node, allowFinal = false, allowRequired = false) {
13616
+ function getTypeOfExpressionExpectingType(node, options) {
13269
13617
  let flags = 64 /* ExpectingType */ |
13270
13618
  8 /* EvaluateStringLiteralAsType */ |
13271
- 32 /* ParamSpecDisallowed */ |
13272
- 128 /* TypeVarTupleDisallowed */ |
13273
13619
  131072 /* ClassVarDisallowed */;
13274
13620
  const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
13275
13621
  if (fileInfo.isStubFile) {
@@ -13278,12 +13624,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
13278
13624
  else {
13279
13625
  flags |= 4194304 /* InterpreterParsesStringLiteral */;
13280
13626
  }
13281
- if (!allowFinal) {
13627
+ if (!(options === null || options === void 0 ? void 0 : options.allowFinal)) {
13282
13628
  flags |= 16 /* FinalDisallowed */;
13283
13629
  }
13284
- if (allowRequired) {
13630
+ if (options === null || options === void 0 ? void 0 : options.allowRequired) {
13285
13631
  flags |= 1048576 /* RequiredAllowed */ | 1024 /* ExpectingTypeAnnotation */;
13286
13632
  }
13633
+ if (options === null || options === void 0 ? void 0 : options.allowUnpackedTuple) {
13634
+ flags |= 2097152 /* AllowUnpackedTupleOrTypeVarTuple */;
13635
+ }
13636
+ else {
13637
+ flags |= 128 /* TypeVarTupleDisallowed */;
13638
+ }
13639
+ if (!(options === null || options === void 0 ? void 0 : options.allowParamSpec)) {
13640
+ flags |= 32 /* ParamSpecDisallowed */;
13641
+ }
13287
13642
  return getTypeOfExpression(node, flags);
13288
13643
  }
13289
13644
  function getBuiltInType(node, name) {
@@ -13487,6 +13842,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
13487
13842
  }
13488
13843
  return declarations.length === 0 ? undefined : declarations;
13489
13844
  }
13845
+ function getAliasFromImport(node) {
13846
+ if (node.parent &&
13847
+ node.parent.nodeType === 23 /* ImportFromAs */ &&
13848
+ node.parent.alias &&
13849
+ node === node.parent.name) {
13850
+ return node.parent.alias;
13851
+ }
13852
+ return undefined;
13853
+ }
13490
13854
  function getDeclarationsForNameNode(node, skipUnreachableCode = true) {
13491
13855
  var _a;
13492
13856
  if (skipUnreachableCode && AnalyzerNodeInfo.isCodeUnreachable(node)) {
@@ -13496,14 +13860,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
13496
13860
  // If the node is part of a "from X import Y as Z" statement and the node
13497
13861
  // is the "Y" (non-aliased) name, we need to look up the alias symbol
13498
13862
  // since the non-aliased name is not in the symbol table.
13499
- if (node.parent &&
13500
- node.parent.nodeType === 23 /* ImportFromAs */ &&
13501
- node.parent.alias &&
13502
- node === node.parent.name) {
13863
+ const alias = getAliasFromImport(node);
13864
+ if (alias) {
13503
13865
  const scope = ScopeUtils.getScopeForNode(node);
13504
13866
  if (scope) {
13505
13867
  // Look up the alias symbol.
13506
- const symbolInScope = scope.lookUpSymbolRecursive(node.parent.alias.value);
13868
+ const symbolInScope = scope.lookUpSymbolRecursive(alias.value);
13507
13869
  if (symbolInScope) {
13508
13870
  // The alias could have more decls that don't refer to this import. Filter
13509
13871
  // out the one(s) that specifically associated with this import statement.
@@ -13616,7 +13978,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
13616
13978
  if (paramDecl) {
13617
13979
  declarations.push(paramDecl);
13618
13980
  }
13619
- else if (types_1.ClassType.isDataClass(baseType)) {
13981
+ else if (types_1.ClassType.isDataClass(baseType) || types_1.ClassType.isTypedDictClass(baseType)) {
13620
13982
  const lookupResults = (0, typeUtils_1.lookUpClassMember)(baseType, paramName);
13621
13983
  if (lookupResults) {
13622
13984
  (0, collectionUtils_1.appendArray)(declarations, lookupResults.symbol.getDeclarations());
@@ -13736,7 +14098,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
13736
14098
  const constraints = declaration.node.boundExpression.expressions.map((constraint) => {
13737
14099
  const constraintType = getTypeOfExpressionExpectingType(constraint).type;
13738
14100
  if ((0, typeUtils_1.requiresSpecialization)(constraintType, /* ignorePseudoGeneric */ true)) {
13739
- addError(localize_1.Localizer.Diagnostic.typeVarGeneric(), constraint);
14101
+ addError(localize_1.Localizer.Diagnostic.typeVarBoundGeneric(), constraint);
13740
14102
  }
13741
14103
  return (0, typeUtils_1.convertToInstance)(constraintType);
13742
14104
  });
@@ -13751,13 +14113,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
13751
14113
  else {
13752
14114
  const boundType = getTypeOfExpressionExpectingType(declaration.node.boundExpression).type;
13753
14115
  if ((0, typeUtils_1.requiresSpecialization)(boundType, /* ignorePseudoGeneric */ true)) {
13754
- addError(localize_1.Localizer.Diagnostic.typeVarGeneric(), declaration.node.boundExpression);
14116
+ addError(localize_1.Localizer.Diagnostic.typeVarConstraintGeneric(), declaration.node.boundExpression);
13755
14117
  }
13756
14118
  if (declaration.node.typeParamCategory === parseNodes_1.TypeParameterCategory.TypeVar) {
13757
14119
  typeVar.details.boundType = (0, typeUtils_1.convertToInstance)(boundType);
13758
14120
  }
13759
14121
  }
13760
14122
  }
14123
+ if (declaration.node.defaultExpression) {
14124
+ // TODO - need to finish. For now, just evaluate the expression
14125
+ // to generate any errors.
14126
+ getTypeOfExpression(declaration.node.defaultExpression, 2097152 /* AllowUnpackedTupleOrTypeVarTuple */);
14127
+ }
13761
14128
  typeVar.details.isTypeParamSyntax = true;
13762
14129
  // Associate the type variable with the owning scope.
13763
14130
  const scopeNode = ParseTreeUtils.getTypeVarScopeNode(declaration.node);
@@ -13787,9 +14154,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
13787
14154
  : undefined;
13788
14155
  let declaredType;
13789
14156
  if (declaration.isRuntimeTypeExpression) {
13790
- declaredType = (0, typeUtils_1.convertToInstance)(getTypeOfExpressionExpectingType(typeAnnotationNode,
13791
- /* allowFinal */ true,
13792
- /* allowRequired */ true).type);
14157
+ declaredType = (0, typeUtils_1.convertToInstance)(getTypeOfExpressionExpectingType(typeAnnotationNode, {
14158
+ allowFinal: true,
14159
+ allowRequired: true,
14160
+ }).type);
13793
14161
  }
13794
14162
  else {
13795
14163
  const declNode = declaration.isDefinedByMemberAccess &&
@@ -14083,6 +14451,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14083
14451
  const decls = symbol.getDeclarations();
14084
14452
  const isFinalVar = (0, symbolUtils_1.isFinalVariable)(symbol);
14085
14453
  let isIncomplete = false;
14454
+ let sawPendingEvaluation = false;
14086
14455
  let includesVariableDecl = false;
14087
14456
  let includesSpeculativeResult = false;
14088
14457
  let declIndexToConsider;
@@ -14131,7 +14500,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14131
14500
  }
14132
14501
  if (considerDecl) {
14133
14502
  const isExplicitTypeAlias = (0, declarationUtils_1.isExplicitTypeAliasDeclaration)(decl);
14134
- const isTypeAlias = isExplicitTypeAlias || (0, declarationUtils_1.isPossibleTypeAliasDeclaration)(decl);
14503
+ const isTypeAlias = isExplicitTypeAlias || isPossibleTypeAliasOrTypedDict(decl);
14135
14504
  if (isExplicitTypeAlias) {
14136
14505
  sawExplicitTypeAlias = true;
14137
14506
  }
@@ -14201,13 +14570,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14201
14570
  }
14202
14571
  }
14203
14572
  isIncomplete = true;
14573
+ // Note that at least one decl could not be evaluated because
14574
+ // it was already in the process of being evaluated.
14575
+ sawPendingEvaluation = true;
14204
14576
  }
14205
14577
  }
14206
14578
  });
14207
14579
  if (typesToCombine.length > 0) {
14208
14580
  const result = {
14209
14581
  type: (0, types_1.combineTypes)(typesToCombine),
14210
- isIncomplete: false,
14582
+ isIncomplete: sawPendingEvaluation,
14211
14583
  includesVariableDecl,
14212
14584
  includesIllegalTypeAliasDecl: !decls.every((decl) => (0, declarationUtils_1.isPossibleTypeAliasDeclaration)(decl)),
14213
14585
  isRecursiveDefinition: false,
@@ -14752,9 +15124,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14752
15124
  }
14753
15125
  }
14754
15126
  else {
14755
- const removedArgs = srcTypeArgs.splice(destUnboundedIndex, srcArgsToCapture);
15127
+ const removedArgTypes = srcTypeArgs.splice(destUnboundedIndex, srcArgsToCapture).map((t) => {
15128
+ if ((0, types_1.isTypeVar)(t.type) && (0, types_1.isUnpackedVariadicTypeVar)(t.type) && !t.type.isVariadicInUnion) {
15129
+ return types_1.TypeVarType.cloneForUnpacked(t.type, /* isInUnion */ true);
15130
+ }
15131
+ return t.type;
15132
+ });
14756
15133
  srcTypeArgs.splice(destUnboundedIndex, 0, {
14757
- type: removedArgs.length > 0 ? (0, types_1.combineTypes)(removedArgs.map((t) => t.type)) : types_1.AnyType.create(),
15134
+ type: removedArgTypes.length > 0 ? (0, types_1.combineTypes)(removedArgTypes) : types_1.AnyType.create(),
14758
15135
  isUnbounded: false,
14759
15136
  });
14760
15137
  }
@@ -14972,14 +15349,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14972
15349
  // and added to the map.
14973
15350
  function assignType(destType, srcType, diag, destTypeVarContext, srcTypeVarContext, flags = 0 /* Default */, recursionCount = 0) {
14974
15351
  var _a, _b;
14975
- // If this is a one-element union that contains a variadic type variable,
14976
- // pull out the subtype.
14977
- if ((0, types_1.isUnion)(destType) && destType.subtypes.length === 1 && (0, types_1.isVariadicTypeVar)(destType.subtypes[0])) {
14978
- destType = destType.subtypes[0];
14979
- }
14980
- if ((0, types_1.isUnion)(srcType) && srcType.subtypes.length === 1 && (0, types_1.isVariadicTypeVar)(srcType.subtypes[0])) {
14981
- srcType = srcType.subtypes[0];
14982
- }
14983
15352
  // Handle the case where the dest and src types are the same object.
14984
15353
  // We can normally shortcut this and say that they are compatible,
14985
15354
  // but if the type includes TypeVars, we need to go through
@@ -15231,34 +15600,38 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15231
15600
  }
15232
15601
  }
15233
15602
  // Is the src a specialized "Type" object?
15234
- if ((0, types_1.isClassInstance)(srcType) && types_1.ClassType.isBuiltIn(srcType, 'type')) {
15235
- const srcTypeArgs = srcType.typeArguments;
15603
+ if ((0, types_1.isClassInstance)(expandedSrcType) && types_1.ClassType.isBuiltIn(expandedSrcType, 'type')) {
15604
+ const srcTypeArgs = expandedSrcType.typeArguments;
15605
+ let typeTypeArg;
15236
15606
  if (srcTypeArgs && srcTypeArgs.length >= 1) {
15237
- if ((0, types_1.isAnyOrUnknown)(srcTypeArgs[0])) {
15238
- if ((0, types_1.isClassInstance)(destType) && types_1.ClassType.isBuiltIn(srcType, 'type')) {
15607
+ typeTypeArg = srcTypeArgs[0];
15608
+ if ((0, types_1.isAnyOrUnknown)(typeTypeArg)) {
15609
+ if ((0, types_1.isClassInstance)(destType) && types_1.ClassType.isBuiltIn(expandedSrcType, 'type')) {
15239
15610
  return true;
15240
15611
  }
15241
15612
  return types_1.TypeBase.isInstantiable(destType);
15242
15613
  }
15243
- if ((0, types_1.isClassInstance)(srcTypeArgs[0]) || (0, types_1.isTypeVar)(srcTypeArgs[0])) {
15244
- if (assignType(destType, (0, typeUtils_1.convertToInstantiable)(srcTypeArgs[0]), diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
15245
- return true;
15246
- }
15247
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.typeAssignmentMismatch().format({
15248
- sourceType: printType(srcType),
15249
- destType: printType(destType),
15250
- }));
15251
- return false;
15614
+ }
15615
+ else {
15616
+ typeTypeArg = objectType !== null && objectType !== void 0 ? objectType : types_1.AnyType.create();
15617
+ }
15618
+ if ((0, types_1.isClassInstance)(typeTypeArg) || (0, types_1.isTypeVar)(typeTypeArg)) {
15619
+ if (assignType(destType, (0, typeUtils_1.convertToInstantiable)(typeTypeArg), diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
15620
+ return true;
15252
15621
  }
15622
+ diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.typeAssignmentMismatch().format({
15623
+ sourceType: printType(srcType),
15624
+ destType: printType(destType),
15625
+ }));
15626
+ return false;
15253
15627
  }
15254
15628
  }
15255
15629
  if ((0, types_1.isInstantiableClass)(destType)) {
15256
- const concreteSrcType = makeTopLevelTypeVarsConcrete(srcType);
15257
- if ((0, types_1.isInstantiableClass)(concreteSrcType)) {
15630
+ if ((0, types_1.isInstantiableClass)(expandedSrcType)) {
15258
15631
  // PEP 544 says that if the dest type is a Type[Proto] class,
15259
15632
  // the source must be a "concrete" (non-protocol) class.
15260
15633
  if (types_1.ClassType.isProtocolClass(destType)) {
15261
- if (types_1.ClassType.isProtocolClass(concreteSrcType) &&
15634
+ if (types_1.ClassType.isProtocolClass(expandedSrcType) &&
15262
15635
  (0, types_1.isInstantiableClass)(srcType) &&
15263
15636
  !srcType.includeSubclasses) {
15264
15637
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.protocolSourceIsNotConcrete().format({
@@ -15268,7 +15641,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15268
15641
  return false;
15269
15642
  }
15270
15643
  }
15271
- if (assignClass(destType, concreteSrcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount,
15644
+ if (assignClass(destType, expandedSrcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount,
15272
15645
  /* reportErrorsUsingObjType */ false)) {
15273
15646
  return true;
15274
15647
  }
@@ -15621,6 +15994,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15621
15994
  // matches for types like `tuple[Any]` and `tuple[int]` from being considered
15622
15995
  // proper subtypes of each other.
15623
15996
  function isProperSubtype(destType, srcType, recursionCount) {
15997
+ // If the destType has a condition, don't consider the srcType a proper subtype.
15998
+ if (destType.condition) {
15999
+ return false;
16000
+ }
15624
16001
  // Shortcut the check if either type is Any or Unknown.
15625
16002
  if ((0, types_1.isAnyOrUnknown)(destType) || (0, types_1.isAnyOrUnknown)(srcType)) {
15626
16003
  return true;
@@ -15687,9 +16064,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15687
16064
  // If so, we need to use a slower path.
15688
16065
  if (!(0, typeUtils_1.requiresSpecialization)(destType)) {
15689
16066
  for (const subtype of destType.subtypes) {
15690
- if (assignType(subtype, srcType, diagAddendum === null || diagAddendum === void 0 ? void 0 : diagAddendum.createAddendum(),
15691
- /* destTypeVarContextClone */ undefined,
15692
- /* srcTypeVarContextClone */ undefined, flags, recursionCount)) {
16067
+ if (assignType(subtype, srcType, diagAddendum === null || diagAddendum === void 0 ? void 0 : diagAddendum.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
15693
16068
  foundMatch = true;
15694
16069
  break;
15695
16070
  }
@@ -16387,7 +16762,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16387
16762
  const effectiveDestType = (flags & 2 /* ReverseTypeVarMatching */) === 0 ? destType : srcType;
16388
16763
  const effectiveSrcType = (flags & 2 /* ReverseTypeVarMatching */) === 0 ? srcType : destType;
16389
16764
  if (effectiveDestType.details.paramSpec) {
16390
- const requiredMatchParamCount = types_1.FunctionType.getFunctionParameters(effectiveDestType).filter((p) => {
16765
+ const requiredMatchParamCount = effectiveDestType.details.parameters.filter((p) => {
16766
+ if (!p.name) {
16767
+ return false;
16768
+ }
16391
16769
  if (p.category === 0 /* Simple */ && (0, types_1.isParamSpec)(p.type)) {
16392
16770
  return false;
16393
16771
  }
@@ -16508,7 +16886,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16508
16886
  // replace that type argument in the assigned type. This function assumes
16509
16887
  // that the caller has already verified that the assignedType is assignable
16510
16888
  // to the declaredType.
16511
- function replaceTypeArgsWithAny(declaredType, assignedType) {
16889
+ function replaceTypeArgsWithAny(declaredType, assignedType, recursionCount = 0) {
16890
+ if (recursionCount > types_1.maxTypeRecursionCount) {
16891
+ return undefined;
16892
+ }
16893
+ recursionCount++;
16512
16894
  // If this is a tuple with defined tuple type arguments, don't overwrite them.
16513
16895
  if (assignedType.tupleTypeArguments) {
16514
16896
  return undefined;
@@ -16529,6 +16911,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16529
16911
  replacedTypeArg = true;
16530
16912
  return expectedTypeArgType;
16531
16913
  }
16914
+ else if ((0, types_1.isClassInstance)(expectedTypeArgType) && (0, types_1.isClassInstance)(typeArg)) {
16915
+ // Recursively replace Any in the type argument.
16916
+ const recursiveReplacement = replaceTypeArgsWithAny(expectedTypeArgType, typeArg, recursionCount);
16917
+ if (recursiveReplacement) {
16918
+ replacedTypeArg = true;
16919
+ return recursiveReplacement;
16920
+ }
16921
+ }
16532
16922
  }
16533
16923
  return typeArg;
16534
16924
  });
@@ -16568,10 +16958,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16568
16958
  // use the concrete type.
16569
16959
  return declaredSubtype;
16570
16960
  }
16571
- else if ((0, types_1.isAnyOrUnknown)(assignedSubtype)) {
16572
- // Any or Unknown do not narrow because they're assignable to all types.
16573
- return declaredSubtype;
16574
- }
16575
16961
  return assignedSubtype;
16576
16962
  }
16577
16963
  return undefined;
@@ -16584,7 +16970,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16584
16970
  return narrowedSubtype;
16585
16971
  });
16586
16972
  // If the result of narrowing is Any, stick with the declared (unnarrowed) type.
16587
- if ((0, types_1.isAnyOrUnknown)(assignedType)) {
16973
+ // If the result of narrowing is an Unknown that is complete, stick with Unknown.
16974
+ // If it's incomplete, propagate the incomplete type for the benefit of
16975
+ // code flow analysis.
16976
+ if ((0, types_1.isAnyOrUnknown)(assignedType) && !(0, typeUtils_1.isIncompleteUnknown)(assignedType)) {
16588
16977
  return declaredType;
16589
16978
  }
16590
16979
  return narrowedType;
@@ -16691,6 +17080,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16691
17080
  const overrideParam = overrideParamDetails.params[i].param;
16692
17081
  if (i >= baseParamDetails.positionOnlyParamCount &&
16693
17082
  !(0, symbolNameUtils_1.isPrivateOrProtectedName)(baseParam.name || '') &&
17083
+ baseParamDetails.params[i].source !== typeUtils_1.ParameterSource.PositionOnly &&
16694
17084
  baseParam.category === 0 /* Simple */ &&
16695
17085
  baseParam.name !== overrideParam.name) {
16696
17086
  if (overrideParam.category === 0 /* Simple */) {
@@ -17101,11 +17491,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17101
17491
  function printFunctionParts(type) {
17102
17492
  return TypePrinter.printFunctionParts(type, evaluatorOptions.printTypeFlags, getFunctionEffectiveReturnType);
17103
17493
  }
17104
- function printType(type, expandTypeAlias = false) {
17494
+ function printType(type, options) {
17105
17495
  let flags = evaluatorOptions.printTypeFlags;
17106
- if (expandTypeAlias) {
17496
+ if (options === null || options === void 0 ? void 0 : options.expandTypeAlias) {
17107
17497
  flags |= 32 /* ExpandTypeAlias */;
17108
17498
  }
17499
+ if (options === null || options === void 0 ? void 0 : options.enforcePythonSyntax) {
17500
+ flags |= 256 /* PythonSyntax */;
17501
+ }
17502
+ if (options === null || options === void 0 ? void 0 : options.useTypingUnpack) {
17503
+ flags |= 512 /* UseTypingUnpack */;
17504
+ }
17109
17505
  return TypePrinter.printType(type, flags, getFunctionEffectiveReturnType);
17110
17506
  }
17111
17507
  // Calls back into the parser to parse the contents of a string literal.