@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
@@ -39,6 +39,7 @@ const diagnosticRules_1 = require("../common/diagnosticRules");
39
39
  const pathUtils_1 = require("../common/pathUtils");
40
40
  const pythonVersion_1 = require("../common/pythonVersion");
41
41
  const textRange_1 = require("../common/textRange");
42
+ const definitionProvider_1 = require("../languageService/definitionProvider");
42
43
  const localize_1 = require("../localization/localize");
43
44
  const parseNodes_1 = require("../parser/parseNodes");
44
45
  const stringTokenUtils_1 = require("../parser/stringTokenUtils");
@@ -50,6 +51,7 @@ const importStatementUtils_1 = require("./importStatementUtils");
50
51
  const ParseTreeUtils = __importStar(require("./parseTreeUtils"));
51
52
  const parseTreeWalker_1 = require("./parseTreeWalker");
52
53
  const patternMatching_1 = require("./patternMatching");
54
+ const regions_1 = require("./regions");
53
55
  const scopeUtils_1 = require("./scopeUtils");
54
56
  const sourceFile_1 = require("./sourceFile");
55
57
  const sourceMapper_1 = require("./sourceMapper");
@@ -102,21 +104,32 @@ const deprecatedSpecialForms = new Map([
102
104
  // functions to be emitted.
103
105
  const isPrintCodeComplexityEnabled = false;
104
106
  class Checker extends parseTreeWalker_1.ParseTreeWalker {
105
- constructor(_importResolver, _evaluator, _moduleNode) {
107
+ constructor(_importResolver, _evaluator, _parseResults, _sourceMapper) {
106
108
  super();
107
109
  this._importResolver = _importResolver;
108
110
  this._evaluator = _evaluator;
109
- this._moduleNode = _moduleNode;
111
+ this._parseResults = _parseResults;
112
+ this._sourceMapper = _sourceMapper;
110
113
  this._isUnboundCheckSuppressed = false;
111
114
  // A list of all nodes that are defined within the module that
112
115
  // have their own scopes.
113
116
  this._scopedNodes = [];
114
117
  // A list of all visited type parameter lists.
115
118
  this._typeParameterLists = [];
116
- this._fileInfo = AnalyzerNodeInfo.getFileInfo(_moduleNode);
119
+ this._moduleNode = _parseResults.parseTree;
120
+ this._fileInfo = AnalyzerNodeInfo.getFileInfo(this._moduleNode);
117
121
  }
118
122
  check() {
119
123
  this._scopedNodes.push(this._moduleNode);
124
+ this._conditionallyReportShadowedModule();
125
+ // Report code complexity issues for the module.
126
+ const codeComplexity = AnalyzerNodeInfo.getCodeFlowComplexity(this._moduleNode);
127
+ if (isPrintCodeComplexityEnabled) {
128
+ console.log(`Code complexity of module ${this._fileInfo.filePath} is ${codeComplexity.toString()}`);
129
+ }
130
+ if (codeComplexity > typeEvaluator_1.maxCodeComplexity) {
131
+ this._evaluator.addDiagnosticForTextRange(this._fileInfo, this._fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.codeTooComplexToAnalyze(), { start: 0, length: 0 });
132
+ }
120
133
  this._walkStatementsAndReportUnreachable(this._moduleNode.statements);
121
134
  // Mark symbols accessed by __all__ as accessed.
122
135
  const dunderAllInfo = AnalyzerNodeInfo.getDunderAllInfo(this._moduleNode);
@@ -128,7 +141,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
128
141
  // defined in this module for things like unaccessed variables.
129
142
  this._validateSymbolTables();
130
143
  this._reportDuplicateImports();
131
- MissingModuleSourceReporter.report(this._importResolver, this._evaluator, this._fileInfo, this._moduleNode);
144
+ this._checkRegions();
132
145
  }
133
146
  walk(node) {
134
147
  if (!AnalyzerNodeInfo.isCodeUnreachable(node)) {
@@ -176,9 +189,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
176
189
  !types_1.ClassType.isBuiltIn(baseClassType, 'Generic')) {
177
190
  if (!types_1.ClassType.isProtocolClass(baseClassType)) {
178
191
  this._evaluator.addError(localize_1.Localizer.Diagnostic.protocolBaseClass().format({
179
- classType: this._evaluator.printType(classTypeResult.classType,
180
- /* expandTypeAlias */ false),
181
- baseType: this._evaluator.printType(baseClassType, /* expandTypeAlias */ false),
192
+ classType: this._evaluator.printType(classTypeResult.classType),
193
+ baseType: this._evaluator.printType(baseClassType),
182
194
  }), arg.valueExpression);
183
195
  }
184
196
  }
@@ -262,7 +274,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
262
274
  else if ((0, typeUtils_1.isPartlyUnknown)(paramType)) {
263
275
  const diagAddendum = new diagnostic_1.DiagnosticAddendum();
264
276
  diagAddendum.addMessage(localize_1.Localizer.DiagnosticAddendum.paramType().format({
265
- paramType: this._evaluator.printType(paramType, /* expandTypeAlias */ true),
277
+ paramType: this._evaluator.printType(paramType, { expandTypeAlias: true }),
266
278
  }));
267
279
  this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportUnknownParameterType, diagnosticRules_1.DiagnosticRule.reportUnknownParameterType, localize_1.Localizer.Diagnostic.paramTypePartiallyUnknown().format({
268
280
  paramName: param.name.value,
@@ -292,7 +304,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
292
304
  }
293
305
  });
294
306
  // Check for invalid use of ParamSpec P.args and P.kwargs.
295
- const paramSpecParams = types_1.FunctionType.getFunctionParameters(functionTypeResult.functionType).filter((param) => {
307
+ const paramSpecParams = functionTypeResult.functionType.details.parameters.filter((param) => {
296
308
  if (param.typeAnnotation && (0, types_1.isTypeVar)(param.type) && (0, types_1.isParamSpec)(param.type)) {
297
309
  if (param.category !== 0 /* Simple */ && param.name && param.type.paramSpecAccess) {
298
310
  return true;
@@ -430,7 +442,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
430
442
  }
431
443
  else if ((0, typeUtils_1.isPartlyUnknown)(returnType)) {
432
444
  this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportUnknownLambdaType, diagnosticRules_1.DiagnosticRule.reportUnknownLambdaType, localize_1.Localizer.Diagnostic.lambdaReturnTypePartiallyUnknown().format({
433
- returnType: this._evaluator.printType(returnType, /* expandTypeAlias */ true),
445
+ returnType: this._evaluator.printType(returnType, { expandTypeAlias: true }),
434
446
  }), node.expression);
435
447
  }
436
448
  }
@@ -449,7 +461,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
449
461
  const returnType = this._evaluator.getType(node);
450
462
  if (!isRevealTypeCall && returnType && this._isTypeValidForUnusedValueTest(returnType)) {
451
463
  this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportUnusedCallResult, diagnosticRules_1.DiagnosticRule.reportUnusedCallResult, localize_1.Localizer.Diagnostic.unusedCallResult().format({
452
- type: this._evaluator.printType(returnType, /* expandTypeAlias */ false),
464
+ type: this._evaluator.printType(returnType),
453
465
  }), node);
454
466
  if ((0, types_1.isClassInstance)(returnType) && types_1.ClassType.isBuiltIn(returnType, 'Coroutine')) {
455
467
  this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportUnusedCoroutine, diagnosticRules_1.DiagnosticRule.reportUnusedCoroutine, localize_1.Localizer.Diagnostic.unusedCoroutine(), node);
@@ -467,7 +479,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
467
479
  const returnType = this._evaluator.getType(node);
468
480
  if (returnType && this._isTypeValidForUnusedValueTest(returnType)) {
469
481
  this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportUnusedCallResult, diagnosticRules_1.DiagnosticRule.reportUnusedCallResult, localize_1.Localizer.Diagnostic.unusedCallResult().format({
470
- type: this._evaluator.printType(returnType, /* expandTypeAlias */ false),
482
+ type: this._evaluator.printType(returnType),
471
483
  }), node);
472
484
  }
473
485
  }
@@ -533,6 +545,15 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
533
545
  // There is no return expression, so "None" is assumed.
534
546
  returnType = types_1.NoneType.createInstance();
535
547
  }
548
+ // If the enclosing function is async and a generator, the return
549
+ // statement is not allowed to have an argument. A syntax error occurs
550
+ // at runtime in this case.
551
+ if ((enclosingFunctionNode === null || enclosingFunctionNode === void 0 ? void 0 : enclosingFunctionNode.isAsync) && node.returnExpression) {
552
+ const functionDecl = AnalyzerNodeInfo.getDeclaration(enclosingFunctionNode);
553
+ if ((functionDecl === null || functionDecl === void 0 ? void 0 : functionDecl.type) === 5 /* Function */ && functionDecl.isGenerator) {
554
+ this._evaluator.addError(localize_1.Localizer.Diagnostic.returnInAsyncGenerator(), node.returnExpression);
555
+ }
556
+ }
536
557
  if (this._evaluator.isNodeReachable(node, /* sourceNode */ undefined) && enclosingFunctionNode) {
537
558
  if (declaredReturnType) {
538
559
  if ((0, types_1.isNever)(declaredReturnType)) {
@@ -573,8 +594,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
573
594
  }
574
595
  if (!returnTypeMatches) {
575
596
  this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.returnTypeMismatch().format({
576
- exprType: this._evaluator.printType(returnType, /* expandTypeAlias */ false),
577
- returnType: this._evaluator.printType(declaredReturnType, /* expandTypeAlias */ false),
597
+ exprType: this._evaluator.printType(returnType),
598
+ returnType: this._evaluator.printType(declaredReturnType),
578
599
  }) + diagAddendum.getString(), node.returnExpression ? node.returnExpression : node);
579
600
  }
580
601
  }
@@ -584,7 +605,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
584
605
  }
585
606
  else if ((0, typeUtils_1.isPartlyUnknown)(returnType)) {
586
607
  this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportUnknownVariableType, diagnosticRules_1.DiagnosticRule.reportUnknownVariableType, localize_1.Localizer.Diagnostic.returnTypePartiallyUnknown().format({
587
- returnType: this._evaluator.printType(returnType, /* expandTypeAlias */ true),
608
+ returnType: this._evaluator.printType(returnType, { expandTypeAlias: true }),
588
609
  }), node.returnExpression);
589
610
  }
590
611
  }
@@ -596,6 +617,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
596
617
  return true;
597
618
  }
598
619
  visitYieldFrom(node) {
620
+ var _a, _b, _c, _d;
599
621
  const yieldFromType = this._evaluator.getType(node.expression) || types_1.UnknownType.create();
600
622
  let yieldType;
601
623
  if ((0, types_1.isClassInstance)(yieldFromType) && types_1.ClassType.isBuiltIn(yieldFromType, 'Coroutine')) {
@@ -604,7 +626,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
604
626
  }
605
627
  else {
606
628
  yieldType =
607
- this._evaluator.getTypeOfIterable(yieldFromType, /* isAsync */ false, node) || types_1.UnknownType.create();
629
+ (_b = (_a = this._evaluator.getTypeOfIterable({ type: yieldFromType }, /* isAsync */ false, node)) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : types_1.UnknownType.create();
608
630
  // Does the iterator return a Generator? If so, get the yield type from it.
609
631
  // If the iterator doesn't return a Generator, use the iterator return type
610
632
  // directly.
@@ -614,7 +636,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
614
636
  }
615
637
  else {
616
638
  yieldType =
617
- this._evaluator.getTypeOfIterator(yieldFromType, /* isAsync */ false, node) || types_1.UnknownType.create();
639
+ (_d = (_c = this._evaluator.getTypeOfIterator({ type: yieldFromType }, /* isAsync */ false, node)) === null || _c === void 0 ? void 0 : _c.type) !== null && _d !== void 0 ? _d : types_1.UnknownType.create();
618
640
  }
619
641
  }
620
642
  this._validateYieldType(node, yieldType);
@@ -634,13 +656,13 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
634
656
  if ((0, types_1.isClass)(subtype)) {
635
657
  if (!(0, typeUtils_1.derivesFromClassRecursive)(subtype, baseExceptionType, /* ignoreUnknown */ false)) {
636
658
  diagAddendum.addMessage(localize_1.Localizer.Diagnostic.exceptionTypeIncorrect().format({
637
- type: this._evaluator.printType(subtype, /* expandTypeAlias */ false),
659
+ type: this._evaluator.printType(subtype),
638
660
  }));
639
661
  }
640
662
  }
641
663
  else {
642
664
  diagAddendum.addMessage(localize_1.Localizer.Diagnostic.exceptionTypeIncorrect().format({
643
- type: this._evaluator.printType(subtype, /* expandTypeAlias */ false),
665
+ type: this._evaluator.printType(subtype),
644
666
  }));
645
667
  }
646
668
  }
@@ -854,10 +876,20 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
854
876
  return false;
855
877
  }
