@zzzen/pyright-internal 1.1.255 → 1.2.0-dev.20220703

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 (1456) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -0
  3. package/dist/analyzer/aliasDeclarationUtils.js +2 -2
  4. package/dist/analyzer/analyzerFileInfo.d.ts +1 -1
  5. package/dist/analyzer/analyzerNodeInfo.d.ts +4 -1
  6. package/dist/analyzer/analyzerNodeInfo.js +12 -1
  7. package/dist/analyzer/analyzerNodeInfo.js.map +1 -1
  8. package/dist/analyzer/backgroundAnalysisProgram.d.ts +1 -0
  9. package/dist/analyzer/backgroundAnalysisProgram.js +3 -0
  10. package/dist/analyzer/backgroundAnalysisProgram.js.map +1 -1
  11. package/dist/analyzer/binder.d.ts +6 -1
  12. package/dist/analyzer/binder.js +142 -32
  13. package/dist/analyzer/binder.js.map +1 -1
  14. package/dist/analyzer/checker.d.ts +4 -1
  15. package/dist/analyzer/checker.js +144 -73
  16. package/dist/analyzer/checker.js.map +1 -1
  17. package/dist/analyzer/codeFlowUtils.js +33 -0
  18. package/dist/analyzer/codeFlowUtils.js.map +1 -1
  19. package/dist/analyzer/constraintSolver.js +6 -3
  20. package/dist/analyzer/constraintSolver.js.map +1 -1
  21. package/dist/analyzer/dataClasses.js +6 -4
  22. package/dist/analyzer/dataClasses.js.map +1 -1
  23. package/dist/analyzer/declaration.d.ts +18 -6
  24. package/dist/analyzer/declaration.js +25 -5
  25. package/dist/analyzer/declaration.js.map +1 -1
  26. package/dist/analyzer/declarationUtils.d.ts +1 -1
  27. package/dist/analyzer/declarationUtils.js +19 -16
  28. package/dist/analyzer/declarationUtils.js.map +1 -1
  29. package/dist/analyzer/importResult.js +7 -0
  30. package/dist/analyzer/importResult.js.map +1 -1
  31. package/dist/analyzer/importStatementUtils.js +10 -1
  32. package/dist/analyzer/importStatementUtils.js.map +1 -1
  33. package/dist/analyzer/namedTuples.js +1 -1
  34. package/dist/analyzer/namedTuples.js.map +1 -1
  35. package/dist/analyzer/packageTypeReport.js +10 -1
  36. package/dist/analyzer/packageTypeReport.js.map +1 -1
  37. package/dist/analyzer/packageTypeVerifier.js +6 -6
  38. package/dist/analyzer/parseTreeUtils.d.ts +3 -3
  39. package/dist/analyzer/parseTreeUtils.js +27 -13
  40. package/dist/analyzer/parseTreeUtils.js.map +1 -1
  41. package/dist/analyzer/parseTreeWalker.d.ts +4 -1
  42. package/dist/analyzer/parseTreeWalker.js +19 -1
  43. package/dist/analyzer/parseTreeWalker.js.map +1 -1
  44. package/dist/analyzer/program.d.ts +2 -1
  45. package/dist/analyzer/program.js +27 -23
  46. package/dist/analyzer/program.js.map +1 -1
  47. package/dist/analyzer/properties.js +2 -0
  48. package/dist/analyzer/properties.js.map +1 -1
  49. package/dist/analyzer/protocols.d.ts +0 -1
  50. package/dist/analyzer/protocols.js +4 -64
  51. package/dist/analyzer/protocols.js.map +1 -1
  52. package/dist/analyzer/scope.js +22 -1
  53. package/dist/analyzer/scope.js.map +1 -1
  54. package/dist/analyzer/service.d.ts +20 -8
  55. package/dist/analyzer/service.js +39 -19
  56. package/dist/analyzer/service.js.map +1 -1
  57. package/dist/analyzer/sourceFile.js +1 -1
  58. package/dist/analyzer/sourceFile.js.map +1 -1
  59. package/dist/analyzer/sourceFileInfoUtils.d.ts +2 -0
  60. package/dist/analyzer/sourceFileInfoUtils.js +15 -0
  61. package/dist/analyzer/sourceFileInfoUtils.js.map +1 -0
  62. package/dist/analyzer/symbol.d.ts +3 -1
  63. package/dist/analyzer/symbol.js +39 -1
  64. package/dist/analyzer/symbol.js.map +1 -1
  65. package/dist/analyzer/tracePrinter.js +8 -4
  66. package/dist/analyzer/tracePrinter.js.map +1 -1
  67. package/dist/analyzer/typeDocStringUtils.js +11 -3
  68. package/dist/analyzer/typeDocStringUtils.js.map +1 -1
  69. package/dist/analyzer/typeEvaluator.js +610 -208
  70. package/dist/analyzer/typeEvaluator.js.map +1 -1
  71. package/dist/analyzer/typeEvaluatorTypes.d.ts +2 -1
  72. package/dist/analyzer/typeEvaluatorTypes.js +65 -1
  73. package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
  74. package/dist/analyzer/typeEvaluatorWithTracker.js +2 -0
  75. package/dist/analyzer/typeEvaluatorWithTracker.js.map +1 -1
  76. package/dist/analyzer/typeGuards.d.ts +2 -0
  77. package/dist/analyzer/typeGuards.js +113 -69
  78. package/dist/analyzer/typeGuards.js.map +1 -1
  79. package/dist/analyzer/typePrinter.js +27 -2
  80. package/dist/analyzer/typePrinter.js.map +1 -1
  81. package/dist/analyzer/typeStubWriter.d.ts +4 -1
  82. package/dist/analyzer/typeStubWriter.js +36 -0
  83. package/dist/analyzer/typeStubWriter.js.map +1 -1
  84. package/dist/analyzer/typeUtils.js +129 -33
  85. package/dist/analyzer/typeUtils.js.map +1 -1
  86. package/dist/analyzer/typedDicts.js +2 -1
  87. package/dist/analyzer/typedDicts.js.map +1 -1
  88. package/dist/analyzer/types.d.ts +12 -4
  89. package/dist/analyzer/types.js +215 -6
  90. package/dist/analyzer/types.js.map +1 -1
  91. package/dist/backgroundAnalysisBase.d.ts +1 -1
  92. package/dist/commands/commands.js +9 -0
  93. package/dist/commands/commands.js.map +1 -1
  94. package/dist/common/commandLineOptions.js +8 -1
  95. package/dist/common/commandLineOptions.js.map +1 -1
  96. package/dist/common/core.js +7 -1
  97. package/dist/common/core.js.map +1 -1
  98. package/dist/common/diagnostic.js +9 -1
  99. package/dist/common/diagnostic.js.map +1 -1
  100. package/dist/common/host.js +7 -1
  101. package/dist/common/host.js.map +1 -1
  102. package/dist/common/pathUtils.d.ts +1 -0
  103. package/dist/common/pathUtils.js +34 -1
  104. package/dist/common/pathUtils.js.map +1 -1
  105. package/dist/common/stringUtils.d.ts +1 -0
  106. package/dist/common/stringUtils.js +8 -1
  107. package/dist/common/stringUtils.js.map +1 -1
  108. package/dist/languageServerBase.d.ts +10 -3
  109. package/dist/languageServerBase.js +40 -14
  110. package/dist/languageServerBase.js.map +1 -1
  111. package/dist/languageService/analyzerServiceExecutor.js +3 -0
  112. package/dist/languageService/analyzerServiceExecutor.js.map +1 -1
  113. package/dist/languageService/autoImporter.js +2 -1
  114. package/dist/languageService/autoImporter.js.map +1 -1
  115. package/dist/languageService/callHierarchyProvider.js +9 -9
  116. package/dist/languageService/completionProvider.d.ts +2 -2
  117. package/dist/languageService/completionProvider.js +22 -18
  118. package/dist/languageService/completionProvider.js.map +1 -1
  119. package/dist/languageService/definitionProvider.js +3 -3
  120. package/dist/languageService/documentSymbolCollector.js +1 -1
  121. package/dist/languageService/documentSymbolProvider.js +10 -7
  122. package/dist/languageService/documentSymbolProvider.js.map +1 -1
  123. package/dist/languageService/hoverProvider.js +19 -5
  124. package/dist/languageService/hoverProvider.js.map +1 -1
  125. package/dist/languageService/referencesProvider.js +8 -5
  126. package/dist/languageService/referencesProvider.js.map +1 -1
  127. package/dist/languageService/tooltipUtils.js +1 -1
  128. package/dist/localization/localize.d.ts +27 -0
  129. package/dist/localization/localize.js +16 -0
  130. package/dist/localization/localize.js.map +1 -1
  131. package/dist/localization/package.nls.en-us.json +18 -2
  132. package/dist/parser/parseNodes.d.ts +44 -5
  133. package/dist/parser/parseNodes.js +191 -4
  134. package/dist/parser/parseNodes.js.map +1 -1
  135. package/dist/parser/parser.d.ts +3 -1
  136. package/dist/parser/parser.js +155 -24
  137. package/dist/parser/parser.js.map +1 -1
  138. package/dist/parser/stringTokenUtils.js +8 -1
  139. package/dist/parser/stringTokenUtils.js.map +1 -1
  140. package/dist/parser/tokenizer.js +4 -3
  141. package/dist/parser/tokenizer.js.map +1 -1
  142. package/dist/parser/tokenizerTypes.d.ts +5 -3
  143. package/dist/parser/tokenizerTypes.js +157 -1
  144. package/dist/parser/tokenizerTypes.js.map +1 -1
  145. package/dist/pyright.js +6 -1
  146. package/dist/pyright.js.map +1 -1
  147. package/dist/tests/chainedSourceFiles.test.js +12 -9
  148. package/dist/tests/chainedSourceFiles.test.js.map +1 -1
  149. package/dist/tests/checker.test.js +4 -0
  150. package/dist/tests/checker.test.js.map +1 -1
  151. package/dist/tests/config.test.js +14 -13
  152. package/dist/tests/config.test.js.map +1 -1
  153. package/dist/tests/debug.test.js +6 -0
  154. package/dist/tests/debug.test.js.map +1 -1
  155. package/dist/tests/fourslash/completions.autoimport.lib.alias.fourslash.d.ts +1 -0
  156. package/dist/tests/fourslash/completions.autoimport.lib.alias.fourslash.js +53 -0
  157. package/dist/tests/fourslash/completions.autoimport.lib.alias.fourslash.js.map +1 -0
  158. package/dist/tests/fourslash/fourslash.d.ts +16 -0
  159. package/dist/tests/fourslash/hover.class.docString.fourslash.d.ts +1 -0
  160. package/dist/tests/fourslash/hover.class.docString.fourslash.js +24 -0
  161. package/dist/tests/fourslash/hover.class.docString.fourslash.js.map +1 -0
  162. package/dist/tests/harness/fourslash/fourSlashParser.js +6 -0
  163. package/dist/tests/harness/fourslash/fourSlashParser.js.map +1 -1
  164. package/dist/tests/harness/fourslash/fourSlashTypes.js +19 -1
  165. package/dist/tests/harness/fourslash/fourSlashTypes.js.map +1 -1
  166. package/dist/tests/harness/fourslash/testLanguageService.js +9 -1
  167. package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
  168. package/dist/tests/harness/fourslash/testState.Consts.d.ts +1 -0
  169. package/dist/tests/harness/fourslash/testState.Consts.js +1 -0
  170. package/dist/tests/harness/fourslash/testState.Consts.js.map +1 -1
  171. package/dist/tests/harness/fourslash/testState.d.ts +4 -3
  172. package/dist/tests/harness/fourslash/testState.js +27 -11
  173. package/dist/tests/harness/fourslash/testState.js.map +1 -1
  174. package/dist/tests/harness/vfs/pathValidation.js +25 -1
  175. package/dist/tests/harness/vfs/pathValidation.js.map +1 -1
  176. package/dist/tests/pathUtils.test.js +17 -0
  177. package/dist/tests/pathUtils.test.js.map +1 -1
  178. package/dist/tests/testUtils.js +1 -1
  179. package/dist/tests/testUtils.js.map +1 -1
  180. package/dist/tests/typeEvaluator1.test.js +9 -1
  181. package/dist/tests/typeEvaluator1.test.js.map +1 -1
  182. package/dist/tests/typeEvaluator2.test.js +9 -1
  183. package/dist/tests/typeEvaluator2.test.js.map +1 -1
  184. package/dist/tests/typeEvaluator3.test.js +4 -0
  185. package/dist/tests/typeEvaluator3.test.js.map +1 -1
  186. package/dist/tests/typeEvaluator5.test.d.ts +1 -0
  187. package/dist/tests/typeEvaluator5.test.js +112 -0
  188. package/dist/tests/typeEvaluator5.test.js.map +1 -0
  189. package/dist/workspaceMap.d.ts +2 -1
  190. package/dist/workspaceMap.js +25 -3
  191. package/dist/workspaceMap.js.map +1 -1
  192. package/package.json +45 -45
  193. package/src/analyzer/aliasDeclarationUtils.ts +0 -169
  194. package/src/analyzer/analysis.ts +0 -92
  195. package/src/analyzer/analyzerFileInfo.ts +0 -56
  196. package/src/analyzer/analyzerNodeInfo.ts +0 -198
  197. package/src/analyzer/backgroundAnalysisProgram.ts +0 -311
  198. package/src/analyzer/binder.ts +0 -4081
  199. package/src/analyzer/checker.ts +0 -5507
  200. package/src/analyzer/circularDependency.ts +0 -52
  201. package/src/analyzer/codeFlowEngine.ts +0 -1548
  202. package/src/analyzer/codeFlowTypes.ts +0 -266
  203. package/src/analyzer/codeFlowUtils.ts +0 -436
  204. package/src/analyzer/commentUtils.ts +0 -174
  205. package/src/analyzer/constraintSolver.ts +0 -926
  206. package/src/analyzer/constructorTransform.ts +0 -317
  207. package/src/analyzer/dataClasses.ts +0 -999
  208. package/src/analyzer/declaration.ts +0 -252
  209. package/src/analyzer/declarationUtils.ts +0 -238
  210. package/src/analyzer/docStringConversion.ts +0 -850
  211. package/src/analyzer/docStringUtils.ts +0 -112
  212. package/src/analyzer/functionTransform.ts +0 -137
  213. package/src/analyzer/importResolver.ts +0 -2308
  214. package/src/analyzer/importResult.ts +0 -98
  215. package/src/analyzer/importStatementUtils.ts +0 -834
  216. package/src/analyzer/namedTuples.ts +0 -422
  217. package/src/analyzer/packageTypeReport.ts +0 -108
  218. package/src/analyzer/packageTypeVerifier.ts +0 -1466
  219. package/src/analyzer/parentDirectoryCache.ts +0 -88
  220. package/src/analyzer/parseTreeCleaner.ts +0 -35
  221. package/src/analyzer/parseTreeUtils.ts +0 -2165
  222. package/src/analyzer/parseTreeWalker.ts +0 -663
  223. package/src/analyzer/patternMatching.ts +0 -1356
  224. package/src/analyzer/program.ts +0 -2778
  225. package/src/analyzer/properties.ts +0 -534
  226. package/src/analyzer/protocols.ts +0 -660
  227. package/src/analyzer/pyTypedUtils.ts +0 -52
  228. package/src/analyzer/pythonPathUtils.ts +0 -201
  229. package/src/analyzer/scope.ts +0 -202
  230. package/src/analyzer/scopeUtils.ts +0 -81
  231. package/src/analyzer/service.ts +0 -1679
  232. package/src/analyzer/sourceFile.ts +0 -1401
  233. package/src/analyzer/sourceMapper.ts +0 -717
  234. package/src/analyzer/staticExpressions.ts +0 -308
  235. package/src/analyzer/symbol.ts +0 -249
  236. package/src/analyzer/symbolNameUtils.ts +0 -50
  237. package/src/analyzer/symbolUtils.ts +0 -49
  238. package/src/analyzer/testWalker.ts +0 -101
  239. package/src/analyzer/tracePrinter.ts +0 -264
  240. package/src/analyzer/typeCache.ts +0 -181
  241. package/src/analyzer/typeDocStringUtils.ts +0 -371
  242. package/src/analyzer/typeEvaluator.ts +0 -23395
  243. package/src/analyzer/typeEvaluatorTypes.ts +0 -452
  244. package/src/analyzer/typeEvaluatorWithTracker.ts +0 -161
  245. package/src/analyzer/typeGuards.ts +0 -1828
  246. package/src/analyzer/typePrinter.ts +0 -807
  247. package/src/analyzer/typeStubWriter.ts +0 -727
  248. package/src/analyzer/typeUtils.ts +0 -3126
  249. package/src/analyzer/typeVarContext.ts +0 -330
  250. package/src/analyzer/typedDicts.ts +0 -950
  251. package/src/analyzer/types.ts +0 -2857
  252. package/src/backgroundAnalysis.ts +0 -49
  253. package/src/backgroundAnalysisBase.ts +0 -606
  254. package/src/backgroundThreadBase.ts +0 -143
  255. package/src/commands/commandController.ts +0 -62
  256. package/src/commands/commandResult.ts +0 -21
  257. package/src/commands/commands.ts +0 -16
  258. package/src/commands/createTypeStub.ts +0 -56
  259. package/src/commands/quickActionCommand.ts +0 -40
  260. package/src/commands/restartServer.ts +0 -20
  261. package/src/common/cancellationUtils.ts +0 -71
  262. package/src/common/chokidarFileWatcherProvider.ts +0 -74
  263. package/src/common/collectionUtils.ts +0 -379
  264. package/src/common/commandLineOptions.ts +0 -132
  265. package/src/common/configOptions.ts +0 -1291
  266. package/src/common/console.ts +0 -201
  267. package/src/common/core.ts +0 -152
  268. package/src/common/crypto.ts +0 -60
  269. package/src/common/debug.ts +0 -144
  270. package/src/common/deferred.ts +0 -78
  271. package/src/common/diagnostic.ts +0 -191
  272. package/src/common/diagnosticRules.ts +0 -80
  273. package/src/common/diagnosticSink.ts +0 -150
  274. package/src/common/editAction.ts +0 -46
  275. package/src/common/extensibility.ts +0 -35
  276. package/src/common/extensions.ts +0 -21
  277. package/src/common/fileBasedCancellationUtils.ts +0 -274
  278. package/src/common/fileSystem.ts +0 -152
  279. package/src/common/fullAccessHost.ts +0 -203
  280. package/src/common/host.ts +0 -49
  281. package/src/common/logTracker.ts +0 -157
  282. package/src/common/lspUtils.ts +0 -18
  283. package/src/common/memUtils.ts +0 -36
  284. package/src/common/pathConsts.ts +0 -16
  285. package/src/common/pathUtils.ts +0 -987
  286. package/src/common/positionUtils.ts +0 -78
  287. package/src/common/progressReporter.ts +0 -53
  288. package/src/common/pythonVersion.ts +0 -74
  289. package/src/common/realFileSystem.ts +0 -433
  290. package/src/common/stringUtils.ts +0 -161
  291. package/src/common/textEditUtils.ts +0 -31
  292. package/src/common/textRange.ts +0 -225
  293. package/src/common/textRangeCollection.ts +0 -122
  294. package/src/common/timing.ts +0 -105
  295. package/src/common/uriParser.ts +0 -26
  296. package/src/common/workspaceEditUtils.ts +0 -100
  297. package/src/languageServerBase.ts +0 -1556
  298. package/src/languageService/analyzerServiceExecutor.ts +0 -144
  299. package/src/languageService/autoImporter.ts +0 -926
  300. package/src/languageService/callHierarchyProvider.ts +0 -476
  301. package/src/languageService/codeActionProvider.ts +0 -85
  302. package/src/languageService/completionProvider.ts +0 -3103
  303. package/src/languageService/definitionProvider.ts +0 -235
  304. package/src/languageService/documentHighlightProvider.ts +0 -61
  305. package/src/languageService/documentSymbolCollector.ts +0 -466
  306. package/src/languageService/documentSymbolProvider.ts +0 -466
  307. package/src/languageService/hoverProvider.ts +0 -499
  308. package/src/languageService/importAdder.ts +0 -437
  309. package/src/languageService/importSorter.ts +0 -196
  310. package/src/languageService/indentationUtils.ts +0 -813
  311. package/src/languageService/quickActions.ts +0 -113
  312. package/src/languageService/referencesProvider.ts +0 -316
  313. package/src/languageService/renameModuleProvider.ts +0 -1400
  314. package/src/languageService/signatureHelpProvider.ts +0 -227
  315. package/src/languageService/tooltipUtils.ts +0 -147
  316. package/src/localization/localize.ts +0 -1272
  317. package/src/localization/package.nls.de.json +0 -3
  318. package/src/localization/package.nls.en-us.json +0 -636
  319. package/src/localization/package.nls.es.json +0 -3
  320. package/src/localization/package.nls.fr.json +0 -3
  321. package/src/localization/package.nls.ja.json +0 -3
  322. package/src/localization/package.nls.ru.json +0 -3
  323. package/src/localization/package.nls.zh-cn.json +0 -3
  324. package/src/localization/package.nls.zh-tw.json +0 -3
  325. package/src/nodeMain.ts +0 -21
  326. package/src/nodeServer.ts +0 -30
  327. package/src/parser/characterStream.ts +0 -145
  328. package/src/parser/characters.ts +0 -285
  329. package/src/parser/parseNodes.ts +0 -2338
  330. package/src/parser/parser.ts +0 -4859
  331. package/src/parser/stringTokenUtils.ts +0 -564
  332. package/src/parser/tokenizer.ts +0 -1379
  333. package/src/parser/tokenizerTypes.ts +0 -420
  334. package/src/parser/unicode.ts +0 -2917
  335. package/src/pyright.ts +0 -824
  336. package/src/pyrightFileSystem.ts +0 -237
  337. package/src/readonlyAugmentedFileSystem.ts +0 -204
  338. package/src/server.ts +0 -298
  339. package/src/tests/chainedSourceFiles.test.ts +0 -183
  340. package/src/tests/checker.test.ts +0 -445
  341. package/src/tests/collectionUtils.test.ts +0 -178
  342. package/src/tests/common.test.ts +0 -117
  343. package/src/tests/config.test.ts +0 -291
  344. package/src/tests/debug.test.ts +0 -120
  345. package/src/tests/deferred.test.ts +0 -54
  346. package/src/tests/diagnosticOverrides.test.ts +0 -104
  347. package/src/tests/docStringConversion.test.ts +0 -823
  348. package/src/tests/docStringUtils.test.ts +0 -57
  349. package/src/tests/documentSymbolCollector.test.ts +0 -735
  350. package/src/tests/filesystem.test.ts +0 -215
  351. package/src/tests/fourSlashParser.test.ts +0 -330
  352. package/src/tests/fourSlashRunner.test.ts +0 -36
  353. package/src/tests/fourslash/completions.autoimport.Lib.Found.Type.fourslash.ts +0 -33
  354. package/src/tests/fourslash/completions.autoimport.Lib.Found.duplication.fourslash.ts +0 -47
  355. package/src/tests/fourslash/completions.autoimport.Lib.NotFound.fourslash.ts +0 -14
  356. package/src/tests/fourslash/completions.autoimport.disabled.fourslash.ts +0 -25
  357. package/src/tests/fourslash/completions.autoimport.duplicates.fourslash.ts +0 -36
  358. package/src/tests/fourslash/completions.autoimport.fourslash.ts +0 -29
  359. package/src/tests/fourslash/completions.autoimport.fromImport.fourslash.ts +0 -130
  360. package/src/tests/fourslash/completions.autoimport.plainText.fourslash.ts +0 -29
  361. package/src/tests/fourslash/completions.autoimport.shadow.fourslash.ts +0 -48
  362. package/src/tests/fourslash/completions.autoimport.submodule.fourslash.ts +0 -31
  363. package/src/tests/fourslash/completions.autoimport.topLevel.fourslash.ts +0 -57
  364. package/src/tests/fourslash/completions.builtinDocstrings.fourslash.ts +0 -117
  365. package/src/tests/fourslash/completions.builtinOverride.fourslash.ts +0 -22
  366. package/src/tests/fourslash/completions.call.stringLiteral.fourslash.ts +0 -55
  367. package/src/tests/fourslash/completions.call.typedDict.fourslash.ts +0 -247
  368. package/src/tests/fourslash/completions.call.typedDict.list.fourslash.ts +0 -163
  369. package/src/tests/fourslash/completions.call.typedDict.states.fourslash.ts +0 -135
  370. package/src/tests/fourslash/completions.classVariable.fourslash.ts +0 -37
  371. package/src/tests/fourslash/completions.comment.fourslash.ts +0 -28
  372. package/src/tests/fourslash/completions.declNames.class.fourslash.ts +0 -35
  373. package/src/tests/fourslash/completions.declNames.exception.fourslash.ts +0 -18
  374. package/src/tests/fourslash/completions.declNames.for.fourslash.ts +0 -30
  375. package/src/tests/fourslash/completions.declNames.importAlias.fourslash.ts +0 -15
  376. package/src/tests/fourslash/completions.declNames.lambda.fourslash.ts +0 -45
  377. package/src/tests/fourslash/completions.declNames.method.fourslash.ts +0 -71
  378. package/src/tests/fourslash/completions.declNames.overload.fourslash.ts +0 -156
  379. package/src/tests/fourslash/completions.declNames.topLevelOverload.fourslash.ts +0 -141
  380. package/src/tests/fourslash/completions.dictionary.keys.complex.fourslash.ts +0 -76
  381. package/src/tests/fourslash/completions.dictionary.keys.expression.fourslash.ts +0 -63
  382. package/src/tests/fourslash/completions.dictionary.keys.literalTypes.fourslash.ts +0 -161
  383. package/src/tests/fourslash/completions.dictionary.keys.simple.fourslash.ts +0 -151
  384. package/src/tests/fourslash/completions.dictionary.keys.stringLiterals.fourslash.ts +0 -116
  385. package/src/tests/fourslash/completions.dictionary.keys.symbols.fourslash.ts +0 -53
  386. package/src/tests/fourslash/completions.enums.members.fourslash.ts +0 -44
  387. package/src/tests/fourslash/completions.excluded.fourslash.ts +0 -12
  388. package/src/tests/fourslash/completions.fourslash.ts +0 -51
  389. package/src/tests/fourslash/completions.fstring.fourslash.ts +0 -33
  390. package/src/tests/fourslash/completions.fstring.stringLiteral.fourslash.ts +0 -96
  391. package/src/tests/fourslash/completions.fuzzyMatching.fourslash.ts +0 -30
  392. package/src/tests/fourslash/completions.importDunderNames.fourslash.ts +0 -31
  393. package/src/tests/fourslash/completions.importSubmodule.fourslash.ts +0 -26
  394. package/src/tests/fourslash/completions.importsDuplicates.fourslash.ts +0 -23
  395. package/src/tests/fourslash/completions.inList.fourslash.ts +0 -33
  396. package/src/tests/fourslash/completions.included.fourslash.ts +0 -12
  397. package/src/tests/fourslash/completions.indexer.keys.getitem.fourslash.ts +0 -57
  398. package/src/tests/fourslash/completions.inherited.function.docFromStub.fourslash.ts +0 -28
  399. package/src/tests/fourslash/completions.inherited.overload.docFromScrWithStub.fourslash.ts +0 -52
  400. package/src/tests/fourslash/completions.inherited.overload.docFromStub.fourslash.ts +0 -53
  401. package/src/tests/fourslash/completions.inherited.property.docFromSrc.fourslash.ts +0 -104
  402. package/src/tests/fourslash/completions.inherited.property.docFromStub.fourslash.ts +0 -108
  403. package/src/tests/fourslash/completions.keywords.pythonVersion.fourslash.ts +0 -72
  404. package/src/tests/fourslash/completions.libCodeAndStub.fourslash.ts +0 -79
  405. package/src/tests/fourslash/completions.libCodeNoStub.fourslash.ts +0 -69
  406. package/src/tests/fourslash/completions.libStub.fourslash.ts +0 -69
  407. package/src/tests/fourslash/completions.literals.fourslash.ts +0 -33
  408. package/src/tests/fourslash/completions.localCode.fourslash.ts +0 -74
  409. package/src/tests/fourslash/completions.moduleContext.UnknownMemberOnInstance.fourslash.ts +0 -17
  410. package/src/tests/fourslash/completions.moduleContext.UnknownStaticFunctionOnClass.fourslash.ts +0 -57
  411. package/src/tests/fourslash/completions.moduleContext.libCodeNoStub.fourslash.ts +0 -30
  412. package/src/tests/fourslash/completions.overloads.fourslash.ts +0 -40
  413. package/src/tests/fourslash/completions.override.default.fourslash.ts +0 -47
  414. package/src/tests/fourslash/completions.override.default.importStub.ts +0 -50
  415. package/src/tests/fourslash/completions.override.default.imported.fourslash.ts +0 -61
  416. package/src/tests/fourslash/completions.override.default.stub.fourslash.ts +0 -47
  417. package/src/tests/fourslash/completions.override.fourslash.ts +0 -47
  418. package/src/tests/fourslash/completions.override.property.fourslash.ts +0 -31
  419. package/src/tests/fourslash/completions.override.property.stub.fourslash.ts +0 -31
  420. package/src/tests/fourslash/completions.override.staticAndClassmethod.fourslash.ts +0 -64
  421. package/src/tests/fourslash/completions.override.stub.fourslash.ts +0 -47
  422. package/src/tests/fourslash/completions.override2.fourslash.ts +0 -71
  423. package/src/tests/fourslash/completions.parameters.fourslash.ts +0 -23
  424. package/src/tests/fourslash/completions.params.fourslash.ts +0 -24
  425. package/src/tests/fourslash/completions.parentFolder.fourslash.ts +0 -17
  426. package/src/tests/fourslash/completions.parentFolders.fourslash.ts +0 -77
  427. package/src/tests/fourslash/completions.plainText.fourslash.ts +0 -34
  428. package/src/tests/fourslash/completions.private.fourslash.ts +0 -64
  429. package/src/tests/fourslash/completions.property.fourslash.ts +0 -28
  430. package/src/tests/fourslash/completions.propertyDocStrings.fourslash.ts +0 -64
  431. package/src/tests/fourslash/completions.self.fourslash.ts +0 -43
  432. package/src/tests/fourslash/completions.stringLiteral.escape.fourslash.ts +0 -71
  433. package/src/tests/fourslash/completions.stringLiteral.fourslash.ts +0 -79
  434. package/src/tests/fourslash/completions.typeAlias.fourslash.ts +0 -29
  435. package/src/tests/fourslash/completions.typeshed.fourslash.ts +0 -9
  436. package/src/tests/fourslash/completions.vardecls.fourslash.ts +0 -40
  437. package/src/tests/fourslash/completions.variableDocStrings.fourslash.ts +0 -69
  438. package/src/tests/fourslash/completions.wildcardimports.fourslash.ts +0 -116
  439. package/src/tests/fourslash/completions.with.fourslash.ts +0 -26
  440. package/src/tests/fourslash/diagnostics.missingModuleSource.fourslash.ts +0 -69
  441. package/src/tests/fourslash/findDefinitions.builtinClass.fourslash.ts +0 -29
  442. package/src/tests/fourslash/findDefinitions.classes.fourslash.ts +0 -101
  443. package/src/tests/fourslash/findDefinitions.definitionFilter.preferSource.fourslash.ts +0 -29
  444. package/src/tests/fourslash/findDefinitions.definitionFilter.preferSource.onlyStubs.ts +0 -24
  445. package/src/tests/fourslash/findDefinitions.definitionFilter.preferStub.fourslash.ts +0 -29
  446. package/src/tests/fourslash/findDefinitions.definitionFilter.preferStub.onlySource.fourslash.ts +0 -25
  447. package/src/tests/fourslash/findDefinitions.fields.fourslash.ts +0 -131
  448. package/src/tests/fourslash/findDefinitions.functions.fourslash.ts +0 -87
  449. package/src/tests/fourslash/findDefinitions.methods.fourslash.ts +0 -162
  450. package/src/tests/fourslash/findDefinitions.modules.fourslash.ts +0 -50
  451. package/src/tests/fourslash/findDefinitions.namespaceImport.fourslash.ts +0 -40
  452. package/src/tests/fourslash/findDefinitions.overloads.fourslash.ts +0 -223
  453. package/src/tests/fourslash/findDefinitions.parameters.fourslash.ts +0 -162
  454. package/src/tests/fourslash/findDefinitions.sourceAndStub.function.fourslash.ts +0 -26
  455. package/src/tests/fourslash/findDefinitions.sourceAndStub.innerClass.fourslash.ts +0 -32
  456. package/src/tests/fourslash/findDefinitions.sourceAndStub.innerClassMethod.fourslash.ts +0 -33
  457. package/src/tests/fourslash/findDefinitions.sourceAndStub.outerClass.fourslash.ts +0 -28
  458. package/src/tests/fourslash/findDefinitions.sourceAndStub.outerClassMethod.fourslash.ts +0 -29
  459. package/src/tests/fourslash/findDefinitions.sourceAndStub.outerClassPropertyReadOnly.fourslash.ts +0 -31
  460. package/src/tests/fourslash/findDefinitions.sourceAndStub.outerClassPropertyReadWrite.fourslash.ts +0 -36
  461. package/src/tests/fourslash/findDefinitions.sourceOnly.class.fourslash.ts +0 -29
  462. package/src/tests/fourslash/findDefinitions.sourceOnly.function1.fourslash.ts +0 -28
  463. package/src/tests/fourslash/findDefinitions.sourceOnly.function2.fourslash.ts +0 -28
  464. package/src/tests/fourslash/findDefinitions.sourceOnly.relativeImport1.fourslash.ts +0 -22
  465. package/src/tests/fourslash/findDefinitions.sourceOnly.relativeImport2.fourslash.ts +0 -22
  466. package/src/tests/fourslash/findDefinitions.stubOnly.fourslash.ts +0 -61
  467. package/src/tests/fourslash/findDefinitions.stubPackages.fourslash.ts +0 -71
  468. package/src/tests/fourslash/findDefinitions.typedDict.keys.fourslash.ts +0 -99
  469. package/src/tests/fourslash/findDefinitions.variables.fourslash.ts +0 -88
  470. package/src/tests/fourslash/findDefinitions.wildcardimports.fourslash.ts +0 -117
  471. package/src/tests/fourslash/findTypeDefinitions.builtinClass.fourslash.ts +0 -26
  472. package/src/tests/fourslash/findTypeDefinitions.classes.fourslash.ts +0 -72
  473. package/src/tests/fourslash/findTypeDefinitions.unions.fourslash.ts +0 -26
  474. package/src/tests/fourslash/findallreferences.classPropertyReadWrite.ts +0 -39
  475. package/src/tests/fourslash/findallreferences.fourslash.ts +0 -34
  476. package/src/tests/fourslash/findallreferences.importalias.fourslash.ts +0 -34
  477. package/src/tests/fourslash/findallreferences.invokedFromLibrary.fourslash.ts +0 -52
  478. package/src/tests/fourslash/findallreferences.module.nested.fourslash.ts +0 -67
  479. package/src/tests/fourslash/findallreferences.modules.duplicated.fourslash.ts +0 -59
  480. package/src/tests/fourslash/findallreferences.modules.fourslash.ts +0 -46
  481. package/src/tests/fourslash/findallreferences.modules.shadow.fourslash.ts +0 -95
  482. package/src/tests/fourslash/findallreferences.openFiles.fourslash.ts +0 -37
  483. package/src/tests/fourslash/findallreferences.parameter.fourslash.ts +0 -24
  484. package/src/tests/fourslash/findallreferences.sourceAndStub.class.fourslash.ts +0 -33
  485. package/src/tests/fourslash/findallreferences.sourceAndStub.classMethod.fourslash.ts +0 -37
  486. package/src/tests/fourslash/findallreferences.sourceAndStub.classPropertyReadOnly.fourslash.ts +0 -40
  487. package/src/tests/fourslash/findallreferences.sourceAndStub.classPropertyReadWrite.fourslash.skip.ts +0 -48
  488. package/src/tests/fourslash/findallreferences.sourceAndStub.function.fourslash.ts +0 -35
  489. package/src/tests/fourslash/findallreferences.variable.fourslash.ts +0 -24
  490. package/src/tests/fourslash/fourslash.ts +0 -411
  491. package/src/tests/fourslash/highlightreferences.attributes.fourslash.ts +0 -31
  492. package/src/tests/fourslash/hover.builtinDocstrings.fourslash.ts +0 -64
  493. package/src/tests/fourslash/hover.classNoInit.fourslash.ts +0 -14
  494. package/src/tests/fourslash/hover.docFromScr.stringFormat.fourslash.ts +0 -52
  495. package/src/tests/fourslash/hover.docFromSrc.fourslash.ts +0 -83
  496. package/src/tests/fourslash/hover.docFromSrc.pkg-vs-module1.fourslash.ts +0 -26
  497. package/src/tests/fourslash/hover.docFromSrc.pkg-vs-module2.fourslash.ts +0 -26
  498. package/src/tests/fourslash/hover.docFromSrc.relativeImport1.fourslash.ts +0 -23
  499. package/src/tests/fourslash/hover.docFromSrc.relativeImport2.fourslash.ts +0 -22
  500. package/src/tests/fourslash/hover.docFromSrc.relativeImport3.fourslash.ts +0 -46
  501. package/src/tests/fourslash/hover.docFromSrc.stubs-package.fourslash.ts +0 -29
  502. package/src/tests/fourslash/hover.docFromSrc.typeshed.fourslash.ts +0 -20
  503. package/src/tests/fourslash/hover.docstring.links.fourslash.ts +0 -12
  504. package/src/tests/fourslash/hover.docstring.overloads.fourslash.ts +0 -41
  505. package/src/tests/fourslash/hover.docstring.split.fourslash.ts +0 -24
  506. package/src/tests/fourslash/hover.fourslash.ts +0 -20
  507. package/src/tests/fourslash/hover.import.django.view.fourslash.ts +0 -27
  508. package/src/tests/fourslash/hover.import.fourslash.ts +0 -11
  509. package/src/tests/fourslash/hover.inherited.docFromSrc.fourslash.ts +0 -63
  510. package/src/tests/fourslash/hover.inherited.docFromSrcWithStub.fourslash.ts +0 -54
  511. package/src/tests/fourslash/hover.inherited.docFromStub.fourslash.ts +0 -42
  512. package/src/tests/fourslash/hover.inherited.overload.docFromSrcWithStub.fourslash.ts +0 -46
  513. package/src/tests/fourslash/hover.inherited.overload.docFromStub.fourslash.ts +0 -47
  514. package/src/tests/fourslash/hover.inherited.property.docFromSrcWithStub.fourslash.ts +0 -87
  515. package/src/tests/fourslash/hover.inherited.property.docFromStub.fourslash.ts +0 -91
  516. package/src/tests/fourslash/hover.init.fourslash.ts +0 -39
  517. package/src/tests/fourslash/hover.libCodeAndStub.fourslash.ts +0 -52
  518. package/src/tests/fourslash/hover.libCodeNoStub.fourslash.ts +0 -41
  519. package/src/tests/fourslash/hover.libStub.fourslash.ts +0 -41
  520. package/src/tests/fourslash/hover.optionalAliasParameter.fourslash.ts +0 -14
  521. package/src/tests/fourslash/hover.plainText.fourslash.ts +0 -21
  522. package/src/tests/fourslash/hover.typedDict.key.fourslash.ts +0 -51
  523. package/src/tests/fourslash/hover.variable.docString.fourslash.ts +0 -41
  524. package/src/tests/fourslash/hover.wildcardimports.fourslash.ts +0 -80
  525. package/src/tests/fourslash/import.publicSymbols.fourslash.ts +0 -65
  526. package/src/tests/fourslash/import.pytyped.dunderAll.fourslash.ts +0 -77
  527. package/src/tests/fourslash/import.pytyped.privateSymbols.fourslash.ts +0 -65
  528. package/src/tests/fourslash/import.pytyped.typeCheckingBasic.fourslash.ts +0 -38
  529. package/src/tests/fourslash/import.pytyped.typeCheckingOff.fourslash.ts +0 -38
  530. package/src/tests/fourslash/import.wildcard.fourslash.ts +0 -27
  531. package/src/tests/fourslash/importnotresolved.fourslash.ts +0 -13
  532. package/src/tests/fourslash/missingModuleSource.disablingInStrictMode.fourslash.ts +0 -20
  533. package/src/tests/fourslash/missingModuleSource.fourslash.ts +0 -14
  534. package/src/tests/fourslash/missingTypeStub.codeAction.fourslash.ts +0 -33
  535. package/src/tests/fourslash/missingTypeStub.command.multipart.fourslash.ts +0 -48
  536. package/src/tests/fourslash/missingTypeStub.command.singlefile.fourslash.ts +0 -38
  537. package/src/tests/fourslash/missingTypeStub.command.singlepart.fourslash.ts +0 -38
  538. package/src/tests/fourslash/missingTypeStub.fourslash.ts +0 -20
  539. package/src/tests/fourslash/missingTypeStub.invokeCodeAction.fourslash.ts +0 -36
  540. package/src/tests/fourslash/noerrors.fourslash.ts +0 -9
  541. package/src/tests/fourslash/orderImports1.command.fourslash.ts +0 -20
  542. package/src/tests/fourslash/orderImports2.command.fourslash.ts +0 -24
  543. package/src/tests/fourslash/rename.externallyHidden.fourslash.ts +0 -24
  544. package/src/tests/fourslash/rename.externallyHidden.params.fourslash.ts +0 -24
  545. package/src/tests/fourslash/rename.fourslash.ts +0 -29
  546. package/src/tests/fourslash/rename.library.fourslash.ts +0 -29
  547. package/src/tests/fourslash/rename.library.sourceAndStub.fourslash.ts +0 -33
  548. package/src/tests/fourslash/rename.multipleDecl.fourslash.ts +0 -21
  549. package/src/tests/fourslash/rename.sourceAndStub.fourslash.ts +0 -37
  550. package/src/tests/fourslash/rename.string.excluded.fourslash.ts +0 -43
  551. package/src/tests/fourslash/rename.string.fourslash.ts +0 -26
  552. package/src/tests/fourslash/signature.builtinDocstrings.fourslash.ts +0 -63
  553. package/src/tests/fourslash/signature.complicated.fourslash.ts +0 -100
  554. package/src/tests/fourslash/signature.cornercases.fourslash.ts +0 -23
  555. package/src/tests/fourslash/signature.docstrings.fourslash.ts +0 -43
  556. package/src/tests/fourslash/signature.docstrings.overloaded.fourslash.ts +0 -50
  557. package/src/tests/fourslash/signature.docstrings.wildcardimports.fourslash.ts +0 -122
  558. package/src/tests/fourslash/signature.overload.fourslash.ts +0 -64
  559. package/src/tests/fourslash/signature.simple.fourslash.ts +0 -104
  560. package/src/tests/harness/fourslash/fourSlashParser.ts +0 -441
  561. package/src/tests/harness/fourslash/fourSlashTypes.ts +0 -134
  562. package/src/tests/harness/fourslash/runner.ts +0 -99
  563. package/src/tests/harness/fourslash/testLanguageService.ts +0 -142
  564. package/src/tests/harness/fourslash/testState.Consts.ts +0 -29
  565. package/src/tests/harness/fourslash/testState.ts +0 -1993
  566. package/src/tests/harness/testAccessHost.ts +0 -23
  567. package/src/tests/harness/testHost.ts +0 -177
  568. package/src/tests/harness/utils.ts +0 -355
  569. package/src/tests/harness/vfs/factory.ts +0 -199
  570. package/src/tests/harness/vfs/filesystem.ts +0 -1893
  571. package/src/tests/harness/vfs/pathValidation.ts +0 -154
  572. package/src/tests/importAdder.test.ts +0 -1361
  573. package/src/tests/importResolver.test.ts +0 -534
  574. package/src/tests/importStatementUtils.test.ts +0 -526
  575. package/src/tests/indentationUtils.ptvs.test.ts +0 -388
  576. package/src/tests/indentationUtils.reindent.test.ts +0 -403
  577. package/src/tests/indentationUtils.test.ts +0 -455
  578. package/src/tests/ipythonMode.test.ts +0 -365
  579. package/src/tests/localizer.test.ts +0 -47
  580. package/src/tests/parseTreeUtils.test.ts +0 -281
  581. package/src/tests/parser.test.ts +0 -99
  582. package/src/tests/pathUtils.test.ts +0 -321
  583. package/src/tests/pyrightFileSystem.test.ts +0 -183
  584. package/src/tests/renameModule.folder.test.ts +0 -261
  585. package/src/tests/renameModule.fromImports.test.ts +0 -952
  586. package/src/tests/renameModule.imports.test.ts +0 -450
  587. package/src/tests/renameModule.misc.test.ts +0 -765
  588. package/src/tests/renameModule.relativePath.test.ts +0 -277
  589. package/src/tests/renameModuleTestUtils.ts +0 -210
  590. package/src/tests/samples/abstractClass1.py +0 -51
  591. package/src/tests/samples/abstractClass2.py +0 -25
  592. package/src/tests/samples/abstractClass3.py +0 -30
  593. package/src/tests/samples/abstractClass4.py +0 -30
  594. package/src/tests/samples/abstractClass5.py +0 -42
  595. package/src/tests/samples/abstractClass6.py +0 -25
  596. package/src/tests/samples/abstractClass7.py +0 -22
  597. package/src/tests/samples/abstractClass8.py +0 -27
  598. package/src/tests/samples/annotated1.py +0 -72
  599. package/src/tests/samples/annotatedVar1.py +0 -22
  600. package/src/tests/samples/annotatedVar2.py +0 -28
  601. package/src/tests/samples/annotatedVar3.py +0 -54
  602. package/src/tests/samples/annotatedVar4.py +0 -24
  603. package/src/tests/samples/annotatedVar5.py +0 -37
  604. package/src/tests/samples/annotatedVar6.py +0 -22
  605. package/src/tests/samples/annotatedVar7.py +0 -13
  606. package/src/tests/samples/annotatedVar8.py +0 -29
  607. package/src/tests/samples/annotations1.py +0 -98
  608. package/src/tests/samples/annotations2.py +0 -33
  609. package/src/tests/samples/annotations3.py +0 -43
  610. package/src/tests/samples/annotations4.py +0 -54
  611. package/src/tests/samples/annotations5.py +0 -9
  612. package/src/tests/samples/annotations6.py +0 -29
  613. package/src/tests/samples/assert1.py +0 -22
  614. package/src/tests/samples/assertType1.py +0 -46
  615. package/src/tests/samples/assignment1.py +0 -58
  616. package/src/tests/samples/assignment10.py +0 -14
  617. package/src/tests/samples/assignment2.py +0 -40
  618. package/src/tests/samples/assignment3.py +0 -46
  619. package/src/tests/samples/assignment4.py +0 -20
  620. package/src/tests/samples/assignment5.py +0 -16
  621. package/src/tests/samples/assignment6.py +0 -25
  622. package/src/tests/samples/assignment7.py +0 -13
  623. package/src/tests/samples/assignment8.py +0 -40
  624. package/src/tests/samples/assignment9.py +0 -25
  625. package/src/tests/samples/assignmentExpr1.py +0 -23
  626. package/src/tests/samples/assignmentExpr2.py +0 -49
  627. package/src/tests/samples/assignmentExpr3.py +0 -27
  628. package/src/tests/samples/assignmentExpr4.py +0 -49
  629. package/src/tests/samples/assignmentExpr5.py +0 -15
  630. package/src/tests/samples/assignmentExpr6.py +0 -10
  631. package/src/tests/samples/assignmentExpr7.py +0 -13
  632. package/src/tests/samples/assignmentExpr8.py +0 -11
  633. package/src/tests/samples/assignmentExpr9.py +0 -28
  634. package/src/tests/samples/async1.py +0 -49
  635. package/src/tests/samples/augmentedAssignment1.py +0 -62
  636. package/src/tests/samples/augmentedAssignment2.py +0 -23
  637. package/src/tests/samples/augmentedAssignment3.py +0 -8
  638. package/src/tests/samples/await1.py +0 -23
  639. package/src/tests/samples/await2.py +0 -25
  640. package/src/tests/samples/badToken1.py +0 -6
  641. package/src/tests/samples/builtins1.py +0 -2
  642. package/src/tests/samples/call1.py +0 -93
  643. package/src/tests/samples/call2.py +0 -118
  644. package/src/tests/samples/call3.py +0 -168
  645. package/src/tests/samples/call4.py +0 -13
  646. package/src/tests/samples/call5.py +0 -95
  647. package/src/tests/samples/call6.py +0 -35
  648. package/src/tests/samples/call7.py +0 -57
  649. package/src/tests/samples/callSite1.py +0 -6
  650. package/src/tests/samples/callSite2.py +0 -12
  651. package/src/tests/samples/callable1.py +0 -53
  652. package/src/tests/samples/callable2.py +0 -58
  653. package/src/tests/samples/callable3.py +0 -28
  654. package/src/tests/samples/callable4.py +0 -32
  655. package/src/tests/samples/callable5.py +0 -40
  656. package/src/tests/samples/callable6.py +0 -83
  657. package/src/tests/samples/callbackProtocol1.py +0 -119
  658. package/src/tests/samples/callbackProtocol2.py +0 -29
  659. package/src/tests/samples/callbackProtocol3.py +0 -23
  660. package/src/tests/samples/callbackProtocol4.py +0 -73
  661. package/src/tests/samples/callbackProtocol5.py +0 -66
  662. package/src/tests/samples/callbackProtocol6.py +0 -66
  663. package/src/tests/samples/callbackProtocol7.py +0 -16
  664. package/src/tests/samples/callbackProtocol8.py +0 -16
  665. package/src/tests/samples/capturedVariable1.py +0 -106
  666. package/src/tests/samples/circular1.py +0 -16
  667. package/src/tests/samples/circular2.py +0 -38
  668. package/src/tests/samples/circularBaseClass.py +0 -17
  669. package/src/tests/samples/classGetItem1.py +0 -30
  670. package/src/tests/samples/classVar1.py +0 -41
  671. package/src/tests/samples/classVar2.py +0 -29
  672. package/src/tests/samples/classVar3.py +0 -46
  673. package/src/tests/samples/classVar4.py +0 -36
  674. package/src/tests/samples/classes1.py +0 -50
  675. package/src/tests/samples/classes3.py +0 -48
  676. package/src/tests/samples/classes4.py +0 -15
  677. package/src/tests/samples/classes5.py +0 -260
  678. package/src/tests/samples/classes6.py +0 -16
  679. package/src/tests/samples/classes7.py +0 -18
  680. package/src/tests/samples/classes8.py +0 -47
  681. package/src/tests/samples/codeFlow1.py +0 -65
  682. package/src/tests/samples/codeFlow2.py +0 -26
  683. package/src/tests/samples/codeFlow3.py +0 -8
  684. package/src/tests/samples/codeFlow4.py +0 -133
  685. package/src/tests/samples/codeFlow5.py +0 -10
  686. package/src/tests/samples/codeFlow6.py +0 -35
  687. package/src/tests/samples/codeFlow7.py +0 -35
  688. package/src/tests/samples/comparison1.py +0 -77
  689. package/src/tests/samples/comparison2.py +0 -37
  690. package/src/tests/samples/complex1.py +0 -17
  691. package/src/tests/samples/constant1.py +0 -40
  692. package/src/tests/samples/constants1.py +0 -64
  693. package/src/tests/samples/constructor1.py +0 -30
  694. package/src/tests/samples/constructor10.py +0 -19
  695. package/src/tests/samples/constructor11.py +0 -32
  696. package/src/tests/samples/constructor12.py +0 -20
  697. package/src/tests/samples/constructor13.py +0 -15
  698. package/src/tests/samples/constructor2.py +0 -180
  699. package/src/tests/samples/constructor3.py +0 -18
  700. package/src/tests/samples/constructor4.py +0 -25
  701. package/src/tests/samples/constructor5.py +0 -25
  702. package/src/tests/samples/constructor6.py +0 -70
  703. package/src/tests/samples/constructor7.py +0 -11
  704. package/src/tests/samples/constructor8.py +0 -99
  705. package/src/tests/samples/constructor9.py +0 -19
  706. package/src/tests/samples/coroutines1.py +0 -60
  707. package/src/tests/samples/coroutines2.py +0 -20
  708. package/src/tests/samples/coroutines3.py +0 -37
  709. package/src/tests/samples/dataclass1.py +0 -44
  710. package/src/tests/samples/dataclass10.py +0 -45
  711. package/src/tests/samples/dataclass11.py +0 -53
  712. package/src/tests/samples/dataclass12.py +0 -32
  713. package/src/tests/samples/dataclass13.py +0 -42
  714. package/src/tests/samples/dataclass14.py +0 -38
  715. package/src/tests/samples/dataclass15.py +0 -58
  716. package/src/tests/samples/dataclass16.py +0 -21
  717. package/src/tests/samples/dataclass17.py +0 -46
  718. package/src/tests/samples/dataclass18.py +0 -57
  719. package/src/tests/samples/dataclass19.py +0 -44
  720. package/src/tests/samples/dataclass2.py +0 -30
  721. package/src/tests/samples/dataclass20.py +0 -71
  722. package/src/tests/samples/dataclass21.py +0 -13
  723. package/src/tests/samples/dataclass3.py +0 -18
  724. package/src/tests/samples/dataclass4.py +0 -64
  725. package/src/tests/samples/dataclass5.py +0 -81
  726. package/src/tests/samples/dataclass6.py +0 -29
  727. package/src/tests/samples/dataclass7.py +0 -93
  728. package/src/tests/samples/dataclass8.py +0 -22
  729. package/src/tests/samples/dataclass9.py +0 -24
  730. package/src/tests/samples/dataclassPostInit1.py +0 -61
  731. package/src/tests/samples/dataclassTransform1.py +0 -71
  732. package/src/tests/samples/dataclassTransform2.py +0 -78
  733. package/src/tests/samples/dataclassTransform3.py +0 -83
  734. package/src/tests/samples/dataclassTransform4.py +0 -87
  735. package/src/tests/samples/decorator1.py +0 -20
  736. package/src/tests/samples/decorator2.py +0 -31
  737. package/src/tests/samples/decorator3.py +0 -27
  738. package/src/tests/samples/decorator4.py +0 -37
  739. package/src/tests/samples/decorator5.py +0 -29
  740. package/src/tests/samples/decorator6.py +0 -34
  741. package/src/tests/samples/defaultInitializer1.py +0 -26
  742. package/src/tests/samples/deprecated1.py +0 -37
  743. package/src/tests/samples/descriptor1.py +0 -134
  744. package/src/tests/samples/descriptor2.py +0 -29
  745. package/src/tests/samples/dictionary1.py +0 -42
  746. package/src/tests/samples/dictionary2.py +0 -14
  747. package/src/tests/samples/dictionary3.py +0 -30
  748. package/src/tests/samples/dictionary4.py +0 -106
  749. package/src/tests/samples/dunderAll1.py +0 -32
  750. package/src/tests/samples/dunderAll2.py +0 -16
  751. package/src/tests/samples/dunderAll3.pyi +0 -16
  752. package/src/tests/samples/duplicateDeclaration1.py +0 -115
  753. package/src/tests/samples/duplicateDeclaration2.py +0 -45
  754. package/src/tests/samples/duplicateImports1.py +0 -13
  755. package/src/tests/samples/ellipsis1.pyi +0 -48
  756. package/src/tests/samples/emptyContainers1.py +0 -89
  757. package/src/tests/samples/enums1.py +0 -52
  758. package/src/tests/samples/enums2.py +0 -15
  759. package/src/tests/samples/enums3.py +0 -24
  760. package/src/tests/samples/enums4.py +0 -23
  761. package/src/tests/samples/enums5.py +0 -16
  762. package/src/tests/samples/enums6.py +0 -33
  763. package/src/tests/samples/enums7.py +0 -54
  764. package/src/tests/samples/enums8.py +0 -14
  765. package/src/tests/samples/expressions1.py +0 -54
  766. package/src/tests/samples/expressions2.py +0 -29
  767. package/src/tests/samples/expressions3.py +0 -26
  768. package/src/tests/samples/expressions4.py +0 -23
  769. package/src/tests/samples/expressions5.py +0 -70
  770. package/src/tests/samples/expressions6.py +0 -14
  771. package/src/tests/samples/expressions7.py +0 -40
  772. package/src/tests/samples/expressions8.py +0 -26
  773. package/src/tests/samples/expressions9.py +0 -14
  774. package/src/tests/samples/final1.py +0 -14
  775. package/src/tests/samples/final2.py +0 -86
  776. package/src/tests/samples/final3.py +0 -179
  777. package/src/tests/samples/final4.pyi +0 -21
  778. package/src/tests/samples/final5.py +0 -18
  779. package/src/tests/samples/forLoop1.py +0 -88
  780. package/src/tests/samples/forLoop2.py +0 -48
  781. package/src/tests/samples/fstring1.py +0 -66
  782. package/src/tests/samples/fstring2.py +0 -12
  783. package/src/tests/samples/fstring3.py +0 -35
  784. package/src/tests/samples/fstring4.py +0 -17
  785. package/src/tests/samples/fstring5.py +0 -17
  786. package/src/tests/samples/fstring6.py +0 -14
  787. package/src/tests/samples/function1.py +0 -12
  788. package/src/tests/samples/function10.py +0 -20
  789. package/src/tests/samples/function11.py +0 -36
  790. package/src/tests/samples/function2.py +0 -7
  791. package/src/tests/samples/function3.py +0 -82
  792. package/src/tests/samples/function4.py +0 -13
  793. package/src/tests/samples/function6.py +0 -24
  794. package/src/tests/samples/function7.py +0 -13
  795. package/src/tests/samples/function8.py +0 -38
  796. package/src/tests/samples/function9.py +0 -75
  797. package/src/tests/samples/functionAnnotation1.py +0 -61
  798. package/src/tests/samples/functionAnnotation2.py +0 -26
  799. package/src/tests/samples/functionAnnotation3.py +0 -37
  800. package/src/tests/samples/functionAnnotation4.py +0 -22
  801. package/src/tests/samples/functionMember1.py +0 -18
  802. package/src/tests/samples/functionMember2.py +0 -45
  803. package/src/tests/samples/generators1.py +0 -122
  804. package/src/tests/samples/generators10.py +0 -18
  805. package/src/tests/samples/generators11.py +0 -27
  806. package/src/tests/samples/generators12.py +0 -25
  807. package/src/tests/samples/generators13.py +0 -65
  808. package/src/tests/samples/generators14.py +0 -19
  809. package/src/tests/samples/generators15.py +0 -26
  810. package/src/tests/samples/generators2.py +0 -31
  811. package/src/tests/samples/generators3.py +0 -42
  812. package/src/tests/samples/generators4.py +0 -33
  813. package/src/tests/samples/generators5.py +0 -24
  814. package/src/tests/samples/generators6.py +0 -14
  815. package/src/tests/samples/generators7.py +0 -18
  816. package/src/tests/samples/generators8.py +0 -12
  817. package/src/tests/samples/generators9.py +0 -19
  818. package/src/tests/samples/generic1.py +0 -41
  819. package/src/tests/samples/genericTypes1.py +0 -12
  820. package/src/tests/samples/genericTypes10.py +0 -38
  821. package/src/tests/samples/genericTypes11.py +0 -26
  822. package/src/tests/samples/genericTypes12.py +0 -14
  823. package/src/tests/samples/genericTypes13.py +0 -27
  824. package/src/tests/samples/genericTypes14.py +0 -22
  825. package/src/tests/samples/genericTypes15.py +0 -13
  826. package/src/tests/samples/genericTypes16.py +0 -15
  827. package/src/tests/samples/genericTypes17.py +0 -24
  828. package/src/tests/samples/genericTypes18.py +0 -135
  829. package/src/tests/samples/genericTypes19.py +0 -32
  830. package/src/tests/samples/genericTypes2.py +0 -40
  831. package/src/tests/samples/genericTypes20.py +0 -44
  832. package/src/tests/samples/genericTypes21.py +0 -29
  833. package/src/tests/samples/genericTypes22.py +0 -23
  834. package/src/tests/samples/genericTypes23.py +0 -27
  835. package/src/tests/samples/genericTypes24.py +0 -32
  836. package/src/tests/samples/genericTypes25.py +0 -37
  837. package/src/tests/samples/genericTypes26.py +0 -31
  838. package/src/tests/samples/genericTypes27.py +0 -14
  839. package/src/tests/samples/genericTypes28.py +0 -51
  840. package/src/tests/samples/genericTypes29.py +0 -24
  841. package/src/tests/samples/genericTypes3.py +0 -13
  842. package/src/tests/samples/genericTypes30.py +0 -32
  843. package/src/tests/samples/genericTypes31.py +0 -30
  844. package/src/tests/samples/genericTypes32.py +0 -25
  845. package/src/tests/samples/genericTypes33.py +0 -46
  846. package/src/tests/samples/genericTypes34.py +0 -54
  847. package/src/tests/samples/genericTypes35.py +0 -45
  848. package/src/tests/samples/genericTypes36.py +0 -35
  849. package/src/tests/samples/genericTypes37.py +0 -26
  850. package/src/tests/samples/genericTypes38.py +0 -15
  851. package/src/tests/samples/genericTypes39.py +0 -82
  852. package/src/tests/samples/genericTypes4.py +0 -37
  853. package/src/tests/samples/genericTypes40.py +0 -38
  854. package/src/tests/samples/genericTypes41.py +0 -16
  855. package/src/tests/samples/genericTypes42.py +0 -32
  856. package/src/tests/samples/genericTypes43.py +0 -24
  857. package/src/tests/samples/genericTypes44.py +0 -33
  858. package/src/tests/samples/genericTypes45.py +0 -43
  859. package/src/tests/samples/genericTypes46.py +0 -66
  860. package/src/tests/samples/genericTypes47.py +0 -39
  861. package/src/tests/samples/genericTypes48.py +0 -18
  862. package/src/tests/samples/genericTypes49.py +0 -41
  863. package/src/tests/samples/genericTypes5.py +0 -42
  864. package/src/tests/samples/genericTypes50.py +0 -62
  865. package/src/tests/samples/genericTypes51.py +0 -55
  866. package/src/tests/samples/genericTypes52.py +0 -34
  867. package/src/tests/samples/genericTypes53.py +0 -42
  868. package/src/tests/samples/genericTypes54.py +0 -31
  869. package/src/tests/samples/genericTypes55.py +0 -61
  870. package/src/tests/samples/genericTypes56.py +0 -19
  871. package/src/tests/samples/genericTypes57.py +0 -30
  872. package/src/tests/samples/genericTypes58.py +0 -52
  873. package/src/tests/samples/genericTypes59.py +0 -71
  874. package/src/tests/samples/genericTypes6.py +0 -49
  875. package/src/tests/samples/genericTypes60.py +0 -27
  876. package/src/tests/samples/genericTypes61.py +0 -34
  877. package/src/tests/samples/genericTypes62.py +0 -26
  878. package/src/tests/samples/genericTypes63.py +0 -32
  879. package/src/tests/samples/genericTypes64.py +0 -16
  880. package/src/tests/samples/genericTypes65.py +0 -15
  881. package/src/tests/samples/genericTypes66.py +0 -30
  882. package/src/tests/samples/genericTypes67.py +0 -57
  883. package/src/tests/samples/genericTypes68.py +0 -14
  884. package/src/tests/samples/genericTypes69.py +0 -45
  885. package/src/tests/samples/genericTypes7.py +0 -24
  886. package/src/tests/samples/genericTypes70.py +0 -31
  887. package/src/tests/samples/genericTypes71.py +0 -72
  888. package/src/tests/samples/genericTypes72.py +0 -24
  889. package/src/tests/samples/genericTypes73.py +0 -14
  890. package/src/tests/samples/genericTypes74.py +0 -23
  891. package/src/tests/samples/genericTypes75.py +0 -45
  892. package/src/tests/samples/genericTypes76.py +0 -107
  893. package/src/tests/samples/genericTypes77.py +0 -26
  894. package/src/tests/samples/genericTypes78.py +0 -23
  895. package/src/tests/samples/genericTypes79.py +0 -37
  896. package/src/tests/samples/genericTypes8.py +0 -26
  897. package/src/tests/samples/genericTypes80.py +0 -10
  898. package/src/tests/samples/genericTypes81.py +0 -32
  899. package/src/tests/samples/genericTypes82.py +0 -19
  900. package/src/tests/samples/genericTypes83.py +0 -28
  901. package/src/tests/samples/genericTypes84.py +0 -11
  902. package/src/tests/samples/genericTypes85.py +0 -20
  903. package/src/tests/samples/genericTypes86.py +0 -15
  904. package/src/tests/samples/genericTypes87.py +0 -21
  905. package/src/tests/samples/genericTypes88.py +0 -25
  906. package/src/tests/samples/genericTypes89.py +0 -17
  907. package/src/tests/samples/genericTypes9.py +0 -109
  908. package/src/tests/samples/genericTypes90.py +0 -12
  909. package/src/tests/samples/genericTypes91.py +0 -20
  910. package/src/tests/samples/import1.py +0 -7
  911. package/src/tests/samples/import10.py +0 -11
  912. package/src/tests/samples/import11.py +0 -11
  913. package/src/tests/samples/import12.py +0 -5
  914. package/src/tests/samples/import13.py +0 -6
  915. package/src/tests/samples/import14.py +0 -10
  916. package/src/tests/samples/import2.py +0 -27
  917. package/src/tests/samples/import3.py +0 -8
  918. package/src/tests/samples/import4.py +0 -15
  919. package/src/tests/samples/import5.py +0 -6
  920. package/src/tests/samples/import6.py +0 -17
  921. package/src/tests/samples/import7.py +0 -14
  922. package/src/tests/samples/import8.py +0 -7
  923. package/src/tests/samples/import9.py +0 -7
  924. package/src/tests/samples/inconsistentConstructor1.py +0 -23
  925. package/src/tests/samples/inconsistentSpaceTab1.py +0 -9
  926. package/src/tests/samples/inconsistentSpaceTab2.py +0 -10
  927. package/src/tests/samples/index1.py +0 -97
  928. package/src/tests/samples/inferredTypes1.py +0 -25
  929. package/src/tests/samples/initVar1.py +0 -23
  930. package/src/tests/samples/initsubclass1.py +0 -46
  931. package/src/tests/samples/initsubclass2.py +0 -16
  932. package/src/tests/samples/isinstance1.py +0 -57
  933. package/src/tests/samples/isinstance10.py +0 -15
  934. package/src/tests/samples/isinstance2.py +0 -28
  935. package/src/tests/samples/isinstance3.py +0 -59
  936. package/src/tests/samples/isinstance4.py +0 -57
  937. package/src/tests/samples/isinstance5.py +0 -8
  938. package/src/tests/samples/isinstance6.py +0 -19
  939. package/src/tests/samples/isinstance7.py +0 -42
  940. package/src/tests/samples/isinstance9.py +0 -26
  941. package/src/tests/samples/kwargsUnpack1.py +0 -116
  942. package/src/tests/samples/lambda1.py +0 -77
  943. package/src/tests/samples/lambda2.py +0 -26
  944. package/src/tests/samples/lambda3.py +0 -34
  945. package/src/tests/samples/lambda4.py +0 -70
  946. package/src/tests/samples/lambda5.py +0 -23
  947. package/src/tests/samples/lambda6.py +0 -15
  948. package/src/tests/samples/lines1.py +0 -14
  949. package/src/tests/samples/list1.py +0 -90
  950. package/src/tests/samples/listComprehension1.py +0 -45
  951. package/src/tests/samples/listComprehension2.py +0 -17
  952. package/src/tests/samples/listComprehension3.py +0 -12
  953. package/src/tests/samples/listComprehension4.py +0 -15
  954. package/src/tests/samples/listComprehension5.py +0 -20
  955. package/src/tests/samples/listComprehension6.py +0 -14
  956. package/src/tests/samples/listComprehension7.py +0 -15
  957. package/src/tests/samples/listComprehension8.py +0 -15
  958. package/src/tests/samples/literalString1.py +0 -43
  959. package/src/tests/samples/literals1.py +0 -48
  960. package/src/tests/samples/literals2.py +0 -30
  961. package/src/tests/samples/literals3.py +0 -40
  962. package/src/tests/samples/literals4.py +0 -10
  963. package/src/tests/samples/literals5.py +0 -28
  964. package/src/tests/samples/literals6.py +0 -90
  965. package/src/tests/samples/literals7.py +0 -38
  966. package/src/tests/samples/loops1.py +0 -45
  967. package/src/tests/samples/loops10.py +0 -11
  968. package/src/tests/samples/loops11.py +0 -22
  969. package/src/tests/samples/loops12.py +0 -18
  970. package/src/tests/samples/loops13.py +0 -13
  971. package/src/tests/samples/loops14.py +0 -22
  972. package/src/tests/samples/loops15.py +0 -22
  973. package/src/tests/samples/loops16.py +0 -322
  974. package/src/tests/samples/loops17.py +0 -9
  975. package/src/tests/samples/loops18.py +0 -23
  976. package/src/tests/samples/loops19.py +0 -14
  977. package/src/tests/samples/loops2.py +0 -25
  978. package/src/tests/samples/loops20.py +0 -41
  979. package/src/tests/samples/loops21.py +0 -18
  980. package/src/tests/samples/loops22.py +0 -21
  981. package/src/tests/samples/loops23.py +0 -16
  982. package/src/tests/samples/loops24.py +0 -12
  983. package/src/tests/samples/loops25.py +0 -45
  984. package/src/tests/samples/loops26.py +0 -12
  985. package/src/tests/samples/loops3.py +0 -11
  986. package/src/tests/samples/loops4.py +0 -17
  987. package/src/tests/samples/loops5.py +0 -14
  988. package/src/tests/samples/loops6.py +0 -25
  989. package/src/tests/samples/loops7.py +0 -14
  990. package/src/tests/samples/loops8.py +0 -17
  991. package/src/tests/samples/loops9.py +0 -25
  992. package/src/tests/samples/match1.py +0 -190
  993. package/src/tests/samples/match10.py +0 -67
  994. package/src/tests/samples/match2.py +0 -340
  995. package/src/tests/samples/match3.py +0 -364
  996. package/src/tests/samples/match4.py +0 -100
  997. package/src/tests/samples/match5.py +0 -70
  998. package/src/tests/samples/match6.py +0 -64
  999. package/src/tests/samples/match7.py +0 -65
  1000. package/src/tests/samples/match8.py +0 -19
  1001. package/src/tests/samples/match9.py +0 -53
  1002. package/src/tests/samples/maxParseDepth1.py +0 -499
  1003. package/src/tests/samples/maxParseDepth2.py +0 -16
  1004. package/src/tests/samples/memberAccess1.py +0 -70
  1005. package/src/tests/samples/memberAccess10.py +0 -65
  1006. package/src/tests/samples/memberAccess11.py +0 -37
  1007. package/src/tests/samples/memberAccess12.py +0 -36
  1008. package/src/tests/samples/memberAccess13.py +0 -17
  1009. package/src/tests/samples/memberAccess14.py +0 -63
  1010. package/src/tests/samples/memberAccess15.py +0 -20
  1011. package/src/tests/samples/memberAccess16.py +0 -12
  1012. package/src/tests/samples/memberAccess17.py +0 -31
  1013. package/src/tests/samples/memberAccess18.py +0 -31
  1014. package/src/tests/samples/memberAccess2.py +0 -45
  1015. package/src/tests/samples/memberAccess3.py +0 -64
  1016. package/src/tests/samples/memberAccess4.py +0 -91
  1017. package/src/tests/samples/memberAccess5.py +0 -26
  1018. package/src/tests/samples/memberAccess6.py +0 -52
  1019. package/src/tests/samples/memberAccess7.py +0 -36
  1020. package/src/tests/samples/memberAccess8.py +0 -75
  1021. package/src/tests/samples/memberAccess9.py +0 -11
  1022. package/src/tests/samples/metaclass1.py +0 -7
  1023. package/src/tests/samples/metaclass2.py +0 -35
  1024. package/src/tests/samples/metaclass3.py +0 -43
  1025. package/src/tests/samples/metaclass4.py +0 -26
  1026. package/src/tests/samples/metaclass5.py +0 -33
  1027. package/src/tests/samples/metaclass6.py +0 -15
  1028. package/src/tests/samples/metaclass7.py +0 -38
  1029. package/src/tests/samples/metaclass8.py +0 -20
  1030. package/src/tests/samples/metaclass9.py +0 -77
  1031. package/src/tests/samples/methodOverride1.py +0 -507
  1032. package/src/tests/samples/methodOverride2.py +0 -74
  1033. package/src/tests/samples/methodOverride3.py +0 -111
  1034. package/src/tests/samples/methodOverride4.py +0 -36
  1035. package/src/tests/samples/missingSuper1.py +0 -73
  1036. package/src/tests/samples/module1.py +0 -13
  1037. package/src/tests/samples/module2.py +0 -7
  1038. package/src/tests/samples/mro1.py +0 -16
  1039. package/src/tests/samples/mro2.py +0 -45
  1040. package/src/tests/samples/mro3.py +0 -30
  1041. package/src/tests/samples/mro4.py +0 -30
  1042. package/src/tests/samples/nameBindings1.py +0 -48
  1043. package/src/tests/samples/nameBindings2.py +0 -9
  1044. package/src/tests/samples/nameBindings3.py +0 -36
  1045. package/src/tests/samples/nameBindings4.py +0 -10
  1046. package/src/tests/samples/nameBindings5.py +0 -53
  1047. package/src/tests/samples/namedTuples1.py +0 -103
  1048. package/src/tests/samples/namedTuples2.py +0 -56
  1049. package/src/tests/samples/namedTuples3.py +0 -15
  1050. package/src/tests/samples/namedTuples4.py +0 -24
  1051. package/src/tests/samples/namedTuples5.py +0 -15
  1052. package/src/tests/samples/namedTuples6.py +0 -31
  1053. package/src/tests/samples/namedTuples7.py +0 -27
  1054. package/src/tests/samples/never1.py +0 -12
  1055. package/src/tests/samples/never2.py +0 -43
  1056. package/src/tests/samples/newType1.py +0 -34
  1057. package/src/tests/samples/newType2.py +0 -25
  1058. package/src/tests/samples/newType3.py +0 -34
  1059. package/src/tests/samples/newType4.py +0 -8
  1060. package/src/tests/samples/none1.py +0 -29
  1061. package/src/tests/samples/none2.py +0 -22
  1062. package/src/tests/samples/noreturn1.py +0 -78
  1063. package/src/tests/samples/noreturn2.py +0 -37
  1064. package/src/tests/samples/noreturn3.py +0 -16
  1065. package/src/tests/samples/noreturn4.py +0 -29
  1066. package/src/tests/samples/operators1.py +0 -101
  1067. package/src/tests/samples/operators2.py +0 -30
  1068. package/src/tests/samples/operators3.py +0 -8
  1069. package/src/tests/samples/operators4.py +0 -22
  1070. package/src/tests/samples/operators5.py +0 -5
  1071. package/src/tests/samples/operators6.py +0 -10
  1072. package/src/tests/samples/operators7.py +0 -24
  1073. package/src/tests/samples/operators8.py +0 -125
  1074. package/src/tests/samples/optional1.py +0 -77
  1075. package/src/tests/samples/optional2.py +0 -23
  1076. package/src/tests/samples/overload1.py +0 -50
  1077. package/src/tests/samples/overload10.py +0 -48
  1078. package/src/tests/samples/overload2.py +0 -37
  1079. package/src/tests/samples/overload3.py +0 -29
  1080. package/src/tests/samples/overload4.py +0 -46
  1081. package/src/tests/samples/overload5.py +0 -333
  1082. package/src/tests/samples/overload6.py +0 -64
  1083. package/src/tests/samples/overload7.py +0 -376
  1084. package/src/tests/samples/overload8.py +0 -89
  1085. package/src/tests/samples/overload9.py +0 -19
  1086. package/src/tests/samples/package1/__init__.py +0 -3
  1087. package/src/tests/samples/package1/psyche/pysche.py +0 -4
  1088. package/src/tests/samples/package1/psyche.py +0 -4
  1089. package/src/tests/samples/package1/sub/__init__.py +0 -5
  1090. package/src/tests/samples/package1/sub.py +0 -4
  1091. package/src/tests/samples/package1/sub.pyi +0 -2
  1092. package/src/tests/samples/paramInference1.py +0 -27
  1093. package/src/tests/samples/paramNames1.py +0 -39
  1094. package/src/tests/samples/paramSpec1.py +0 -64
  1095. package/src/tests/samples/paramSpec10.py +0 -57
  1096. package/src/tests/samples/paramSpec11.py +0 -36
  1097. package/src/tests/samples/paramSpec12.py +0 -88
  1098. package/src/tests/samples/paramSpec13.py +0 -112
  1099. package/src/tests/samples/paramSpec14.py +0 -30
  1100. package/src/tests/samples/paramSpec15.py +0 -28
  1101. package/src/tests/samples/paramSpec16.py +0 -28
  1102. package/src/tests/samples/paramSpec17.py +0 -34
  1103. package/src/tests/samples/paramSpec18.py +0 -43
  1104. package/src/tests/samples/paramSpec19.py +0 -93
  1105. package/src/tests/samples/paramSpec2.py +0 -29
  1106. package/src/tests/samples/paramSpec20.py +0 -87
  1107. package/src/tests/samples/paramSpec21.py +0 -58
  1108. package/src/tests/samples/paramSpec22.py +0 -26
  1109. package/src/tests/samples/paramSpec23.py +0 -21
  1110. package/src/tests/samples/paramSpec24.py +0 -67
  1111. package/src/tests/samples/paramSpec25.py +0 -36
  1112. package/src/tests/samples/paramSpec26.py +0 -25
  1113. package/src/tests/samples/paramSpec27.py +0 -57
  1114. package/src/tests/samples/paramSpec28.py +0 -39
  1115. package/src/tests/samples/paramSpec29.py +0 -37
  1116. package/src/tests/samples/paramSpec3.py +0 -71
  1117. package/src/tests/samples/paramSpec30.py +0 -49
  1118. package/src/tests/samples/paramSpec31.py +0 -16
  1119. package/src/tests/samples/paramSpec32.py +0 -57
  1120. package/src/tests/samples/paramSpec33.py +0 -29
  1121. package/src/tests/samples/paramSpec34.py +0 -29
  1122. package/src/tests/samples/paramSpec35.py +0 -24
  1123. package/src/tests/samples/paramSpec36.py +0 -43
  1124. package/src/tests/samples/paramSpec37.py +0 -25
  1125. package/src/tests/samples/paramSpec4.py +0 -109
  1126. package/src/tests/samples/paramSpec5.py +0 -29
  1127. package/src/tests/samples/paramSpec6.py +0 -17
  1128. package/src/tests/samples/paramSpec7.py +0 -22
  1129. package/src/tests/samples/paramSpec8.py +0 -45
  1130. package/src/tests/samples/paramSpec9.py +0 -57
  1131. package/src/tests/samples/paramType1.py +0 -71
  1132. package/src/tests/samples/parameters1.py +0 -16
  1133. package/src/tests/samples/partial1.py +0 -163
  1134. package/src/tests/samples/partial2.py +0 -31
  1135. package/src/tests/samples/private1.py +0 -55
  1136. package/src/tests/samples/private2.py +0 -11
  1137. package/src/tests/samples/project1/pyrightconfig.json +0 -5
  1138. package/src/tests/samples/project1/sample1.py +0 -0
  1139. package/src/tests/samples/project1/subfolder1/sample2.py +0 -0
  1140. package/src/tests/samples/project1/subfolder1/subfolder1-1/sample3.py +0 -0
  1141. package/src/tests/samples/project2/pyrightconfig.json +0 -3
  1142. package/src/tests/samples/project3/pyrightconfig.json +0 -7
  1143. package/src/tests/samples/project4/presentfile.py +0 -0
  1144. package/src/tests/samples/project4/pyrightconfig.json +0 -11
  1145. package/src/tests/samples/project4/subfolder/presentfile2.py +0 -0
  1146. package/src/tests/samples/project4/subfolder/presentfile3.py +0 -0
  1147. package/src/tests/samples/project5/pyrightconfig.json +0 -4
  1148. package/src/tests/samples/project6/app1.py +0 -0
  1149. package/src/tests/samples/project6/app2.py +0 -0
  1150. package/src/tests/samples/project6/projectA/foo/__init__.py +0 -0
  1151. package/src/tests/samples/project6/projectA/foo/bar/__init__.py +0 -0
  1152. package/src/tests/samples/project6/projectB/foo/__init__.py +0 -0
  1153. package/src/tests/samples/project6/projectB/foo/baz/__init__.py +0 -0
  1154. package/src/tests/samples/project_src/src/module1.py +0 -0
  1155. package/src/tests/samples/project_src_is_pkg/src/__init__.py +0 -0
  1156. package/src/tests/samples/project_src_is_pkg/src/module1.py +0 -0
  1157. package/src/tests/samples/project_src_with_config_extra_paths/pyrightconfig.json +0 -3
  1158. package/src/tests/samples/project_src_with_config_extra_paths/src/module1.py +0 -0
  1159. package/src/tests/samples/project_src_with_config_no_extra_paths/pyrightconfig.json +0 -2
  1160. package/src/tests/samples/project_src_with_config_no_extra_paths/src/module1.py +0 -0
  1161. package/src/tests/samples/project_src_with_extra_paths/src/_vendored/vendored1.py +0 -1
  1162. package/src/tests/samples/project_src_with_extra_paths/src/module1.py +0 -2
  1163. package/src/tests/samples/project_with_pyproject_toml/pyproject.toml +0 -7
  1164. package/src/tests/samples/project_with_venv_auto_detect_exclude/myvenv/Lib/site-packages/library1.py +0 -0
  1165. package/src/tests/samples/project_with_venv_auto_detect_exclude/myvenv/pyvenv.cfg +0 -0
  1166. package/src/tests/samples/project_with_venv_auto_detect_exclude/pyrightconfig.json +0 -2
  1167. package/src/tests/samples/project_with_venv_auto_detect_exclude/sample1.py +0 -0
  1168. package/src/tests/samples/project_with_venv_auto_detect_exclude/subfolder1/sample2.py +0 -0
  1169. package/src/tests/samples/project_with_venv_auto_detect_exclude/subfolder1/subfolder1-1/sample3.py +0 -0
  1170. package/src/tests/samples/project_with_venv_auto_detect_include/excluded/excluded1.py +0 -0
  1171. package/src/tests/samples/project_with_venv_auto_detect_include/myvenv/Lib/site-packages/library1.py +0 -0
  1172. package/src/tests/samples/project_with_venv_auto_detect_include/myvenv/pyvenv.cfg +0 -0
  1173. package/src/tests/samples/project_with_venv_auto_detect_include/pyrightconfig.json +0 -3
  1174. package/src/tests/samples/project_with_venv_auto_detect_include/sample1.py +0 -0
  1175. package/src/tests/samples/project_with_venv_auto_detect_include/subfolder1/sample2.py +0 -0
  1176. package/src/tests/samples/project_with_venv_auto_detect_include/subfolder1/subfolder1-1/sample3.py +0 -0
  1177. package/src/tests/samples/properties1.py +0 -64
  1178. package/src/tests/samples/properties10.py +0 -19
  1179. package/src/tests/samples/properties11.py +0 -45
  1180. package/src/tests/samples/properties12.py +0 -23
  1181. package/src/tests/samples/properties13.py +0 -15
  1182. package/src/tests/samples/properties2.py +0 -34
  1183. package/src/tests/samples/properties3.py +0 -93
  1184. package/src/tests/samples/properties4.py +0 -17
  1185. package/src/tests/samples/properties5.py +0 -29
  1186. package/src/tests/samples/properties6.py +0 -35
  1187. package/src/tests/samples/properties7.py +0 -30
  1188. package/src/tests/samples/properties8.py +0 -26
  1189. package/src/tests/samples/properties9.py +0 -24
  1190. package/src/tests/samples/protocol1.py +0 -132
  1191. package/src/tests/samples/protocol10.py +0 -36
  1192. package/src/tests/samples/protocol11.py +0 -32
  1193. package/src/tests/samples/protocol12.py +0 -12
  1194. package/src/tests/samples/protocol13.py +0 -26
  1195. package/src/tests/samples/protocol14.py +0 -27
  1196. package/src/tests/samples/protocol15.py +0 -27
  1197. package/src/tests/samples/protocol16.py +0 -22
  1198. package/src/tests/samples/protocol17.py +0 -94
  1199. package/src/tests/samples/protocol18.py +0 -27
  1200. package/src/tests/samples/protocol19.py +0 -39
  1201. package/src/tests/samples/protocol2.py +0 -38
  1202. package/src/tests/samples/protocol20.py +0 -22
  1203. package/src/tests/samples/protocol21.py +0 -26
  1204. package/src/tests/samples/protocol22.py +0 -43
  1205. package/src/tests/samples/protocol23.py +0 -41
  1206. package/src/tests/samples/protocol24.py +0 -74
  1207. package/src/tests/samples/protocol25.py +0 -31
  1208. package/src/tests/samples/protocol26.py +0 -40
  1209. package/src/tests/samples/protocol27.py +0 -76
  1210. package/src/tests/samples/protocol28.py +0 -32
  1211. package/src/tests/samples/protocol29.py +0 -26
  1212. package/src/tests/samples/protocol3.py +0 -110
  1213. package/src/tests/samples/protocol30.py +0 -30
  1214. package/src/tests/samples/protocol31.py +0 -22
  1215. package/src/tests/samples/protocol32.py +0 -67
  1216. package/src/tests/samples/protocol33.py +0 -39
  1217. package/src/tests/samples/protocol34.py +0 -21
  1218. package/src/tests/samples/protocol4.py +0 -22
  1219. package/src/tests/samples/protocol5.py +0 -25
  1220. package/src/tests/samples/protocol6.py +0 -65
  1221. package/src/tests/samples/protocol7.py +0 -24
  1222. package/src/tests/samples/protocol8.py +0 -34
  1223. package/src/tests/samples/protocol9.py +0 -35
  1224. package/src/tests/samples/protocolModule1.py +0 -15
  1225. package/src/tests/samples/protocolModule2.py +0 -83
  1226. package/src/tests/samples/protocolModule3.py +0 -14
  1227. package/src/tests/samples/protocolModule4.py +0 -26
  1228. package/src/tests/samples/pseudoGeneric1.py +0 -20
  1229. package/src/tests/samples/pyrightIgnore1.py +0 -11
  1230. package/src/tests/samples/pyrightIgnore2.py +0 -24
  1231. package/src/tests/samples/python2.py +0 -31
  1232. package/src/tests/samples/recursiveTypeAlias1.py +0 -79
  1233. package/src/tests/samples/recursiveTypeAlias2.py +0 -32
  1234. package/src/tests/samples/recursiveTypeAlias3.py +0 -26
  1235. package/src/tests/samples/recursiveTypeAlias4.py +0 -55
  1236. package/src/tests/samples/recursiveTypeAlias5.pyi +0 -10
  1237. package/src/tests/samples/recursiveTypeAlias6.py +0 -25
  1238. package/src/tests/samples/recursiveTypeAlias7.py +0 -15
  1239. package/src/tests/samples/recursiveTypeAlias8.py +0 -38
  1240. package/src/tests/samples/recursiveTypeAlias9.py +0 -22
  1241. package/src/tests/samples/required1.py +0 -47
  1242. package/src/tests/samples/required2.py +0 -56
  1243. package/src/tests/samples/required3.py +0 -22
  1244. package/src/tests/samples/returnTypes1.py +0 -26
  1245. package/src/tests/samples/revealedType1.py +0 -30
  1246. package/src/tests/samples/sample1.py +0 -6
  1247. package/src/tests/samples/self1.py +0 -93
  1248. package/src/tests/samples/self2.py +0 -195
  1249. package/src/tests/samples/self3.py +0 -9
  1250. package/src/tests/samples/self4.py +0 -18
  1251. package/src/tests/samples/self5.py +0 -26
  1252. package/src/tests/samples/setComprehension1.py +0 -34
  1253. package/src/tests/samples/slots1.py +0 -63
  1254. package/src/tests/samples/slots2.py +0 -38
  1255. package/src/tests/samples/slots3.py +0 -35
  1256. package/src/tests/samples/specialization1.py +0 -78
  1257. package/src/tests/samples/specialization2.py +0 -51
  1258. package/src/tests/samples/staticExpressions1.py +0 -52
  1259. package/src/tests/samples/strings1.py +0 -22
  1260. package/src/tests/samples/subscript1.py +0 -74
  1261. package/src/tests/samples/subscript2.py +0 -55
  1262. package/src/tests/samples/subscript3.py +0 -135
  1263. package/src/tests/samples/suiteExpectedColon1.py +0 -4
  1264. package/src/tests/samples/suiteExpectedColon2.py +0 -2
  1265. package/src/tests/samples/suiteExpectedColon3.py +0 -2
  1266. package/src/tests/samples/super1.py +0 -57
  1267. package/src/tests/samples/super2.py +0 -29
  1268. package/src/tests/samples/super3.py +0 -10
  1269. package/src/tests/samples/super4.py +0 -24
  1270. package/src/tests/samples/super5.py +0 -28
  1271. package/src/tests/samples/super6.py +0 -17
  1272. package/src/tests/samples/super7.py +0 -52
  1273. package/src/tests/samples/super8.py +0 -7
  1274. package/src/tests/samples/super9.py +0 -36
  1275. package/src/tests/samples/test_file1.py +0 -0
  1276. package/src/tests/samples/threePartVersion1.py +0 -33
  1277. package/src/tests/samples/totalOrdering1.py +0 -52
  1278. package/src/tests/samples/tryExcept1.py +0 -39
  1279. package/src/tests/samples/tryExcept10.py +0 -12
  1280. package/src/tests/samples/tryExcept2.py +0 -16
  1281. package/src/tests/samples/tryExcept3.py +0 -12
  1282. package/src/tests/samples/tryExcept4.py +0 -28
  1283. package/src/tests/samples/tryExcept5.py +0 -30
  1284. package/src/tests/samples/tryExcept6.py +0 -27
  1285. package/src/tests/samples/tryExcept7.py +0 -17
  1286. package/src/tests/samples/tryExcept8.py +0 -69
  1287. package/src/tests/samples/tryExcept9.py +0 -42
  1288. package/src/tests/samples/tupleUnpack1.py +0 -63
  1289. package/src/tests/samples/tupleUnpack2.py +0 -56
  1290. package/src/tests/samples/tupleUnpack3.py +0 -28
  1291. package/src/tests/samples/tuples1.py +0 -185
  1292. package/src/tests/samples/tuples10.py +0 -30
  1293. package/src/tests/samples/tuples11.py +0 -21
  1294. package/src/tests/samples/tuples12.py +0 -31
  1295. package/src/tests/samples/tuples13.py +0 -26
  1296. package/src/tests/samples/tuples15.py +0 -16
  1297. package/src/tests/samples/tuples16.py +0 -14
  1298. package/src/tests/samples/tuples2.py +0 -23
  1299. package/src/tests/samples/tuples3.py +0 -15
  1300. package/src/tests/samples/tuples4.py +0 -21
  1301. package/src/tests/samples/tuples5.py +0 -16
  1302. package/src/tests/samples/tuples6.py +0 -56
  1303. package/src/tests/samples/tuples7.py +0 -61
  1304. package/src/tests/samples/tuples8.py +0 -98
  1305. package/src/tests/samples/tuples9.py +0 -17
  1306. package/src/tests/samples/typeAlias1.py +0 -37
  1307. package/src/tests/samples/typeAlias10.py +0 -45
  1308. package/src/tests/samples/typeAlias11.py +0 -37
  1309. package/src/tests/samples/typeAlias12.py +0 -20
  1310. package/src/tests/samples/typeAlias13.py +0 -53
  1311. package/src/tests/samples/typeAlias14.py +0 -29
  1312. package/src/tests/samples/typeAlias15.py +0 -24
  1313. package/src/tests/samples/typeAlias16.py +0 -24
  1314. package/src/tests/samples/typeAlias2.py +0 -26
  1315. package/src/tests/samples/typeAlias3.py +0 -35
  1316. package/src/tests/samples/typeAlias4.py +0 -68
  1317. package/src/tests/samples/typeAlias5.py +0 -56
  1318. package/src/tests/samples/typeAlias6.py +0 -51
  1319. package/src/tests/samples/typeAlias7.py +0 -50
  1320. package/src/tests/samples/typeAlias8.py +0 -24
  1321. package/src/tests/samples/typeAlias9.py +0 -35
  1322. package/src/tests/samples/typeGuard1.py +0 -68
  1323. package/src/tests/samples/typeGuard2.py +0 -58
  1324. package/src/tests/samples/typeGuard3.py +0 -98
  1325. package/src/tests/samples/typeIgnore1.py +0 -10
  1326. package/src/tests/samples/typeIgnore2.py +0 -20
  1327. package/src/tests/samples/typeIgnore3.py +0 -22
  1328. package/src/tests/samples/typeIgnore4.py +0 -10
  1329. package/src/tests/samples/typeIgnore5.py +0 -7
  1330. package/src/tests/samples/typeNarrowing1.py +0 -56
  1331. package/src/tests/samples/typeNarrowing2.py +0 -14
  1332. package/src/tests/samples/typeNarrowing3.py +0 -47
  1333. package/src/tests/samples/typeNarrowing4.py +0 -24
  1334. package/src/tests/samples/typeNarrowing5.py +0 -19
  1335. package/src/tests/samples/typeNarrowing6.py +0 -27
  1336. package/src/tests/samples/typeNarrowing7.py +0 -71
  1337. package/src/tests/samples/typeNarrowingAssert1.py +0 -24
  1338. package/src/tests/samples/typeNarrowingCallable1.py +0 -78
  1339. package/src/tests/samples/typeNarrowingEnum1.py +0 -58
  1340. package/src/tests/samples/typeNarrowingEnum2.py +0 -71
  1341. package/src/tests/samples/typeNarrowingFalsy1.py +0 -50
  1342. package/src/tests/samples/typeNarrowingIn1.py +0 -97
  1343. package/src/tests/samples/typeNarrowingIsNone1.py +0 -56
  1344. package/src/tests/samples/typeNarrowingIsNone2.py +0 -8
  1345. package/src/tests/samples/typeNarrowingIsNoneTuple1.py +0 -42
  1346. package/src/tests/samples/typeNarrowingIsNoneTuple2.py +0 -35
  1347. package/src/tests/samples/typeNarrowingIsinstance1.py +0 -162
  1348. package/src/tests/samples/typeNarrowingIsinstance2.py +0 -14
  1349. package/src/tests/samples/typeNarrowingIsinstance3.py +0 -78
  1350. package/src/tests/samples/typeNarrowingIsinstance4.py +0 -50
  1351. package/src/tests/samples/typeNarrowingIsinstance5.py +0 -39
  1352. package/src/tests/samples/typeNarrowingIsinstance6.py +0 -77
  1353. package/src/tests/samples/typeNarrowingIsinstance7.py +0 -19
  1354. package/src/tests/samples/typeNarrowingIsinstance8.py +0 -19
  1355. package/src/tests/samples/typeNarrowingLiteral1.py +0 -35
  1356. package/src/tests/samples/typeNarrowingLiteral2.py +0 -63
  1357. package/src/tests/samples/typeNarrowingLiteralMember1.py +0 -140
  1358. package/src/tests/samples/typeNarrowingLocalConst1.py +0 -136
  1359. package/src/tests/samples/typeNarrowingNoneMember1.py +0 -102
  1360. package/src/tests/samples/typeNarrowingTuple1.py +0 -23
  1361. package/src/tests/samples/typeNarrowingTupleLength1.py +0 -47
  1362. package/src/tests/samples/typeNarrowingTypeIs1.py +0 -95
  1363. package/src/tests/samples/typeNarrowingTypedDict1.py +0 -99
  1364. package/src/tests/samples/typeNarrowingTypedDict2.py +0 -35
  1365. package/src/tests/samples/typeNarrowingTypedDict3.py +0 -45
  1366. package/src/tests/samples/typePromotions1.py +0 -30
  1367. package/src/tests/samples/typeVar1.py +0 -23
  1368. package/src/tests/samples/typeVar10.py +0 -21
  1369. package/src/tests/samples/typeVar11.py +0 -12
  1370. package/src/tests/samples/typeVar2.py +0 -26
  1371. package/src/tests/samples/typeVar3.py +0 -73
  1372. package/src/tests/samples/typeVar4.py +0 -45
  1373. package/src/tests/samples/typeVar5.py +0 -75
  1374. package/src/tests/samples/typeVar6.py +0 -115
  1375. package/src/tests/samples/typeVar7.py +0 -171
  1376. package/src/tests/samples/typeVar8.py +0 -30
  1377. package/src/tests/samples/typeVar9.py +0 -118
  1378. package/src/tests/samples/typedDict1.py +0 -63
  1379. package/src/tests/samples/typedDict10.py +0 -34
  1380. package/src/tests/samples/typedDict11.py +0 -12
  1381. package/src/tests/samples/typedDict12.py +0 -103
  1382. package/src/tests/samples/typedDict13.py +0 -14
  1383. package/src/tests/samples/typedDict14.py +0 -25
  1384. package/src/tests/samples/typedDict15.py +0 -53
  1385. package/src/tests/samples/typedDict16.py +0 -103
  1386. package/src/tests/samples/typedDict17.py +0 -24
  1387. package/src/tests/samples/typedDict18.py +0 -43
  1388. package/src/tests/samples/typedDict2.py +0 -56
  1389. package/src/tests/samples/typedDict3.py +0 -40
  1390. package/src/tests/samples/typedDict4.py +0 -68
  1391. package/src/tests/samples/typedDict5.py +0 -50
  1392. package/src/tests/samples/typedDict6.py +0 -77
  1393. package/src/tests/samples/typedDict7.py +0 -22
  1394. package/src/tests/samples/typedDict8.py +0 -19
  1395. package/src/tests/samples/typedDict9.py +0 -22
  1396. package/src/tests/samples/unbound1.py +0 -18
  1397. package/src/tests/samples/unbound2.py +0 -12
  1398. package/src/tests/samples/unbound3.py +0 -13
  1399. package/src/tests/samples/unbound4.py +0 -25
  1400. package/src/tests/samples/unicode1.py +0 -39
  1401. package/src/tests/samples/uninitializedVariable1.py +0 -27
  1402. package/src/tests/samples/unions1.py +0 -79
  1403. package/src/tests/samples/unions2.py +0 -15
  1404. package/src/tests/samples/unions3.py +0 -48
  1405. package/src/tests/samples/unions4.py +0 -20
  1406. package/src/tests/samples/unions5.py +0 -43
  1407. package/src/tests/samples/unnecessaryCast1.py +0 -13
  1408. package/src/tests/samples/unnecessaryIsInstance1.py +0 -91
  1409. package/src/tests/samples/unnecessaryIsSubclass1.py +0 -22
  1410. package/src/tests/samples/unpack1.py +0 -56
  1411. package/src/tests/samples/unpack2.py +0 -27
  1412. package/src/tests/samples/unpack3.py +0 -16
  1413. package/src/tests/samples/unpack4.py +0 -15
  1414. package/src/tests/samples/unreachable1.py +0 -112
  1415. package/src/tests/samples/unusedCallResult1.py +0 -67
  1416. package/src/tests/samples/unusedCoroutine1.py +0 -23
  1417. package/src/tests/samples/unusedExpression1.py +0 -34
  1418. package/src/tests/samples/unusedVariable1.py +0 -21
  1419. package/src/tests/samples/variadicTypeVar1.py +0 -51
  1420. package/src/tests/samples/variadicTypeVar10.py +0 -65
  1421. package/src/tests/samples/variadicTypeVar11.py +0 -72
  1422. package/src/tests/samples/variadicTypeVar12.py +0 -26
  1423. package/src/tests/samples/variadicTypeVar13.py +0 -35
  1424. package/src/tests/samples/variadicTypeVar14.py +0 -72
  1425. package/src/tests/samples/variadicTypeVar2.py +0 -63
  1426. package/src/tests/samples/variadicTypeVar3.py +0 -86
  1427. package/src/tests/samples/variadicTypeVar4.py +0 -71
  1428. package/src/tests/samples/variadicTypeVar5.py +0 -131
  1429. package/src/tests/samples/variadicTypeVar6.py +0 -78
  1430. package/src/tests/samples/variadicTypeVar7.py +0 -59
  1431. package/src/tests/samples/variadicTypeVar8.py +0 -116
  1432. package/src/tests/samples/variadicTypeVar9.py +0 -38
  1433. package/src/tests/samples/with1.py +0 -117
  1434. package/src/tests/samples/with2.py +0 -63
  1435. package/src/tests/samples/with3.py +0 -66
  1436. package/src/tests/samples/with4.py +0 -24
  1437. package/src/tests/samples/with5.py +0 -33
  1438. package/src/tests/samples/zipfs/bad.egg +0 -1
  1439. package/src/tests/samples/zipfs/bad.zip +0 -1
  1440. package/src/tests/samples/zipfs/basic.egg +0 -0
  1441. package/src/tests/samples/zipfs/basic.zip +0 -0
  1442. package/src/tests/samples/zipfs/corrupt.egg +0 -0
  1443. package/src/tests/samples/zipfs/corrupt.zip +0 -0
  1444. package/src/tests/sourceFile.test.ts +0 -25
  1445. package/src/tests/stringUtils.test.ts +0 -63
  1446. package/src/tests/symbolNameUtils.test.ts +0 -77
  1447. package/src/tests/testState.test.ts +0 -579
  1448. package/src/tests/testUtils.ts +0 -251
  1449. package/src/tests/tokenizer.test.ts +0 -1534
  1450. package/src/tests/typeEvaluator1.test.ts +0 -1372
  1451. package/src/tests/typeEvaluator2.test.ts +0 -1253
  1452. package/src/tests/typeEvaluator3.test.ts +0 -1279
  1453. package/src/tests/typeEvaluator4.test.ts +0 -1178
  1454. package/src/tests/updateSymbolReference.test.ts +0 -1107
  1455. package/src/tests/zipfs.test.ts +0 -116
  1456. package/src/workspaceMap.ts +0 -76