856
878
  visitImportAs(node) {
879
+ this._conditionallyReportShadowedImport(node);
857
880
  this._evaluator.evaluateTypesForStatement(node);
858
- return false;
881
+ return true;
859
882
  }
860
883
  visitImportFrom(node) {
884
+ // Verify that any "__future__" import occurs at the top of the file.
885
+ if (node.module.leadingDots === 0 &&
886
+ node.module.nameParts.length === 1 &&
887
+ node.module.nameParts[0].value === '__future__') {
888
+ if (!ParseTreeUtils.isValidLocationForFutureImport(node)) {
889
+ this._evaluator.addError(localize_1.Localizer.Diagnostic.futureImportLocationNotAllowed(), node);
890
+ }
891
+ }
892
+ this._conditionallyReportShadowedImport(node);
861
893
  if (!node.isWildcardImport) {
862
894
  node.imports.forEach((importAs) => {
863
895
  this._evaluator.evaluateTypesForStatement(importAs);
@@ -872,6 +904,41 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
872
904
  this._evaluator.addDiagnosticForTextRange(this._fileInfo, this._fileInfo.diagnosticRuleSet.reportWildcardImportFromLibrary, diagnosticRules_1.DiagnosticRule.reportWildcardImportFromLibrary, localize_1.Localizer.Diagnostic.wildcardLibraryImport(), node.wildcardToken || node);
873
905
  }
874
906
  }
907
+ return true;
908
+ }
909
+ visitImportFromAs(node) {
910
+ if (this._fileInfo.isStubFile) {
911
+ return false;
912
+ }
913
+ const decls = this._evaluator.getDeclarationsForNameNode(node.name);
914
+ if (!decls) {
915
+ return false;
916
+ }
917
+ for (const decl of decls) {
918
+ if (!(0, declaration_1.isAliasDeclaration)(decl) || !decl.submoduleFallback || decl.node !== node) {
919
+ // If it is not implicitly imported module, move to next.
920
+ continue;
921
+ }
922
+ const resolvedAlias = this._evaluator.resolveAliasDeclaration(decl, /* resolveLocalNames */ true);
923
+ if (!(resolvedAlias === null || resolvedAlias === void 0 ? void 0 : resolvedAlias.path) || !(0, sourceMapper_1.isStubFile)(resolvedAlias.path)) {
924
+ continue;
925
+ }
926
+ const importResult = this._getImportResult(node, resolvedAlias.path);
927
+ if (!importResult) {
928
+ continue;
929
+ }
930
+ this._addMissingModuleSourceDiagnosticIfNeeded(importResult, node.name);
931
+ break;
932
+ }
933
+ return false;
934
+ }
935
+ visitModuleName(node) {
936
+ if (this._fileInfo.isStubFile) {
937
+ return false;
938
+ }
939
+ const importResult = AnalyzerNodeInfo.getImportInfo(node);
940
+ (0, debug_1.assert)(importResult !== undefined);
941
+ this._addMissingModuleSourceDiagnosticIfNeeded(importResult, node);
875
942
  return false;
876
943
  }
877
944
  visitTypeParameterList(node) {
@@ -914,6 +981,31 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
914
981
  // Don't explore further.
915
982
  return false;
916
983
  }
984
+ _getImportResult(node, filePath) {
985
+ const execEnv = this._importResolver.getConfigOption().findExecEnvironment(filePath);
986
+ const moduleNameNode = node.parent.module;
987
+ // Handle both absolute and relative imports.
988
+ const moduleName = moduleNameNode.leadingDots === 0
989
+ ? this._importResolver.getModuleNameForImport(filePath, execEnv).moduleName
990
+ : (0, importStatementUtils_1.getRelativeModuleName)(this._importResolver.fileSystem, this._fileInfo.filePath, filePath);
991
+ if (!moduleName) {
992
+ return undefined;
993
+ }
994
+ return this._importResolver.resolveImport(this._fileInfo.filePath, execEnv, (0, importResolver_1.createImportedModuleDescriptor)(moduleName));
995
+ }
996
+ _addMissingModuleSourceDiagnosticIfNeeded(importResult, node) {
997
+ if (importResult.isNativeLib ||
998
+ !importResult.isStubFile ||
999
+ importResult.importType === 0 /* BuiltIn */ ||
1000
+ !importResult.nonStubImportResult ||
1001
+ importResult.nonStubImportResult.isImportFound) {
1002
+ return;
1003
+ }
1004
+ // Type stub found, but source is missing.
1005
+ this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportMissingModuleSource, diagnosticRules_1.DiagnosticRule.reportMissingModuleSource, localize_1.Localizer.Diagnostic.importSourceResolveFailure().format({
1006
+ importName: importResult.importName,
1007
+ }), node);
1008
+ }
917
1009
  _reportUnnecessaryConditionExpression(expression) {
918
1010
  if (expression.nodeType === 7 /* BinaryOperation */) {
919
1011
  if (expression.operator === 36 /* And */ || expression.operator === 37 /* Or */) {
@@ -941,6 +1033,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
941
1033
  }
942
1034
  }
943
1035
  _reportUnusedExpression(node) {
1036
+ var _a, _b;
944
1037
  if (this._fileInfo.diagnosticRuleSet.reportUnusedExpression === 'none') {
945
1038
  return;
946
1039
  }
@@ -964,6 +1057,16 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
964
1057
  reportAsUnused = true;
965
1058
  }
966
1059
  }
1060
+ if (reportAsUnused &&
1061
+ this._fileInfo.ipythonMode === sourceFile_1.IPythonMode.CellDocs &&
1062
+ ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 47 /* StatementList */ &&
1063
+ node.parent.statements[node.parent.statements.length - 1] === node &&
1064
+ ((_b = node.parent.parent) === null || _b === void 0 ? void 0 : _b.nodeType) === 36 /* Module */ &&
1065
+ node.parent.parent.statements[node.parent.parent.statements.length - 1] === node.parent) {
1066
+ // Exclude an expression at the end of a notebook cell, as that is treated as
1067
+ // the cell's value.
1068
+ reportAsUnused = false;
1069
+ }
967
1070
  if (reportAsUnused) {
968
1071
  this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportUnusedExpression, diagnosticRules_1.DiagnosticRule.reportUnusedExpression, localize_1.Localizer.Diagnostic.unusedExpression(), node);
969
1072
  }
@@ -1040,8 +1143,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
1040
1143
  : localize_1.Localizer.Diagnostic.containmentAlwaysTrue();
1041
1144
  };
1042
1145
  this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportUnnecessaryContains, diagnosticRules_1.DiagnosticRule.reportUnnecessaryContains, getMessage().format({
1043
- leftType: this._evaluator.printType(leftType, /* expandTypeAlias */ true),
1044
- rightType: this._evaluator.printType(elementType, /* expandTypeAlias */ true),
1146
+ leftType: this._evaluator.printType(leftType, { expandTypeAlias: true }),
1147
+ rightType: this._evaluator.printType(elementType, { expandTypeAlias: true }),
1045
1148
  }), node);