@@ -1,4859 +0,0 @@
1
- /*
2
- * parser.ts
3
- * Copyright (c) Microsoft Corporation.
4
- * Licensed under the MIT license.
5
- * Author: Eric Traut
6
- *
7
- * Based on code from python-language-server repository:
8
- * https://github.com/Microsoft/python-language-server
9
- *
10
- * Parser for the Python language. Converts a stream of tokens
11
- * into an abstract syntax tree (AST).
12
- */
13
-
14
- import Char from 'typescript-char';
15
-
16
- import { appendArray } from '../common/collectionUtils';
17
- import { assert } from '../common/debug';
18
- import { Diagnostic, DiagnosticAddendum } from '../common/diagnostic';
19
- import { DiagnosticSink } from '../common/diagnosticSink';
20
- import { convertOffsetsToRange, convertPositionToOffset } from '../common/positionUtils';
21
- import { latestStablePythonVersion, PythonVersion } from '../common/pythonVersion';
22
- import { TextRange } from '../common/textRange';
23
- import { TextRangeCollection } from '../common/textRangeCollection';
24
- import { timingStats } from '../common/timing';
25
- import { Localizer } from '../localization/localize';
26
- import {
27
- ArgumentCategory,
28
- ArgumentNode,
29
- AssertNode,
30
- AssignmentExpressionNode,
31
- AssignmentNode,
32
- AugmentedAssignmentNode,
33
- AwaitNode,
34
- BinaryOperationNode,
35
- BreakNode,
36
- CallNode,
37
- CaseNode,
38
- ClassNode,
39
- ConstantNode,
40
- ContinueNode,
41
- DecoratorNode,
42
- DelNode,
43
- DictionaryEntryNode,
44
- DictionaryExpandEntryNode,
45
- DictionaryKeyEntryNode,
46
- DictionaryNode,
47
- EllipsisNode,
48
- ErrorExpressionCategory,
49
- ErrorNode,
50
- ExceptNode,
51
- ExpressionNode,
52
- extendRange,
53
- FormatStringNode,
54
- ForNode,
55
- FunctionAnnotationNode,
56
- FunctionNode,
57
- getNextNodeId,
58
- GlobalNode,
59
- IfNode,
60
- ImportAsNode,
61
- ImportFromAsNode,
62
- ImportFromNode,
63
- ImportNode,
64
- IndexNode,
65
- LambdaNode,
66
- ListComprehensionForIfNode,
67
- ListComprehensionForNode,
68
- ListComprehensionIfNode,
69
- ListComprehensionNode,
70
- ListNode,
71
- MatchNode,
72
- MemberAccessNode,
73
- ModuleNameNode,
74
- ModuleNode,
75
- NameNode,
76
- NonlocalNode,
77
- NumberNode,
78
- ParameterCategory,
79
- ParameterNode,
80
- ParseNode,
81
- ParseNodeType,
82
- PassNode,
83
- PatternAsNode,
84
- PatternAtomNode,
85
- PatternCaptureNode,
86
- PatternClassArgumentNode,
87
- PatternClassNode,
88
- PatternLiteralNode,
89
- PatternMappingEntryNode,
90
- PatternMappingExpandEntryNode,
91
- PatternMappingKeyEntryNode,
92
- PatternMappingNode,
93
- PatternSequenceNode,
94
- PatternValueNode,
95
- RaiseNode,
96
- ReturnNode,
97
- SetNode,
98
- SliceNode,
99
- StatementListNode,
100
- StatementNode,
101
- StringListNode,
102
- StringNode,
103
- SuiteNode,
104
- TernaryNode,
105
- TryNode,
106
- TupleNode,
107
- TypeAnnotationNode,
108
- UnaryOperationNode,
109
- UnpackNode,
110
- WhileNode,
111
- WithItemNode,
112
- WithNode,
113
- YieldFromNode,
114
- YieldNode,
115
- } from './parseNodes';
116
- import * as StringTokenUtils from './stringTokenUtils';
117
- import { Tokenizer, TokenizerOutput } from './tokenizer';
118
- import {
119
- DedentToken,
120
- IdentifierToken,
121
- IndentToken,
122
- KeywordToken,
123
- KeywordType,
124
- NumberToken,
125
- OperatorToken,
126
- OperatorType,
127
- StringToken,
128
- StringTokenFlags,
129
- Token,
130
- TokenType,
131
- } from './tokenizerTypes';
132
-
133
- interface ListResult<T> {
134
- list: T[];
135
- trailingComma: boolean;
136
- parseError?: ErrorNode | undefined;
137
- }
138
-
139
- interface SubscriptListResult {
140
- list: ArgumentNode[];
141
- trailingComma: boolean;
142
- }
143
-
144
- export class ParseOptions {
145
- constructor() {
146
- this.isStubFile = false;
147
- this.pythonVersion = latestStablePythonVersion;
148
- this.reportInvalidStringEscapeSequence = false;
149
- this.skipFunctionAndClassBody = false;
150
- this.ipythonMode = false;
151
- this.reportErrorsForParsedStringContents = false;
152
- }
153
-
154
- isStubFile: boolean;
155
- pythonVersion: PythonVersion;
156
- reportInvalidStringEscapeSequence: boolean;
157
- skipFunctionAndClassBody: boolean;
158
- ipythonMode: boolean;
159
- reportErrorsForParsedStringContents: boolean;
160
- }
161
-
162
- export interface ParseResults {
163
- text: string;
164
- parseTree: ModuleNode;
165
- importedModules: ModuleImport[];
166
- futureImports: Map<string, boolean>;
167
- tokenizerOutput: TokenizerOutput;
168
- containsWildcardImport: boolean;
169
- typingSymbolAliases: Map<string, string>;
170
- }
171
-
172
- export interface ParseExpressionTextResults {
173
- parseTree?: ExpressionNode | FunctionAnnotationNode | undefined;
174
- lines: TextRangeCollection<TextRange>;
175
- diagnostics: Diagnostic[];
176
- }
177
-
178
- export interface ModuleImport {
179
- nameNode: ModuleNameNode;
180
- leadingDots: number;
181
- nameParts: string[];
182
-
183
- // Used for "from X import Y" pattern. An empty
184
- // array implies "from X import *".
185
- importedSymbols: string[] | undefined;
186
- }
187
-
188
- export interface ArgListResult {
189
- args: ArgumentNode[];
190
- trailingComma: boolean;
191
- }
192
-
193
- const enum ParseTextMode {
194
- Expression,
195
- VariableAnnotation,
196
- FunctionAnnotation,
197
- }
198
-
199
- // Limit the max child node depth to prevent stack overflows.
200
- const maxChildNodeDepth = 256;
201
-
202
- export class Parser {
203
- private _fileContents?: string;
204
- private _tokenizerOutput?: TokenizerOutput;
205
- private _tokenIndex = 0;
206
- private _areErrorsSuppressed = false;
207
- private _parseOptions: ParseOptions = new ParseOptions();
208
- private _diagSink: DiagnosticSink = new DiagnosticSink();
209
- private _isInLoop = false;
210
- private _isInFunction = false;
211
- private _isInFinally = false;
212
- private _isParsingTypeAnnotation = false;
213
- private _isParsingIndexTrailer = false;
214
- private _futureImportMap = new Map<string, boolean>();
215
- private _importedModules: ModuleImport[] = [];
216
- private _containsWildcardImport = false;
217
- private _assignmentExpressionsAllowed = true;
218
- private _typingImportAliases: string[] = [];
219
- private _typingSymbolAliases: Map<string, string> = new Map<string, string>();
220
-
221
- parseSourceFile(fileContents: string, parseOptions: ParseOptions, diagSink: DiagnosticSink): ParseResults {
222
- timingStats.tokenizeFileTime.timeOperation(() => {
223
- this._startNewParse(fileContents, 0, fileContents.length, parseOptions, diagSink);
224
- });
225
-
226
- const moduleNode = ModuleNode.create({ start: 0, length: fileContents.length });
227
-
228
- timingStats.parseFileTime.timeOperation(() => {
229
- while (!this._atEof()) {
230
- if (!this._consumeTokenIfType(TokenType.NewLine)) {
231
- // Handle a common error case and try to recover.
232
- const nextToken = this._peekToken();
233
- if (nextToken.type === TokenType.Indent) {
234
- this._getNextToken();
235
- const indentToken = nextToken as IndentToken;
236
- if (indentToken.isIndentAmbiguous) {
237
- this._addError(Localizer.Diagnostic.inconsistentTabs(), indentToken);
238
- } else {
239
- this._addError(Localizer.Diagnostic.unexpectedIndent(), nextToken);
240
- }
241
- }
242
-
243
- const statement = this._parseStatement();
244
- if (!statement) {
245
- // Perform basic error recovery to get to the next line.
246
- this._consumeTokensUntilType([TokenType.NewLine]);
247
- } else {
248
- statement.parent = moduleNode;
249
- moduleNode.statements.push(statement);
250
- }
251
- }
252
- }
253
- });
254
-
255
- assert(this._tokenizerOutput !== undefined);
256
- return {
257
- text: fileContents,
258
- parseTree: moduleNode,
259
- importedModules: this._importedModules,
260
- futureImports: this._futureImportMap,
261
- tokenizerOutput: this._tokenizerOutput!,
262
- containsWildcardImport: this._containsWildcardImport,
263
- typingSymbolAliases: this._typingSymbolAliases,
264
- };
265
- }
266
-
267
- parseTextExpression(
268
- fileContents: string,
269
- textOffset: number,
270
- textLength: number,
271
- parseOptions: ParseOptions,
272
- parseTextMode = ParseTextMode.Expression,
273
- initialParenDepth = 0,
274
- typingSymbolAliases?: Map<string, string>
275
- ): ParseExpressionTextResults {
276
- const diagSink = new DiagnosticSink();
277
- this._startNewParse(fileContents, textOffset, textLength, parseOptions, diagSink, initialParenDepth);
278
-
279
- if (typingSymbolAliases) {
280
- this._typingSymbolAliases = new Map<string, string>(typingSymbolAliases);
281
- }
282
-
283
- let parseTree: ExpressionNode | FunctionAnnotationNode | undefined;
284
- if (parseTextMode === ParseTextMode.VariableAnnotation) {
285
- parseTree = this._parseTypeAnnotation();
286
- } else if (parseTextMode === ParseTextMode.FunctionAnnotation) {
287
- parseTree = this._parseFunctionTypeAnnotation();
288
- } else {
289
- const exprListResult = this._parseTestOrStarExpressionList(
290
- /* allowAssignmentExpression */ false,
291
- /* allowMultipleUnpack */ true
292
- );
293
- if (exprListResult.parseError) {
294
- parseTree = exprListResult.parseError;
295
- } else {
296
- if (exprListResult.list.length === 0) {
297
- this._addError(Localizer.Diagnostic.expectedExpr(), this._peekToken());
298
- }
299
- parseTree = this._makeExpressionOrTuple(exprListResult, /* enclosedInParens */ false);
300
- }
301
- }
302
-
303
- if (this._peekTokenType() === TokenType.NewLine) {
304
- this._getNextToken();
305
- }
306
-
307
- if (!this._atEof()) {
308
- this._addError(Localizer.Diagnostic.unexpectedExprToken(), this._peekToken());
309
- }
310
-
311
- return {
312
- parseTree,
313
- lines: this._tokenizerOutput!.lines,
314
- diagnostics: diagSink.fetchAndClear(),
315
- };
316
- }
317
-
318
- private _startNewParse(
319
- fileContents: string,
320
- textOffset: number,
321
- textLength: number,
322
- parseOptions: ParseOptions,
323
- diagSink: DiagnosticSink,
324
- initialParenDepth = 0
325
- ) {
326
- this._fileContents = fileContents;
327
- this._parseOptions = parseOptions;
328
- this._diagSink = diagSink;
329
-
330
- // Tokenize the file contents.
331
- const tokenizer = new Tokenizer();
332
- this._tokenizerOutput = tokenizer.tokenize(
333
- fileContents,
334
- textOffset,
335
- textLength,
336
- initialParenDepth,
337
- this._parseOptions.ipythonMode
338
- );
339
- this._tokenIndex = 0;
340
- }
341
-
342
- // stmt: simple_stmt | compound_stmt
343
- // compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | with_stmt
344
- // | funcdef | classdef | decorated | async_stmt
345
- private _parseStatement(): StatementNode | ErrorNode | undefined {
346
- // Handle the errant condition of a dedent token here to provide
347
- // better recovery.
348
- if (this._consumeTokenIfType(TokenType.Dedent)) {
349
- this._addError(Localizer.Diagnostic.unexpectedUnindent(), this._peekToken());
350
- }
351
-
352
- switch (this._peekKeywordType()) {
353
- case KeywordType.If:
354
- return this._parseIfStatement();
355
-
356
- case KeywordType.While:
357
- return this._parseWhileStatement();
358
-
359
- case KeywordType.For:
360
- return this._parseForStatement();
361
-
362
- case KeywordType.Try:
363
- return this._parseTryStatement();
364
-
365
- case KeywordType.With:
366
- return this._parseWithStatement();
367
-
368
- case KeywordType.Def:
369
- return this._parseFunctionDef();
370
-
371
- case KeywordType.Class:
372
- return this._parseClassDef();
373
-
374
- case KeywordType.Async:
375
- return this._parseAsyncStatement();
376
-
377
- case KeywordType.Match: {
378
- // Match is considered a "soft" keyword, so we will treat
379
- // it as an identifier if it is followed by an unexpected
380
- // token.
381
- const peekToken = this._peekToken(1);
382
- let isInvalidMatchToken = false;
383
-
384
- if (
385
- peekToken.type === TokenType.Colon ||
386
- peekToken.type === TokenType.Semicolon ||
387
- peekToken.type === TokenType.Comma ||
388
- peekToken.type === TokenType.Dot ||
389
- peekToken.type === TokenType.NewLine ||
390
- peekToken.type === TokenType.EndOfStream
391
- ) {
392
- isInvalidMatchToken = true;
393
- } else if (peekToken.type === TokenType.Operator) {
394
- const operatorToken = peekToken as OperatorToken;
395
- if (
396
- operatorToken.operatorType !== OperatorType.Multiply &&
397
- operatorToken.operatorType !== OperatorType.Subtract
398
- ) {
399
- isInvalidMatchToken = true;
400
- }
401
- }
402
-
403
- if (!isInvalidMatchToken) {
404
- // Try to parse the match statement. If it doesn't appear to
405
- // be a match statement, treat as a non-keyword and reparse.
406
- const matchStatement = this._parseMatchStatement();
407
- if (matchStatement) {
408
- return matchStatement;
409
- }
410
- }
411
- }
412
- }
413
-
414
- if (this._peekOperatorType() === OperatorType.MatrixMultiply) {
415
- return this._parseDecorated();
416
- }
417
-
418
- return this._parseSimpleStatement();
419
- }
420
-
421
- // async_stmt: 'async' (funcdef | with_stmt | for_stmt)
422
- private _parseAsyncStatement(): StatementNode | undefined {
423
- const asyncToken = this._getKeywordToken(KeywordType.Async);
424
-
425
- switch (this._peekKeywordType()) {
426
- case KeywordType.Def:
427
- return this._parseFunctionDef(asyncToken);
428
-
429
- case KeywordType.With:
430
- return this._parseWithStatement(asyncToken);
431
-
432
- case KeywordType.For:
433
- return this._parseForStatement(asyncToken);
434
- }
435
-
436
- this._addError(Localizer.Diagnostic.unexpectedAsyncToken(), asyncToken);
437
-
438
- return undefined;
439
- }
440
-
441
- // match_stmt: "match" subject_expr ':' NEWLINE INDENT case_block+ DEDENT
442
- // subject_expr:
443
- // | star_named_expression ',' star_named_expressions?
444
- // | named_expression
445
- private _parseMatchStatement(): MatchNode | undefined {
446
- // Parse the subject expression with errors suppressed. If it's not
447
- // followed by a colon, we'll assume this is not a match statement.
448
- // We need to do this because "match" is considered a soft keyword,
449
- // and we need to distinguish between "match(2)" and "match (2):"
450
- // and between "match[2]" and "match [2]:"
451
- let smellsLikeMatchStatement = false;
452
- this._suppressErrors(() => {
453
- const curTokenIndex = this._tokenIndex;
454
-
455
- this._getKeywordToken(KeywordType.Match);
456
- const expression = this._parseTestOrStarListAsExpression(
457
- /* allowAssignmentExpression */ true,
458
- /* allowMultipleUnpack */ true,
459
- ErrorExpressionCategory.MissingPatternSubject,
460
- Localizer.Diagnostic.expectedReturnExpr()
461
- );
462
- smellsLikeMatchStatement =
463
- expression.nodeType !== ParseNodeType.Error && this._peekToken().type === TokenType.Colon;
464
-
465
- // Set the token index back to the start.
466
- this._tokenIndex = curTokenIndex;
467
- });
468
-
469
- if (!smellsLikeMatchStatement) {
470
- return undefined;
471
- }
472
-
473
- const matchToken = this._getKeywordToken(KeywordType.Match);
474
-
475
- const subjectExpression = this._parseTestOrStarListAsExpression(
476
- /* allowAssignmentExpression */ true,
477
- /* allowMultipleUnpack */ true,
478
- ErrorExpressionCategory.MissingPatternSubject,
479
- Localizer.Diagnostic.expectedReturnExpr()
480
- );
481
- const matchNode = MatchNode.create(matchToken, subjectExpression);
482
-
483
- const nextToken = this._peekToken();
484
-
485
- if (!this._consumeTokenIfType(TokenType.Colon)) {
486
- this._addError(Localizer.Diagnostic.expectedColon(), nextToken);
487
-
488
- // Try to perform parse recovery by consuming tokens until
489
- // we find the end of the line.
490
- if (this._consumeTokensUntilType([TokenType.NewLine, TokenType.Colon])) {
491
- this._getNextToken();
492
- }
493
- } else if (!this._consumeTokenIfType(TokenType.NewLine)) {
494
- this._addError(Localizer.Diagnostic.expectedNewline(), nextToken);
495
- } else {
496
- const possibleIndent = this._peekToken();
497
- if (!this._consumeTokenIfType(TokenType.Indent)) {
498
- this._addError(Localizer.Diagnostic.expectedIndentedBlock(), this._peekToken());
499
- } else {
500
- const indentToken = possibleIndent as IndentToken;
501
- if (indentToken.isIndentAmbiguous) {
502
- this._addError(Localizer.Diagnostic.inconsistentTabs(), indentToken);
503
- }
504
- }
505
-
506
- while (true) {
507
- // Handle a common error here and see if we can recover.
508
- const nextToken = this._peekToken();
509
- if (nextToken.type === TokenType.Indent) {
510
- this._getNextToken();
511
- const indentToken = nextToken as IndentToken;
512
- if (indentToken.isIndentAmbiguous) {
513
- this._addError(Localizer.Diagnostic.inconsistentTabs(), indentToken);
514
- } else {
515
- this._addError(Localizer.Diagnostic.unexpectedIndent(), nextToken);
516
- }
517
- }
518
-
519
- const caseStatement = this._parseCaseStatement();
520
- if (!caseStatement) {
521
- // Perform basic error recovery to get to the next line.
522
- if (this._consumeTokensUntilType([TokenType.NewLine, TokenType.Colon])) {
523
- this._getNextToken();
524
- }
525
- } else {
526
- caseStatement.parent = matchNode;
527
- matchNode.cases.push(caseStatement);
528
- }
529
-
530
- const dedentToken = this._peekToken() as DedentToken;
531
- if (this._consumeTokenIfType(TokenType.Dedent)) {
532
- if (!dedentToken.matchesIndent) {
533
- this._addError(Localizer.Diagnostic.inconsistentIndent(), dedentToken);
534
- }
535
- if (dedentToken.isDedentAmbiguous) {
536
- this._addError(Localizer.Diagnostic.inconsistentTabs(), dedentToken);
537
- }
538
- break;
539
- }
540
-
541
- if (this._peekTokenType() === TokenType.EndOfStream) {
542
- break;
543
- }
544
- }
545
-
546
- if (matchNode.cases.length > 0) {
547
- extendRange(matchNode, matchNode.cases[matchNode.cases.length - 1]);
548
- } else {
549
- this._addError(Localizer.Diagnostic.zeroCaseStatementsFound(), matchToken);
550
- }
551
- }
552
-
553
- // This feature requires Python 3.10.
554
- if (this._getLanguageVersion() < PythonVersion.V3_10) {
555
- this._addError(Localizer.Diagnostic.matchIncompatible(), matchToken);
556
- }
557
-
558
- // Validate that only the last entry uses an irrefutable pattern.
559
- for (let i = 0; i < matchNode.cases.length - 1; i++) {
560
- const caseNode = matchNode.cases[i];
561
- if (!caseNode.guardExpression && caseNode.isIrrefutable) {
562
- this._addError(Localizer.Diagnostic.casePatternIsIrrefutable(), caseNode.pattern);
563
- }
564
- }
565
-
566
- return matchNode;
567
- }
568
-
569
- // case_block: "case" patterns [guard] ':' block
570
- // patterns: sequence_pattern | as_pattern
571
- // guard: 'if' named_expression
572
- private _parseCaseStatement(): CaseNode | undefined {
573
- const caseToken = this._peekToken();
574
-
575
- if (!this._consumeTokenIfKeyword(KeywordType.Case)) {
576
- this._addError(Localizer.Diagnostic.expectedCase(), caseToken);
577
- return undefined;
578
- }
579
-
580
- const patternList = this._parsePatternSequence();
581
- let casePattern: PatternAtomNode;
582
-
583
- if (patternList.parseError) {
584
- casePattern = patternList.parseError;
585
- } else if (patternList.list.length === 0) {
586
- this._addError(Localizer.Diagnostic.expectedPatternExpr(), this._peekToken());
587
- casePattern = ErrorNode.create(caseToken, ErrorExpressionCategory.MissingPattern);
588
- } else if (patternList.list.length === 1 && !patternList.trailingComma) {
589
- const pattern = patternList.list[0].orPatterns[0];
590
-
591
- if (pattern.nodeType === ParseNodeType.PatternCapture && pattern.isStar) {
592
- casePattern = PatternSequenceNode.create(patternList.list[0], patternList.list);
593
- } else {
594
- casePattern = patternList.list[0];
595
- }
596
- } else {
597
- casePattern = PatternSequenceNode.create(patternList.list[0], patternList.list);
598
- }
599
-
600
- let guardExpression: ExpressionNode | undefined;
601
- if (this._consumeTokenIfKeyword(KeywordType.If)) {
602
- guardExpression = this._parseTestExpression(/* allowAssignmentExpression */ true);
603
- }
604
-
605
- const suite = this._parseSuite(this._isInFunction);
606
- return CaseNode.create(caseToken, casePattern, this._isPatternIrrefutable(casePattern), guardExpression, suite);
607
- }
608
-
609
- // PEP 634 defines the concept of an "irrefutable" pattern - a pattern that
610
- // will always be matched.
611
- private _isPatternIrrefutable(node: PatternAtomNode): boolean {
612
- if (node.nodeType === ParseNodeType.PatternCapture) {
613
- return true;
614
- }
615
-
616
- if (node.nodeType === ParseNodeType.PatternAs) {
617
- return node.orPatterns.some((pattern) => this._isPatternIrrefutable(pattern));
618
- }
619
-
620
- return false;
621
- }
622
-
623
- private _getPatternTargetNames(node: PatternAtomNode, nameMap: Map<string, boolean>): void {
624
- switch (node.nodeType) {
625
- case ParseNodeType.PatternSequence: {
626
- node.entries.forEach((subpattern) => {
627
- this._getPatternTargetNames(subpattern, nameMap);
628
- });
629
- break;
630
- }
631
-
632
- case ParseNodeType.PatternClass: {
633
- node.arguments.forEach((arg) => {
634
- this._getPatternTargetNames(arg.pattern, nameMap);
635
- });
636
- break;
637
- }
638
-
639
- case ParseNodeType.PatternAs: {
640
- if (node.target) {
641
- nameMap.set(node.target.value, true);
642
- }
643
- node.orPatterns.forEach((subpattern) => {
644
- this._getPatternTargetNames(subpattern, nameMap);
645
- });
646
- break;
647
- }
648
-
649
- case ParseNodeType.PatternCapture: {
650
- if (!node.isWildcard) {
651
- nameMap.set(node.target.value, true);
652
- }
653
- break;
654
- }
655
-
656
- case ParseNodeType.PatternMapping: {
657
- node.entries.forEach((mapEntry) => {
658
- if (mapEntry.nodeType === ParseNodeType.PatternMappingExpandEntry) {
659
- nameMap.set(mapEntry.target.value, true);
660
- } else {
661
- this._getPatternTargetNames(mapEntry.keyPattern, nameMap);
662
- this._getPatternTargetNames(mapEntry.valuePattern, nameMap);
663
- }
664
- });
665
- break;
666
- }
667
-
668
- case ParseNodeType.PatternLiteral:
669
- case ParseNodeType.PatternValue:
670
- case ParseNodeType.Error: {
671
- break;
672
- }
673
- }
674
- }
675
-
676
- private _parsePatternSequence() {
677
- const patternList = this._parseExpressionListGeneric(() => this._parsePatternAs());
678
-
679
- // Check for more than one star entry.
680
- const starEntries = patternList.list.filter(
681
- (entry) =>
682
- entry.orPatterns.length === 1 &&
683
- entry.orPatterns[0].nodeType === ParseNodeType.PatternCapture &&
684
- entry.orPatterns[0].isStar
685
- );
686
- if (starEntries.length > 1) {
687
- this._addError(Localizer.Diagnostic.duplicateStarPattern(), starEntries[1].orPatterns[0]);
688
- }
689
-
690
- // Look for redundant capture targets.
691
- const captureTargetMap = new Map<string, PatternAtomNode>();
692
- patternList.list.forEach((asPattern) => {
693
- asPattern.orPatterns.forEach((patternAtom) => {
694
- if (
695
- patternAtom.nodeType === ParseNodeType.PatternCapture &&
696
- !patternAtom.isStar &&
697
- !patternAtom.isWildcard
698
- ) {
699
- if (captureTargetMap.has(patternAtom.target.value)) {
700
- this._addError(
701
- Localizer.Diagnostic.duplicateCapturePatternTarget().format({
702
- name: patternAtom.target.value,
703
- }),
704
- patternAtom
705
- );
706
- } else {
707
- captureTargetMap.set(patternAtom.target.value, patternAtom);
708
- }
709
- }
710
- });
711
- });
712
-
713
- return patternList;
714
- }
715
-
716
- // as_pattern: or_pattern ['as' NAME]
717
- // or_pattern: '|'.pattern_atom+
718
- private _parsePatternAs(): PatternAsNode {
719
- const orPatterns: PatternAtomNode[] = [];
720
-
721
- while (true) {
722
- const patternAtom = this._parsePatternAtom();
723
- orPatterns.push(patternAtom);
724
-
725
- if (!this._consumeTokenIfOperator(OperatorType.BitwiseOr)) {
726
- break;
727
- }
728
- }
729
-
730
- if (orPatterns.length > 1) {
731
- // Star patterns cannot be ORed with other patterns.
732
- orPatterns.forEach((patternAtom) => {
733
- if (patternAtom.nodeType === ParseNodeType.PatternCapture && patternAtom.isStar) {
734
- this._addError(Localizer.Diagnostic.starPatternInOrPattern(), patternAtom);
735
- }
736
- });
737
- }
738
-
739
- let target: NameNode | undefined;
740
- if (this._consumeTokenIfKeyword(KeywordType.As)) {
741
- const nameToken = this._getTokenIfIdentifier();
742
- if (nameToken) {
743
- target = NameNode.create(nameToken);
744
- } else {
745
- this._addError(Localizer.Diagnostic.expectedNameAfterAs(), this._peekToken());
746
- }
747
- }
748
-
749
- // Star patterns cannot be used with AS pattern.
750
- if (
751
- target &&
752
- orPatterns.length === 1 &&
753
- orPatterns[0].nodeType === ParseNodeType.PatternCapture &&
754
- orPatterns[0].isStar
755
- ) {
756
- this._addError(Localizer.Diagnostic.starPatternInAsPattern(), orPatterns[0]);
757
- }
758
-
759
- // Validate that irrefutable patterns are not in any entries other than the last.
760
- orPatterns.forEach((orPattern, index) => {
761
- if (index < orPatterns.length - 1 && this._isPatternIrrefutable(orPattern)) {
762
- this._addError(Localizer.Diagnostic.orPatternIrrefutable(), orPattern);
763
- }
764
- });
765
-
766
- // Validate that all bound variables are the same within all or patterns.
767
- const fullNameMap = new Map<string, boolean>();
768
- orPatterns.forEach((orPattern) => {
769
- this._getPatternTargetNames(orPattern, fullNameMap);
770
- });
771
-
772
- orPatterns.forEach((orPattern) => {
773
- const localNameMap = new Map<string, boolean>();
774
- this._getPatternTargetNames(orPattern, localNameMap);
775
-
776
- if (localNameMap.size < fullNameMap.size) {
777
- const missingNames = Array.from(fullNameMap.keys()).filter((name) => !localNameMap.has(name));
778
- const diag = new DiagnosticAddendum();
779
- diag.addMessage(
780
- Localizer.DiagnosticAddendum.orPatternMissingName().format({
781
- name: missingNames.map((name) => `"${name}"`).join(', '),
782
- })
783
- );
784
- this._addError(Localizer.Diagnostic.orPatternMissingName() + diag.getString(), orPattern);
785
- }
786
- });
787
-
788
- return PatternAsNode.create(orPatterns, target);
789
- }
790
-
791
- // pattern_atom:
792
- // | literal_pattern
793
- // | name_or_attr
794
- // | '(' as_pattern ')'
795
- // | '[' [sequence_pattern] ']'
796
- // | '(' [sequence_pattern] ')'
797
- // | '{' [items_pattern] '}'
798
- // | name_or_attr '(' [pattern_arguments ','?] ')'
799
- // name_or_attr: attr | NAME
800
- // attr: name_or_attr '.' NAME
801
- // sequence_pattern: ','.maybe_star_pattern+ ','?
802
- // maybe_star_pattern: '*' NAME | pattern
803
- // items_pattern: ','.key_value_pattern+ ','?
804
- private _parsePatternAtom(): PatternAtomNode {
805
- const patternLiteral = this._parsePatternLiteral();
806
- if (patternLiteral) {
807
- return patternLiteral;
808
- }
809
-
810
- const patternCaptureOrValue = this._parsePatternCaptureOrValue();
811
- if (patternCaptureOrValue) {
812
- const openParenToken = this._peekToken();
813
- if (
814
- patternCaptureOrValue.nodeType === ParseNodeType.Error ||
815
- !this._consumeTokenIfType(TokenType.OpenParenthesis)
816
- ) {
817
- return patternCaptureOrValue;
818
- }
819
-
820
- const args = this._parseClassPatternArgList();
821
-
822
- const classNameExpr =
823
- patternCaptureOrValue.nodeType === ParseNodeType.PatternCapture
824
- ? patternCaptureOrValue.target
825
- : patternCaptureOrValue.expression;
826
- const classPattern = PatternClassNode.create(classNameExpr, args);
827
-
828
- if (!this._consumeTokenIfType(TokenType.CloseParenthesis)) {
829
- this._addError(Localizer.Diagnostic.expectedCloseParen(), openParenToken);
830
-
831
- // Consume the remainder of tokens on the line for error
832
- // recovery.
833
- this._consumeTokensUntilType([TokenType.NewLine]);
834
-
835
- // Extend the node's range to include the rest of the line.
836
- // This helps the signatureHelpProvider.
837
- extendRange(classPattern, this._peekToken());
838
- }
839
-
840
- return classPattern;
841
- }
842
-
843
- const nextToken = this._peekToken();
844
- const nextOperator = this._peekOperatorType();
845
-
846
- if (nextOperator === OperatorType.Multiply) {
847
- const starToken = this._getNextToken();
848
- const identifierToken = this._getTokenIfIdentifier();
849
- if (!identifierToken) {
850
- this._addError(Localizer.Diagnostic.expectedIdentifier(), this._peekToken());
851
- return ErrorNode.create(starToken, ErrorExpressionCategory.MissingExpression);
852
- } else {
853
- return PatternCaptureNode.create(NameNode.create(identifierToken), starToken);
854
- }
855
- }
856
-
857
- if (nextToken.type === TokenType.OpenParenthesis || nextToken.type === TokenType.OpenBracket) {
858
- const startToken = this._getNextToken();
859
- const patternList = this._parsePatternSequence();
860
- let casePattern: PatternAtomNode;
861
-
862
- if (patternList.parseError) {
863
- casePattern = patternList.parseError;
864
- } else if (
865
- patternList.list.length === 1 &&
866
- !patternList.trailingComma &&
867
- startToken.type === TokenType.OpenParenthesis
868
- ) {
869
- const pattern = patternList.list[0].orPatterns[0];
870
-
871
- if (pattern.nodeType === ParseNodeType.PatternCapture && pattern.isStar) {
872
- casePattern = PatternSequenceNode.create(startToken, patternList.list);
873
- } else {
874
- casePattern = patternList.list[0];
875
- }
876
-
877
- extendRange(casePattern, nextToken);
878
- } else {
879
- casePattern = PatternSequenceNode.create(startToken, patternList.list);
880
- }
881
-
882
- const endToken = this._peekToken();
883
- if (
884
- this._consumeTokenIfType(
885
- nextToken.type === TokenType.OpenParenthesis ? TokenType.CloseParenthesis : TokenType.CloseBracket
886
- )
887
- ) {
888
- extendRange(casePattern, endToken);
889
- } else {
890
- this._addError(
891
- nextToken.type === TokenType.OpenParenthesis
892
- ? Localizer.Diagnostic.expectedCloseParen()
893
- : Localizer.Diagnostic.expectedCloseBracket(),
894
- nextToken
895
- );
896
- this._consumeTokensUntilType([
897
- TokenType.Colon,
898
- nextToken.type === TokenType.OpenParenthesis ? TokenType.CloseParenthesis : TokenType.CloseBracket,
899
- ]);
900
- }
901
-
902
- return casePattern;
903
- } else if (nextToken.type === TokenType.OpenCurlyBrace) {
904
- const firstToken = this._getNextToken();
905
- const mappingPattern = this._parsePatternMapping(firstToken);
906
- const lastToken = this._peekToken();
907
-
908
- if (this._consumeTokenIfType(TokenType.CloseCurlyBrace)) {
909
- extendRange(mappingPattern, lastToken);
910
- } else {
911
- this._addError(Localizer.Diagnostic.expectedCloseBrace(), nextToken);
912
- this._consumeTokensUntilType([TokenType.Colon, TokenType.CloseCurlyBrace]);
913
- }
914
-
915
- return mappingPattern;
916
- }
917
-
918
- return this._handleExpressionParseError(
919
- ErrorExpressionCategory.MissingPattern,
920
- Localizer.Diagnostic.expectedPatternExpr()
921
- );
922
- }
923
-
924
- // pattern_arguments:
925
- // | positional_patterns [',' keyword_patterns]
926
- // | keyword_patterns
927
- // positional_patterns: ','.as_pattern+
928
- // keyword_patterns: ','.keyword_pattern+
929
- private _parseClassPatternArgList(): PatternClassArgumentNode[] {
930
- const argList: PatternClassArgumentNode[] = [];
931
- let sawKeywordArg = false;
932
-
933
- while (true) {
934
- const nextTokenType = this._peekTokenType();
935
- if (
936
- nextTokenType === TokenType.CloseParenthesis ||
937
- nextTokenType === TokenType.NewLine ||
938
- nextTokenType === TokenType.EndOfStream
939
- ) {
940
- break;
941
- }
942
-
943
- const arg = this._parseClassPatternArgument();
944
- if (arg.name) {
945
- sawKeywordArg = true;
946
- } else if (sawKeywordArg && !arg.name) {
947
- this._addError(Localizer.Diagnostic.positionArgAfterNamedArg(), arg);
948
- }
949
- argList.push(arg);
950
-
951
- if (!this._consumeTokenIfType(TokenType.Comma)) {
952
- break;
953
- }
954
- }
955
-
956
- return argList;
957
- }
958
-
959
- // keyword_pattern: NAME '=' as_pattern
960
- private _parseClassPatternArgument(): PatternClassArgumentNode {
961
- const firstToken = this._peekToken();
962
- const secondToken = this._peekToken(1);
963
-
964
- let keywordName: NameNode | undefined;
965
-
966
- if (
967
- (firstToken.type === TokenType.Identifier || firstToken.type === TokenType.Keyword) &&
968
- secondToken.type === TokenType.Operator &&
969
- (secondToken as OperatorToken).operatorType === OperatorType.Assign
970
- ) {
971
- this._getNextToken();
972
- keywordName = NameNode.create(firstToken as IdentifierToken);
973
- this._getNextToken();
974
- }
975
-
976
- const pattern = this._parsePatternAs();
977
-
978
- return PatternClassArgumentNode.create(pattern, keywordName);
979
- }
980
-
981
- // literal_pattern:
982
- // | signed_number
983
- // | signed_number '+' NUMBER
984
- // | signed_number '-' NUMBER
985
- // | strings
986
- // | 'None'
987
- // | 'True'
988
- // | 'False'
989
- private _parsePatternLiteral(): PatternLiteralNode | undefined {
990
- const nextToken = this._peekToken();
991
- const nextOperator = this._peekOperatorType();
992
-
993
- if (nextToken.type === TokenType.Number || nextOperator === OperatorType.Subtract) {
994
- return this._parsePatternLiteralNumber();
995
- }
996
-
997
- if (nextToken.type === TokenType.String) {
998
- const stringList = this._parseAtom() as StringListNode;
999
- assert(stringList.nodeType === ParseNodeType.StringList);
1000
-
1001
- // Check for f-strings, which are not allowed.
1002
- stringList.strings.forEach((stringAtom) => {
1003
- if (stringAtom.token.flags & StringTokenFlags.Format) {
1004
- this._addError(Localizer.Diagnostic.formatStringInPattern(), stringAtom);
1005
- }
1006
- });
1007
-
1008
- return PatternLiteralNode.create(stringList);
1009
- }
1010
-
1011
- if (nextToken.type === TokenType.Keyword) {
1012
- const keywordToken = nextToken as KeywordToken;
1013
- if (
1014
- keywordToken.keywordType === KeywordType.False ||
1015
- keywordToken.keywordType === KeywordType.True ||
1016
- keywordToken.keywordType === KeywordType.None
1017
- ) {
1018
- return PatternLiteralNode.create(this._parseAtom());
1019
- }
1020
- }
1021
-
1022
- return undefined;
1023
- }
1024
-
1025
- // signed_number: NUMBER | '-' NUMBER
1026
- private _parsePatternLiteralNumber(): PatternLiteralNode {
1027
- const expression = this._parseArithmeticExpression();
1028
- let realValue: ExpressionNode | undefined;
1029
- let imagValue: ExpressionNode | undefined;
1030
-
1031
- if (expression.nodeType === ParseNodeType.BinaryOperation) {
1032
- if (expression.operator === OperatorType.Subtract || expression.operator === OperatorType.Add) {
1033
- realValue = expression.leftExpression;
1034
- imagValue = expression.rightExpression;
1035
- }
1036
- } else {
1037
- realValue = expression;
1038
- }
1039
-
1040
- if (realValue) {
1041
- if (realValue.nodeType === ParseNodeType.UnaryOperation && realValue.operator === OperatorType.Subtract) {
1042
- realValue = realValue.expression;
1043
- }
1044
-
1045
- if (realValue.nodeType !== ParseNodeType.Number || (imagValue !== undefined && realValue.isImaginary)) {
1046
- this._addError(Localizer.Diagnostic.expectedComplexNumberLiteral(), expression);
1047
- imagValue = undefined;
1048
- }
1049
- }
1050
-
1051
- if (imagValue) {
1052
- if (imagValue.nodeType === ParseNodeType.UnaryOperation && imagValue.operator === OperatorType.Subtract) {
1053
- imagValue = imagValue.expression;
1054
- }
1055
-
1056
- if (imagValue.nodeType !== ParseNodeType.Number || !imagValue.isImaginary) {
1057
- this._addError(Localizer.Diagnostic.expectedComplexNumberLiteral(), expression);
1058
- }
1059
- }
1060
-
1061
- return PatternLiteralNode.create(expression);
1062
- }
1063
-
1064
- private _parsePatternMapping(firstToken: Token): PatternMappingNode | ErrorNode {
1065
- const itemList = this._parseExpressionListGeneric(() => this._parsePatternMappingItem());
1066
-
1067
- if (itemList.list.length > 0) {
1068
- // Verify there's at most one ** entry.
1069
- const starStarEntries = itemList.list.filter(
1070
- (entry) => entry.nodeType === ParseNodeType.PatternMappingExpandEntry
1071
- );
1072
- if (starStarEntries.length > 1) {
1073
- this._addError(Localizer.Diagnostic.duplicateStarStarPattern(), starStarEntries[1]);
1074
- }
1075
-
1076
- return PatternMappingNode.create(firstToken, itemList.list);
1077
- }
1078
-
1079
- return itemList.parseError || ErrorNode.create(this._peekToken(), ErrorExpressionCategory.MissingPattern);
1080
- }
1081
-
1082
- // key_value_pattern:
1083
- // | (literal_pattern | attr) ':' as_pattern
1084
- // | '**' NAME
1085
- private _parsePatternMappingItem(): PatternMappingEntryNode | ErrorNode {
1086
- let keyExpression: PatternLiteralNode | PatternValueNode | ErrorNode | undefined;
1087
- const doubleStar = this._peekToken();
1088
-
1089
- if (this._consumeTokenIfOperator(OperatorType.Power)) {
1090
- const identifierToken = this._getTokenIfIdentifier();
1091
- if (!identifierToken) {
1092
- this._addError(Localizer.Diagnostic.expectedIdentifier(), this._peekToken());
1093
- return ErrorNode.create(this._peekToken(), ErrorExpressionCategory.MissingPattern);
1094
- }
1095
-
1096
- const nameNode = NameNode.create(identifierToken);
1097
- if (identifierToken.value === '_') {
1098
- this._addError(Localizer.Diagnostic.starStarWildcardNotAllowed(), nameNode);
1099
- }
1100
-
1101
- return PatternMappingExpandEntryNode.create(doubleStar, nameNode);
1102
- }
1103
-
1104
- const patternLiteral = this._parsePatternLiteral();
1105
- if (patternLiteral) {
1106
- keyExpression = patternLiteral;
1107
- } else {
1108
- const patternCaptureOrValue = this._parsePatternCaptureOrValue();
1109
- if (patternCaptureOrValue) {
1110
- if (patternCaptureOrValue.nodeType === ParseNodeType.PatternValue) {
1111
- keyExpression = patternCaptureOrValue;
1112
- } else {
1113
- this._addError(Localizer.Diagnostic.expectedPatternValue(), patternCaptureOrValue);
1114
- keyExpression = ErrorNode.create(this._peekToken(), ErrorExpressionCategory.MissingPattern);
1115
- }
1116
- }
1117
- }
1118
-
1119
- if (!keyExpression) {
1120
- this._addError(Localizer.Diagnostic.expectedPatternExpr(), this._peekToken());
1121
- keyExpression = ErrorNode.create(this._peekToken(), ErrorExpressionCategory.MissingPattern);
1122
- }
1123
-
1124
- let valuePattern: PatternAtomNode | undefined;
1125
- if (!this._consumeTokenIfType(TokenType.Colon)) {
1126
- this._addError(Localizer.Diagnostic.expectedColon(), this._peekToken());
1127
- valuePattern = ErrorNode.create(this._peekToken(), ErrorExpressionCategory.MissingPattern);
1128
- } else {
1129
- valuePattern = this._parsePatternAs();
1130
- }
1131
-
1132
- return PatternMappingKeyEntryNode.create(keyExpression, valuePattern);
1133
- }
1134
-
1135
- private _parsePatternCaptureOrValue(): PatternCaptureNode | PatternValueNode | ErrorNode | undefined {
1136
- const nextToken = this._peekToken();
1137
-
1138
- if (nextToken.type === TokenType.Identifier || nextToken.type === TokenType.Keyword) {
1139
- let nameOrMember: NameNode | MemberAccessNode | undefined;
1140
-
1141
- while (true) {
1142
- const identifierToken = this._getTokenIfIdentifier();
1143
- if (identifierToken) {
1144
- const nameNode = NameNode.create(identifierToken);
1145
- nameOrMember = nameOrMember ? MemberAccessNode.create(nameOrMember, nameNode) : nameNode;
1146
- } else {
1147
- this._addError(Localizer.Diagnostic.expectedIdentifier(), this._peekToken());
1148
- break;
1149
- }
1150
-
1151
- if (!this._consumeTokenIfType(TokenType.Dot)) {
1152
- break;
1153
- }
1154
- }
1155
-
1156
- if (!nameOrMember) {
1157
- this._addError(Localizer.Diagnostic.expectedIdentifier(), this._peekToken());
1158
- return ErrorNode.create(this._peekToken(), ErrorExpressionCategory.MissingPattern);
1159
- }
1160
-
1161
- if (nameOrMember.nodeType === ParseNodeType.MemberAccess) {
1162
- return PatternValueNode.create(nameOrMember);
1163
- }
1164
-
1165
- return PatternCaptureNode.create(nameOrMember);
1166
- }
1167
-
1168
- return undefined;
1169
- }
1170
-
1171
- // if_stmt: 'if' test_suite ('elif' test_suite)* ['else' suite]
1172
- // test_suite: test suite
1173
- // test: or_test ['if' or_test 'else' test] | lambdef
1174
- private _parseIfStatement(keywordType: KeywordType.If | KeywordType.Elif = KeywordType.If): IfNode {
1175
- const ifOrElifToken = this._getKeywordToken(keywordType);
1176
-
1177
- const test = this._parseTestExpression(/* allowAssignmentExpression */ true);
1178
- const suite = this._parseSuite(this._isInFunction);
1179
- const ifNode = IfNode.create(ifOrElifToken, test, suite);
1180
-
1181
- if (this._consumeTokenIfKeyword(KeywordType.Else)) {
1182
- ifNode.elseSuite = this._parseSuite(this._isInFunction);
1183
- ifNode.elseSuite.parent = ifNode;
1184
- extendRange(ifNode, ifNode.elseSuite);
1185
- } else if (this._peekKeywordType() === KeywordType.Elif) {
1186
- // Recursively handle an "elif" statement.
1187
- ifNode.elseSuite = this._parseIfStatement(KeywordType.Elif);
1188
- ifNode.elseSuite.parent = ifNode;
1189
- extendRange(ifNode, ifNode.elseSuite);
1190
- }
1191
-
1192
- return ifNode;
1193
- }
1194
-
1195
- private _parseLoopSuite(disallowTypeComment = false): SuiteNode {
1196
- const wasInLoop = this._isInLoop;
1197
- const wasInFinally = this._isInFinally;
1198
- this._isInLoop = true;
1199
- this._isInFinally = false;
1200
-
1201
- const suite = this._parseSuite(this._isInFunction, /* skipBody */ false, () => {
1202
- if (disallowTypeComment) {
1203
- this._detectUnsupportedTypeAnnotationComment();
1204
- }
1205
- });
1206
-
1207
- this._isInLoop = wasInLoop;
1208
- this._isInFinally = wasInFinally;
1209
-
1210
- return suite;
1211
- }
1212
-
1213
- // suite: ':' (simple_stmt | NEWLINE INDENT stmt+ DEDENT)
1214
- private _parseSuite(isFunction = false, skipBody = false, postColonCallback?: () => void): SuiteNode {
1215
- const nextToken = this._peekToken();
1216
- const suite = SuiteNode.create(nextToken);
1217
-
1218
- if (!this._consumeTokenIfType(TokenType.Colon)) {
1219
- this._addError(Localizer.Diagnostic.expectedColon(), nextToken);
1220
-
1221
- // Try to perform parse recovery by consuming tokens.
1222
- if (this._consumeTokensUntilType([TokenType.NewLine, TokenType.Colon])) {
1223
- if (this._peekTokenType() === TokenType.Colon) {
1224
- this._getNextToken();
1225
- } else if (this._peekToken(1).type !== TokenType.Indent) {
1226
- // Bail so we resume the at the next statement.
1227
- // We can't parse as a simple statement as we've skipped all but the newline.
1228
- this._getNextToken();
1229
- return suite;
1230
- }
1231
- }
1232
- }
1233
-
1234
- if (skipBody) {
1235
- if (this._consumeTokenIfType(TokenType.NewLine)) {
1236
- let indent = 0;
1237
- while (true) {
1238
- const nextToken = this._getNextToken();
1239
- if (nextToken.type === TokenType.Indent) {
1240
- indent++;
1241
- }
1242
-
1243
- if (nextToken.type === TokenType.Dedent) {
1244
- if ((nextToken as DedentToken).isDedentAmbiguous) {
1245
- this._addError(Localizer.Diagnostic.inconsistentTabs(), nextToken);
1246
- }
1247
-
1248
- indent--;
1249
-
1250
- if (indent === 0) {
1251
- break;
1252
- }
1253
- }
1254
-
1255
- if (nextToken.type === TokenType.EndOfStream) {
1256
- break;
1257
- }
1258
- }
1259
- } else {
1260
- // consume tokens
1261
- this._parseSimpleStatement();
1262
- }
1263
-
1264
- if (this._tokenIndex > 0) {
1265
- extendRange(suite, this._tokenizerOutput!.tokens.getItemAt(this._tokenIndex - 1));
1266
- }
1267
-
1268
- return suite;
1269
- }
1270
-
1271
- if (postColonCallback) {
1272
- postColonCallback();
1273
- }
1274
-
1275
- const wasFunction = this._isInFunction;
1276
- this._isInFunction = isFunction;
1277
-
1278
- if (this._consumeTokenIfType(TokenType.NewLine)) {
1279
- if (postColonCallback) {
1280
- postColonCallback();
1281
- }
1282
-
1283
- const possibleIndent = this._peekToken();
1284
- if (!this._consumeTokenIfType(TokenType.Indent)) {
1285
- this._addError(Localizer.Diagnostic.expectedIndentedBlock(), this._peekToken());
1286
- } else {
1287
- const indentToken = possibleIndent as IndentToken;
1288
- if (indentToken.isIndentAmbiguous) {
1289
- this._addError(Localizer.Diagnostic.inconsistentTabs(), indentToken);
1290
- }
1291
- }
1292
-
1293
- while (true) {
1294
- // Handle a common error here and see if we can recover.
1295
- const nextToken = this._peekToken();
1296
- if (nextToken.type === TokenType.Indent) {
1297
- this._getNextToken();
1298
- const indentToken = nextToken as IndentToken;
1299
- if (indentToken.isIndentAmbiguous) {
1300
- this._addError(Localizer.Diagnostic.inconsistentTabs(), indentToken);
1301
- } else {
1302
- this._addError(Localizer.Diagnostic.unexpectedIndent(), nextToken);
1303
- }
1304
- }
1305
-
1306
- const statement = this._parseStatement();
1307
- if (!statement) {
1308
- // Perform basic error recovery to get to the next line.
1309
- this._consumeTokensUntilType([TokenType.NewLine]);
1310
- } else {
1311
- statement.parent = suite;
1312
- suite.statements.push(statement);
1313
- }
1314
-
1315
- const dedentToken = this._peekToken() as DedentToken;
1316
- if (this._consumeTokenIfType(TokenType.Dedent)) {
1317
- if (!dedentToken.matchesIndent) {
1318
- this._addError(Localizer.Diagnostic.inconsistentIndent(), dedentToken);
1319
- }
1320
- if (dedentToken.isDedentAmbiguous) {
1321
- this._addError(Localizer.Diagnostic.inconsistentTabs(), dedentToken);
1322
- }
1323
- break;
1324
- }
1325
-
1326
- if (this._peekTokenType() === TokenType.EndOfStream) {
1327
- break;
1328
- }
1329
- }
1330
- } else {
1331
- const simpleStatement = this._parseSimpleStatement();
1332
- suite.statements.push(simpleStatement);
1333
- simpleStatement.parent = suite;
1334
- }
1335
-
1336
- if (suite.statements.length > 0) {
1337
- extendRange(suite, suite.statements[suite.statements.length - 1]);
1338
- }
1339
-
1340
- this._isInFunction = wasFunction;
1341
-
1342
- return suite;
1343
- }
1344
-
1345
- // for_stmt: [async] 'for' exprlist 'in' testlist suite ['else' suite]
1346
- private _parseForStatement(asyncToken?: KeywordToken): ForNode {
1347
- const forToken = this._getKeywordToken(KeywordType.For);
1348
-
1349
- const targetExpr = this._parseExpressionListAsPossibleTuple(
1350
- ErrorExpressionCategory.MissingExpression,
1351
- Localizer.Diagnostic.expectedExpr(),
1352
- forToken
1353
- );
1354
-
1355
- let seqExpr: ExpressionNode;
1356
- let forSuite: SuiteNode;
1357
- let elseSuite: SuiteNode | undefined;
1358
-
1359
- if (!this._consumeTokenIfKeyword(KeywordType.In)) {
1360
- seqExpr = this._handleExpressionParseError(
1361
- ErrorExpressionCategory.MissingIn,
1362
- Localizer.Diagnostic.expectedIn()
1363
- );
1364
- forSuite = SuiteNode.create(this._peekToken());
1365
- } else {
1366
- seqExpr = this._parseTestOrStarListAsExpression(
1367
- /* allowAssignmentExpression */ false,
1368
- /* allowMultipleUnpack */ true,
1369
- ErrorExpressionCategory.MissingExpression,
1370
- Localizer.Diagnostic.expectedInExpr()
1371
- );
1372
-
1373
- forSuite = this._parseLoopSuite(/* disallowTypeComment */ true);
1374
-
1375
- // Versions of Python earlier than 3.9 didn't allow unpack operators if the
1376
- // tuple wasn't enclosed in parentheses.
1377
- if (this._getLanguageVersion() < PythonVersion.V3_9 && !this._parseOptions.isStubFile) {
1378
- if (seqExpr.nodeType === ParseNodeType.Tuple && !seqExpr.enclosedInParens) {
1379
- let sawStar = false;
1380
- seqExpr.expressions.forEach((expr) => {
1381
- if (expr.nodeType === ParseNodeType.Unpack && !sawStar) {
1382
- this._addError(Localizer.Diagnostic.unpackOperatorNotAllowed(), expr);
1383
- sawStar = true;
1384
- }
1385
- });
1386
- }
1387
- }
1388
-
1389
- if (this._consumeTokenIfKeyword(KeywordType.Else)) {
1390
- elseSuite = this._parseSuite(this._isInFunction);
1391
- }
1392
- }
1393
-
1394
- const forNode = ForNode.create(forToken, targetExpr, seqExpr, forSuite);
1395
- forNode.elseSuite = elseSuite;
1396
- if (elseSuite) {
1397
- extendRange(forNode, elseSuite);
1398
- elseSuite.parent = forNode;
1399
- }
1400
-
1401
- if (asyncToken) {
1402
- forNode.isAsync = true;
1403
- forNode.asyncToken = asyncToken;
1404
- extendRange(forNode, asyncToken);
1405
- }
1406
-
1407
- return forNode;
1408
- }
1409
-
1410
- // comp_iter: comp_for | comp_if
1411
- private _tryParseListComprehension(target: ParseNode): ListComprehensionNode | undefined {
1412
- const compFor = this._tryParseCompForStatement();
1413
-
1414
- if (!compFor) {
1415
- return undefined;
1416
- }
1417
-
1418
- if (target.nodeType === ParseNodeType.Unpack) {
1419
- this._addError(Localizer.Diagnostic.unpackIllegalInComprehension(), target);
1420
- } else if (target.nodeType === ParseNodeType.DictionaryExpandEntry) {
1421
- this._addError(Localizer.Diagnostic.dictExpandIllegalInComprehension(), target);
1422
- }
1423
-
1424
- const listCompNode = ListComprehensionNode.create(target);
1425
-
1426
- const forIfList: ListComprehensionForIfNode[] = [compFor];
1427
- while (true) {
1428
- const compIter = this._tryParseCompForStatement() || this._tryParseCompIfStatement();
1429
- if (!compIter) {
1430
- break;
1431
- }
1432
- compIter.parent = listCompNode;
1433
- forIfList.push(compIter);
1434
- }
1435
-
1436
- listCompNode.forIfNodes = forIfList;
1437
- if (forIfList.length > 0) {
1438
- forIfList.forEach((comp) => {
1439
- comp.parent = listCompNode;
1440
- });
1441
- extendRange(listCompNode, forIfList[forIfList.length - 1]);
1442
- }
1443
- return listCompNode;
1444
- }
1445
-
1446
- // comp_for: ['async'] 'for' exprlist 'in' or_test [comp_iter]
1447
- private _tryParseCompForStatement(): ListComprehensionForNode | undefined {
1448
- const startTokenKeywordType = this._peekKeywordType();
1449
-
1450
- if (startTokenKeywordType === KeywordType.Async) {
1451
- const nextToken = this._peekToken(1) as KeywordToken;
1452
- if (nextToken.type !== TokenType.Keyword || nextToken.keywordType !== KeywordType.For) {
1453
- return undefined;
1454
- }
1455
- } else if (startTokenKeywordType !== KeywordType.For) {
1456
- return undefined;
1457
- }
1458
-
1459
- let asyncToken: KeywordToken | undefined;
1460
- if (this._peekKeywordType() === KeywordType.Async) {
1461
- asyncToken = this._getKeywordToken(KeywordType.Async);
1462
- }
1463
-
1464
- const forToken = this._getKeywordToken(KeywordType.For);
1465
-
1466
- const targetExpr = this._parseExpressionListAsPossibleTuple(
1467
- ErrorExpressionCategory.MissingExpression,
1468
- Localizer.Diagnostic.expectedExpr(),
1469
- forToken
1470
- );
1471
- let seqExpr: ExpressionNode | undefined;
1472
-
1473
- if (!this._consumeTokenIfKeyword(KeywordType.In)) {
1474
- seqExpr = this._handleExpressionParseError(
1475
- ErrorExpressionCategory.MissingIn,
1476
- Localizer.Diagnostic.expectedIn()
1477
- );
1478
- } else {
1479
- this._disallowAssignmentExpression(() => {
1480
- seqExpr = this._parseOrTest();
1481
- });
1482
- }
1483
-
1484
- const compForNode = ListComprehensionForNode.create(asyncToken || forToken, targetExpr, seqExpr!);
1485
-
1486
- if (asyncToken) {
1487
- compForNode.isAsync = true;
1488
- compForNode.asyncToken = asyncToken;
1489
- }
1490
-
1491
- return compForNode;
1492
- }
1493
-
1494
- // comp_if: 'if' test_nocond [comp_iter]
1495
- // comp_iter: comp_for | comp_if
1496
- private _tryParseCompIfStatement(): ListComprehensionIfNode | undefined {
1497
- if (this._peekKeywordType() !== KeywordType.If) {
1498
- return undefined;
1499
- }
1500
-
1501
- const ifToken = this._getKeywordToken(KeywordType.If);
1502
- const ifExpr =
1503
- this._tryParseLambdaExpression() ||
1504
- this._parseAssignmentExpression(/* disallowAssignmentExpression */ true);
1505
-
1506
- const compIfNode = ListComprehensionIfNode.create(ifToken, ifExpr);
1507
-
1508
- return compIfNode;
1509
- }
1510
-
1511
- // while_stmt: 'while' test suite ['else' suite]
1512
- private _parseWhileStatement(): WhileNode {
1513
- const whileToken = this._getKeywordToken(KeywordType.While);
1514
-
1515
- const whileNode = WhileNode.create(
1516
- whileToken,
1517
- this._parseTestExpression(/* allowAssignmentExpression */ true),
1518
- this._parseLoopSuite()
1519
- );
1520
-
1521
- if (this._consumeTokenIfKeyword(KeywordType.Else)) {
1522
- whileNode.elseSuite = this._parseSuite(this._isInFunction);
1523
- whileNode.elseSuite.parent = whileNode;
1524
- extendRange(whileNode, whileNode.elseSuite);
1525
- }
1526
-
1527
- return whileNode;
1528
- }
1529
-
1530
- // try_stmt: ('try' suite
1531
- // ((except_clause suite)+
1532
- // ['else' suite]
1533
- // ['finally' suite] |
1534
- // 'finally' suite))
1535
- // except_clause: 'except' [test ['as' NAME]]
1536
- private _parseTryStatement(): TryNode {
1537
- const tryToken = this._getKeywordToken(KeywordType.Try);
1538
- const trySuite = this._parseSuite(this._isInFunction);
1539
- const tryNode = TryNode.create(tryToken, trySuite);
1540
- let sawCatchAllExcept = false;
1541
-
1542
- while (true) {
1543
- const exceptToken = this._peekToken();
1544
- if (!this._consumeTokenIfKeyword(KeywordType.Except)) {
1545
- break;
1546
- }
1547
-
1548
- // See if this is a Python 3.11 exception group.
1549
- const possibleStarToken = this._peekToken();
1550
- let isExceptGroup = false;
1551
- if (this._consumeTokenIfOperator(OperatorType.Multiply)) {
1552
- if (this._getLanguageVersion() < PythonVersion.V3_11 && !this._parseOptions.isStubFile) {
1553
- this._addError(Localizer.Diagnostic.exceptionGroupIncompatible(), possibleStarToken);
1554
- }
1555
- isExceptGroup = true;
1556
- }
1557
-
1558
- let typeExpr: ExpressionNode | undefined;
1559
- let symbolName: IdentifierToken | undefined;
1560
- if (this._peekTokenType() !== TokenType.Colon) {
1561
- typeExpr = this._parseTestExpression(/* allowAssignmentExpression */ true);
1562
-
1563
- if (this._consumeTokenIfKeyword(KeywordType.As)) {
1564
- symbolName = this._getTokenIfIdentifier();
1565
- if (!symbolName) {
1566
- this._addError(Localizer.Diagnostic.expectedNameAfterAs(), this._peekToken());
1567
- }
1568
- } else {
1569
- // Handle the python 2.x syntax in a graceful manner.
1570
- const peekToken = this._peekToken();
1571
- if (this._consumeTokenIfType(TokenType.Comma)) {
1572
- this._addError(Localizer.Diagnostic.expectedAsAfterException(), peekToken);
1573
-
1574
- // Parse the expression expected in python 2.x, but discard it.
1575
- this._parseTestExpression(/* allowAssignmentExpression */ false);
1576
- }
1577
- }
1578
- }
1579
-
1580
- if (!typeExpr) {
1581
- if (sawCatchAllExcept) {
1582
- this._addError(Localizer.Diagnostic.duplicateCatchAll(), exceptToken);
1583
- }
1584
- sawCatchAllExcept = true;
1585
- } else {
1586
- if (sawCatchAllExcept) {
1587
- this._addError(Localizer.Diagnostic.namedExceptAfterCatchAll(), typeExpr);
1588
- }
1589
- }
1590
-
1591
- const exceptSuite = this._parseSuite(this._isInFunction);
1592
- const exceptNode = ExceptNode.create(exceptToken, exceptSuite, isExceptGroup);
1593
- if (typeExpr) {
1594
- exceptNode.typeExpression = typeExpr;
1595
- exceptNode.typeExpression.parent = exceptNode;
1596
- }
1597
-
1598
- if (symbolName) {
1599
- exceptNode.name = NameNode.create(symbolName);
1600
- exceptNode.name.parent = exceptNode;
1601
- }
1602
-
1603
- tryNode.exceptClauses.push(exceptNode);
1604
- exceptNode.parent = tryNode;
1605
- }
1606
-
1607
- if (tryNode.exceptClauses.length > 0) {
1608
- extendRange(tryNode, tryNode.exceptClauses[tryNode.exceptClauses.length - 1]);
1609
-
1610
- if (this._consumeTokenIfKeyword(KeywordType.Else)) {
1611
- tryNode.elseSuite = this._parseSuite(this._isInFunction);
1612
- tryNode.elseSuite.parent = tryNode;
1613
- extendRange(tryNode, tryNode.elseSuite);
1614
- }
1615
- }
1616
-
1617
- if (this._consumeTokenIfKeyword(KeywordType.Finally)) {
1618
- tryNode.finallySuite = this._parseSuite(this._isInFunction);
1619
- tryNode.finallySuite.parent = tryNode;
1620
- extendRange(tryNode, tryNode.finallySuite);
1621
- }
1622
-
1623
- if (!tryNode.finallySuite && tryNode.exceptClauses.length === 0) {
1624
- this._addError(Localizer.Diagnostic.tryWithoutExcept(), tryToken);
1625
- }
1626
-
1627
- return tryNode;
1628
- }
1629
-
1630
- // funcdef: 'def' NAME parameters ['->' test] ':' suite
1631
- // parameters: '(' [typedargslist] ')'
1632
- private _parseFunctionDef(asyncToken?: KeywordToken, decorators?: DecoratorNode[]): FunctionNode | ErrorNode {
1633
- const defToken = this._getKeywordToken(KeywordType.Def);
1634
-
1635
- const nameToken = this._getTokenIfIdentifier();
1636
- if (!nameToken) {
1637
- this._addError(Localizer.Diagnostic.expectedFunctionName(), defToken);
1638
- return ErrorNode.create(
1639
- defToken,
1640
- ErrorExpressionCategory.MissingFunctionParameterList,
1641
- undefined,
1642
- decorators
1643
- );
1644
- }
1645
-
1646
- const openParenToken = this._peekToken();
1647
- if (!this._consumeTokenIfType(TokenType.OpenParenthesis)) {
1648
- this._addError(Localizer.Diagnostic.expectedOpenParen(), this._peekToken());
1649
- return ErrorNode.create(
1650
- nameToken,
1651
- ErrorExpressionCategory.MissingFunctionParameterList,
1652
- NameNode.create(nameToken),
1653
- decorators
1654
- );
1655
- }
1656
-
1657
- const paramList = this._parseVarArgsList(TokenType.CloseParenthesis, /* allowAnnotations */ true);
1658
-
1659
- if (!this._consumeTokenIfType(TokenType.CloseParenthesis)) {
1660
- this._addError(Localizer.Diagnostic.expectedCloseParen(), openParenToken);
1661
- this._consumeTokensUntilType([TokenType.Colon]);
1662
- }
1663
-
1664
- let returnType: ExpressionNode | undefined;
1665
- if (this._consumeTokenIfType(TokenType.Arrow)) {
1666
- returnType = this._parseTypeAnnotation();
1667
- }
1668
-
1669
- let functionTypeAnnotationToken: StringToken | undefined;
1670
- const suite = this._parseSuite(/* isFunction */ true, this._parseOptions.skipFunctionAndClassBody, () => {
1671
- if (!functionTypeAnnotationToken) {
1672
- functionTypeAnnotationToken = this._getTypeAnnotationCommentText();
1673
- }
1674
- });
1675
-
1676
- const functionNode = FunctionNode.create(defToken, NameNode.create(nameToken), suite);
1677
- if (asyncToken) {
1678
- functionNode.isAsync = true;
1679
- extendRange(functionNode, asyncToken);
1680
- }
1681
-
1682
- functionNode.parameters = paramList;
1683
- paramList.forEach((param) => {
1684
- param.parent = functionNode;
1685
- });
1686
-
1687
- if (decorators) {
1688
- functionNode.decorators = decorators;
1689
- decorators.forEach((decorator) => {
1690
- decorator.parent = functionNode;
1691
- });
1692
-
1693
- if (decorators.length > 0) {
1694
- extendRange(functionNode, decorators[0]);
1695
- }
1696
- }
1697
-
1698
- if (returnType) {
1699
- functionNode.returnTypeAnnotation = returnType;
1700
- functionNode.returnTypeAnnotation.parent = functionNode;
1701
- extendRange(functionNode, returnType);
1702
- }
1703
-
1704
- // If there was a type annotation comment for the function,
1705
- // parse it now.
1706
- if (functionTypeAnnotationToken) {
1707
- this._parseFunctionTypeAnnotationComment(functionTypeAnnotationToken, functionNode);
1708
- }
1709
-
1710
- return functionNode;
1711
- }
1712
-
1713
- // typedargslist: (
1714
- // tfpdef ['=' test] (',' tfpdef ['=' test])*
1715
- // [ ','
1716
- // [
1717
- // '*' [tfpdef] (',' tfpdef ['=' test])* [',' ['**' tfpdef [',']]]
1718
- // | '**' tfpdef [',']
1719
- // ]
1720
- // ]
1721
- // | '*' [tfpdef] (',' tfpdef ['=' test])* [',' ['**' tfpdef [',']]]
1722
- // | '**' tfpdef [','])
1723
- // tfpdef: NAME [':' test]
1724
- // vfpdef: NAME;
1725
- private _parseVarArgsList(terminator: TokenType, allowAnnotations: boolean): ParameterNode[] {
1726
- const paramMap = new Map<string, string>();
1727
- const paramList: ParameterNode[] = [];
1728
- let sawDefaultParam = false;
1729
- let reportedNonDefaultParamErr = false;
1730
- let sawKeywordOnlySeparator = false;
1731
- let sawPositionOnlySeparator = false;
1732
- let sawArgs = false;
1733
- let sawKwArgs = false;
1734
-
1735
- while (true) {
1736
- if (this._peekTokenType() === terminator) {
1737
- break;
1738
- }
1739
-
1740
- const param = this._parseParameter(allowAnnotations);
1741
- if (!param) {
1742
- this._consumeTokensUntilType([terminator]);
1743
- break;
1744
- }
1745
-
1746
- if (param.name) {
1747
- const name = param.name.value;
1748
- if (paramMap.has(name)) {
1749
- this._addError(Localizer.Diagnostic.duplicateParam().format({ name }), param.name);
1750
- } else {
1751
- paramMap.set(name, name);
1752
- }
1753
- } else if (param.category === ParameterCategory.Simple) {
1754
- if (paramList.length === 0) {
1755
- this._addError(Localizer.Diagnostic.positionOnlyFirstParam(), param);
1756
- }
1757
- }
1758
-
1759
- if (param.category === ParameterCategory.Simple) {
1760
- if (!param.name) {
1761
- if (sawPositionOnlySeparator) {
1762
- this._addError(Localizer.Diagnostic.duplicatePositionOnly(), param);
1763
- } else if (sawKeywordOnlySeparator) {
1764
- this._addError(Localizer.Diagnostic.positionOnlyAfterKeywordOnly(), param);
1765
- } else if (sawArgs) {
1766
- this._addError(Localizer.Diagnostic.positionOnlyAfterArgs(), param);
1767
- }
1768
- sawPositionOnlySeparator = true;
1769
- } else {
1770
- if (param.defaultValue) {
1771
- sawDefaultParam = true;
1772
- } else if (sawDefaultParam && !sawKeywordOnlySeparator && !sawArgs) {
1773
- // Report this error only once.
1774
- if (!reportedNonDefaultParamErr) {
1775
- this._addError(Localizer.Diagnostic.nonDefaultAfterDefault(), param);
1776
- reportedNonDefaultParamErr = true;
1777
- }
1778
- }
1779
- }
1780
- }
1781
-
1782
- paramList.push(param);
1783
-
1784
- if (param.category === ParameterCategory.VarArgList) {
1785
- if (!param.name) {
1786
- if (sawKeywordOnlySeparator) {
1787
- this._addError(Localizer.Diagnostic.duplicateKeywordOnly(), param);
1788
- } else if (sawArgs) {
1789
- this._addError(Localizer.Diagnostic.keywordOnlyAfterArgs(), param);
1790
- }
1791
- sawKeywordOnlySeparator = true;
1792
- } else {
1793
- if (sawKeywordOnlySeparator || sawArgs) {
1794
- this._addError(Localizer.Diagnostic.duplicateArgsParam(), param);
1795
- }
1796
- sawArgs = true;
1797
- }
1798
- }
1799
-
1800
- if (param.category === ParameterCategory.VarArgDictionary) {
1801
- if (sawKwArgs) {
1802
- this._addError(Localizer.Diagnostic.duplicateKwargsParam(), param);
1803
- }
1804
- sawKwArgs = true;
1805
- } else if (sawKwArgs) {
1806
- this._addError(Localizer.Diagnostic.paramAfterKwargsParam(), param);
1807
- }
1808
-
1809
- const foundComma = this._consumeTokenIfType(TokenType.Comma);
1810
-
1811
- if (allowAnnotations && !param.typeAnnotation) {
1812
- // Look for a type annotation comment at the end of the line.
1813
- const typeAnnotationComment = this._parseVariableTypeAnnotationComment();
1814
- if (typeAnnotationComment) {
1815
- param.typeAnnotationComment = typeAnnotationComment;
1816
- param.typeAnnotationComment.parent = param;
1817
- extendRange(param, param.typeAnnotationComment);
1818
- }
1819
- }
1820
-
1821
- if (!foundComma) {
1822
- break;
1823
- }
1824
- }
1825
-
1826
- if (paramList.length > 0) {
1827
- const lastParam = paramList[paramList.length - 1];
1828
- if (lastParam.category === ParameterCategory.VarArgList && !lastParam.name) {
1829
- this._addError(Localizer.Diagnostic.expectedNamedParameter(), lastParam);
1830
- }
1831
- }
1832
-
1833
- return paramList;
1834
- }
1835
-
1836
- private _parseParameter(allowAnnotations: boolean): ParameterNode {
1837
- let starCount = 0;
1838
- let slashCount = 0;
1839
- const firstToken = this._peekToken();
1840
-
1841
- if (this._consumeTokenIfOperator(OperatorType.Multiply)) {
1842
- starCount = 1;
1843
- } else if (this._consumeTokenIfOperator(OperatorType.Power)) {
1844
- starCount = 2;
1845
- } else if (this._consumeTokenIfOperator(OperatorType.Divide)) {
1846
- if (this._getLanguageVersion() < PythonVersion.V3_8 && !this._parseOptions.isStubFile) {
1847
- this._addError(Localizer.Diagnostic.positionOnlyIncompatible(), firstToken);
1848
- }
1849
- slashCount = 1;
1850
- }
1851
-
1852
- const paramName = this._getTokenIfIdentifier();
1853
- if (!paramName) {
1854
- if (starCount === 1) {
1855
- const paramNode = ParameterNode.create(firstToken, ParameterCategory.VarArgList);
1856
- return paramNode;
1857
- } else if (slashCount === 1) {
1858
- const paramNode = ParameterNode.create(firstToken, ParameterCategory.Simple);
1859
- return paramNode;
1860
- }
1861
-
1862
- // Check for the Python 2.x parameter sublist syntax and handle it gracefully.
1863
- if (this._peekTokenType() === TokenType.OpenParenthesis) {
1864
- const sublistStart = this._getNextToken();
1865
- if (this._consumeTokensUntilType([TokenType.CloseParenthesis])) {
1866
- this._getNextToken();
1867
- }
1868
- this._addError(Localizer.Diagnostic.sublistParamsIncompatible(), sublistStart);
1869
- } else {
1870
- this._addError(Localizer.Diagnostic.expectedParamName(), this._peekToken());
1871
- }
1872
- }
1873
-
1874
- let paramType = ParameterCategory.Simple;
1875
- if (starCount === 1) {
1876
- paramType = ParameterCategory.VarArgList;
1877
- } else if (starCount === 2) {
1878
- paramType = ParameterCategory.VarArgDictionary;
1879
- }
1880
- const paramNode = ParameterNode.create(firstToken, paramType);
1881
- if (paramName) {
1882
- paramNode.name = NameNode.create(paramName);
1883
- paramNode.name.parent = paramNode;
1884
- extendRange(paramNode, paramName);
1885
- }
1886
-
1887
- if (allowAnnotations && this._consumeTokenIfType(TokenType.Colon)) {
1888
- paramNode.typeAnnotation = this._parseTypeAnnotation(paramType === ParameterCategory.VarArgList);
1889
- paramNode.typeAnnotation.parent = paramNode;
1890
- extendRange(paramNode, paramNode.typeAnnotation);
1891
- }
1892
-
1893
- if (this._consumeTokenIfOperator(OperatorType.Assign)) {
1894
- paramNode.defaultValue = this._parseTestExpression(/* allowAssignmentExpression */ false);
1895
- paramNode.defaultValue.parent = paramNode;
1896
- extendRange(paramNode, paramNode.defaultValue);
1897
-
1898
- if (starCount > 0) {
1899
- this._addError(Localizer.Diagnostic.defaultValueNotAllowed(), paramNode.defaultValue);
1900
- }
1901
- }
1902
-
1903
- return paramNode;
1904
- }
1905
-
1906
- // with_stmt: 'with' with_item (',' with_item)* ':' suite
1907
- // Python 3.10 adds support for optional parentheses around
1908
- // with_item list.
1909
- private _parseWithStatement(asyncToken?: KeywordToken): WithNode {
1910
- const withToken = this._getKeywordToken(KeywordType.With);
1911
- let withItemList: WithItemNode[] = [];
1912
-
1913
- const possibleParen = this._peekToken();
1914
-
1915
- // If the expression starts with a paren, parse it as though the
1916
- // paren is enclosing the list of "with items". This is done as a
1917
- // "dry run" to determine whether the entire list of "with items"
1918
- // is enclosed in parentheses.
1919
- let isParenthesizedWithItemList = false;
1920
- if (possibleParen.type === TokenType.OpenParenthesis) {
1921
- const openParenTokenIndex = this._tokenIndex;
1922
-
1923
- this._suppressErrors(() => {
1924
- this._getNextToken();
1925
- while (true) {
1926
- withItemList.push(this._parseWithItem());
1927
- if (!this._consumeTokenIfType(TokenType.Comma)) {
1928
- break;
1929
- }
1930
-
1931
- if (this._peekToken().type === TokenType.CloseParenthesis) {
1932
- break;
1933
- }
1934
- }
1935
-
1936
- if (
1937
- this._peekToken().type === TokenType.CloseParenthesis &&
1938
- this._peekToken(1).type === TokenType.Colon
1939
- ) {
1940
- isParenthesizedWithItemList = withItemList.length !== 1 || withItemList[0].target !== undefined;
1941
- }
1942
-
1943
- this._tokenIndex = openParenTokenIndex;
1944
- withItemList = [];
1945
- });
1946
- }
1947
-
1948
- if (isParenthesizedWithItemList) {
1949
- this._consumeTokenIfType(TokenType.OpenParenthesis);
1950
- if (this._getLanguageVersion() < PythonVersion.V3_9) {
1951
- this._addError(Localizer.Diagnostic.parenthesizedContextManagerIllegal(), possibleParen);
1952
- }
1953
- }
1954
-
1955
- while (true) {
1956
- withItemList.push(this._parseWithItem());
1957
-
1958
- if (!this._consumeTokenIfType(TokenType.Comma)) {
1959
- break;
1960
- }
1961
-
1962
- if (this._peekToken().type === TokenType.CloseParenthesis) {
1963
- break;
1964
- }
1965
- }
1966
-
1967
- if (isParenthesizedWithItemList) {
1968
- if (!this._consumeTokenIfType(TokenType.CloseParenthesis)) {
1969
- this._addError(Localizer.Diagnostic.expectedCloseParen(), possibleParen);
1970
- }
1971
- }
1972
-
1973
- const withSuite = this._parseSuite(this._isInFunction, /* skipBody */ false, () => {
1974
- this._detectUnsupportedTypeAnnotationComment();
1975
- });
1976
- const withNode = WithNode.create(withToken, withSuite);
1977
- if (asyncToken) {
1978
- withNode.isAsync = true;
1979
- withNode.asyncToken = asyncToken;
1980
- extendRange(withNode, asyncToken);
1981
- }
1982
-
1983
- withNode.withItems = withItemList;
1984
- withItemList.forEach((withItem) => {
1985
- withItem.parent = withNode;
1986
- });
1987
-
1988
- return withNode;
1989
- }
1990
-
1991
- // with_item: test ['as' expr]
1992
- private _parseWithItem(): WithItemNode {
1993
- const expr = this._parseTestExpression(/* allowAssignmentExpression */ true);
1994
- const itemNode = WithItemNode.create(expr);
1995
-
1996
- if (this._consumeTokenIfKeyword(KeywordType.As)) {
1997
- itemNode.target = this._parseExpression(/* allowUnpack */ false);
1998
- itemNode.target.parent = itemNode;
1999
- extendRange(itemNode, itemNode.target);
2000
- }
2001
-
2002
- return itemNode;
2003
- }
2004
-
2005
- // decorators: decorator+
2006
- // decorated: decorators (classdef | funcdef | async_funcdef)
2007
- private _parseDecorated(): StatementNode | undefined {
2008
- const decoratorList: DecoratorNode[] = [];
2009
-
2010
- while (true) {
2011
- if (this._peekOperatorType() === OperatorType.MatrixMultiply) {
2012
- decoratorList.push(this._parseDecorator());
2013
- } else {
2014
- break;
2015
- }
2016
- }
2017
-
2018
- const nextToken = this._peekToken() as KeywordToken;
2019
- if (nextToken.type === TokenType.Keyword) {
2020
- if (nextToken.keywordType === KeywordType.Async) {
2021
- this._getNextToken();
2022
-
2023
- if (this._peekKeywordType() !== KeywordType.Def) {
2024
- this._addError(Localizer.Diagnostic.expectedFunctionAfterAsync(), this._peekToken());
2025
- } else {
2026
- return this._parseFunctionDef(nextToken, decoratorList);
2027
- }
2028
- } else if (nextToken.keywordType === KeywordType.Def) {
2029
- return this._parseFunctionDef(undefined, decoratorList);
2030
- } else if (nextToken.keywordType === KeywordType.Class) {
2031
- return this._parseClassDef(decoratorList);
2032
- }
2033
- }
2034
-
2035
- this._addError(Localizer.Diagnostic.expectedAfterDecorator(), this._peekToken());
2036
-
2037
- // Return a dummy class declaration so the completion provider has
2038
- // some parse nodes to work with.
2039
- return ClassNode.createDummyForDecorators(decoratorList);
2040
- }
2041
-
2042
- // decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE
2043
- private _parseDecorator(): DecoratorNode {
2044
- const atOperator = this._getNextToken() as OperatorToken;
2045
- assert(atOperator.operatorType === OperatorType.MatrixMultiply);
2046
-
2047
- const expression = this._parseTestExpression(/* allowAssignmentExpression */ true);
2048
-
2049
- // Versions of Python prior to 3.9 support a limited set of
2050
- // expression forms.
2051
- if (this._getLanguageVersion() < PythonVersion.V3_9) {
2052
- let isSupportedExpressionForm = false;
2053
- if (this._isNameOrMemberAccessExpression(expression)) {
2054
- isSupportedExpressionForm = true;
2055
- } else if (
2056
- expression.nodeType === ParseNodeType.Call &&
2057
- this._isNameOrMemberAccessExpression(expression.leftExpression)
2058
- ) {
2059
- isSupportedExpressionForm = true;
2060
- }
2061
-
2062
- if (!isSupportedExpressionForm) {
2063
- this._addError(Localizer.Diagnostic.expectedDecoratorExpr(), expression);
2064
- }
2065
- }
2066
-
2067
- const decoratorNode = DecoratorNode.create(atOperator, expression);
2068
-
2069
- if (!this._consumeTokenIfType(TokenType.NewLine)) {
2070
- this._addError(Localizer.Diagnostic.expectedDecoratorNewline(), this._peekToken());
2071
- this._consumeTokensUntilType([TokenType.NewLine]);
2072
- }
2073
-
2074
- return decoratorNode;
2075
- }
2076
-
2077
- private _isNameOrMemberAccessExpression(expression: ExpressionNode): boolean {
2078
- if (expression.nodeType === ParseNodeType.Name) {
2079
- return true;
2080
- } else if (expression.nodeType === ParseNodeType.MemberAccess) {
2081
- return this._isNameOrMemberAccessExpression(expression.leftExpression);
2082
- }
2083
-
2084
- return false;
2085
- }
2086
-
2087
- // classdef: 'class' NAME ['(' [arglist] ')'] suite
2088
- private _parseClassDef(decorators?: DecoratorNode[]): ClassNode {
2089
- const classToken = this._getKeywordToken(KeywordType.Class);
2090
-
2091
- let nameToken = this._getTokenIfIdentifier();
2092
- if (!nameToken) {
2093
- this._addError(Localizer.Diagnostic.expectedClassName(), this._peekToken());
2094
- nameToken = IdentifierToken.create(0, 0, '', /* comments */ undefined);
2095
- }
2096
-
2097
- let argList: ArgumentNode[] = [];
2098
- const openParenToken = this._peekToken();
2099
- if (this._consumeTokenIfType(TokenType.OpenParenthesis)) {
2100
- argList = this._parseArgList().args;
2101
-
2102
- if (!this._consumeTokenIfType(TokenType.CloseParenthesis)) {
2103
- this._addError(Localizer.Diagnostic.expectedCloseParen(), openParenToken);
2104
- }
2105
- }
2106
-
2107
- const suite = this._parseSuite(/* isFunction */ false, this._parseOptions.skipFunctionAndClassBody);
2108
-
2109
- const classNode = ClassNode.create(classToken, NameNode.create(nameToken), suite);
2110
- classNode.arguments = argList;
2111
- argList.forEach((arg) => {
2112
- arg.parent = classNode;
2113
- });
2114
-
2115
- if (decorators) {
2116
- classNode.decorators = decorators;
2117
- if (decorators.length > 0) {
2118
- decorators.forEach((decorator) => {
2119
- decorator.parent = classNode;
2120
- });
2121
- extendRange(classNode, decorators[0]);
2122
- }
2123
- }
2124
-
2125
- return classNode;
2126
- }
2127
-
2128
- private _parsePassStatement(): PassNode {
2129
- return PassNode.create(this._getKeywordToken(KeywordType.Pass));
2130
- }
2131
-
2132
- private _parseBreakStatement(): BreakNode {
2133
- const breakToken = this._getKeywordToken(KeywordType.Break);
2134
-
2135
- if (!this._isInLoop) {
2136
- this._addError(Localizer.Diagnostic.breakOutsideLoop(), breakToken);
2137
- }
2138
-
2139
- return BreakNode.create(breakToken);
2140
- }
2141
-
2142
- private _parseContinueStatement(): ContinueNode {
2143
- const continueToken = this._getKeywordToken(KeywordType.Continue);
2144
-
2145
- if (!this._isInLoop) {
2146
- this._addError(Localizer.Diagnostic.continueOutsideLoop(), continueToken);
2147
- } else if (this._isInFinally) {
2148
- this._addError(Localizer.Diagnostic.continueInFinally(), continueToken);
2149
- }
2150
-
2151
- return ContinueNode.create(continueToken);
2152
- }
2153
-
2154
- // return_stmt: 'return' [testlist]
2155
- private _parseReturnStatement(): ReturnNode {
2156
- const returnToken = this._getKeywordToken(KeywordType.Return);
2157
-
2158
- const returnNode = ReturnNode.create(returnToken);
2159
-
2160
- if (!this._isInFunction) {
2161
- this._addError(Localizer.Diagnostic.returnOutsideFunction(), returnToken);
2162
- }
2163
-
2164
- if (!this._isNextTokenNeverExpression()) {
2165
- const returnExpr = this._parseTestOrStarListAsExpression(
2166
- /* allowAssignmentExpression */ true,
2167
- /* allowMultipleUnpack */ true,
2168
- ErrorExpressionCategory.MissingExpression,
2169
- Localizer.Diagnostic.expectedReturnExpr()
2170
- );
2171
- this._reportConditionalErrorForStarTupleElement(returnExpr);
2172
- returnNode.returnExpression = returnExpr;
2173
- returnNode.returnExpression.parent = returnNode;
2174
- extendRange(returnNode, returnExpr);
2175
- }
2176
-
2177
- return returnNode;
2178
- }
2179
-
2180
- // import_from: ('from' (('.' | '...')* dotted_name | ('.' | '...')+)
2181
- // 'import' ('*' | '(' import_as_names ')' | import_as_names))
2182
- // import_as_names: import_as_name (',' import_as_name)* [',']
2183
- // import_as_name: NAME ['as' NAME]
2184
- private _parseFromStatement(): ImportFromNode {
2185
- const fromToken = this._getKeywordToken(KeywordType.From);
2186
-
2187
- const modName = this._parseDottedModuleName(/* allowJustDots */ true);
2188
- const importFromNode = ImportFromNode.create(fromToken, modName);
2189
-
2190
- // Handle imports from __future__ specially because they can
2191
- // change the way we interpret the rest of the file.
2192
- const isFutureImport =
2193
- modName.leadingDots === 0 && modName.nameParts.length === 1 && modName.nameParts[0].value === '__future__';
2194
-
2195
- const possibleInputToken = this._peekToken();
2196
- if (!this._consumeTokenIfKeyword(KeywordType.Import)) {
2197
- this._addError(Localizer.Diagnostic.expectedImport(), this._peekToken());
2198
- if (!modName.hasTrailingDot) {
2199
- importFromNode.missingImportKeyword = true;
2200
- }
2201
- } else {
2202
- extendRange(importFromNode, possibleInputToken);
2203
-
2204
- // Look for "*" token.
2205
- const possibleStarToken = this._peekToken();
2206
- if (this._consumeTokenIfOperator(OperatorType.Multiply)) {
2207
- extendRange(importFromNode, possibleStarToken);
2208
- importFromNode.isWildcardImport = true;
2209
- importFromNode.wildcardToken = possibleStarToken;
2210
- this._containsWildcardImport = true;
2211
- } else {
2212
- const openParenToken = this._peekToken();
2213
- const inParen = this._consumeTokenIfType(TokenType.OpenParenthesis);
2214
- let trailingCommaToken: Token | undefined;
2215
-
2216
- while (true) {
2217
- const importName = this._getTokenIfIdentifier();
2218
- if (!importName) {
2219
- break;
2220
- }
2221
-
2222
- trailingCommaToken = undefined;
2223
-
2224
- const importFromAsNode = ImportFromAsNode.create(NameNode.create(importName));
2225
-
2226
- if (this._consumeTokenIfKeyword(KeywordType.As)) {
2227
- const aliasName = this._getTokenIfIdentifier();
2228
- if (!aliasName) {
2229
- this._addError(Localizer.Diagnostic.expectedImportAlias(), this._peekToken());
2230
- } else {
2231
- importFromAsNode.alias = NameNode.create(aliasName);
2232
- importFromAsNode.alias.parent = importFromAsNode;
2233
- extendRange(importFromAsNode, aliasName);
2234
- }
2235
- }
2236
-
2237
- importFromNode.imports.push(importFromAsNode);
2238
- importFromAsNode.parent = importFromNode;
2239
- extendRange(importFromNode, importFromAsNode);
2240
-
2241
- if (isFutureImport) {
2242
- // Add the future import to the map.
2243
- this._futureImportMap.set(importName.value, true);
2244
- }
2245
-
2246
- const nextToken = this._peekToken();
2247
- if (!this._consumeTokenIfType(TokenType.Comma)) {
2248
- break;
2249
- }
2250
- trailingCommaToken = nextToken;
2251
- }
2252
-
2253
- if (importFromNode.imports.length === 0) {
2254
- this._addError(Localizer.Diagnostic.expectedImportSymbols(), this._peekToken());
2255
- }
2256
-
2257
- if (inParen) {
2258
- importFromNode.usesParens = true;
2259
-
2260
- const nextToken = this._peekToken();
2261
- if (!this._consumeTokenIfType(TokenType.CloseParenthesis)) {
2262
- this._addError(Localizer.Diagnostic.expectedCloseParen(), openParenToken);
2263
- } else {
2264
- extendRange(importFromNode, nextToken);
2265
- }
2266
- } else if (trailingCommaToken) {
2267
- this._addError(Localizer.Diagnostic.trailingCommaInFromImport(), trailingCommaToken);
2268
- }
2269
- }
2270
- }
2271
-
2272
- this._importedModules.push({
2273
- nameNode: importFromNode.module,
2274
- leadingDots: importFromNode.module.leadingDots,
2275
- nameParts: importFromNode.module.nameParts.map((p) => p.value),
2276
- importedSymbols: importFromNode.imports.map((imp) => imp.name.value),
2277
- });
2278
-
2279
- let isTypingImport = false;
2280
- if (importFromNode.module.nameParts.length === 1) {
2281
- const firstNamePartValue = importFromNode.module.nameParts[0].value;
2282
- if (firstNamePartValue === 'typing' || firstNamePartValue === 'typing_extensions') {
2283
- isTypingImport = true;
2284
- }
2285
- }
2286
-
2287
- if (isTypingImport) {
2288
- const typingSymbolsOfInterest = ['Literal', 'TypeAlias', 'Annotated'];
2289
-
2290
- if (importFromNode.isWildcardImport) {
2291
- typingSymbolsOfInterest.forEach((s) => {
2292
- this._typingSymbolAliases.set(s, s);
2293
- });
2294
- } else {
2295
- importFromNode.imports.forEach((imp) => {
2296
- if (typingSymbolsOfInterest.some((s) => s === imp.name.value)) {
2297
- this._typingSymbolAliases.set(imp.alias?.value || imp.name.value, imp.name.value);
2298
- }
2299
- });
2300
- }
2301
- }
2302
-
2303
- return importFromNode;
2304
- }
2305
-
2306
- // import_name: 'import' dotted_as_names
2307
- // dotted_as_names: dotted_as_name (',' dotted_as_name)*
2308
- // dotted_as_name: dotted_name ['as' NAME]
2309
- private _parseImportStatement(): ImportNode {
2310
- const importToken = this._getKeywordToken(KeywordType.Import);
2311
-
2312
- const importNode = ImportNode.create(importToken);
2313
-
2314
- while (true) {
2315
- const modName = this._parseDottedModuleName();
2316
-
2317
- const importAsNode = ImportAsNode.create(modName);
2318
-
2319
- if (this._consumeTokenIfKeyword(KeywordType.As)) {
2320
- const aliasToken = this._getTokenIfIdentifier();
2321
- if (aliasToken) {
2322
- importAsNode.alias = NameNode.create(aliasToken);
2323
- importAsNode.alias.parent = importAsNode;
2324
- extendRange(importAsNode, importAsNode.alias);
2325
- } else {
2326
- this._addError(Localizer.Diagnostic.expectedImportAlias(), this._peekToken());
2327
- }
2328
- }
2329
-
2330
- if (importAsNode.module.leadingDots > 0) {
2331
- this._addError(Localizer.Diagnostic.relativeImportNotAllowed(), importAsNode.module);
2332
- }
2333
-
2334
- importNode.list.push(importAsNode);
2335
- importAsNode.parent = importNode;
2336
-
2337
- this._importedModules.push({
2338
- nameNode: importAsNode.module,
2339
- leadingDots: importAsNode.module.leadingDots,
2340
- nameParts: importAsNode.module.nameParts.map((p) => p.value),
2341
- importedSymbols: undefined,
2342
- });
2343
-
2344
- if (modName.nameParts.length === 1) {
2345
- const firstNamePartValue = modName.nameParts[0].value;
2346
- if (firstNamePartValue === 'typing' || firstNamePartValue === 'typing_extensions') {
2347
- this._typingImportAliases.push(importAsNode.alias?.value || firstNamePartValue);
2348
- }
2349
- }
2350
-
2351
- if (!this._consumeTokenIfType(TokenType.Comma)) {
2352
- break;
2353
- }
2354
- }
2355
-
2356
- if (importNode.list.length > 0) {
2357
- extendRange(importNode, importNode.list[importNode.list.length - 1]);
2358
- }
2359
-
2360
- return importNode;
2361
- }
2362
-
2363
- // ('.' | '...')* dotted_name | ('.' | '...')+
2364
- // dotted_name: NAME ('.' NAME)*
2365
- private _parseDottedModuleName(allowJustDots = false): ModuleNameNode {
2366
- const moduleNameNode = ModuleNameNode.create(this._peekToken());
2367
-
2368
- while (true) {
2369
- const token = this._getTokenIfType(TokenType.Ellipsis) ?? this._getTokenIfType(TokenType.Dot);
2370
- if (token) {
2371
- if (token.type === TokenType.Ellipsis) {
2372
- moduleNameNode.leadingDots += 3;
2373
- } else {
2374
- moduleNameNode.leadingDots++;
2375
- }
2376
-
2377
- extendRange(moduleNameNode, token);
2378
- } else {
2379
- break;
2380
- }
2381
- }
2382
-
2383
- while (true) {
2384
- const identifier = this._getTokenIfIdentifier();
2385
- if (!identifier) {
2386
- if (!allowJustDots || moduleNameNode.leadingDots === 0 || moduleNameNode.nameParts.length > 0) {
2387
- this._addError(Localizer.Diagnostic.expectedModuleName(), this._peekToken());
2388
- moduleNameNode.hasTrailingDot = true;
2389
- }
2390
- break;
2391
- }
2392
-
2393
- const namePart = NameNode.create(identifier);
2394
- moduleNameNode.nameParts.push(namePart);
2395
- namePart.parent = moduleNameNode;
2396
- extendRange(moduleNameNode, namePart);
2397
-
2398
- const nextToken = this._peekToken();
2399
- if (!this._consumeTokenIfType(TokenType.Dot)) {
2400
- break;
2401
- }
2402
-
2403
- // Extend the module name to include the dot.
2404
- extendRange(moduleNameNode, nextToken);
2405
- }
2406
-
2407
- return moduleNameNode;
2408
- }
2409
-
2410
- private _parseGlobalStatement(): GlobalNode {
2411
- const globalToken = this._getKeywordToken(KeywordType.Global);
2412
-
2413
- const globalNode = GlobalNode.create(globalToken);
2414
- globalNode.nameList = this._parseNameList();
2415
- if (globalNode.nameList.length > 0) {
2416
- globalNode.nameList.forEach((name) => {
2417
- name.parent = globalNode;
2418
- });
2419
- extendRange(globalNode, globalNode.nameList[globalNode.nameList.length - 1]);
2420
- }
2421
- return globalNode;
2422
- }
2423
-
2424
- private _parseNonlocalStatement(): NonlocalNode {
2425
- const nonlocalToken = this._getKeywordToken(KeywordType.Nonlocal);
2426
-
2427
- const nonlocalNode = NonlocalNode.create(nonlocalToken);
2428
- nonlocalNode.nameList = this._parseNameList();
2429
- if (nonlocalNode.nameList.length > 0) {
2430
- nonlocalNode.nameList.forEach((name) => {
2431
- name.parent = nonlocalNode;
2432
- });
2433
- extendRange(nonlocalNode, nonlocalNode.nameList[nonlocalNode.nameList.length - 1]);
2434
- }
2435
- return nonlocalNode;
2436
- }
2437
-
2438
- private _parseNameList(): NameNode[] {
2439
- const nameList: NameNode[] = [];
2440
-
2441
- while (true) {
2442
- const name = this._getTokenIfIdentifier();
2443
- if (!name) {
2444
- this._addError(Localizer.Diagnostic.expectedIdentifier(), this._peekToken());
2445
- break;
2446
- }
2447
-
2448
- nameList.push(NameNode.create(name));
2449
-
2450
- if (!this._consumeTokenIfType(TokenType.Comma)) {
2451
- break;
2452
- }
2453
- }
2454
-
2455
- return nameList;
2456
- }
2457
-
2458
- // raise_stmt: 'raise' [test ['from' test]]
2459
- // (old) raise_stmt: 'raise' [test [',' test [',' test]]]
2460
- private _parseRaiseStatement(): RaiseNode {
2461
- const raiseToken = this._getKeywordToken(KeywordType.Raise);
2462
-
2463
- const raiseNode = RaiseNode.create(raiseToken);
2464
- if (!this._isNextTokenNeverExpression()) {
2465
- raiseNode.typeExpression = this._parseTestExpression(/* allowAssignmentExpression */ true);
2466
- raiseNode.typeExpression.parent = raiseNode;
2467
- extendRange(raiseNode, raiseNode.typeExpression);
2468
-
2469
- if (this._consumeTokenIfKeyword(KeywordType.From)) {
2470
- raiseNode.valueExpression = this._parseTestExpression(/* allowAssignmentExpression */ true);
2471
- raiseNode.valueExpression.parent = raiseNode;
2472
- extendRange(raiseNode, raiseNode.valueExpression);
2473
- } else {
2474
- if (this._consumeTokenIfType(TokenType.Comma)) {
2475
- // Handle the Python 2.x variant
2476
- raiseNode.valueExpression = this._parseTestExpression(/* allowAssignmentExpression */ true);
2477
- raiseNode.valueExpression.parent = raiseNode;
2478
- extendRange(raiseNode, raiseNode.valueExpression);
2479
-
2480
- if (this._consumeTokenIfType(TokenType.Comma)) {
2481
- raiseNode.tracebackExpression = this._parseTestExpression(/* allowAssignmentExpression */ true);
2482
- raiseNode.tracebackExpression.parent = raiseNode;
2483
- extendRange(raiseNode, raiseNode.tracebackExpression);
2484
- }
2485
- }
2486
- }
2487
- }
2488
-
2489
- return raiseNode;
2490
- }
2491
-
2492
- // assert_stmt: 'assert' test [',' test]
2493
- private _parseAssertStatement(): AssertNode {
2494
- const assertToken = this._getKeywordToken(KeywordType.Assert);
2495
-
2496
- const expr = this._parseTestExpression(/* allowAssignmentExpression */ true);
2497
- const assertNode = AssertNode.create(assertToken, expr);
2498
-
2499
- if (this._consumeTokenIfType(TokenType.Comma)) {
2500
- const exceptionExpr = this._parseTestExpression(/* allowAssignmentExpression */ true);
2501
- assertNode.exceptionExpression = exceptionExpr;
2502
- assertNode.exceptionExpression.parent = assertNode;
2503
- extendRange(assertNode, exceptionExpr);
2504
- }
2505
-
2506
- return assertNode;
2507
- }
2508
-
2509
- // del_stmt: 'del' exprlist
2510
- private _parseDelStatement(): DelNode {
2511
- const delToken = this._getKeywordToken(KeywordType.Del);
2512
-
2513
- const exprListResult = this._parseExpressionList(/* allowStar */ true);
2514
- if (!exprListResult.parseError && exprListResult.list.length === 0) {
2515
- this._addError(Localizer.Diagnostic.expectedDelExpr(), this._peekToken());
2516
- }
2517
- const delNode = DelNode.create(delToken);
2518
- delNode.expressions = exprListResult.list;
2519
- if (delNode.expressions.length > 0) {
2520
- delNode.expressions.forEach((expr) => {
2521
- expr.parent = delNode;
2522
- });
2523
- extendRange(delNode, delNode.expressions[delNode.expressions.length - 1]);
2524
- }
2525
- return delNode;
2526
- }
2527
-
2528
- // yield_expr: 'yield' [yield_arg]
2529
- // yield_arg: 'from' test | testlist
2530
- private _parseYieldExpression(): YieldNode | YieldFromNode {
2531
- const yieldToken = this._getKeywordToken(KeywordType.Yield);
2532
-
2533
- const nextToken = this._peekToken();
2534
- if (this._consumeTokenIfKeyword(KeywordType.From)) {
2535
- if (this._getLanguageVersion() < PythonVersion.V3_3) {
2536
- this._addError(Localizer.Diagnostic.yieldFromIllegal(), nextToken);
2537
- }
2538
- return YieldFromNode.create(yieldToken, this._parseTestExpression(/* allowAssignmentExpression */ true));
2539
- }
2540
-
2541
- let exprList: ExpressionNode | undefined;
2542
- if (!this._isNextTokenNeverExpression()) {
2543
- exprList = this._parseTestOrStarListAsExpression(
2544
- /* allowAssignmentExpression */ true,
2545
- /* allowMultipleUnpack */ true,
2546
- ErrorExpressionCategory.MissingExpression,
2547
- Localizer.Diagnostic.expectedYieldExpr()
2548
- );
2549
- this._reportConditionalErrorForStarTupleElement(exprList);
2550
- }
2551
-
2552
- return YieldNode.create(yieldToken, exprList);
2553
- }
2554
-
2555
- private _tryParseYieldExpression(): YieldNode | YieldFromNode | undefined {
2556
- if (this._peekKeywordType() !== KeywordType.Yield) {
2557
- return undefined;
2558
- }
2559
-
2560
- return this._parseYieldExpression();
2561
- }
2562
-
2563
- // simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE
2564
- private _parseSimpleStatement(): StatementListNode {
2565
- const statement = StatementListNode.create(this._peekToken());
2566
-
2567
- while (true) {
2568
- // Swallow invalid tokens to make sure we make forward progress.
2569
- if (this._peekTokenType() === TokenType.Invalid) {
2570
- const invalidToken = this._getNextToken();
2571
- const text = this._fileContents!.substr(invalidToken.start, invalidToken.length);
2572
-
2573
- const firstCharCode = text.charCodeAt(0);
2574
-
2575
- // Remove any non-printable characters.
2576
- this._addError(
2577
- Localizer.Diagnostic.invalidTokenChars().format({ text: `\\u${firstCharCode.toString(16)}` }),
2578
- invalidToken
2579
- );
2580
- this._consumeTokensUntilType([TokenType.NewLine]);
2581
- break;
2582
- }
2583
-
2584
- const smallStatement = this._parseSmallStatement();
2585
- statement.statements.push(smallStatement);
2586
- smallStatement.parent = statement;
2587
- extendRange(statement, smallStatement);
2588
-
2589
- if (smallStatement.nodeType === ParseNodeType.Error) {
2590
- // No need to log an error here. We assume that
2591
- // it was already logged by _parseSmallStatement.
2592
- break;
2593
- }
2594
-
2595
- // Consume the semicolon if present.
2596
- if (!this._consumeTokenIfType(TokenType.Semicolon)) {
2597
- break;
2598
- }
2599
-
2600
- const nextTokenType = this._peekTokenType();
2601
- if (nextTokenType === TokenType.NewLine || nextTokenType === TokenType.EndOfStream) {
2602
- break;
2603
- }
2604
- }
2605
-
2606
- if (!this._consumeTokenIfType(TokenType.NewLine)) {
2607
- this._addError(Localizer.Diagnostic.expectedNewlineOrSemicolon(), this._peekToken());
2608
- }
2609
-
2610
- return statement;
2611
- }
2612
-
2613
- // small_stmt: (expr_stmt | del_stmt | pass_stmt | flow_stmt |
2614
- // import_stmt | global_stmt | nonlocal_stmt | assert_stmt)
2615
- // flow_stmt: break_stmt | continue_stmt | return_stmt | raise_stmt | yield_stmt
2616
- // import_stmt: import_name | import_from
2617
- private _parseSmallStatement(): ParseNode {
2618
- switch (this._peekKeywordType()) {
2619
- case KeywordType.Pass:
2620
- return this._parsePassStatement();
2621
-
2622
- case KeywordType.Break:
2623
- return this._parseBreakStatement();
2624
-
2625
- case KeywordType.Continue:
2626
- return this._parseContinueStatement();
2627
-
2628
- case KeywordType.Return:
2629
- return this._parseReturnStatement();
2630
-
2631
- case KeywordType.From:
2632
- return this._parseFromStatement();
2633
-
2634
- case KeywordType.Import:
2635
- return this._parseImportStatement();
2636
-
2637
- case KeywordType.Global:
2638
- return this._parseGlobalStatement();
2639
-
2640
- case KeywordType.Nonlocal:
2641
- return this._parseNonlocalStatement();
2642
-
2643
- case KeywordType.Raise:
2644
- return this._parseRaiseStatement();
2645
-
2646
- case KeywordType.Assert:
2647
- return this._parseAssertStatement();
2648
-
2649
- case KeywordType.Del:
2650
- return this._parseDelStatement();
2651
-
2652
- case KeywordType.Yield:
2653
- return this._parseYieldExpression();
2654
- }
2655
-
2656
- return this._parseExpressionStatement();
2657
- }
2658
-
2659
- private _makeExpressionOrTuple(
2660
- exprListResult: ListResult<ExpressionNode>,
2661
- enclosedInParens: boolean
2662
- ): ExpressionNode {
2663
- // A single-element tuple with no trailing comma is simply an expression
2664
- // that's surrounded by parens.
2665
- if (exprListResult.list.length === 1 && !exprListResult.trailingComma) {
2666
- if (exprListResult.list[0].nodeType === ParseNodeType.Unpack) {
2667
- this._addError(Localizer.Diagnostic.unpackOperatorNotAllowed(), exprListResult.list[0]);
2668
- }
2669
- return exprListResult.list[0];
2670
- }
2671
-
2672
- // To accommodate empty tuples ("()"), we will reach back to get
2673
- // the opening parenthesis as the opening token.
2674
-
2675
- const tupleStartRange: TextRange =
2676
- exprListResult.list.length > 0 ? exprListResult.list[0] : this._peekToken(-1);
2677
-
2678
- const tupleNode = TupleNode.create(tupleStartRange, enclosedInParens);
2679
- tupleNode.expressions = exprListResult.list;
2680
- if (exprListResult.list.length > 0) {
2681
- exprListResult.list.forEach((expr) => {
2682
- expr.parent = tupleNode;
2683
- });
2684
- extendRange(tupleNode, exprListResult.list[exprListResult.list.length - 1]);
2685
- }
2686
-
2687
- return tupleNode;
2688
- }
2689
-
2690
- private _parseExpressionListAsPossibleTuple(
2691
- errorCategory: ErrorExpressionCategory,
2692
- errorString: string,
2693
- errorToken: Token
2694
- ): ExpressionNode {
2695
- if (this._isNextTokenNeverExpression()) {
2696
- this._addError(errorString, errorToken);
2697
- return ErrorNode.create(errorToken, errorCategory);
2698
- }
2699
-
2700
- const exprListResult = this._parseExpressionList(/* allowStar */ true);
2701
- if (exprListResult.parseError) {
2702
- return exprListResult.parseError;
2703
- }
2704
- return this._makeExpressionOrTuple(exprListResult, /* enclosedInParens */ false);
2705
- }
2706
-
2707
- private _parseTestListAsExpression(errorCategory: ErrorExpressionCategory, errorString: string): ExpressionNode {
2708
- if (this._isNextTokenNeverExpression()) {
2709
- return this._handleExpressionParseError(errorCategory, errorString);
2710
- }
2711
-
2712
- const exprListResult = this._parseTestExpressionList();
2713
- if (exprListResult.parseError) {
2714
- return exprListResult.parseError;
2715
- }
2716
- return this._makeExpressionOrTuple(exprListResult, /* enclosedInParens */ false);
2717
- }
2718
-
2719
- private _parseTestOrStarListAsExpression(
2720
- allowAssignmentExpression: boolean,
2721
- allowMultipleUnpack: boolean,
2722
- errorCategory: ErrorExpressionCategory,
2723
- errorString: string
2724
- ): ExpressionNode {
2725
- if (this._isNextTokenNeverExpression()) {
2726
- return this._handleExpressionParseError(errorCategory, errorString);
2727
- }
2728
-
2729
- const exprListResult = this._parseTestOrStarExpressionList(allowAssignmentExpression, allowMultipleUnpack);
2730
- if (exprListResult.parseError) {
2731
- return exprListResult.parseError;
2732
- }
2733
- return this._makeExpressionOrTuple(exprListResult, /* enclosedInParens */ false);
2734
- }
2735
-
2736
- private _parseExpressionList(allowStar: boolean): ListResult<ExpressionNode> {
2737
- return this._parseExpressionListGeneric(() => this._parseExpression(allowStar));
2738
- }
2739
-
2740
- // testlist: test (',' test)* [',']
2741
- private _parseTestExpressionList(): ListResult<ExpressionNode> {
2742
- return this._parseExpressionListGeneric(() => this._parseTestExpression(/* allowAssignmentExpression */ false));
2743
- }
2744
-
2745
- private _parseTestOrStarExpressionList(
2746
- allowAssignmentExpression: boolean,
2747
- allowMultipleUnpack: boolean
2748
- ): ListResult<ExpressionNode> {
2749
- const exprListResult = this._parseExpressionListGeneric(() =>
2750
- this._parseTestOrStarExpression(allowAssignmentExpression)
2751
- );
2752
-
2753
- if (!allowMultipleUnpack && !exprListResult.parseError) {
2754
- let sawStar = false;
2755
- for (const expr of exprListResult.list) {
2756
- if (expr.nodeType === ParseNodeType.Unpack) {
2757
- if (sawStar) {
2758
- this._addError(Localizer.Diagnostic.duplicateUnpack(), expr);
2759
- break;
2760
- }
2761
- sawStar = true;
2762
- }
2763
- }
2764
- }
2765
-
2766
- return exprListResult;
2767
- }
2768
-
2769
- // exp_or_star: expr | star_expr
2770
- // expr: xor_expr ('|' xor_expr)*
2771
- // star_expr: '*' expr
2772
- private _parseExpression(allowUnpack: boolean): ExpressionNode {
2773
- const startToken = this._peekToken();
2774
-
2775
- if (allowUnpack && this._consumeTokenIfOperator(OperatorType.Multiply)) {
2776
- return UnpackNode.create(startToken, this._parseExpression(/* allowUnpack */ false));
2777
- }
2778
-
2779
- return this._parseBitwiseOrExpression();
2780
- }
2781
-
2782
- // test_or_star: test | star_expr
2783
- private _parseTestOrStarExpression(allowAssignmentExpression: boolean): ExpressionNode {
2784
- if (this._peekOperatorType() === OperatorType.Multiply) {
2785
- return this._parseExpression(/* allowUnpack */ true);
2786
- }
2787
-
2788
- return this._parseTestExpression(allowAssignmentExpression);
2789
- }
2790
-
2791
- // test: or_test ['if' or_test 'else' test] | lambdef
2792
- private _parseTestExpression(allowAssignmentExpression: boolean): ExpressionNode {
2793
- if (this._peekKeywordType() === KeywordType.Lambda) {
2794
- return this._parseLambdaExpression();
2795
- }
2796
-
2797
- const ifExpr = allowAssignmentExpression ? this._parseAssignmentExpression() : this._parseOrTest();
2798
- if (ifExpr.nodeType === ParseNodeType.Error) {
2799
- return ifExpr;
2800
- }
2801
-
2802
- if (!this._consumeTokenIfKeyword(KeywordType.If)) {
2803
- return ifExpr;
2804
- }
2805
-
2806
- const testExpr = this._parseOrTest();
2807
- if (testExpr.nodeType === ParseNodeType.Error) {
2808
- return testExpr;
2809
- }
2810
-
2811
- if (!this._consumeTokenIfKeyword(KeywordType.Else)) {
2812
- return this._handleExpressionParseError(
2813
- ErrorExpressionCategory.MissingElse,
2814
- Localizer.Diagnostic.expectedElse()
2815
- );
2816
- }
2817
-
2818
- const elseExpr = this._parseTestExpression(/* allowAssignmentExpression */ true);
2819
- if (elseExpr.nodeType === ParseNodeType.Error) {
2820
- return elseExpr;
2821
- }
2822
-
2823
- return TernaryNode.create(ifExpr, testExpr, elseExpr);
2824
- }
2825
-
2826
- // assign_expr: NAME := test
2827
- private _parseAssignmentExpression(disallowAssignmentExpression = false) {
2828
- const leftExpr = this._parseOrTest();
2829
- if (leftExpr.nodeType === ParseNodeType.Error) {
2830
- return leftExpr;
2831
- }
2832
-
2833
- if (leftExpr.nodeType !== ParseNodeType.Name) {
2834
- return leftExpr;
2835
- }
2836
-
2837
- const walrusToken = this._peekToken();
2838
- if (!this._consumeTokenIfOperator(OperatorType.Walrus)) {
2839
- return leftExpr;
2840
- }
2841
-
2842
- if (!this._assignmentExpressionsAllowed || this._isParsingTypeAnnotation || disallowAssignmentExpression) {
2843
- this._addError(Localizer.Diagnostic.walrusNotAllowed(), walrusToken);
2844
- }
2845
-
2846
- if (this._getLanguageVersion() < PythonVersion.V3_8) {
2847
- this._addError(Localizer.Diagnostic.walrusIllegal(), walrusToken);
2848
- }
2849
-
2850
- const rightExpr = this._parseTestExpression(/* allowAssignmentExpression */ false);
2851
-
2852
- return AssignmentExpressionNode.create(leftExpr, rightExpr);
2853
- }
2854
-
2855
- // or_test: and_test ('or' and_test)*
2856
- private _parseOrTest(): ExpressionNode {
2857
- let leftExpr = this._parseAndTest();
2858
- if (leftExpr.nodeType === ParseNodeType.Error) {
2859
- return leftExpr;
2860
- }
2861
-
2862
- while (true) {
2863
- const peekToken = this._peekToken();
2864
- if (!this._consumeTokenIfKeyword(KeywordType.Or)) {
2865
- break;
2866
- }
2867
- const rightExpr = this._parseAndTest();
2868
- leftExpr = this._createBinaryOperationNode(leftExpr, rightExpr, peekToken, OperatorType.Or);
2869
- }
2870
-
2871
- return leftExpr;
2872
- }
2873
-
2874
- // and_test: not_test ('and' not_test)*
2875
- private _parseAndTest(): ExpressionNode {
2876
- let leftExpr = this._parseNotTest();
2877
- if (leftExpr.nodeType === ParseNodeType.Error) {
2878
- return leftExpr;
2879
- }
2880
-
2881
- while (true) {
2882
- const peekToken = this._peekToken();
2883
- if (!this._consumeTokenIfKeyword(KeywordType.And)) {
2884
- break;
2885
- }
2886
- const rightExpr = this._parseNotTest();
2887
- leftExpr = this._createBinaryOperationNode(leftExpr, rightExpr, peekToken, OperatorType.And);
2888
- }
2889
-
2890
- return leftExpr;
2891
- }
2892
-
2893
- // not_test: 'not' not_test | comparison
2894
- private _parseNotTest(): ExpressionNode {
2895
- const notToken = this._peekToken();
2896
- if (this._consumeTokenIfKeyword(KeywordType.Not)) {
2897
- const notExpr = this._parseNotTest();
2898
- return this._createUnaryOperationNode(notToken, notExpr, OperatorType.Not);
2899
- }
2900
-
2901
- return this._parseComparison();
2902
- }
2903
-
2904
- // comparison: expr (comp_op expr)*
2905
- // comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not'
2906
- private _parseComparison(): ExpressionNode {
2907
- let leftExpr = this._parseBitwiseOrExpression();
2908
- if (leftExpr.nodeType === ParseNodeType.Error) {
2909
- return leftExpr;
2910
- }
2911
-
2912
- while (true) {
2913
- let comparisonOperator: OperatorType | undefined;
2914
- const peekToken = this._peekToken();
2915
-
2916
- if (Tokenizer.isOperatorComparison(this._peekOperatorType())) {
2917
- comparisonOperator = this._peekOperatorType();
2918
- if (comparisonOperator === OperatorType.LessOrGreaterThan) {
2919
- this._addError(Localizer.Diagnostic.operatorLessOrGreaterDeprecated(), peekToken);
2920
- comparisonOperator = OperatorType.NotEquals;
2921
- }
2922
- this._getNextToken();
2923
- } else if (this._consumeTokenIfKeyword(KeywordType.In)) {
2924
- comparisonOperator = OperatorType.In;
2925
- } else if (this._consumeTokenIfKeyword(KeywordType.Is)) {
2926
- if (this._consumeTokenIfKeyword(KeywordType.Not)) {
2927
- comparisonOperator = OperatorType.IsNot;
2928
- } else {
2929
- comparisonOperator = OperatorType.Is;
2930
- }
2931
- } else if (this._peekKeywordType() === KeywordType.Not) {
2932
- const tokenAfterNot = this._peekToken(1);
2933
- if (
2934
- tokenAfterNot.type === TokenType.Keyword &&
2935
- (tokenAfterNot as KeywordToken).keywordType === KeywordType.In
2936
- ) {
2937
- this._getNextToken();
2938
- this._getNextToken();
2939
- comparisonOperator = OperatorType.NotIn;
2940
- }
2941
- }
2942
-
2943
- if (comparisonOperator === undefined) {
2944
- break;
2945
- }
2946
-
2947
- const rightExpr = this._parseComparison();
2948
- leftExpr = this._createBinaryOperationNode(leftExpr, rightExpr, peekToken, comparisonOperator);
2949
- }
2950
-
2951
- return leftExpr;
2952
- }
2953
-
2954
- // expr: xor_expr ('|' xor_expr)*
2955
- private _parseBitwiseOrExpression(): ExpressionNode {
2956
- let leftExpr = this._parseBitwiseXorExpression();
2957
- if (leftExpr.nodeType === ParseNodeType.Error) {
2958
- return leftExpr;
2959
- }
2960
-
2961
- while (true) {
2962
- const peekToken = this._peekToken();
2963
- if (!this._consumeTokenIfOperator(OperatorType.BitwiseOr)) {
2964
- break;
2965
- }
2966
- const rightExpr = this._parseBitwiseXorExpression();
2967
- leftExpr = this._createBinaryOperationNode(leftExpr, rightExpr, peekToken, OperatorType.BitwiseOr);
2968
- }
2969
-
2970
- return leftExpr;
2971
- }
2972
-
2973
- // xor_expr: and_expr ('^' and_expr)*
2974
- private _parseBitwiseXorExpression(): ExpressionNode {
2975
- let leftExpr = this._parseBitwiseAndExpression();
2976
- if (leftExpr.nodeType === ParseNodeType.Error) {
2977
- return leftExpr;
2978
- }
2979
-
2980
- while (true) {
2981
- const peekToken = this._peekToken();
2982
- if (!this._consumeTokenIfOperator(OperatorType.BitwiseXor)) {
2983
- break;
2984
- }
2985
- const rightExpr = this._parseBitwiseAndExpression();
2986
- leftExpr = this._createBinaryOperationNode(leftExpr, rightExpr, peekToken, OperatorType.BitwiseXor);
2987
- }
2988
-
2989
- return leftExpr;
2990
- }
2991
-
2992
- // and_expr: shift_expr ('&' shift_expr)*
2993
- private _parseBitwiseAndExpression(): ExpressionNode {
2994
- let leftExpr = this._parseShiftExpression();
2995
- if (leftExpr.nodeType === ParseNodeType.Error) {
2996
- return leftExpr;
2997
- }
2998
-
2999
- while (true) {
3000
- const peekToken = this._peekToken();
3001
- if (!this._consumeTokenIfOperator(OperatorType.BitwiseAnd)) {
3002
- break;
3003
- }
3004
- const rightExpr = this._parseShiftExpression();
3005
- leftExpr = this._createBinaryOperationNode(leftExpr, rightExpr, peekToken, OperatorType.BitwiseAnd);
3006
- }
3007
-
3008
- return leftExpr;
3009
- }
3010
-
3011
- // shift_expr: arith_expr (('<<'|'>>') arith_expr)*
3012
- private _parseShiftExpression(): ExpressionNode {
3013
- let leftExpr = this._parseArithmeticExpression();
3014
- if (leftExpr.nodeType === ParseNodeType.Error) {
3015
- return leftExpr;
3016
- }
3017
-
3018
- let peekToken = this._peekToken();
3019
- let nextOperator = this._peekOperatorType();
3020
- while (nextOperator === OperatorType.LeftShift || nextOperator === OperatorType.RightShift) {
3021
- this._getNextToken();
3022
- const rightExpr = this._parseArithmeticExpression();
3023
- leftExpr = this._createBinaryOperationNode(leftExpr, rightExpr, peekToken, nextOperator);
3024
- peekToken = this._peekToken();
3025
- nextOperator = this._peekOperatorType();
3026
- }
3027
-
3028
- return leftExpr;
3029
- }
3030
-
3031
- // arith_expr: term (('+'|'-') term)*
3032
- private _parseArithmeticExpression(): ExpressionNode {
3033
- let leftExpr = this._parseArithmeticTerm();
3034
- if (leftExpr.nodeType === ParseNodeType.Error) {
3035
- return leftExpr;
3036
- }
3037
-
3038
- let peekToken = this._peekToken();
3039
- let nextOperator = this._peekOperatorType();
3040
- while (nextOperator === OperatorType.Add || nextOperator === OperatorType.Subtract) {
3041
- this._getNextToken();
3042
- const rightExpr = this._parseArithmeticTerm();
3043
- if (rightExpr.nodeType === ParseNodeType.Error) {
3044
- return rightExpr;
3045
- }
3046
-
3047
- leftExpr = this._createBinaryOperationNode(leftExpr, rightExpr, peekToken, nextOperator);
3048
- peekToken = this._peekToken();
3049
- nextOperator = this._peekOperatorType();
3050
- }
3051
-
3052
- return leftExpr;
3053
- }
3054
-
3055
- // term: factor (('*'|'@'|'/'|'%'|'//') factor)*
3056
- private _parseArithmeticTerm(): ExpressionNode {
3057
- let leftExpr = this._parseArithmeticFactor();
3058
- if (leftExpr.nodeType === ParseNodeType.Error) {
3059
- return leftExpr;
3060
- }
3061
-
3062
- let peekToken = this._peekToken();
3063
- let nextOperator = this._peekOperatorType();
3064
- while (
3065
- nextOperator === OperatorType.Multiply ||
3066
- nextOperator === OperatorType.MatrixMultiply ||
3067
- nextOperator === OperatorType.Divide ||
3068
- nextOperator === OperatorType.Mod ||
3069
- nextOperator === OperatorType.FloorDivide
3070
- ) {
3071
- this._getNextToken();
3072
- const rightExpr = this._parseArithmeticFactor();
3073
- leftExpr = this._createBinaryOperationNode(leftExpr, rightExpr, peekToken, nextOperator);
3074
- peekToken = this._peekToken();
3075
- nextOperator = this._peekOperatorType();
3076
- }
3077
-
3078
- return leftExpr;
3079
- }
3080
-
3081
- // factor: ('+'|'-'|'~') factor | power
3082
- // power: atom_expr ['**' factor]
3083
- private _parseArithmeticFactor(): ExpressionNode {
3084
- const nextToken = this._peekToken();
3085
- const nextOperator = this._peekOperatorType();
3086
- if (
3087
- nextOperator === OperatorType.Add ||
3088
- nextOperator === OperatorType.Subtract ||
3089
- nextOperator === OperatorType.BitwiseInvert
3090
- ) {
3091
- this._getNextToken();
3092
- const expression = this._parseArithmeticFactor();
3093
- return this._createUnaryOperationNode(nextToken, expression, nextOperator);
3094
- }
3095
-
3096
- const leftExpr = this._parseAtomExpression();
3097
- if (leftExpr.nodeType === ParseNodeType.Error) {
3098
- return leftExpr;
3099
- }
3100
-
3101
- const peekToken = this._peekToken();
3102
- if (this._consumeTokenIfOperator(OperatorType.Power)) {
3103
- const rightExpr = this._parseArithmeticFactor();
3104
- return this._createBinaryOperationNode(leftExpr, rightExpr, peekToken, OperatorType.Power);
3105
- }
3106
-
3107
- return leftExpr;
3108
- }
3109
-
3110
- // Determines whether the expression refers to a type exported by the typing
3111
- // or typing_extensions modules. We can directly evaluate the types at binding
3112
- // time. We assume here that the code isn't making use of some custom type alias
3113
- // to refer to the typing types.
3114
- private _isTypingAnnotation(typeAnnotation: ExpressionNode, name: string): boolean {
3115
- if (typeAnnotation.nodeType === ParseNodeType.Name) {
3116
- const alias = this._typingSymbolAliases.get(typeAnnotation.value);
3117
- if (alias === name) {
3118
- return true;
3119
- }
3120
- } else if (typeAnnotation.nodeType === ParseNodeType.MemberAccess) {
3121
- if (
3122
- typeAnnotation.leftExpression.nodeType === ParseNodeType.Name &&
3123
- typeAnnotation.memberName.value === name
3124
- ) {
3125
- const baseName = typeAnnotation.leftExpression.value;
3126
- return this._typingImportAliases.some((alias) => alias === baseName);
3127
- }
3128
- }
3129
-
3130
- return false;
3131
- }
3132
-
3133
- // atom_expr: ['await'] atom trailer*
3134
- // trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME
3135
- private _parseAtomExpression(): ExpressionNode {
3136
- let awaitToken: KeywordToken | undefined;
3137
- if (this._peekKeywordType() === KeywordType.Await && !this._isParsingTypeAnnotation) {
3138
- awaitToken = this._getKeywordToken(KeywordType.Await);
3139
- if (this._getLanguageVersion() < PythonVersion.V3_5) {
3140
- this._addError(Localizer.Diagnostic.awaitIllegal(), awaitToken);
3141
- }
3142
- }
3143
-
3144
- let atomExpression = this._parseAtom();
3145
- if (atomExpression.nodeType === ParseNodeType.Error) {
3146
- return atomExpression;
3147
- }
3148
-
3149
- // Consume trailers.
3150
- while (true) {
3151
- // Is it a function call?
3152
- const startOfTrailerToken = this._peekToken();
3153
- if (this._consumeTokenIfType(TokenType.OpenParenthesis)) {
3154
- // Generally, function calls are not allowed within type annotations,
3155
- // but they are permitted in "Annotated" annotations.
3156
- const wasParsingTypeAnnotation = this._isParsingTypeAnnotation;
3157
- this._isParsingTypeAnnotation = false;
3158
-
3159
- const argListResult = this._parseArgList();
3160
- const callNode = CallNode.create(atomExpression, argListResult.args, argListResult.trailingComma);
3161
-
3162
- if (argListResult.args.length > 1 || argListResult.trailingComma) {
3163
- argListResult.args.forEach((arg) => {
3164
- if (arg.valueExpression.nodeType === ParseNodeType.ListComprehension) {
3165
- if (!arg.valueExpression.isParenthesized) {
3166
- this._addError(Localizer.Diagnostic.generatorNotParenthesized(), arg.valueExpression);
3167
- }
3168
- }
3169
- });
3170
- }
3171
-
3172
- const nextToken = this._peekToken();
3173
- let isArgListTerminated = false;
3174
- if (!this._consumeTokenIfType(TokenType.CloseParenthesis)) {
3175
- this._addError(Localizer.Diagnostic.expectedCloseParen(), startOfTrailerToken);
3176
-
3177
- // Consume the remainder of tokens on the line for error
3178
- // recovery.
3179
- this._consumeTokensUntilType([TokenType.NewLine]);
3180
-
3181
- // Extend the node's range to include the rest of the line.
3182
- // This helps the signatureHelpProvider.
3183
- extendRange(callNode, this._peekToken());
3184
- } else {
3185
- extendRange(callNode, nextToken);
3186
- isArgListTerminated = true;
3187
- }
3188
-
3189
- this._isParsingTypeAnnotation = wasParsingTypeAnnotation;
3190
-
3191
- if (this._isParsingTypeAnnotation) {
3192
- const diag = new DiagnosticAddendum();
3193
- if (atomExpression.nodeType === ParseNodeType.Name && atomExpression.value === 'type') {
3194
- diag.addMessage(Localizer.DiagnosticAddendum.useTypeInstead());
3195
- this._addError(Localizer.Diagnostic.typeCallNotAllowed() + diag.getString(), callNode);
3196
- }
3197
- }
3198
-
3199
- atomExpression = callNode;
3200
-
3201
- if (atomExpression.maxChildDepth !== undefined && atomExpression.maxChildDepth >= maxChildNodeDepth) {
3202
- atomExpression = ErrorNode.create(atomExpression, ErrorExpressionCategory.MaxDepthExceeded);
3203
- this._addError(Localizer.Diagnostic.maxParseDepthExceeded(), atomExpression);
3204
- }
3205
-
3206
- // If the argument list wasn't terminated, break out of the loop
3207
- if (!isArgListTerminated) {
3208
- break;
3209
- }
3210
- } else if (this._consumeTokenIfType(TokenType.OpenBracket)) {
3211
- // Is it an index operator?
3212
-
3213
- // This is an unfortunate hack that's necessary to accommodate 'Literal'
3214
- // and 'Annotated' type annotations properly. We need to suspend treating
3215
- // strings as type annotations within a Literal or Annotated subscript.
3216
- const wasParsingIndexTrailer = this._isParsingIndexTrailer;
3217
- const wasParsingTypeAnnotation = this._isParsingTypeAnnotation;
3218
-
3219
- if (
3220
- this._isTypingAnnotation(atomExpression, 'Literal') ||
3221
- this._isTypingAnnotation(atomExpression, 'Annotated')
3222
- ) {
3223
- this._isParsingTypeAnnotation = false;
3224
- }
3225
-
3226
- this._isParsingIndexTrailer = true;
3227
- const subscriptList = this._parseSubscriptList();
3228
- this._isParsingTypeAnnotation = wasParsingTypeAnnotation;
3229
- this._isParsingIndexTrailer = wasParsingIndexTrailer;
3230
-
3231
- const closingToken = this._peekToken();
3232
-
3233
- const indexNode = IndexNode.create(
3234
- atomExpression,
3235
- subscriptList.list,
3236
- subscriptList.trailingComma,
3237
- closingToken
3238
- );
3239
- extendRange(indexNode, indexNode);
3240
-
3241
- if (!this._consumeTokenIfType(TokenType.CloseBracket)) {
3242
- // Handle the error case, but don't use the error node in this
3243
- // case because it creates problems for the completion provider.
3244
- this._handleExpressionParseError(
3245
- ErrorExpressionCategory.MissingIndexCloseBracket,
3246
- Localizer.Diagnostic.expectedCloseBracket(),
3247
- startOfTrailerToken,
3248
- indexNode
3249
- );
3250
- }
3251
-
3252
- atomExpression = indexNode;
3253
-
3254
- if (atomExpression.maxChildDepth !== undefined && atomExpression.maxChildDepth >= maxChildNodeDepth) {
3255
- atomExpression = ErrorNode.create(atomExpression, ErrorExpressionCategory.MaxDepthExceeded);
3256
- this._addError(Localizer.Diagnostic.maxParseDepthExceeded(), atomExpression);
3257
- }
3258
- } else if (this._consumeTokenIfType(TokenType.Dot)) {
3259
- // Is it a member access?
3260
- const memberName = this._getTokenIfIdentifier();
3261
- if (!memberName) {
3262
- return this._handleExpressionParseError(
3263
- ErrorExpressionCategory.MissingMemberAccessName,
3264
- Localizer.Diagnostic.expectedMemberName(),
3265
- startOfTrailerToken,
3266
- atomExpression,
3267
- [TokenType.Keyword]
3268
- );
3269
- }
3270
- atomExpression = MemberAccessNode.create(atomExpression, NameNode.create(memberName));
3271
-
3272
- if (atomExpression.maxChildDepth !== undefined && atomExpression.maxChildDepth >= maxChildNodeDepth) {
3273
- atomExpression = ErrorNode.create(atomExpression, ErrorExpressionCategory.MaxDepthExceeded);
3274
- this._addError(Localizer.Diagnostic.maxParseDepthExceeded(), atomExpression);
3275
- }
3276
- } else {
3277
- break;
3278
- }
3279
- }
3280
-
3281
- if (awaitToken) {
3282
- return AwaitNode.create(awaitToken, atomExpression);
3283
- }
3284
-
3285
- return atomExpression;
3286
- }
3287
-
3288
- // subscriptlist: subscript (',' subscript)* [',']
3289
- private _parseSubscriptList(): SubscriptListResult {
3290
- const argList: ArgumentNode[] = [];
3291
- let sawKeywordArg = false;
3292
- let trailingComma = false;
3293
-
3294
- while (true) {
3295
- const firstToken = this._peekToken();
3296
-
3297
- if (firstToken.type !== TokenType.Colon && this._isNextTokenNeverExpression()) {
3298
- break;
3299
- }
3300
-
3301
- let argType = ArgumentCategory.Simple;
3302
- if (this._consumeTokenIfOperator(OperatorType.Multiply)) {
3303
- argType = ArgumentCategory.UnpackedList;
3304
- } else if (this._consumeTokenIfOperator(OperatorType.Power)) {
3305
- argType = ArgumentCategory.UnpackedDictionary;
3306
- }
3307
-
3308
- const startOfSubscriptIndex = this._tokenIndex;
3309
- let valueExpr = this._parsePossibleSlice();
3310
- let nameIdentifier: IdentifierToken | undefined;
3311
-
3312
- // Is this a keyword argument?
3313
- if (argType === ArgumentCategory.Simple) {
3314
- if (this._consumeTokenIfOperator(OperatorType.Assign)) {
3315
- const nameExpr = valueExpr;
3316
- valueExpr = this._parsePossibleSlice();
3317
-
3318
- if (nameExpr.nodeType === ParseNodeType.Name) {
3319
- nameIdentifier = nameExpr.token;
3320
- } else {
3321
- this._addError(Localizer.Diagnostic.expectedParamName(), nameExpr);
3322
- }
3323
- } else if (
3324
- valueExpr.nodeType === ParseNodeType.Name &&
3325
- this._peekOperatorType() === OperatorType.Walrus
3326
- ) {
3327
- this._tokenIndex = startOfSubscriptIndex;
3328
- valueExpr = this._parseTestExpression(/* allowAssignmentExpression */ true);
3329
-
3330
- // Python 3.10 and newer allow assignment expressions to be used inside of a subscript.
3331
- if (!this._parseOptions.isStubFile && this._getLanguageVersion() < PythonVersion.V3_10) {
3332
- this._addError(Localizer.Diagnostic.assignmentExprInSubscript(), valueExpr);
3333
- }
3334
- }
3335
- }
3336
-
3337
- const argNode = ArgumentNode.create(firstToken, valueExpr, argType);
3338
- if (nameIdentifier) {
3339
- argNode.name = NameNode.create(nameIdentifier);
3340
- argNode.name.parent = argNode;
3341
- }
3342
-
3343
- if (argNode.name) {
3344
- sawKeywordArg = true;
3345
- } else if (sawKeywordArg && argNode.argumentCategory === ArgumentCategory.Simple) {
3346
- this._addError(Localizer.Diagnostic.positionArgAfterNamedArg(), argNode);
3347
- }
3348
- argList.push(argNode);
3349
-
3350
- if (argNode.name) {
3351
- this._addError(Localizer.Diagnostic.keywordSubscriptIllegal(), argNode.name);
3352
- }
3353
-
3354
- if (argType !== ArgumentCategory.Simple) {
3355
- const unpackAllowed =
3356
- this._parseOptions.isStubFile || this._getLanguageVersion() >= PythonVersion.V3_11;
3357
-
3358
- if (argType === ArgumentCategory.UnpackedDictionary || !unpackAllowed) {
3359
- this._addError(Localizer.Diagnostic.unpackedSubscriptIllegal(), argNode);
3360
- }
3361
- }
3362
-
3363
- if (!this._consumeTokenIfType(TokenType.Comma)) {
3364
- trailingComma = false;
3365
- break;
3366
- }
3367
-
3368
- trailingComma = true;
3369
- }
3370
-
3371
- // An empty subscript list is illegal.
3372
- if (argList.length === 0) {
3373
- const errorNode = this._handleExpressionParseError(
3374
- ErrorExpressionCategory.MissingIndexOrSlice,
3375
- Localizer.Diagnostic.expectedSliceIndex(),
3376
- /* targetToken */ undefined,
3377
- /* childNode */ undefined,
3378
- [TokenType.CloseBracket]
3379
- );
3380
- argList.push(ArgumentNode.create(this._peekToken(), errorNode, ArgumentCategory.Simple));
3381
- }
3382
-
3383
- return {
3384
- list: argList,
3385
- trailingComma,
3386
- };
3387
- }
3388
-
3389
- // subscript: test | [test] ':' [test] [sliceop]
3390
- // sliceop: ':' [test]
3391
- private _parsePossibleSlice(): ExpressionNode {
3392
- const firstToken = this._peekToken();
3393
- const sliceExpressions: (ExpressionNode | undefined)[] = [undefined, undefined, undefined];
3394
- let sliceIndex = 0;
3395
- let sawColon = false;
3396
-
3397
- while (true) {
3398
- const nextTokenType = this._peekTokenType();
3399
- if (nextTokenType === TokenType.CloseBracket || nextTokenType === TokenType.Comma) {
3400
- break;
3401
- }
3402
-
3403
- if (nextTokenType !== TokenType.Colon) {
3404
- sliceExpressions[sliceIndex] = this._parseTestExpression(/* allowAssignmentExpression */ false);
3405
- }
3406
- sliceIndex++;
3407
-
3408
- if (sliceIndex >= 3 || !this._consumeTokenIfType(TokenType.Colon)) {
3409
- break;
3410
- }
3411
- sawColon = true;
3412
- }
3413
-
3414
- // If this was a simple expression with no colons return it.
3415
- if (!sawColon) {
3416
- if (sliceExpressions[0]) {
3417
- return sliceExpressions[0];
3418
- }
3419
-
3420
- return ErrorNode.create(this._peekToken(), ErrorExpressionCategory.MissingIndexOrSlice);
3421
- }
3422
-
3423
- const sliceNode = SliceNode.create(firstToken);
3424
- sliceNode.startValue = sliceExpressions[0];
3425
- if (sliceNode.startValue) {
3426
- sliceNode.startValue.parent = sliceNode;
3427
- }
3428
- sliceNode.endValue = sliceExpressions[1];
3429
- if (sliceNode.endValue) {
3430
- sliceNode.endValue.parent = sliceNode;
3431
- }
3432
- sliceNode.stepValue = sliceExpressions[2];
3433
- if (sliceNode.stepValue) {
3434
- sliceNode.stepValue.parent = sliceNode;
3435
- }
3436
- const extension = sliceExpressions[2] || sliceExpressions[1] || sliceExpressions[0];
3437
- if (extension) {
3438
- extendRange(sliceNode, extension);
3439
- }
3440
-
3441
- return sliceNode;
3442
- }
3443
-
3444
- // arglist: argument (',' argument)* [',']
3445
- private _parseArgList(): ArgListResult {
3446
- const argList: ArgumentNode[] = [];
3447
- let sawKeywordArg = false;
3448
- let trailingComma = false;
3449
-
3450
- while (true) {
3451
- const nextTokenType = this._peekTokenType();
3452
- if (
3453
- nextTokenType === TokenType.CloseParenthesis ||
3454
- nextTokenType === TokenType.NewLine ||
3455
- nextTokenType === TokenType.EndOfStream
3456
- ) {
3457
- break;
3458
- }
3459
-
3460
- trailingComma = false;
3461
- const arg = this._parseArgument();
3462
- if (arg.name) {
3463
- sawKeywordArg = true;
3464
- } else if (sawKeywordArg && arg.argumentCategory === ArgumentCategory.Simple) {
3465
- this._addError(Localizer.Diagnostic.positionArgAfterNamedArg(), arg);
3466
- }
3467
- argList.push(arg);
3468
-
3469
- if (!this._consumeTokenIfType(TokenType.Comma)) {
3470
- break;
3471
- }
3472
-
3473
- trailingComma = true;
3474
- }
3475
-
3476
- return { args: argList, trailingComma };
3477
- }
3478
-
3479
- // argument: ( test [comp_for] |
3480
- // test '=' test |
3481
- // '**' test |
3482
- // '*' test )
3483
- private _parseArgument(): ArgumentNode {
3484
- const firstToken = this._peekToken();
3485
-
3486
- let argType = ArgumentCategory.Simple;
3487
- if (this._consumeTokenIfOperator(OperatorType.Multiply)) {
3488
- argType = ArgumentCategory.UnpackedList;
3489
- } else if (this._consumeTokenIfOperator(OperatorType.Power)) {
3490
- argType = ArgumentCategory.UnpackedDictionary;
3491
- }
3492
-
3493
- let valueExpr = this._parseTestExpression(/* allowAssignmentExpression */ true);
3494
- let nameIdentifier: IdentifierToken | undefined;
3495
-
3496
- if (argType === ArgumentCategory.Simple) {
3497
- if (this._consumeTokenIfOperator(OperatorType.Assign)) {
3498
- const nameExpr = valueExpr;
3499
- valueExpr = this._parseTestExpression(/* allowAssignmentExpression */ false);
3500
-
3501
- if (nameExpr.nodeType === ParseNodeType.Name) {
3502
- nameIdentifier = nameExpr.token;
3503
- } else {
3504
- this._addError(Localizer.Diagnostic.expectedParamName(), nameExpr);
3505
- }
3506
- } else {
3507
- const listComp = this._tryParseListComprehension(valueExpr);
3508
- if (listComp) {
3509
- valueExpr = listComp;
3510
- }
3511
- }
3512
- }
3513
-
3514
- const argNode = ArgumentNode.create(firstToken, valueExpr, argType);
3515
- if (nameIdentifier) {
3516
- argNode.name = NameNode.create(nameIdentifier);
3517
- argNode.name.parent = argNode;
3518
- }
3519
-
3520
- return argNode;
3521
- }
3522
-
3523
- // atom: ('(' [yield_expr | testlist_comp] ')' |
3524
- // '[' [testlist_comp] ']' |
3525
- // '{' [dictorsetmaker] '}' |
3526
- // NAME | NUMBER | STRING+ | '...' | 'None' | 'True' | 'False' | '__debug__')
3527
- private _parseAtom(): ExpressionNode {
3528
- const nextToken = this._peekToken();
3529
-
3530
- if (nextToken.type === TokenType.Ellipsis) {
3531
- return EllipsisNode.create(this._getNextToken());
3532
- }
3533
-
3534
- if (nextToken.type === TokenType.Number) {
3535
- return NumberNode.create(this._getNextToken() as NumberToken);
3536
- }
3537
-
3538
- if (nextToken.type === TokenType.Identifier) {
3539
- return NameNode.create(this._getNextToken() as IdentifierToken);
3540
- }
3541
-
3542
- if (nextToken.type === TokenType.String) {
3543
- return this._parseStringList();
3544
- }
3545
-
3546
- if (nextToken.type === TokenType.Backtick) {
3547
- this._getNextToken();
3548
-
3549
- // Atoms with backticks are no longer allowed in Python 3.x, but they
3550
- // were a thing in Python 2.x. We'll parse them to improve parse recovery
3551
- // and emit an error.
3552
- this._addError(Localizer.Diagnostic.backticksIllegal(), nextToken);
3553
-
3554
- const expressionNode = this._parseTestListAsExpression(
3555
- ErrorExpressionCategory.MissingExpression,
3556
- Localizer.Diagnostic.expectedExpr()
3557
- );
3558
-
3559
- this._consumeTokenIfType(TokenType.Backtick);
3560
- return expressionNode;
3561
- }
3562
-
3563
- if (nextToken.type === TokenType.OpenParenthesis) {
3564
- const possibleTupleNode = this._parseTupleAtom();
3565
- if (
3566
- possibleTupleNode.nodeType === ParseNodeType.Tuple &&
3567
- this._isParsingTypeAnnotation &&
3568
- !this._isParsingIndexTrailer
3569
- ) {
3570
- // This is allowed inside of an index trailer, specifically
3571
- // to support Tuple[()], which is the documented way to annotate
3572
- // a zero-length tuple.
3573
- const diag = new DiagnosticAddendum();
3574
- diag.addMessage(Localizer.DiagnosticAddendum.useTupleInstead());
3575
- this._addError(Localizer.Diagnostic.tupleInAnnotation() + diag.getString(), possibleTupleNode);
3576
- }
3577
-
3578
- if (possibleTupleNode.nodeType === ParseNodeType.BinaryOperation) {
3579
- // Mark the binary expression as parenthesized so we don't attempt
3580
- // to use comparison chaining, which isn't appropriate when the
3581
- // expression is parenthesized.
3582
- possibleTupleNode.parenthesized = true;
3583
- }
3584
-
3585
- if (possibleTupleNode.nodeType === ParseNodeType.StringList) {
3586
- possibleTupleNode.isParenthesized = true;
3587
- }
3588
-
3589
- if (possibleTupleNode.nodeType === ParseNodeType.ListComprehension) {
3590
- possibleTupleNode.isParenthesized = true;
3591
- }
3592
-
3593
- return possibleTupleNode;
3594
- } else if (nextToken.type === TokenType.OpenBracket) {
3595
- const listNode = this._parseListAtom();
3596
- if (this._isParsingTypeAnnotation && !this._isParsingIndexTrailer) {
3597
- const diag = new DiagnosticAddendum();
3598
- diag.addMessage(Localizer.DiagnosticAddendum.useListInstead());
3599
- this._addError(Localizer.Diagnostic.listInAnnotation() + diag.getString(), listNode);
3600
- }
3601
- return listNode;
3602
- } else if (nextToken.type === TokenType.OpenCurlyBrace) {
3603
- const dictNode = this._parseDictionaryOrSetAtom();
3604
- if (this._isParsingTypeAnnotation) {
3605
- const diag = new DiagnosticAddendum();
3606
- diag.addMessage(Localizer.DiagnosticAddendum.useDictInstead());
3607
- this._addError(Localizer.Diagnostic.dictInAnnotation() + diag.getString(), dictNode);
3608
- }
3609
- return dictNode;
3610
- }
3611
-
3612
- if (nextToken.type === TokenType.Keyword) {
3613
- const keywordToken = nextToken as KeywordToken;
3614
- if (
3615
- keywordToken.keywordType === KeywordType.False ||
3616
- keywordToken.keywordType === KeywordType.True ||
3617
- keywordToken.keywordType === KeywordType.Debug ||
3618
- keywordToken.keywordType === KeywordType.None
3619
- ) {
3620
- return ConstantNode.create(this._getNextToken() as KeywordToken);
3621
- }
3622
-
3623
- // Make an identifier out of the keyword.
3624
- const keywordAsIdentifier = this._getTokenIfIdentifier();
3625
- if (keywordAsIdentifier) {
3626
- return NameNode.create(keywordAsIdentifier);
3627
- }
3628
- }
3629
-
3630
- return this._handleExpressionParseError(
3631
- ErrorExpressionCategory.MissingExpression,
3632
- Localizer.Diagnostic.expectedExpr()
3633
- );
3634
- }
3635
-
3636
- // Allocates a dummy "error expression" and consumes the remainder
3637
- // of the tokens on the line for error recovery. A partially-completed
3638
- // child node can be passed to help the completion provider determine
3639
- // what to do.
3640
- private _handleExpressionParseError(
3641
- category: ErrorExpressionCategory,
3642
- errorMsg: string,
3643
- targetToken?: Token,
3644
- childNode?: ExpressionNode,
3645
- additionalStopTokens?: TokenType[]
3646
- ): ErrorNode {
3647
- this._addError(errorMsg, targetToken ?? this._peekToken());
3648
- const expr = ErrorNode.create(this._peekToken(), category, childNode);
3649
- const stopTokens = [TokenType.NewLine];
3650
- if (additionalStopTokens) {
3651
- appendArray(stopTokens, additionalStopTokens);
3652
- }
3653
- this._consumeTokensUntilType(stopTokens);
3654
- return expr;
3655
- }
3656
-
3657
- // lambdef: 'lambda' [varargslist] ':' test
3658
- private _parseLambdaExpression(allowConditional = true): LambdaNode {
3659
- const lambdaToken = this._getKeywordToken(KeywordType.Lambda);
3660
-
3661
- const argList = this._parseVarArgsList(TokenType.Colon, /* allowAnnotations */ false);
3662
-
3663
- if (!this._consumeTokenIfType(TokenType.Colon)) {
3664
- this._addError(Localizer.Diagnostic.expectedColon(), this._peekToken());
3665
- }
3666
-
3667
- let testExpr: ExpressionNode;
3668
- if (allowConditional) {
3669
- testExpr = this._parseTestExpression(/* allowAssignmentExpression */ false);
3670
- } else {
3671
- testExpr = this._tryParseLambdaExpression(/* allowConditional */ false) || this._parseOrTest();
3672
- }
3673
-
3674
- const lambdaNode = LambdaNode.create(lambdaToken, testExpr);
3675
- lambdaNode.parameters = argList;
3676
- argList.forEach((arg) => {
3677
- arg.parent = lambdaNode;
3678
- });
3679
- return lambdaNode;
3680
- }
3681
-
3682
- private _tryParseLambdaExpression(allowConditional = true): LambdaNode | undefined {
3683
- if (this._peekKeywordType() !== KeywordType.Lambda) {
3684
- return undefined;
3685
- }
3686
-
3687
- return this._parseLambdaExpression(allowConditional);
3688
- }
3689
-
3690
- // ('(' [yield_expr | testlist_comp] ')'
3691
- // testlist_comp: (test | star_expr) (comp_for | (',' (test | star_expr))* [','])
3692
- private _parseTupleAtom(): ExpressionNode {
3693
- const startParen = this._getNextToken();
3694
- assert(startParen.type === TokenType.OpenParenthesis);
3695
-
3696
- const yieldExpr = this._tryParseYieldExpression();
3697
- if (yieldExpr) {
3698
- if (this._peekTokenType() !== TokenType.CloseParenthesis) {
3699
- return this._handleExpressionParseError(
3700
- ErrorExpressionCategory.MissingTupleCloseParen,
3701
- Localizer.Diagnostic.expectedCloseParen(),
3702
- startParen,
3703
- yieldExpr
3704
- );
3705
- } else {
3706
- extendRange(yieldExpr, this._getNextToken());
3707
- }
3708
-
3709
- return yieldExpr;
3710
- }
3711
-
3712
- const exprListResult = this._parseTestListWithComprehension();
3713
- const tupleOrExpression = this._makeExpressionOrTuple(exprListResult, /* enclosedInParens */ true);
3714
- const isExpression = exprListResult.list.length === 1 && !exprListResult.trailingComma;
3715
-
3716
- if (!isExpression) {
3717
- extendRange(tupleOrExpression, startParen);
3718
- }
3719
-
3720
- if (this._peekTokenType() !== TokenType.CloseParenthesis) {
3721
- return this._handleExpressionParseError(
3722
- ErrorExpressionCategory.MissingTupleCloseParen,
3723
- Localizer.Diagnostic.expectedCloseParen(),
3724
- startParen,
3725
- exprListResult.parseError ?? tupleOrExpression
3726
- );
3727
- } else {
3728
- const nextToken = this._getNextToken();
3729
- if (!isExpression) {
3730
- extendRange(tupleOrExpression, nextToken);
3731
- }
3732
- }
3733
-
3734
- return tupleOrExpression;
3735
- }
3736
-
3737
- // '[' [testlist_comp] ']'
3738
- // testlist_comp: (test | star_expr) (comp_for | (',' (test | star_expr))* [','])
3739
- private _parseListAtom(): ListNode | ErrorNode {
3740
- const startBracket = this._getNextToken();
3741
- assert(startBracket.type === TokenType.OpenBracket);
3742
-
3743
- const exprListResult = this._parseTestListWithComprehension();
3744
- const closeBracket: Token | undefined = this._peekToken();
3745
- if (!this._consumeTokenIfType(TokenType.CloseBracket)) {
3746
- return this._handleExpressionParseError(
3747
- ErrorExpressionCategory.MissingListCloseBracket,
3748
- Localizer.Diagnostic.expectedCloseBracket(),
3749
- startBracket,
3750
- exprListResult.parseError ?? _createList()
3751
- );
3752
- }
3753
-
3754
- return _createList();
3755
-
3756
- function _createList() {
3757
- const listAtom = ListNode.create(startBracket);
3758
-
3759
- if (closeBracket) {
3760
- extendRange(listAtom, closeBracket);
3761
- }
3762
-
3763
- if (exprListResult.list.length > 0) {
3764
- exprListResult.list.forEach((expr) => {
3765
- expr.parent = listAtom;
3766
- });
3767
- extendRange(listAtom, exprListResult.list[exprListResult.list.length - 1]);
3768
- }
3769
-
3770
- listAtom.entries = exprListResult.list;
3771
- return listAtom;
3772
- }
3773
- }
3774
-
3775
- private _parseTestListWithComprehension(): ListResult<ExpressionNode> {
3776
- let sawComprehension = false;
3777
-
3778
- return this._parseExpressionListGeneric(
3779
- () => {
3780
- let expr = this._parseTestOrStarExpression(/* allowAssignmentExpression */ true);
3781
- const listComp = this._tryParseListComprehension(expr);
3782
- if (listComp) {
3783
- expr = listComp;
3784
- sawComprehension = true;
3785
- }
3786
- return expr;
3787
- },
3788
- () => this._isNextTokenNeverExpression(),
3789
- () => sawComprehension
3790
- );
3791
- }
3792
-
3793
- // '{' [dictorsetmaker] '}'
3794
- // dictorsetmaker: (
3795
- // (dictentry (comp_for | (',' dictentry)* [',']))
3796
- // | (setentry (comp_for | (',' setentry)* [',']))
3797
- // )
3798
- // dictentry: (test ':' test | '**' expr)
3799
- // setentry: test | star_expr
3800
- private _parseDictionaryOrSetAtom(): DictionaryNode | SetNode {
3801
- const startBrace = this._getNextToken();
3802
- assert(startBrace.type === TokenType.OpenCurlyBrace);
3803
-
3804
- const dictionaryEntries: DictionaryEntryNode[] = [];
3805
- const setEntries: ExpressionNode[] = [];
3806
- let isDictionary = false;
3807
- let isSet = false;
3808
- let sawListComprehension = false;
3809
- let isFirstEntry = true;
3810
- let trailingCommaToken: Token | undefined;
3811
-
3812
- while (true) {
3813
- if (this._peekTokenType() === TokenType.CloseCurlyBrace) {
3814
- break;
3815
- }
3816
-
3817
- trailingCommaToken = undefined;
3818
-
3819
- let doubleStarExpression: ExpressionNode | undefined;
3820
- let keyExpression: ExpressionNode | undefined;
3821
- let valueExpression: ExpressionNode | undefined;
3822
- const doubleStar = this._peekToken();
3823
-
3824
- if (this._consumeTokenIfOperator(OperatorType.Power)) {
3825
- doubleStarExpression = this._parseExpression(/* allowUnpack */ false);
3826
- } else {
3827
- keyExpression = this._parseTestOrStarExpression(/* allowAssignmentExpression */ true);
3828
-
3829
- if (this._consumeTokenIfType(TokenType.Colon)) {
3830
- valueExpression = this._parseTestExpression(/* allowAssignmentExpression */ false);
3831
- }
3832
- }
3833
-
3834
- if (keyExpression && valueExpression) {
3835
- if (keyExpression.nodeType === ParseNodeType.Unpack) {
3836
- this._addError(Localizer.Diagnostic.unpackInDict(), keyExpression);
3837
- }
3838
-
3839
- if (isSet) {
3840
- this._addError(Localizer.Diagnostic.keyValueInSet(), valueExpression);
3841
- } else {
3842
- const keyEntryNode = DictionaryKeyEntryNode.create(keyExpression, valueExpression);
3843
- let dictEntry: DictionaryEntryNode = keyEntryNode;
3844
- const listComp = this._tryParseListComprehension(keyEntryNode);
3845
- if (listComp) {
3846
- dictEntry = listComp;
3847
- sawListComprehension = true;
3848
-
3849
- if (!isFirstEntry) {
3850
- this._addError(Localizer.Diagnostic.comprehensionInDict(), dictEntry);
3851
- }
3852
- }
3853
- dictionaryEntries.push(dictEntry);
3854
- isDictionary = true;
3855
- }
3856
- } else if (doubleStarExpression) {
3857
- if (isSet) {
3858
- this._addError(Localizer.Diagnostic.unpackInSet(), doubleStarExpression);
3859
- } else {
3860
- const listEntryNode = DictionaryExpandEntryNode.create(doubleStarExpression);
3861
- extendRange(listEntryNode, doubleStar);
3862
- let expandEntryNode: DictionaryEntryNode = listEntryNode;
3863
- const listComp = this._tryParseListComprehension(listEntryNode);
3864
- if (listComp) {
3865
- expandEntryNode = listComp;
3866
- sawListComprehension = true;
3867
-
3868
- if (!isFirstEntry) {
3869
- this._addError(Localizer.Diagnostic.comprehensionInDict(), doubleStarExpression);
3870
- }
3871
- }
3872
- dictionaryEntries.push(expandEntryNode);
3873
- isDictionary = true;
3874
- }
3875
- } else {
3876
- assert(keyExpression !== undefined);
3877
- if (keyExpression) {
3878
- if (isDictionary) {
3879
- const missingValueErrorNode = ErrorNode.create(
3880
- this._peekToken(),
3881
- ErrorExpressionCategory.MissingDictValue
3882
- );
3883
- const keyEntryNode = DictionaryKeyEntryNode.create(keyExpression, missingValueErrorNode);
3884
- dictionaryEntries.push(keyEntryNode);
3885
- this._addError(Localizer.Diagnostic.dictKeyValuePairs(), keyExpression);
3886
- } else {
3887
- const listComp = this._tryParseListComprehension(keyExpression);
3888
- if (listComp) {
3889
- keyExpression = listComp;
3890
- sawListComprehension = true;
3891
-
3892
- if (!isFirstEntry) {
3893
- this._addError(Localizer.Diagnostic.comprehensionInSet(), keyExpression);
3894
- }
3895
- }
3896
- setEntries.push(keyExpression);
3897
- isSet = true;
3898
- }
3899
- }
3900
- }
3901
-
3902
- // List comprehension statements always end the list.
3903
- if (sawListComprehension) {
3904
- break;
3905
- }
3906
-
3907
- if (this._peekTokenType() !== TokenType.Comma) {
3908
- break;
3909
- }
3910
-
3911
- trailingCommaToken = this._getNextToken();
3912
-
3913
- isFirstEntry = false;
3914
- }
3915
-
3916
- let closeCurlyBrace: Token | undefined = this._peekToken();
3917
- if (!this._consumeTokenIfType(TokenType.CloseCurlyBrace)) {
3918
- this._addError(Localizer.Diagnostic.expectedCloseBrace(), startBrace);
3919
- closeCurlyBrace = undefined;
3920
- }
3921
-
3922
- if (isSet) {
3923
- const setAtom = SetNode.create(startBrace);
3924
- if (closeCurlyBrace) {
3925
- extendRange(setAtom, closeCurlyBrace);
3926
- }
3927
-
3928
- if (setEntries.length > 0) {
3929
- extendRange(setAtom, setEntries[setEntries.length - 1]);
3930
- }
3931
-
3932
- setEntries.forEach((entry) => {
3933
- entry.parent = setAtom;
3934
- });
3935
-
3936
- setAtom.entries = setEntries;
3937
- return setAtom;
3938
- }
3939
-
3940
- const dictionaryAtom = DictionaryNode.create(startBrace);
3941
-
3942
- if (trailingCommaToken) {
3943
- dictionaryAtom.trailingCommaToken = trailingCommaToken;
3944
- extendRange(dictionaryAtom, trailingCommaToken);
3945
- }
3946
-
3947
- if (closeCurlyBrace) {
3948
- extendRange(dictionaryAtom, closeCurlyBrace);
3949
- }
3950
-
3951
- if (dictionaryEntries.length > 0) {
3952
- dictionaryEntries.forEach((entry) => {
3953
- entry.parent = dictionaryAtom;
3954
- });
3955
- extendRange(dictionaryAtom, dictionaryEntries[dictionaryEntries.length - 1]);
3956
- }
3957
- dictionaryAtom.entries = dictionaryEntries;
3958
- return dictionaryAtom;
3959
- }
3960
-
3961
- private _parseExpressionListGeneric<T extends ParseNode = ExpressionNode>(
3962
- parser: () => T | ErrorNode,
3963
- terminalCheck: () => boolean = () => this._isNextTokenNeverExpression(),
3964
- finalEntryCheck: () => boolean = () => false
3965
- ): ListResult<T> {
3966
- let trailingComma = false;
3967
- const list: T[] = [];
3968
- let parseError: ErrorNode | undefined;
3969
-
3970
- while (true) {
3971
- if (terminalCheck()) {
3972
- break;
3973
- }
3974
-
3975
- const expr = parser();
3976
- if (expr.nodeType === ParseNodeType.Error) {
3977
- parseError = expr as ErrorNode;
3978
- break;
3979
- }
3980
- list.push(expr);
3981
-
3982
- // Should we stop without checking for a trailing comma?
3983
- if (finalEntryCheck()) {
3984
- break;
3985
- }
3986
-
3987
- if (!this._consumeTokenIfType(TokenType.Comma)) {
3988
- trailingComma = false;
3989
- break;
3990
- }
3991
-
3992
- trailingComma = true;
3993
- }
3994
-
3995
- return { trailingComma, list, parseError };
3996
- }
3997
-
3998
- // expr_stmt: testlist_star_expr (annassign | augassign (yield_expr | testlist) |
3999
- // ('=' (yield_expr | testlist_star_expr))*)
4000
- // testlist_star_expr: (test|star_expr) (',' (test|star_expr))* [',']
4001
- // annassign: ':' test ['=' (yield_expr | testlist_star_expr)]
4002
- // augassign: ('+=' | '-=' | '*=' | '@=' | '/=' | '%=' | '&=' | '|=' | '^=' |
4003
- // '<<=' | '>>=' | '**=' | '//=')
4004
- private _parseExpressionStatement(): ExpressionNode {
4005
- let leftExpr = this._parseTestOrStarListAsExpression(
4006
- /* allowAssignmentExpression */ false,
4007
- /* allowMultipleUnpack */ false,
4008
- ErrorExpressionCategory.MissingExpression,
4009
- Localizer.Diagnostic.expectedExpr()
4010
- );
4011
- let annotationExpr: ExpressionNode | undefined;
4012
-
4013
- if (leftExpr.nodeType === ParseNodeType.Error) {
4014
- return leftExpr;
4015
- }
4016
-
4017
- // Is this a type annotation assignment?
4018
- if (this._consumeTokenIfType(TokenType.Colon)) {
4019
- annotationExpr = this._parseTypeAnnotation();
4020
- leftExpr = TypeAnnotationNode.create(leftExpr, annotationExpr);
4021
-
4022
- if (!this._parseOptions.isStubFile && this._getLanguageVersion() < PythonVersion.V3_6) {
4023
- this._addError(Localizer.Diagnostic.varAnnotationIllegal(), annotationExpr);
4024
- }
4025
-
4026
- if (!this._consumeTokenIfOperator(OperatorType.Assign)) {
4027
- return leftExpr;
4028
- }
4029
-
4030
- // This is an unfortunate hack that's necessary to accommodate 'TypeAlias'
4031
- // declarations properly. We need to treat this assignment differently than
4032
- // most because the expression on the right side is treated like a type
4033
- // annotation and therefore allows string-literal forward declarations.
4034
- const isTypeAliasDeclaration = this._isTypingAnnotation(annotationExpr, 'TypeAlias');
4035
-
4036
- const wasParsingTypeAnnotation = this._isParsingTypeAnnotation;
4037
- if (isTypeAliasDeclaration) {
4038
- this._isParsingTypeAnnotation = true;
4039
- }
4040
-
4041
- const rightExpr =
4042
- this._tryParseYieldExpression() ||
4043
- this._parseTestOrStarListAsExpression(
4044
- /* allowAssignmentExpression */ false,
4045
- /* allowMultipleUnpack */ true,
4046
- ErrorExpressionCategory.MissingExpression,
4047
- Localizer.Diagnostic.expectedAssignRightHandExpr()
4048
- );
4049
-
4050
- this._isParsingTypeAnnotation = wasParsingTypeAnnotation;
4051
-
4052
- return AssignmentNode.create(leftExpr, rightExpr);
4053
- }
4054
-
4055
- // Is this a simple assignment?
4056
- if (this._consumeTokenIfOperator(OperatorType.Assign)) {
4057
- return this._parseChainAssignments(leftExpr);
4058
- }
4059
-
4060
- if (Tokenizer.isOperatorAssignment(this._peekOperatorType())) {
4061
- const operatorToken = this._getNextToken() as OperatorToken;
4062
-
4063
- const rightExpr =
4064
- this._tryParseYieldExpression() ||
4065
- this._parseTestListAsExpression(
4066
- ErrorExpressionCategory.MissingExpression,
4067
- Localizer.Diagnostic.expectedBinaryRightHandExpr()
4068
- );
4069
-
4070
- // Make a shallow copy of the dest expression but give it a new ID.
4071
- const destExpr = Object.assign({}, leftExpr);
4072
- destExpr.id = getNextNodeId();
4073
-
4074
- return AugmentedAssignmentNode.create(leftExpr, rightExpr, operatorToken.operatorType, destExpr);
4075
- }
4076
-
4077
- return leftExpr;
4078
- }
4079
-
4080
- private _parseChainAssignments(leftExpr: ExpressionNode): ExpressionNode {
4081
- let rightExpr =
4082
- this._tryParseYieldExpression() ||
4083
- this._parseTestOrStarListAsExpression(
4084
- /* allowAssignmentExpression */ false,
4085
- /* allowMultipleUnpack */ true,
4086
- ErrorExpressionCategory.MissingExpression,
4087
- Localizer.Diagnostic.expectedAssignRightHandExpr()
4088
- );
4089
-
4090
- if (rightExpr.nodeType === ParseNodeType.Error) {
4091
- return AssignmentNode.create(leftExpr, rightExpr);
4092
- }
4093
-
4094
- // Recur until we've consumed the entire chain.
4095
- if (this._consumeTokenIfOperator(OperatorType.Assign)) {
4096
- rightExpr = this._parseChainAssignments(rightExpr);
4097
- if (rightExpr.nodeType === ParseNodeType.Error) {
4098
- return rightExpr;
4099
- }
4100
- }
4101
-
4102
- const assignmentNode = AssignmentNode.create(leftExpr, rightExpr);
4103
-
4104
- // Look for a type annotation comment at the end of the line.
4105
- const typeAnnotationComment = this._parseVariableTypeAnnotationComment();
4106
- if (typeAnnotationComment) {
4107
- assignmentNode.typeAnnotationComment = typeAnnotationComment;
4108
- assignmentNode.typeAnnotationComment.parent = assignmentNode;
4109
- extendRange(assignmentNode, assignmentNode.typeAnnotationComment);
4110
- }
4111
-
4112
- return assignmentNode;
4113
- }
4114
-
4115
- private _parseFunctionTypeAnnotation(): FunctionAnnotationNode | undefined {
4116
- const openParenToken = this._peekToken();
4117
- if (!this._consumeTokenIfType(TokenType.OpenParenthesis)) {
4118
- this._addError(Localizer.Diagnostic.expectedOpenParen(), this._peekToken());
4119
- return undefined;
4120
- }
4121
-
4122
- let paramAnnotations: ExpressionNode[] = [];
4123
-
4124
- while (true) {
4125
- const nextTokenType = this._peekTokenType();
4126
- if (
4127
- nextTokenType === TokenType.CloseParenthesis ||
4128
- nextTokenType === TokenType.NewLine ||
4129
- nextTokenType === TokenType.EndOfStream
4130
- ) {
4131
- break;
4132
- }
4133
-
4134
- // Consume "*" or "**" indicators but don't do anything with them.
4135
- // (We don't enforce that these are present, absent, or match
4136
- // the corresponding parameter types.)
4137
- this._consumeTokenIfOperator(OperatorType.Multiply) || this._consumeTokenIfOperator(OperatorType.Power);
4138
-
4139
- const paramAnnotation = this._parseTypeAnnotation();
4140
- paramAnnotations.push(paramAnnotation);
4141
-
4142
- if (!this._consumeTokenIfType(TokenType.Comma)) {
4143
- break;
4144
- }
4145
- }
4146
-
4147
- if (!this._consumeTokenIfType(TokenType.CloseParenthesis)) {
4148
- this._addError(Localizer.Diagnostic.expectedCloseParen(), openParenToken);
4149
- this._consumeTokensUntilType([TokenType.Colon]);
4150
- }
4151
-
4152
- if (!this._consumeTokenIfType(TokenType.Arrow)) {
4153
- this._addError(Localizer.Diagnostic.expectedArrow(), this._peekToken());
4154
- return undefined;
4155
- }
4156
-
4157
- const returnType = this._parseTypeAnnotation();
4158
-
4159
- let isParamListEllipsis = false;
4160
- if (paramAnnotations.length === 1 && paramAnnotations[0].nodeType === ParseNodeType.Ellipsis) {
4161
- paramAnnotations = [];
4162
- isParamListEllipsis = true;
4163
- }
4164
-
4165
- return FunctionAnnotationNode.create(openParenToken, isParamListEllipsis, paramAnnotations, returnType);
4166
- }
4167
-
4168
- private _parseTypeAnnotation(allowUnpack = false): ExpressionNode {
4169
- // Temporary set a flag that indicates we're parsing a type annotation.
4170
- const wasParsingTypeAnnotation = this._isParsingTypeAnnotation;
4171
- this._isParsingTypeAnnotation = true;
4172
-
4173
- // Allow unpack operators.
4174
- const startToken = this._peekToken();
4175
- const isUnpack = this._consumeTokenIfOperator(OperatorType.Multiply);
4176
-
4177
- if (isUnpack) {
4178
- if (!allowUnpack) {
4179
- this._addError(Localizer.Diagnostic.unpackInAnnotation(), startToken);
4180
- } else if (!this._parseOptions.isStubFile && this._getLanguageVersion() < PythonVersion.V3_11) {
4181
- this._addError(Localizer.Diagnostic.unpackedSubscriptIllegal(), startToken);
4182
- }
4183
- }
4184
-
4185
- let result = this._parseTestExpression(/* allowAssignmentExpression */ false);
4186
- if (isUnpack && allowUnpack) {
4187
- result = UnpackNode.create(startToken, result);
4188
- }
4189
-
4190
- this._isParsingTypeAnnotation = wasParsingTypeAnnotation;
4191
-
4192
- return result;
4193
- }
4194
-
4195
- private _reportStringTokenErrors(stringToken: StringToken, unescapedResult: StringTokenUtils.UnescapedString) {
4196
- if (stringToken.flags & StringTokenFlags.Unterminated) {
4197
- this._addError(Localizer.Diagnostic.stringUnterminated(), stringToken);
4198
- }
4199
-
4200
- if (unescapedResult.nonAsciiInBytes) {
4201
- this._addError(Localizer.Diagnostic.stringNonAsciiBytes(), stringToken);
4202
- }
4203
-
4204
- if (stringToken.flags & StringTokenFlags.Format) {
4205
- if (this._getLanguageVersion() < PythonVersion.V3_6) {
4206
- this._addError(Localizer.Diagnostic.formatStringIllegal(), stringToken);
4207
- }
4208
-
4209
- if (stringToken.flags & StringTokenFlags.Bytes) {
4210
- this._addError(Localizer.Diagnostic.formatStringBytes(), stringToken);
4211
- }
4212
-
4213
- if (stringToken.flags & StringTokenFlags.Unicode) {
4214
- this._addError(Localizer.Diagnostic.formatStringUnicode(), stringToken);
4215
- }
4216
- }
4217
- }
4218
-
4219
- private _makeStringNode(stringToken: StringToken): StringNode {
4220
- const unescapedResult = StringTokenUtils.getUnescapedString(stringToken);
4221
- this._reportStringTokenErrors(stringToken, unescapedResult);
4222
- return StringNode.create(stringToken, unescapedResult.value, unescapedResult.unescapeErrors.length > 0);
4223
- }
4224
-
4225
- private _getTypeAnnotationCommentText(): StringToken | undefined {
4226
- if (this._tokenIndex === 0) {
4227
- return undefined;
4228
- }
4229
-
4230
- const curToken = this._tokenizerOutput!.tokens.getItemAt(this._tokenIndex - 1);
4231
- const nextToken = this._tokenizerOutput!.tokens.getItemAt(this._tokenIndex);
4232
-
4233
- if (curToken.start + curToken.length === nextToken.start) {
4234
- return undefined;
4235
- }
4236
-
4237
- const interTokenContents = this._fileContents!.substring(curToken.start + curToken.length, nextToken.start);
4238
- const commentRegEx = /^(\s*#\s*type:\s*)([^\r\n]*)/;
4239
- const match = interTokenContents.match(commentRegEx);
4240
- if (!match) {
4241
- return undefined;
4242
- }
4243
-
4244
- // Synthesize a string token and StringNode.
4245
- const typeString = match[2];
4246
-
4247
- // Ignore all "ignore" comments. Include "[" in the regular
4248
- // expression because mypy supports ignore comments of the
4249
- // form ignore[errorCode, ...]. We'll treat these as regular
4250
- // ignore statements (as though no errorCodes were included).
4251
- if (typeString.trim().match(/^ignore(\s|\[|$)/)) {
4252
- return undefined;
4253
- }
4254
-
4255
- const tokenOffset = curToken.start + curToken.length + match[1].length;
4256
- return StringToken.create(
4257
- tokenOffset,
4258
- typeString.length,
4259
- StringTokenFlags.None,
4260
- typeString,
4261
- 0,
4262
- /* comments */ undefined
4263
- );
4264
- }
4265
-
4266
- private _detectUnsupportedTypeAnnotationComment(): void {
4267
- const stringToken = this._getTypeAnnotationCommentText();
4268
- if (!stringToken) {
4269
- return undefined;
4270
- }
4271
-
4272
- this._addError(Localizer.Diagnostic.annotationNotSupported(), stringToken);
4273
- }
4274
-
4275
- private _parseVariableTypeAnnotationComment(): ExpressionNode | undefined {
4276
- const stringToken = this._getTypeAnnotationCommentText();
4277
- if (!stringToken) {
4278
- return undefined;
4279
- }
4280
-
4281
- const stringNode = this._makeStringNode(stringToken);
4282
- const stringListNode = StringListNode.create([stringNode]);
4283
- const parser = new Parser();
4284
- const parseResults = parser.parseTextExpression(
4285
- this._fileContents!,
4286
- stringToken.start,
4287
- stringToken.length,
4288
- this._parseOptions,
4289
- ParseTextMode.VariableAnnotation,
4290
- /* initialParenDepth */ undefined,
4291
- this._typingSymbolAliases
4292
- );
4293
-
4294
- parseResults.diagnostics.forEach((diag) => {
4295
- this._addError(diag.message, stringListNode);
4296
- });
4297
-
4298
- if (!parseResults.parseTree) {
4299
- return undefined;
4300
- }
4301
-
4302
- assert(parseResults.parseTree.nodeType !== ParseNodeType.FunctionAnnotation);
4303
- return parseResults.parseTree;
4304
- }
4305
-
4306
- private _parseFunctionTypeAnnotationComment(stringToken: StringToken, functionNode: FunctionNode): void {
4307
- const stringNode = this._makeStringNode(stringToken);
4308
- const stringListNode = StringListNode.create([stringNode]);
4309
- const parser = new Parser();
4310
- const parseResults = parser.parseTextExpression(
4311
- this._fileContents!,
4312
- stringToken.start,
4313
- stringToken.length,
4314
- this._parseOptions,
4315
- ParseTextMode.FunctionAnnotation,
4316
- /* initialParenDepth */ undefined,
4317
- this._typingSymbolAliases
4318
- );
4319
-
4320
- parseResults.diagnostics.forEach((diag) => {
4321
- this._addError(diag.message, stringListNode);
4322
- });
4323
-
4324
- if (!parseResults.parseTree || parseResults.parseTree.nodeType !== ParseNodeType.FunctionAnnotation) {
4325
- return;
4326
- }
4327
-
4328
- const functionAnnotation = parseResults.parseTree;
4329
-
4330
- functionNode.functionAnnotationComment = functionAnnotation;
4331
- functionAnnotation.parent = functionNode;
4332
- extendRange(functionNode, functionAnnotation);
4333
- }
4334
-
4335
- private _parseFormatStringSegment(
4336
- stringToken: StringToken,
4337
- segment: StringTokenUtils.FormatStringSegment,
4338
- segmentOffset: number,
4339
- segmentLength: number
4340
- ) {
4341
- assert(segment.isExpression);
4342
- const parser = new Parser();
4343
- const parseResults = parser.parseTextExpression(
4344
- this._fileContents!,
4345
- stringToken.start + stringToken.prefixLength + stringToken.quoteMarkLength + segment.offset + segmentOffset,
4346
- segmentLength,
4347
- this._parseOptions,
4348
- ParseTextMode.Expression,
4349
- /* initialParenDepth */ 1,
4350
- this._typingSymbolAliases
4351
- );
4352
-
4353
- parseResults.diagnostics.forEach((diag) => {
4354
- const textRangeStart =
4355
- (diag.range ? convertPositionToOffset(diag.range.start, parseResults.lines) : stringToken.start) ||
4356
- stringToken.start;
4357
- const textRangeEnd =
4358
- (diag.range
4359
- ? (convertPositionToOffset(diag.range.end, parseResults.lines) || 0) + 1
4360
- : stringToken.start + stringToken.length) || stringToken.start + stringToken.length;
4361
- const textRange = { start: textRangeStart, length: textRangeEnd - textRangeStart };
4362
- this._addError(diag.message, textRange);
4363
- });
4364
-
4365
- return parseResults.parseTree;
4366
- }
4367
-
4368
- private _parseFormatString(stringToken: StringToken): FormatStringNode {
4369
- const unescapedResult = StringTokenUtils.getUnescapedString(stringToken);
4370
- this._reportStringTokenErrors(stringToken, unescapedResult);
4371
-
4372
- const formatExpressions: ExpressionNode[] = [];
4373
-
4374
- for (const segment of unescapedResult.formatStringSegments) {
4375
- if (segment.isExpression) {
4376
- // Determine if we need to truncate the expression because it
4377
- // contains formatting directives that start with a ! or :.
4378
- const segmentExprLength = this._getFormatStringExpressionLength(segment.value.trimEnd());
4379
- const parseTree = this._parseFormatStringSegment(stringToken, segment, 0, segmentExprLength);
4380
- if (parseTree) {
4381
- assert(parseTree.nodeType !== ParseNodeType.FunctionAnnotation);
4382
- formatExpressions.push(parseTree);
4383
- }
4384
-
4385
- // Look for additional expressions within the format directive.
4386
- const formatDirective = segment.value.substr(segmentExprLength);
4387
- let braceDepth = 0;
4388
- let startOfExprOffset = 0;
4389
- for (let i = 0; i < formatDirective.length; i++) {
4390
- if (formatDirective.charCodeAt(i) === Char.OpenBrace) {
4391
- if (braceDepth === 0) {
4392
- startOfExprOffset = i + 1;
4393
- }
4394
- braceDepth++;
4395
- } else if (formatDirective.charCodeAt(i) === Char.CloseBrace) {
4396
- if (braceDepth > 0) {
4397
- braceDepth--;
4398
- if (braceDepth === 0) {
4399
- const formatSegmentLength = this._getFormatStringExpressionLength(
4400
- segment.value.substr(segmentExprLength + startOfExprOffset, i - startOfExprOffset)
4401
- );
4402
- const parseTree = this._parseFormatStringSegment(
4403
- stringToken,
4404
- segment,
4405
- segmentExprLength + startOfExprOffset,
4406
- formatSegmentLength
4407
- );
4408
- if (parseTree) {
4409
- assert(parseTree.nodeType !== ParseNodeType.FunctionAnnotation);
4410
- formatExpressions.push(parseTree);
4411
- }
4412
- }
4413
- }
4414
- }
4415
- }
4416
- }
4417
- }
4418
-
4419
- return FormatStringNode.create(
4420
- stringToken,
4421
- unescapedResult.value,
4422
- unescapedResult.unescapeErrors.length > 0,
4423
- formatExpressions
4424
- );
4425
- }
4426
-
4427
- private _getFormatStringExpressionLength(segmentValue: string): number {
4428
- let segmentExprLength = 0;
4429
-
4430
- // PEP 498 says: Expressions cannot contain ':' or '!' outside of
4431
- // strings or parentheses, brackets, or braces. The exception is
4432
- // that the '!=' operator is allowed as a special case.
4433
- const quoteStack: string[] = [];
4434
- let braceCount = 0;
4435
- let parenCount = 0;
4436
- let bracketCount = 0;
4437
- let indexOfDebugEqual: number | undefined;
4438
-
4439
- while (segmentExprLength < segmentValue.length) {
4440
- const curChar = segmentValue[segmentExprLength];
4441
- const ignoreSeparator = quoteStack.length > 0 || braceCount > 0 || parenCount > 0 || bracketCount > 0;
4442
- const inString = quoteStack.length > 0;
4443
-
4444
- if (curChar === '=') {
4445
- indexOfDebugEqual = segmentExprLength;
4446
- } else {
4447
- if (curChar === ':') {
4448
- if (!ignoreSeparator) {
4449
- break;
4450
- }
4451
- } else if (curChar === '!') {
4452
- if (!ignoreSeparator) {
4453
- // Allow !=, as per PEP 498
4454
- if (
4455
- segmentExprLength === segmentValue.length - 1 ||
4456
- segmentValue[segmentExprLength + 1] !== '='
4457
- ) {
4458
- break;
4459
- }
4460
- }
4461
- } else if (curChar === "'" || curChar === '"') {
4462
- let quoteSequence = curChar;
4463
- if (
4464
- segmentExprLength + 2 < segmentValue.length &&
4465
- segmentValue[segmentExprLength + 1] === curChar &&
4466
- segmentValue[segmentExprLength + 2] === curChar
4467
- ) {
4468
- quoteSequence = curChar + curChar + curChar;
4469
- segmentExprLength += 2;
4470
- }
4471
-
4472
- if (quoteStack.length > 0 && quoteStack[quoteStack.length - 1] === quoteSequence) {
4473
- quoteStack.pop();
4474
- } else if (quoteStack.length === 0) {
4475
- quoteStack.push(quoteSequence);
4476
- }
4477
- } else if (curChar === '(') {
4478
- if (!inString) {
4479
- parenCount++;
4480
- }
4481
- } else if (curChar === ')') {
4482
- if (!inString && parenCount > 0) {
4483
- parenCount--;
4484
- }
4485
- } else if (curChar === '{') {
4486
- if (!inString) {
4487
- braceCount++;
4488
- }
4489
- } else if (curChar === '}') {
4490
- if (!inString && braceCount > 0) {
4491
- braceCount--;
4492
- }
4493
- } else if (curChar === '[') {
4494
- if (!inString) {
4495
- bracketCount++;
4496
- }
4497
- } else if (curChar === ']') {
4498
- if (!inString && bracketCount > 0) {
4499
- bracketCount--;
4500
- }
4501
- }
4502
-
4503
- if (curChar !== ' ') {
4504
- indexOfDebugEqual = undefined;
4505
- }
4506
- }
4507
-
4508
- segmentExprLength++;
4509
- }
4510
-
4511
- // Handle Python 3.8 f-string formatting expressions that
4512
- // end in an "=".
4513
- if (this._parseOptions.pythonVersion >= PythonVersion.V3_8 && indexOfDebugEqual !== undefined) {
4514
- segmentExprLength = indexOfDebugEqual;
4515
- }
4516
-
4517
- return segmentExprLength;
4518
- }
4519
-
4520
- private _createBinaryOperationNode(
4521
- leftExpression: ExpressionNode,
4522
- rightExpression: ExpressionNode,
4523
- operatorToken: Token,
4524
- operator: OperatorType
4525
- ) {
4526
- // Determine if we're exceeding the max parse depth. If so, replace
4527
- // the subnode with an error node. Otherwise we risk crashing in the binder
4528
- // or type evaluator.
4529
- if (leftExpression.maxChildDepth !== undefined && leftExpression.maxChildDepth >= maxChildNodeDepth) {
4530
- leftExpression = ErrorNode.create(leftExpression, ErrorExpressionCategory.MaxDepthExceeded);
4531
- this._addError(Localizer.Diagnostic.maxParseDepthExceeded(), leftExpression);
4532
- }
4533
-
4534
- if (rightExpression.maxChildDepth !== undefined && rightExpression.maxChildDepth >= maxChildNodeDepth) {
4535
- rightExpression = ErrorNode.create(rightExpression, ErrorExpressionCategory.MaxDepthExceeded);
4536
- this._addError(Localizer.Diagnostic.maxParseDepthExceeded(), rightExpression);
4537
- }
4538
-
4539
- return BinaryOperationNode.create(leftExpression, rightExpression, operatorToken, operator);
4540
- }
4541
-
4542
- private _createUnaryOperationNode(operatorToken: Token, expression: ExpressionNode, operator: OperatorType) {
4543
- // Determine if we're exceeding the max parse depth. If so, replace
4544
- // the subnode with an error node. Otherwise we risk crashing in the binder
4545
- // or type evaluator.
4546
- if (expression.maxChildDepth !== undefined && expression.maxChildDepth >= maxChildNodeDepth) {
4547
- expression = ErrorNode.create(expression, ErrorExpressionCategory.MaxDepthExceeded);
4548
- this._addError(Localizer.Diagnostic.maxParseDepthExceeded(), expression);
4549
- }
4550
-
4551
- return UnaryOperationNode.create(operatorToken, expression, operator);
4552
- }
4553
-
4554
- private _parseStringList(): StringListNode {
4555
- const stringList: (StringNode | FormatStringNode)[] = [];
4556
-
4557
- while (this._peekTokenType() === TokenType.String) {
4558
- const stringToken = this._getNextToken() as StringToken;
4559
- if (stringToken.flags & StringTokenFlags.Format) {
4560
- stringList.push(this._parseFormatString(stringToken));
4561
- } else {
4562
- stringList.push(this._makeStringNode(stringToken));
4563
- }
4564
- }
4565
-
4566
- const stringNode = StringListNode.create(stringList);
4567
-
4568
- // If we're parsing a type annotation, parse the contents of the string.
4569
- if (this._isParsingTypeAnnotation) {
4570
- // Don't allow multiple strings because we have no way of reporting
4571
- // parse errors that span strings.
4572
- if (stringNode.strings.length > 1) {
4573
- this._addError(Localizer.Diagnostic.annotationSpansStrings(), stringNode);
4574
- } else if (stringNode.strings[0].token.flags & StringTokenFlags.Format) {
4575
- this._addError(Localizer.Diagnostic.annotationFormatString(), stringNode);
4576
- } else {
4577
- const stringToken = stringNode.strings[0].token;
4578
- const stringValue = StringTokenUtils.getUnescapedString(stringNode.strings[0].token);
4579
- const unescapedString = stringValue.value;
4580
- const tokenOffset = stringToken.start;
4581
- const prefixLength = stringToken.prefixLength + stringToken.quoteMarkLength;
4582
-
4583
- // Don't allow escape characters because we have no way of mapping
4584
- // error ranges back to the escaped text.
4585
- if (unescapedString.length !== stringToken.length - prefixLength - stringToken.quoteMarkLength) {
4586
- this._addError(Localizer.Diagnostic.annotationStringEscape(), stringNode);
4587
- } else {
4588
- const parser = new Parser();
4589
- const parseResults = parser.parseTextExpression(
4590
- this._fileContents!,
4591
- tokenOffset + prefixLength,
4592
- unescapedString.length,
4593
- this._parseOptions,
4594
- ParseTextMode.VariableAnnotation,
4595
- (stringNode.strings[0].token.flags & StringTokenFlags.Triplicate) !== 0 ? 1 : 0,
4596
- this._typingSymbolAliases
4597
- );
4598
-
4599
- if (
4600
- parseResults.diagnostics.length === 0 ||
4601
- this._parseOptions.reportErrorsForParsedStringContents
4602
- ) {
4603
- parseResults.diagnostics.forEach((diag) => {
4604
- this._addError(diag.message, stringNode);
4605
- });
4606
-
4607
- if (parseResults.parseTree) {
4608
- assert(parseResults.parseTree.nodeType !== ParseNodeType.FunctionAnnotation);
4609
- stringNode.typeAnnotation = parseResults.parseTree;
4610
- stringNode.typeAnnotation.parent = stringNode;
4611
- }
4612
- }
4613
- }
4614
- }
4615
- }
4616
-
4617
- return stringNode;
4618
- }
4619
-
4620
- // Python 3.8 added support for star (unpack) expressions in tuples
4621
- // following a return or yield statement in cases where the tuple
4622
- // wasn't surrounded in parentheses.
4623
- private _reportConditionalErrorForStarTupleElement(possibleTupleExpr: ExpressionNode) {
4624
- if (possibleTupleExpr.nodeType !== ParseNodeType.Tuple) {
4625
- return;
4626
- }
4627
-
4628
- if (possibleTupleExpr.enclosedInParens) {
4629
- return;
4630
- }
4631
-
4632
- if (this._parseOptions.pythonVersion >= PythonVersion.V3_8) {
4633
- return;
4634
- }
4635
-
4636
- for (const expr of possibleTupleExpr.expressions) {
4637
- if (expr.nodeType === ParseNodeType.Unpack) {
4638
- this._addError(Localizer.Diagnostic.unpackTuplesIllegal(), expr);
4639
- return;
4640
- }
4641
- }
4642
- }
4643
-
4644
- // Peeks at the next token and returns true if it can never
4645
- // represent the start of an expression.
4646
- private _isNextTokenNeverExpression(): boolean {
4647
- const nextToken = this._peekToken();
4648
- switch (nextToken.type) {
4649
- case TokenType.Keyword: {
4650
- switch (this._peekKeywordType()) {
4651
- case KeywordType.For:
4652
- case KeywordType.In:
4653
- case KeywordType.If:
4654
- return true;
4655
- }
4656
- break;
4657
- }
4658
-
4659
- case TokenType.Operator: {
4660
- switch (this._peekOperatorType()) {
4661
- case OperatorType.AddEqual:
4662
- case OperatorType.SubtractEqual:
4663
- case OperatorType.MultiplyEqual:
4664
- case OperatorType.DivideEqual:
4665
- case OperatorType.ModEqual:
4666
- case OperatorType.BitwiseAndEqual:
4667
- case OperatorType.BitwiseOrEqual:
4668
- case OperatorType.BitwiseXorEqual:
4669
- case OperatorType.LeftShiftEqual:
4670
- case OperatorType.RightShiftEqual:
4671
- case OperatorType.PowerEqual:
4672
- case OperatorType.FloorDivideEqual:
4673
- case OperatorType.Assign:
4674
- return true;
4675
- }
4676
- break;
4677
- }
4678
-
4679
- case TokenType.Indent:
4680
- case TokenType.Dedent:
4681
- case TokenType.NewLine:
4682
- case TokenType.EndOfStream:
4683
- case TokenType.Semicolon:
4684
- case TokenType.CloseParenthesis:
4685
- case TokenType.CloseBracket:
4686
- case TokenType.CloseCurlyBrace:
4687
- case TokenType.Comma:
4688
- case TokenType.Colon:
4689
- return true;
4690
- }
4691
-
4692
- return false;
4693
- }
4694
-
4695
- private _disallowAssignmentExpression(callback: () => void) {
4696
- const wasAllowed = this._assignmentExpressionsAllowed;
4697
- this._assignmentExpressionsAllowed = false;
4698
-
4699
- callback();
4700
-
4701
- this._assignmentExpressionsAllowed = wasAllowed;
4702
- }
4703
-
4704
- private _getNextToken(): Token {
4705
- const token = this._tokenizerOutput!.tokens.getItemAt(this._tokenIndex);
4706
- if (!this._atEof()) {
4707
- this._tokenIndex++;
4708
- }
4709
-
4710
- return token;
4711
- }
4712
-
4713
- private _atEof(): boolean {
4714
- // Are we pointing at the last token in the stream (which is
4715
- // assumed to be an end-of-stream token)?
4716
- return this._tokenIndex >= this._tokenizerOutput!.tokens.count - 1;
4717
- }
4718
-
4719
- private _peekToken(count = 0): Token {
4720
- if (this._tokenIndex + count < 0) {
4721
- return this._tokenizerOutput!.tokens.getItemAt(0);
4722
- }
4723
-
4724
- if (this._tokenIndex + count >= this._tokenizerOutput!.tokens.count) {
4725
- return this._tokenizerOutput!.tokens.getItemAt(this._tokenizerOutput!.tokens.count - 1);
4726
- }
4727
-
4728
- return this._tokenizerOutput!.tokens.getItemAt(this._tokenIndex + count);
4729
- }
4730
-
4731
- private _peekTokenType(): TokenType {
4732
- return this._peekToken().type;
4733
- }
4734
-
4735
- private _peekKeywordType(): KeywordType | undefined {
4736
- const nextToken = this._peekToken();
4737
- if (nextToken.type !== TokenType.Keyword) {
4738
- return undefined;
4739
- }
4740
-
4741
- return (nextToken as KeywordToken).keywordType;
4742
- }
4743
-
4744
- private _peekOperatorType(): OperatorType | undefined {
4745
- const nextToken = this._peekToken();
4746
- if (nextToken.type !== TokenType.Operator) {
4747
- return undefined;
4748
- }
4749
-
4750
- return (nextToken as OperatorToken).operatorType;
4751
- }
4752
-
4753
- private _getTokenIfIdentifier(): IdentifierToken | undefined {
4754
- const nextToken = this._peekToken();
4755
- if (nextToken.type === TokenType.Identifier) {
4756
- return this._getNextToken() as IdentifierToken;
4757
- }
4758
-
4759
- // If the next token is invalid, treat it as an identifier.
4760
- if (nextToken.type === TokenType.Invalid) {
4761
- this._getNextToken();
4762
- this._addError(Localizer.Diagnostic.invalidIdentifierChar(), nextToken);
4763
- return IdentifierToken.create(nextToken.start, nextToken.length, '', nextToken.comments);
4764
- }
4765
-
4766
- // If this is a "soft keyword", it can be converted into an identifier.
4767
- if (nextToken.type === TokenType.Keyword) {
4768
- const keywordType = this._peekKeywordType();
4769
- const softKeywords = [KeywordType.Debug, KeywordType.Match, KeywordType.Case];
4770
- if (softKeywords.find((type) => type === keywordType)) {
4771
- const keywordText = this._fileContents!.substr(nextToken.start, nextToken.length);
4772
- this._getNextToken();
4773
- return IdentifierToken.create(nextToken.start, nextToken.length, keywordText, nextToken.comments);
4774
- }
4775
- }
4776
-
4777
- return undefined;
4778
- }
4779
-
4780
- // Consumes tokens until the next one in the stream is
4781
- // either a specified terminator or the end-of-stream
4782
- // token.
4783
- private _consumeTokensUntilType(terminators: TokenType[]): boolean {
4784
- while (true) {
4785
- const token = this._peekToken();
4786
- if (terminators.some((term) => term === token.type)) {
4787
- return true;
4788
- }
4789
-
4790
- if (token.type === TokenType.EndOfStream) {
4791
- return false;
4792
- }
4793
-
4794
- this._getNextToken();
4795
- }
4796
- }
4797
-
4798
- private _getTokenIfType(tokenType: TokenType): Token | undefined {
4799
- if (this._peekTokenType() === tokenType) {
4800
- return this._getNextToken();
4801
- }
4802
-
4803
- return undefined;
4804
- }
4805
-
4806
- private _consumeTokenIfType(tokenType: TokenType): boolean {
4807
- return !!this._getTokenIfType(tokenType);
4808
- }
4809
-
4810
- private _consumeTokenIfKeyword(keywordType: KeywordType): boolean {
4811
- if (this._peekKeywordType() === keywordType) {
4812
- this._getNextToken();
4813
- return true;
4814
- }
4815
-
4816
- return false;
4817
- }
4818
-
4819
- private _consumeTokenIfOperator(operatorType: OperatorType): boolean {
4820
- if (this._peekOperatorType() === operatorType) {
4821
- this._getNextToken();
4822
- return true;
4823
- }
4824
-
4825
- return false;
4826
- }
4827
-
4828
- private _getKeywordToken(keywordType: KeywordType): KeywordToken {
4829
- const keywordToken = this._getNextToken() as KeywordToken;
4830
- assert(keywordToken.type === TokenType.Keyword);
4831
- assert(keywordToken.keywordType === keywordType);
4832
- return keywordToken;
4833
- }
4834
-
4835
- private _getLanguageVersion() {
4836
- return this._parseOptions.pythonVersion;
4837
- }
4838
-
4839
- private _suppressErrors(callback: () => void) {
4840
- const errorsWereSuppressed = this._areErrorsSuppressed;
4841
- try {
4842
- this._areErrorsSuppressed = true;
4843
- callback();
4844
- } finally {
4845
- this._areErrorsSuppressed = errorsWereSuppressed;
4846
- }
4847
- }
4848
-
4849
- private _addError(message: string, range: TextRange) {
4850
- assert(range !== undefined);
4851
-
4852
- if (!this._areErrorsSuppressed) {
4853
- this._diagSink.addError(
4854
- message,
4855
- convertOffsetsToRange(range.start, range.start + range.length, this._tokenizerOutput!.lines)
4856
- );
4857
- }
4858
- }
4859
- }