1046
1149
  }
1047
1150
  }
@@ -1080,8 +1183,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
1080
1183
  });
1081
1184
  if (!isPossiblyTrue) {
1082
1185
  this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportUnnecessaryComparison, diagnosticRules_1.DiagnosticRule.reportUnnecessaryComparison, getMessage().format({
1083
- leftType: this._evaluator.printType(leftType, /* expandTypeAlias */ true),
1084
- rightType: this._evaluator.printType(rightType, /* expandTypeAlias */ true),
1186
+ leftType: this._evaluator.printType(leftType, { expandTypeAlias: true }),
1187
+ rightType: this._evaluator.printType(rightType, { expandTypeAlias: true }),
1085
1188
  }), node);
1086
1189
  }
1087
1190
  }
@@ -1104,8 +1207,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
1104
1207
  });
1105
1208
  });
1106
1209
  if (!isComparable) {
1107
- const leftTypeText = this._evaluator.printType(leftType, /* expandTypeAlias */ true);
1108
- const rightTypeText = this._evaluator.printType(rightType, /* expandTypeAlias */ true);
1210
+ const leftTypeText = this._evaluator.printType(leftType, { expandTypeAlias: true });
1211
+ const rightTypeText = this._evaluator.printType(rightType, { expandTypeAlias: true });
1109
1212
  this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportUnnecessaryComparison, diagnosticRules_1.DiagnosticRule.reportUnnecessaryComparison, getMessage().format({
1110
1213
  leftType: leftTypeText,
1111
1214
  rightType: rightTypeText,
@@ -1445,8 +1548,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
1445
1548
  if (!(0, types_1.isNever)(overloadReturnType) &&
1446
1549
  !this._evaluator.assignType(implementationReturnType, overloadReturnType, returnDiag.createAddendum(), implTypeVarContext, overloadTypeVarContext, 8 /* SkipSolveTypeVars */)) {
1447
1550
  returnDiag.addMessage(localize_1.Localizer.DiagnosticAddendum.functionReturnTypeMismatch().format({
1448
- sourceType: this._evaluator.printType(overloadReturnType, /* expandTypeAlias */ false),
1449
- destType: this._evaluator.printType(implementationReturnType, /* expandTypeAlias */ false),
1551
+ sourceType: this._evaluator.printType(overloadReturnType),
1552
+ destType: this._evaluator.printType(implementationReturnType),
1450
1553
  }));
1451
1554
  diag === null || diag === void 0 ? void 0 : diag.addAddendum(returnDiag);
1452
1555
  isLegal = false;
@@ -1557,6 +1660,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
1557
1660
  }
1558
1661
  }
1559
1662
  _validateExceptionType(exceptionType, errorNode) {
1663
+ var _a, _b;
1560
1664
  const baseExceptionType = this._evaluator.getBuiltInType(errorNode, 'BaseException');
1561
1665
  const derivesFromBaseException = (classType) => {
1562
1666
  if (!baseExceptionType || !(0, types_1.isInstantiableClass)(baseExceptionType)) {
@@ -1573,14 +1677,13 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
1573
1677
  if ((0, types_1.isInstantiableClass)(exceptionType)) {
1574
1678
  if (!derivesFromBaseException(exceptionType)) {
1575
1679
  diagAddendum.addMessage(localize_1.Localizer.Diagnostic.exceptionTypeIncorrect().format({
1576
- type: this._evaluator.printType(exceptionType, /* expandTypeAlias */ false),
1680
+ type: this._evaluator.printType(exceptionType),
1577
1681
  }));
1578
1682
  }
1579
1683
  resultingExceptionType = types_1.ClassType.cloneAsInstance(exceptionType);
1580
1684
  }
1581
1685
  else if ((0, types_1.isClassInstance)(exceptionType)) {
1582
- const iterableType = this._evaluator.getTypeOfIterator(exceptionType, /* isAsync */ false, errorNode) ||
1583
- types_1.UnknownType.create();
1686
+ const iterableType = (_b = (_a = this._evaluator.getTypeOfIterator({ type: exceptionType }, /* isAsync */ false, errorNode)) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : types_1.UnknownType.create();
1584
1687
  resultingExceptionType = (0, typeUtils_1.mapSubtypes)(iterableType, (subtype) => {
1585
1688
  if ((0, types_1.isAnyOrUnknown)(subtype)) {
1586
1689
  return subtype;
@@ -1588,13 +1691,13 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
1588
1691
  if ((0, types_1.isInstantiableClass)(subtype)) {
1589
1692
  if (!derivesFromBaseException(subtype)) {
1590
1693
  diagAddendum.addMessage(localize_1.Localizer.Diagnostic.exceptionTypeIncorrect().format({
1591
- type: this._evaluator.printType(exceptionType, /* expandTypeAlias */ false),
1694
+ type: this._evaluator.printType(exceptionType),
1592
1695
  }));
1593
1696
  }
1594
1697
  return types_1.ClassType.cloneAsInstance(subtype);
1595
1698
  }
1596
1699
  diagAddendum.addMessage(localize_1.Localizer.Diagnostic.exceptionTypeIncorrect().format({
1597
- type: this._evaluator.printType(exceptionType, /* expandTypeAlias */ false),
1700
+ type: this._evaluator.printType(exceptionType),
1598
1701
  }));
1599
1702
  return types_1.UnknownType.create();
1600
1703
  });
@@ -1602,7 +1705,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
1602
1705
  }
1603
1706
  if (!diagAddendum.isEmpty()) {
1604
1707
  this._evaluator.addError(localize_1.Localizer.Diagnostic.exceptionTypeNotClass().format({
1605
- type: this._evaluator.printType(exceptionType, /* expandTypeAlias */ false),
1708
+ type: this._evaluator.printType(exceptionType),
1606
1709
  }), errorNode);
1607
1710
  }
1608
1711
  return resultingExceptionType || types_1.UnknownType.create();
@@ -1991,6 +2094,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
1991
2094
  });
1992
2095
  }
1993
2096
  _conditionallyReportUnusedDeclaration(decl, isPrivate) {
2097
+ var _a;
1994
2098
  let diagnosticLevel;
1995
2099
  let nameNode;
1996
2100
  let message;
@@ -2001,8 +2105,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
2001
2105
  rule = diagnosticRules_1.DiagnosticRule.reportUnusedImport;
2002
2106
  if (decl.node.nodeType === 21 /* ImportAs */) {
2003
2107
  if (decl.node.alias) {
2004
- // Aliases in stub files are assumed to be re-exports.
2005
- if (!this._fileInfo.isStubFile) {
2108
+ // For statements of the form "import x as x", don't mark "x" as unaccessed
2109
+ // because it's assumed to be re-exported.
2110
+ // See https://typing.readthedocs.io/en/latest/source/stubs.html#imports.
2111
+ if (decl.node.alias.value !== decl.moduleName) {
2006
2112
  nameNode = decl.node.alias;
2007
2113
  }
2008
2114
  }
@@ -2021,9 +2127,9 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
2021
2127
  }
2022
2128
  else if (decl.node.nodeType === 23 /* ImportFromAs */) {
2023
2129
  const importFrom = decl.node.parent;
2024
- // If this is a stub file that is using the "from A import B as C" or "from . import C",
2025
- // don't mark "C" as unaccessed because it's assumed to be re-exported.
2026
- const isReexport = this._fileInfo.isStubFile && decl.node.alias !== undefined;
2130
+ // For statements of the form "from y import x as x", don't mark "x" as
2131
+ // unaccessed because it's assumed to be re-exported.
2132
+ const isReexport = ((_a = decl.node.alias) === null || _a === void 0 ? void 0 : _a.value) === decl.node.name.value;
2027
2133
  // If this is a __future__ import, it's OK for the import symbol to be unaccessed.
2028
2134
  const isFuture = importFrom.module.nameParts.length === 1 &&
2029
2135
  importFrom.module.nameParts[0].value === '__future__';
@@ -2152,10 +2258,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
2152
2258
  diag.addMessage(localize_1.Localizer.DiagnosticAddendum.typeVarNotAllowed());
2153
2259
  this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, isInstanceCheck
2154
2260
  ? localize_1.Localizer.Diagnostic.isInstanceInvalidType().format({
2155
- type: this._evaluator.printType(arg1Type, /* expandTypeAlias */ false),
2261
+ type: this._evaluator.printType(arg1Type),
2156
2262
  }) + diag.getString()
2157
2263
  : localize_1.Localizer.Diagnostic.isSubclassInvalidType().format({
2158
- type: this._evaluator.printType(arg1Type, /* expandTypeAlias */ false),
2264
+ type: this._evaluator.printType(arg1Type),
2159
2265
  }) + diag.getString(), node.arguments[1]);
2160
2266
  }
2161
2267
  // If this call is within an assert statement, we won't check whether
@@ -2315,12 +2421,12 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
2315
2421
  if (!arg1IncludesSubclasses && (0, types_1.isTypeSame)(filteredType, arg0Type, { ignorePseudoGeneric: true })) {
2316
2422
  this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportUnnecessaryIsInstance, diagnosticRules_1.DiagnosticRule.reportUnnecessaryIsInstance, isInstanceCheck
2317
2423
  ? localize_1.Localizer.Diagnostic.unnecessaryIsInstanceAlways().format({
2318
- testType: this._evaluator.printType(arg0Type, /* expandTypeAlias */ false),
2319
- classType: this._evaluator.printType(getTestType(), /* expandTypeAlias */ false),
2424
+ testType: this._evaluator.printType(arg0Type),
2425
+ classType: this._evaluator.printType(getTestType()),
2320
2426
  })
2321
2427
  : localize_1.Localizer.Diagnostic.unnecessaryIsSubclassAlways().format({
2322
- testType: this._evaluator.printType(arg0Type, /* expandTypeAlias */ false),
2323
- classType: this._evaluator.printType(getTestType(), /* expandTypeAlias */ false),
2428
+ testType: this._evaluator.printType(arg0Type),
2429
+ classType: this._evaluator.printType(getTestType()),
2324
2430
  }), node);
2325
2431
  }
2326
2432
  }
@@ -2416,6 +2522,79 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
2416
2522
  }
2417
2523
  }
2418
2524
  }
2525
+ _conditionallyReportShadowedModule() {
2526
+ if (this._fileInfo.diagnosticRuleSet.reportShadowedImports === 'none') {
2527
+ return;
2528
+ }
2529
+ // Check the module we're in.
2530
+ const moduleName = this._fileInfo.moduleName;
2531
+ const desc = {
2532
+ nameParts: moduleName.split('.'),
2533
+ leadingDots: 0,
2534
+ importedSymbols: [],
2535
+ };
2536
+ const stdlibPath = this._importResolver.getTypeshedStdLibPath(this._fileInfo.executionEnvironment);
2537
+ if (stdlibPath &&
2538
+ this._importResolver.isStdlibModule(desc, this._fileInfo.executionEnvironment) &&
2539
+ this._sourceMapper.isUserCode(this._fileInfo.filePath)) {
2540
+ // This means the user has a module that is overwriting the stdlib module.
2541
+ const diag = this._evaluator.addDiagnosticForTextRange(this._fileInfo, this._fileInfo.diagnosticRuleSet.reportShadowedImports, diagnosticRules_1.DiagnosticRule.reportShadowedImports, localize_1.Localizer.Diagnostic.stdlibModuleOverridden().format({
2542
+ name: moduleName,
2543
+ path: this._fileInfo.filePath,
2544
+ }), this._moduleNode);
2545
+ // Add a quick action that renames the file.
2546
+ if (diag) {
2547
+ const renameAction = {
2548
+ action: "renameShadowedFile" /* RenameShadowedFileAction */,
2549
+ oldFile: this._fileInfo.filePath,
2550
+ newFile: this._sourceMapper.getNextFileName(this._fileInfo.filePath),
2551
+ };
2552
+ diag.addAction(renameAction);
2553
+ }
2554
+ }
2555
+ }
2556
+ _conditionallyReportShadowedImport(node) {
2557
+ if (this._fileInfo.diagnosticRuleSet.reportShadowedImports === 'none') {
2558
+ return;
2559
+ }
2560
+ const namePartNodes = node.nodeType === 21 /* ImportAs */
2561
+ ? node.module.nameParts
2562
+ : node.nodeType === 23 /* ImportFromAs */
2563
+ ? [node.name]
2564
+ : node.module.nameParts;
2565
+ const nameParts = namePartNodes.map((n) => n.value);
2566
+ const module = {
2567
+ nameParts,
2568
+ leadingDots: 0,
2569
+ importedSymbols: [],
2570
+ };
2571
+ // Make sure the module is a potential stdlib one so we don't spend the time
2572
+ // searching for the definition.
2573
+ const stdlibPath = this._importResolver.getTypeshedStdLibPath(this._fileInfo.executionEnvironment);
2574
+ if (stdlibPath && this._importResolver.isStdlibModule(module, this._fileInfo.executionEnvironment)) {
2575
+ // If the definition for this name is in 'user' module, it is overwriting the stdlib module.
2576
+ const definitions = definitionProvider_1.DefinitionProvider.getDefinitionsForNode(this._sourceMapper, namePartNodes[namePartNodes.length - 1], definitionProvider_1.DefinitionFilter.All, this._evaluator);
2577
+ const paths = definitions ? definitions.map((d) => d.path) : [];
2578
+ paths.forEach((p) => {
2579
+ if (!p.startsWith(stdlibPath) && !(0, sourceMapper_1.isStubFile)(p) && this._sourceMapper.isUserCode(p)) {
2580
+ // This means the user has a module that is overwriting the stdlib module.
2581
+ const diag = this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportShadowedImports, diagnosticRules_1.DiagnosticRule.reportShadowedImports, localize_1.Localizer.Diagnostic.stdlibModuleOverridden().format({
2582
+ name: nameParts.join('.'),
2583
+ path: p,
2584
+ }), node);
2585
+ // Add a quick action that renames the file.
2586
+ if (diag) {
2587
+ const renameAction = {
2588
+ action: "renameShadowedFile" /* RenameShadowedFileAction */,
2589
+ oldFile: p,
2590
+ newFile: this._sourceMapper.getNextFileName(p),
2591
+ };
2592
+ diag.addAction(renameAction);
2593
+ }
2594
+ }
2595
+ });
2596
+ }
2597
+ }
2419
2598
  _conditionallyReportPrivateUsage(node) {
2420
2599
  var _a;
2421
2600
  if (this._fileInfo.diagnosticRuleSet.reportPrivateUsage === 'none') {
@@ -2624,7 +2803,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
2624
2803
  }
2625
2804
  else if ((0, typeUtils_1.isPartlyUnknown)(declaredReturnType)) {
2626
2805
  this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportUnknownVariableType, diagnosticRules_1.DiagnosticRule.reportUnknownVariableType, localize_1.Localizer.Diagnostic.declaredReturnTypePartiallyUnknown().format({
2627
- returnType: this._evaluator.printType(declaredReturnType, /* expandTypeAlias */ true),
2806
+ returnType: this._evaluator.printType(declaredReturnType, { expandTypeAlias: true }),
2628
2807
  }), returnAnnotation);
2629
2808
  }
2630
2809
  const diag = new diagnostic_1.DiagnosticAddendum();
@@ -2663,8 +2842,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
2663
2842
  // the return type matches. This check can also be skipped for an overload.
2664
2843
  if (!ParseTreeUtils.isSuiteEmpty(node.suite) && !types_1.FunctionType.isOverloaded(functionType)) {
2665
2844
  this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.returnMissing().format({
2666
- returnType: this._evaluator.printType(declaredReturnType,
2667
- /* expandTypeAlias */ false),
2845
+ returnType: this._evaluator.printType(declaredReturnType),
2668
2846
  }) + diagAddendum.getString(), returnAnnotation);
2669
2847
  }
2670
2848
  }
@@ -2678,7 +2856,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
2678
2856
  }
2679
2857
  else if ((0, typeUtils_1.isPartlyUnknown)(inferredReturnType)) {
2680
2858
  this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportUnknownParameterType, diagnosticRules_1.DiagnosticRule.reportUnknownParameterType, localize_1.Localizer.Diagnostic.returnTypePartiallyUnknown().format({
2681
- returnType: this._evaluator.printType(inferredReturnType, /* expandTypeAlias */ true),
2859
+ returnType: this._evaluator.printType(inferredReturnType, { expandTypeAlias: true }),
2682
2860
  }), node.name);
2683
2861
  }
2684
2862
  }
@@ -2776,7 +2954,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
2776
2954
  }
2777
2955
  }
2778
2956
  else if (decls[0].type === 5 /* Function */) {
2779
- if (ParseTreeUtils.isSuiteEmpty(decls[0].node.suite) && decls[0]) {
2957
+ if (decls.every((decl) => decl.type !== 5 /* Function */ || ParseTreeUtils.isSuiteEmpty(decl.node.suite))) {
2780
2958
  if ((0, pathUtils_1.getFileExtension)(decls[0].path).toLowerCase() !== '.pyi') {
2781
2959
  if (!isSymbolImplemented(name)) {
2782
2960
  diagAddendum.addMessage(localize_1.Localizer.DiagnosticAddendum.missingProtocolMember().format({
@@ -2902,6 +3080,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
2902
3080
  // Reports the case where an instance variable is not declared or initialized
2903
3081
  // within the class body or constructor method.
2904
3082
  _validateInstanceVariableInitialization(classType) {
3083
+ // This check doesn't apply to stub files.
3084
+ if (this._fileInfo.isStubFile) {
3085
+ return;
3086
+ }
2905
3087
  // This check can be expensive, so don't perform it if the corresponding
2906
3088
  // rule is disabled.
2907
3089
  if (this._fileInfo.diagnosticRuleSet.reportUninitializedInstanceVariable === 'none') {
@@ -3341,6 +3523,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
3341
3523
  if ((0, types_1.isAnyOrUnknown)(typeOfSymbol)) {
3342
3524
  return;
3343
3525
  }
3526
+ let foundOverride = false;
3344
3527
  for (const baseClass of classType.details.baseClasses) {
3345
3528
  if (!(0, types_1.isClass)(baseClass)) {
3346
3529
  continue;
@@ -3355,10 +3538,35 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
3355
3538
  if (!baseClassAndSymbol) {
3356
3539
  continue;
3357
3540
  }
3541
+ foundOverride = true;
3358
3542
  this._validateBaseClassOverride(baseClassAndSymbol, symbol, typeOfSymbol, classType, name);
3359
3543
  }
3544
+ if (!foundOverride) {
3545
+ // If this is a method decorated with @override, validate that there
3546
+ // is a base class method of the same name.
3547
+ this._validateOverrideDecorator(typeOfSymbol);
3548
+ }
3360
3549
  });
3361
3550
  }
3551
+ // Determines whether the type is a function or overloaded function with an @override
3552
+ // decorator. In this case, an error is reported because no base class has declared
3553
+ // a method of the same name.
3554
+ _validateOverrideDecorator(overrideType) {
3555
+ let overrideFunction;
3556
+ if ((0, types_1.isFunction)(overrideType)) {
3557
+ overrideFunction = overrideType;
3558
+ }
3559
+ else if ((0, types_1.isOverloadedFunction)(overrideType)) {
3560
+ overrideFunction = types_1.OverloadedFunctionType.getImplementation(overrideType);
3561
+ }
3562
+ if (!overrideFunction ||
3563
+ !types_1.FunctionType.isOverridden(overrideFunction) ||
3564
+ !overrideFunction.details.declaration) {
3565
+ return;
3566
+ }
3567
+ const funcNode = overrideFunction.details.declaration.node;
3568
+ this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.overrideNotFound().format({ name: funcNode.name.value }), funcNode.name);
3569
+ }
3362
3570
  _validateBaseClassOverride(baseClassAndSymbol, overrideSymbol, overrideType, childClassType, memberName) {
3363
3571
  if (!(0, types_1.isInstantiableClass)(baseClassAndSymbol.classType)) {
3364
3572
  return;
@@ -3430,7 +3638,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
3430
3638
  const diag = this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportIncompatibleMethodOverride, diagnosticRules_1.DiagnosticRule.reportIncompatibleMethodOverride, localize_1.Localizer.Diagnostic.methodOverridden().format({
3431
3639
  name: memberName,
3432
3640
  className: baseClassAndSymbol.classType.details.name,
3433
- type: this._evaluator.printType(overrideType, /* expandTypeAlias */ false),
3641
+ type: this._evaluator.printType(overrideType),
3434
3642
  }), lastDecl.node);
3435
3643
  const origDecl = (0, symbolUtils_1.getLastTypedDeclaredForSymbol)(baseClassAndSymbol.symbol);
3436
3644
  if (diag && origDecl) {
@@ -3647,9 +3855,12 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
3647
3855
  }
3648
3856
  }
3649
3857
  else {
3858
+ const decoratorIsPresent = node.decorators.length > 0;
3859
+ const isOverloaded = types_1.FunctionType.isOverloaded(functionType);
3650
3860
  // The presence of a decorator can change the behavior, so we need
3651
- // to back off from this check if a decorator is present.
3652
- if (node.decorators.length === 0) {
3861
+ // to back off from this check if a decorator is present. An overload
3862
+ // is a decorator, but we'll ignore that here.
3863
+ if (isOverloaded || !decoratorIsPresent) {
3653
3864
  let paramName = '';
3654
3865
  let firstParamIsSimple = true;
3655
3866
  if (node.parameters.length > 0) {
@@ -3777,7 +3988,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
3777
3988
  if (!this._evaluator.assignType(paramType, expectedType)) {
3778
3989
  this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.clsSelfParamTypeMismatch().format({
3779
3990
  name: paramInfo.name,
3780
- classType: this._evaluator.printType(expectedType, /* expandTypeAlias */ false),
3991
+ classType: this._evaluator.printType(expectedType),
3781
3992
  }), paramInfo.typeAnnotation);
3782
3993
  }
3783
3994
  }
@@ -3808,8 +4019,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
3808
4019
  const diagAddendum = new diagnostic_1.DiagnosticAddendum();
3809
4020
  if (!this._evaluator.assignType(declaredYieldType, yieldType, diagAddendum)) {
3810
4021
  this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.yieldTypeMismatch().format({
3811
- exprType: this._evaluator.printType(yieldType, /* expandTypeAlias */ false),
3812
- yieldType: this._evaluator.printType(declaredYieldType, /* expandTypeAlias */ false),
4022
+ exprType: this._evaluator.printType(yieldType),
4023
+ yieldType: this._evaluator.printType(declaredYieldType),
3813
4024
  }) + diagAddendum.getString(), node.expression || node);
3814
4025
  }
3815
4026
  }
@@ -3821,6 +4032,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
3821
4032
  let sawUnknownExceptionType = false;
3822
4033
  const exceptionTypesSoFar = [];
3823
4034
  node.exceptClauses.forEach((except) => {
4035
+ var _a, _b;
3824
4036
  if (sawUnknownExceptionType || except.isExceptGroup || !except.typeExpression) {
3825
4037
  return;
3826
4038
  }
@@ -3839,8 +4051,9 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
3839
4051
  typesOfThisExcept.push(exceptionType);
3840
4052
  }
3841
4053
  else if ((0, types_1.isClassInstance)(exceptionType)) {
3842
- const iterableType = this._evaluator.getTypeOfIterator(exceptionType, /* isAsync */ false, /* errorNode */ undefined) ||
3843
- types_1.UnknownType.create();
4054
+ const iterableType = (_b = (_a = this._evaluator.getTypeOfIterator({ type: exceptionType },
4055
+ /* isAsync */ false,
4056
+ /* errorNode */ undefined)) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : types_1.UnknownType.create();
3844
4057
  (0, typeUtils_1.doForEachSubtype)(iterableType, (subtype) => {
3845
4058
  if ((0, types_1.isAnyOrUnknown)(subtype)) {
3846
4059
  sawUnknownExceptionType = true;
@@ -3915,94 +4128,33 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
3915
4128
  }
3916
4129
  });
3917
4130
  }
3918
- }
3919
- exports.Checker = Checker;
3920
- class MissingModuleSourceReporter extends parseTreeWalker_1.ParseTreeWalker {
3921
- constructor(_importResolver, _evaluator, _fileInfo) {
3922
- super();
3923
- this._importResolver = _importResolver;
3924
- this._evaluator = _evaluator;
3925
- this._fileInfo = _fileInfo;
3926
- }
3927
- static report(importResolver, evaluator, fileInfo, node) {
3928
- if (fileInfo.isStubFile) {
3929
- // Don't report this for stub files.
3930
- return;
3931
- }
3932
- new MissingModuleSourceReporter(importResolver, evaluator, fileInfo).walk(node);
3933
- }
3934
- visitNode(node) {
3935
- // Optimization. don't walk into expressions which can't
3936
- // have import statement as child nodes.
3937
- if ((0, parseNodes_1.isExpressionNode)(node)) {
3938
- return [];
3939
- }
3940
- return super.visitNode(node);
3941
- }
3942
- visitModule(node) {
3943
- const codeComplexity = AnalyzerNodeInfo.getCodeFlowComplexity(node);
3944
- if (isPrintCodeComplexityEnabled) {
3945
- console.log(`Code complexity of module ${this._fileInfo.filePath} is ${codeComplexity.toString()}`);
3946
- }
3947
- if (codeComplexity > typeEvaluator_1.maxCodeComplexity) {
3948
- this._evaluator.addDiagnosticForTextRange(this._fileInfo, this._fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.codeTooComplexToAnalyze(), { start: 0, length: 0 });
3949
- return false;
3950
- }
3951
- return true;
3952
- }
3953
- visitModuleName(node) {
3954
- const importResult = AnalyzerNodeInfo.getImportInfo(node);
3955
- (0, debug_1.assert)(importResult !== undefined);
3956
- this._addMissingModuleSourceDiagnosticIfNeeded(importResult, node);
3957
- return false;
3958
- }
3959
- visitImportFromAs(node) {
3960
- const decls = this._evaluator.getDeclarationsForNameNode(node.name);
3961
- if (!decls) {
3962
- return false;
3963
- }
3964
- for (const decl of decls) {
3965
- if (!(0, declaration_1.isAliasDeclaration)(decl) || !decl.submoduleFallback || decl.node !== node) {
3966
- // If it is not implicitly imported module, move to next.
3967
- continue;
3968
- }
3969
- const resolvedAlias = this._evaluator.resolveAliasDeclaration(decl, /* resolveLocalNames */ true);
3970
- if (!(resolvedAlias === null || resolvedAlias === void 0 ? void 0 : resolvedAlias.path) || !(0, sourceMapper_1.isStubFile)(resolvedAlias.path)) {
3971
- continue;
4131
+ _checkRegions() {
4132
+ const regionComments = (0, regions_1.getRegionComments)(this._parseResults);
4133
+ const regionStack = [];
4134
+ regionComments.forEach((regionComment) => {
4135
+ if (regionComment.type === 0 /* Region */) {
4136
+ regionStack.push(regionComment);
3972
4137
  }
3973
- const importResult = this._getImportResult(node, resolvedAlias.path);
3974
- if (!importResult) {
3975
- continue;
4138
+ else {
4139
+ if (regionStack.length > 0) {
4140
+ regionStack.pop();
4141
+ }
4142
+ else {
4143
+ this._addDiagnosticForRegionComment(regionComment, localize_1.Localizer.Diagnostic.unmatchedEndregionComment());
4144
+ }
3976
4145
  }
3977
- this._addMissingModuleSourceDiagnosticIfNeeded(importResult, node.name);
3978
- break;
3979
- }
3980
- return false;
3981
- }
3982
- _getImportResult(node, filePath) {
3983
- const execEnv = this._importResolver.getConfigOption().findExecEnvironment(filePath);
3984
- const moduleNameNode = node.parent.module;
3985
- // Handle both absolute and relative imports.
3986
- const moduleName = moduleNameNode.leadingDots === 0
3987
- ? this._importResolver.getModuleNameForImport(filePath, execEnv).moduleName
3988
- : (0, importStatementUtils_1.getRelativeModuleName)(this._importResolver.fileSystem, this._fileInfo.filePath, filePath);
3989
- if (!moduleName) {
3990
- return undefined;
3991
- }
3992
- return this._importResolver.resolveImport(this._fileInfo.filePath, execEnv, (0, importResolver_1.createImportedModuleDescriptor)(moduleName));
4146
+ });
4147
+ regionStack.forEach((regionComment) => {
4148
+ this._addDiagnosticForRegionComment(regionComment, localize_1.Localizer.Diagnostic.unmatchedRegionComment());
4149
+ });
3993
4150
  }
3994
- _addMissingModuleSourceDiagnosticIfNeeded(importResult, node) {
3995
- if (importResult.isNativeLib ||
3996
- !importResult.isStubFile ||
3997
- importResult.importType === 0 /* BuiltIn */ ||
3998
- !importResult.nonStubImportResult ||
3999
- importResult.nonStubImportResult.isImportFound) {
4000
- return;
4001
- }
4002
- // Type stub found, but source is missing.
4003
- this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportMissingModuleSource, diagnosticRules_1.DiagnosticRule.reportMissingModuleSource, localize_1.Localizer.Diagnostic.importSourceResolveFailure().format({
4004
- importName: importResult.importName,
4005
- }), node);
4151
+ _addDiagnosticForRegionComment(regionComment, message) {
4152
+ // extend range to include # character
4153
+ const range = regionComment.comment;
4154
+ range.start -= 1;
4155
+ range.length += 1;
4156
+ return this._evaluator.addDiagnosticForTextRange(this._fileInfo, 'error', '', message, range);
4006
4157
  }
4007
4158
  }
4159
+ exports.Checker = Checker;
4008
4160
  //# sourceMappingURL=checker.js.map