@zzzen/pyright-internal 1.1.255 → 1.2.0-beta

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 (1409) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -0
  3. package/dist/analyzer/analyzerFileInfo.d.ts +1 -1
  4. package/dist/analyzer/backgroundAnalysisProgram.d.ts +1 -0
  5. package/dist/analyzer/backgroundAnalysisProgram.js +3 -0
  6. package/dist/analyzer/backgroundAnalysisProgram.js.map +1 -1
  7. package/dist/analyzer/binder.js +9 -2
  8. package/dist/analyzer/binder.js.map +1 -1
  9. package/dist/analyzer/checker.js +19 -26
  10. package/dist/analyzer/checker.js.map +1 -1
  11. package/dist/analyzer/codeFlowUtils.js +33 -0
  12. package/dist/analyzer/codeFlowUtils.js.map +1 -1
  13. package/dist/analyzer/dataClasses.js +6 -4
  14. package/dist/analyzer/dataClasses.js.map +1 -1
  15. package/dist/analyzer/declaration.js +11 -1
  16. package/dist/analyzer/declaration.js.map +1 -1
  17. package/dist/analyzer/importResult.js +7 -0
  18. package/dist/analyzer/importResult.js.map +1 -1
  19. package/dist/analyzer/importStatementUtils.js +10 -1
  20. package/dist/analyzer/importStatementUtils.js.map +1 -1
  21. package/dist/analyzer/namedTuples.js +1 -1
  22. package/dist/analyzer/namedTuples.js.map +1 -1
  23. package/dist/analyzer/packageTypeReport.js +10 -1
  24. package/dist/analyzer/packageTypeReport.js.map +1 -1
  25. package/dist/analyzer/parseTreeUtils.js +11 -2
  26. package/dist/analyzer/parseTreeUtils.js.map +1 -1
  27. package/dist/analyzer/program.d.ts +2 -1
  28. package/dist/analyzer/program.js +27 -23
  29. package/dist/analyzer/program.js.map +1 -1
  30. package/dist/analyzer/protocols.js +3 -1
  31. package/dist/analyzer/protocols.js.map +1 -1
  32. package/dist/analyzer/scope.js +22 -1
  33. package/dist/analyzer/scope.js.map +1 -1
  34. package/dist/analyzer/service.d.ts +20 -8
  35. package/dist/analyzer/service.js +39 -19
  36. package/dist/analyzer/service.js.map +1 -1
  37. package/dist/analyzer/sourceFile.js +1 -1
  38. package/dist/analyzer/sourceFile.js.map +1 -1
  39. package/dist/analyzer/sourceFileInfoUtils.d.ts +2 -0
  40. package/dist/analyzer/sourceFileInfoUtils.js +15 -0
  41. package/dist/analyzer/sourceFileInfoUtils.js.map +1 -0
  42. package/dist/analyzer/symbol.d.ts +3 -1
  43. package/dist/analyzer/symbol.js +39 -1
  44. package/dist/analyzer/symbol.js.map +1 -1
  45. package/dist/analyzer/typeDocStringUtils.js +10 -2
  46. package/dist/analyzer/typeDocStringUtils.js.map +1 -1
  47. package/dist/analyzer/typeEvaluator.js +86 -32
  48. package/dist/analyzer/typeEvaluator.js.map +1 -1
  49. package/dist/analyzer/typeEvaluatorTypes.d.ts +0 -1
  50. package/dist/analyzer/typeEvaluatorTypes.js +65 -1
  51. package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
  52. package/dist/analyzer/typeGuards.d.ts +2 -0
  53. package/dist/analyzer/typeGuards.js +113 -69
  54. package/dist/analyzer/typeGuards.js.map +1 -1
  55. package/dist/analyzer/typePrinter.js +23 -1
  56. package/dist/analyzer/typePrinter.js.map +1 -1
  57. package/dist/analyzer/typeUtils.js +119 -28
  58. package/dist/analyzer/typeUtils.js.map +1 -1
  59. package/dist/analyzer/typedDicts.js +2 -1
  60. package/dist/analyzer/typedDicts.js.map +1 -1
  61. package/dist/analyzer/types.d.ts +1 -0
  62. package/dist/analyzer/types.js +195 -1
  63. package/dist/analyzer/types.js.map +1 -1
  64. package/dist/backgroundAnalysisBase.d.ts +1 -1
  65. package/dist/commands/commands.js +9 -0
  66. package/dist/commands/commands.js.map +1 -1
  67. package/dist/common/commandLineOptions.js +8 -1
  68. package/dist/common/commandLineOptions.js.map +1 -1
  69. package/dist/common/core.js +7 -1
  70. package/dist/common/core.js.map +1 -1
  71. package/dist/common/diagnostic.js +9 -1
  72. package/dist/common/diagnostic.js.map +1 -1
  73. package/dist/common/host.js +7 -1
  74. package/dist/common/host.js.map +1 -1
  75. package/dist/common/pathUtils.d.ts +1 -0
  76. package/dist/common/pathUtils.js +34 -1
  77. package/dist/common/pathUtils.js.map +1 -1
  78. package/dist/common/stringUtils.d.ts +1 -0
  79. package/dist/common/stringUtils.js +8 -1
  80. package/dist/common/stringUtils.js.map +1 -1
  81. package/dist/languageServerBase.d.ts +10 -3
  82. package/dist/languageServerBase.js +40 -14
  83. package/dist/languageServerBase.js.map +1 -1
  84. package/dist/languageService/analyzerServiceExecutor.js +3 -0
  85. package/dist/languageService/analyzerServiceExecutor.js.map +1 -1
  86. package/dist/languageService/autoImporter.js +2 -1
  87. package/dist/languageService/autoImporter.js.map +1 -1
  88. package/dist/languageService/completionProvider.d.ts +2 -2
  89. package/dist/languageService/completionProvider.js +3 -5
  90. package/dist/languageService/completionProvider.js.map +1 -1
  91. package/dist/parser/parseNodes.d.ts +3 -0
  92. package/dist/parser/parseNodes.js +110 -2
  93. package/dist/parser/parseNodes.js.map +1 -1
  94. package/dist/parser/parser.d.ts +0 -1
  95. package/dist/parser/parser.js +26 -12
  96. package/dist/parser/parser.js.map +1 -1
  97. package/dist/parser/stringTokenUtils.js +8 -1
  98. package/dist/parser/stringTokenUtils.js.map +1 -1
  99. package/dist/parser/tokenizerTypes.js +155 -1
  100. package/dist/parser/tokenizerTypes.js.map +1 -1
  101. package/dist/pyright.js +6 -1
  102. package/dist/pyright.js.map +1 -1
  103. package/dist/tests/chainedSourceFiles.test.js +12 -9
  104. package/dist/tests/chainedSourceFiles.test.js.map +1 -1
  105. package/dist/tests/checker.test.js +4 -0
  106. package/dist/tests/checker.test.js.map +1 -1
  107. package/dist/tests/config.test.js +14 -13
  108. package/dist/tests/config.test.js.map +1 -1
  109. package/dist/tests/debug.test.js +6 -0
  110. package/dist/tests/debug.test.js.map +1 -1
  111. package/dist/tests/fourslash/completions.autoimport.lib.alias.fourslash.d.ts +1 -0
  112. package/dist/tests/fourslash/completions.autoimport.lib.alias.fourslash.js +53 -0
  113. package/dist/tests/fourslash/completions.autoimport.lib.alias.fourslash.js.map +1 -0
  114. package/dist/tests/fourslash/fourslash.d.ts +16 -0
  115. package/dist/tests/fourslash/hover.class.docString.fourslash.d.ts +1 -0
  116. package/dist/tests/fourslash/hover.class.docString.fourslash.js +24 -0
  117. package/dist/tests/fourslash/hover.class.docString.fourslash.js.map +1 -0
  118. package/dist/tests/harness/fourslash/fourSlashParser.js +6 -0
  119. package/dist/tests/harness/fourslash/fourSlashParser.js.map +1 -1
  120. package/dist/tests/harness/fourslash/fourSlashTypes.js +19 -1
  121. package/dist/tests/harness/fourslash/fourSlashTypes.js.map +1 -1
  122. package/dist/tests/harness/fourslash/testLanguageService.js +9 -1
  123. package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
  124. package/dist/tests/harness/fourslash/testState.Consts.d.ts +1 -0
  125. package/dist/tests/harness/fourslash/testState.Consts.js +1 -0
  126. package/dist/tests/harness/fourslash/testState.Consts.js.map +1 -1
  127. package/dist/tests/harness/fourslash/testState.d.ts +4 -3
  128. package/dist/tests/harness/fourslash/testState.js +27 -11
  129. package/dist/tests/harness/fourslash/testState.js.map +1 -1
  130. package/dist/tests/harness/vfs/pathValidation.js +25 -1
  131. package/dist/tests/harness/vfs/pathValidation.js.map +1 -1
  132. package/dist/tests/pathUtils.test.js +17 -0
  133. package/dist/tests/pathUtils.test.js.map +1 -1
  134. package/dist/tests/testUtils.js +1 -1
  135. package/dist/tests/testUtils.js.map +1 -1
  136. package/dist/tests/typeEvaluator1.test.js +9 -1
  137. package/dist/tests/typeEvaluator1.test.js.map +1 -1
  138. package/dist/tests/typeEvaluator2.test.js +9 -1
  139. package/dist/tests/typeEvaluator2.test.js.map +1 -1
  140. package/dist/tests/typeEvaluator3.test.js +4 -0
  141. package/dist/tests/typeEvaluator3.test.js.map +1 -1
  142. package/dist/workspaceMap.d.ts +2 -1
  143. package/dist/workspaceMap.js +25 -3
  144. package/dist/workspaceMap.js.map +1 -1
  145. package/package.json +45 -45
  146. package/src/analyzer/aliasDeclarationUtils.ts +0 -169
  147. package/src/analyzer/analysis.ts +0 -92
  148. package/src/analyzer/analyzerFileInfo.ts +0 -56
  149. package/src/analyzer/analyzerNodeInfo.ts +0 -198
  150. package/src/analyzer/backgroundAnalysisProgram.ts +0 -311
  151. package/src/analyzer/binder.ts +0 -4081
  152. package/src/analyzer/checker.ts +0 -5507
  153. package/src/analyzer/circularDependency.ts +0 -52
  154. package/src/analyzer/codeFlowEngine.ts +0 -1548
  155. package/src/analyzer/codeFlowTypes.ts +0 -266
  156. package/src/analyzer/codeFlowUtils.ts +0 -436
  157. package/src/analyzer/commentUtils.ts +0 -174
  158. package/src/analyzer/constraintSolver.ts +0 -926
  159. package/src/analyzer/constructorTransform.ts +0 -317
  160. package/src/analyzer/dataClasses.ts +0 -999
  161. package/src/analyzer/declaration.ts +0 -252
  162. package/src/analyzer/declarationUtils.ts +0 -238
  163. package/src/analyzer/docStringConversion.ts +0 -850
  164. package/src/analyzer/docStringUtils.ts +0 -112
  165. package/src/analyzer/functionTransform.ts +0 -137
  166. package/src/analyzer/importResolver.ts +0 -2308
  167. package/src/analyzer/importResult.ts +0 -98
  168. package/src/analyzer/importStatementUtils.ts +0 -834
  169. package/src/analyzer/namedTuples.ts +0 -422
  170. package/src/analyzer/packageTypeReport.ts +0 -108
  171. package/src/analyzer/packageTypeVerifier.ts +0 -1466
  172. package/src/analyzer/parentDirectoryCache.ts +0 -88
  173. package/src/analyzer/parseTreeCleaner.ts +0 -35
  174. package/src/analyzer/parseTreeUtils.ts +0 -2165
  175. package/src/analyzer/parseTreeWalker.ts +0 -663
  176. package/src/analyzer/patternMatching.ts +0 -1356
  177. package/src/analyzer/program.ts +0 -2778
  178. package/src/analyzer/properties.ts +0 -534
  179. package/src/analyzer/protocols.ts +0 -660
  180. package/src/analyzer/pyTypedUtils.ts +0 -52
  181. package/src/analyzer/pythonPathUtils.ts +0 -201
  182. package/src/analyzer/scope.ts +0 -202
  183. package/src/analyzer/scopeUtils.ts +0 -81
  184. package/src/analyzer/service.ts +0 -1679
  185. package/src/analyzer/sourceFile.ts +0 -1401
  186. package/src/analyzer/sourceMapper.ts +0 -717
  187. package/src/analyzer/staticExpressions.ts +0 -308
  188. package/src/analyzer/symbol.ts +0 -249
  189. package/src/analyzer/symbolNameUtils.ts +0 -50
  190. package/src/analyzer/symbolUtils.ts +0 -49
  191. package/src/analyzer/testWalker.ts +0 -101
  192. package/src/analyzer/tracePrinter.ts +0 -264
  193. package/src/analyzer/typeCache.ts +0 -181
  194. package/src/analyzer/typeDocStringUtils.ts +0 -371
  195. package/src/analyzer/typeEvaluator.ts +0 -23395
  196. package/src/analyzer/typeEvaluatorTypes.ts +0 -452
  197. package/src/analyzer/typeEvaluatorWithTracker.ts +0 -161
  198. package/src/analyzer/typeGuards.ts +0 -1828
  199. package/src/analyzer/typePrinter.ts +0 -807
  200. package/src/analyzer/typeStubWriter.ts +0 -727
  201. package/src/analyzer/typeUtils.ts +0 -3126
  202. package/src/analyzer/typeVarContext.ts +0 -330
  203. package/src/analyzer/typedDicts.ts +0 -950
  204. package/src/analyzer/types.ts +0 -2857
  205. package/src/backgroundAnalysis.ts +0 -49
  206. package/src/backgroundAnalysisBase.ts +0 -606
  207. package/src/backgroundThreadBase.ts +0 -143
  208. package/src/commands/commandController.ts +0 -62
  209. package/src/commands/commandResult.ts +0 -21
  210. package/src/commands/commands.ts +0 -16
  211. package/src/commands/createTypeStub.ts +0 -56
  212. package/src/commands/quickActionCommand.ts +0 -40
  213. package/src/commands/restartServer.ts +0 -20
  214. package/src/common/cancellationUtils.ts +0 -71
  215. package/src/common/chokidarFileWatcherProvider.ts +0 -74
  216. package/src/common/collectionUtils.ts +0 -379
  217. package/src/common/commandLineOptions.ts +0 -132
  218. package/src/common/configOptions.ts +0 -1291
  219. package/src/common/console.ts +0 -201
  220. package/src/common/core.ts +0 -152
  221. package/src/common/crypto.ts +0 -60
  222. package/src/common/debug.ts +0 -144
  223. package/src/common/deferred.ts +0 -78
  224. package/src/common/diagnostic.ts +0 -191
  225. package/src/common/diagnosticRules.ts +0 -80
  226. package/src/common/diagnosticSink.ts +0 -150
  227. package/src/common/editAction.ts +0 -46
  228. package/src/common/extensibility.ts +0 -35
  229. package/src/common/extensions.ts +0 -21
  230. package/src/common/fileBasedCancellationUtils.ts +0 -274
  231. package/src/common/fileSystem.ts +0 -152
  232. package/src/common/fullAccessHost.ts +0 -203
  233. package/src/common/host.ts +0 -49
  234. package/src/common/logTracker.ts +0 -157
  235. package/src/common/lspUtils.ts +0 -18
  236. package/src/common/memUtils.ts +0 -36
  237. package/src/common/pathConsts.ts +0 -16
  238. package/src/common/pathUtils.ts +0 -987
  239. package/src/common/positionUtils.ts +0 -78
  240. package/src/common/progressReporter.ts +0 -53
  241. package/src/common/pythonVersion.ts +0 -74
  242. package/src/common/realFileSystem.ts +0 -433
  243. package/src/common/stringUtils.ts +0 -161
  244. package/src/common/textEditUtils.ts +0 -31
  245. package/src/common/textRange.ts +0 -225
  246. package/src/common/textRangeCollection.ts +0 -122
  247. package/src/common/timing.ts +0 -105
  248. package/src/common/uriParser.ts +0 -26
  249. package/src/common/workspaceEditUtils.ts +0 -100
  250. package/src/languageServerBase.ts +0 -1556
  251. package/src/languageService/analyzerServiceExecutor.ts +0 -144
  252. package/src/languageService/autoImporter.ts +0 -926
  253. package/src/languageService/callHierarchyProvider.ts +0 -476
  254. package/src/languageService/codeActionProvider.ts +0 -85
  255. package/src/languageService/completionProvider.ts +0 -3103
  256. package/src/languageService/definitionProvider.ts +0 -235
  257. package/src/languageService/documentHighlightProvider.ts +0 -61
  258. package/src/languageService/documentSymbolCollector.ts +0 -466
  259. package/src/languageService/documentSymbolProvider.ts +0 -466
  260. package/src/languageService/hoverProvider.ts +0 -499
  261. package/src/languageService/importAdder.ts +0 -437
  262. package/src/languageService/importSorter.ts +0 -196
  263. package/src/languageService/indentationUtils.ts +0 -813
  264. package/src/languageService/quickActions.ts +0 -113
  265. package/src/languageService/referencesProvider.ts +0 -316
  266. package/src/languageService/renameModuleProvider.ts +0 -1400
  267. package/src/languageService/signatureHelpProvider.ts +0 -227
  268. package/src/languageService/tooltipUtils.ts +0 -147
  269. package/src/localization/localize.ts +0 -1272
  270. package/src/localization/package.nls.de.json +0 -3
  271. package/src/localization/package.nls.en-us.json +0 -636
  272. package/src/localization/package.nls.es.json +0 -3
  273. package/src/localization/package.nls.fr.json +0 -3
  274. package/src/localization/package.nls.ja.json +0 -3
  275. package/src/localization/package.nls.ru.json +0 -3
  276. package/src/localization/package.nls.zh-cn.json +0 -3
  277. package/src/localization/package.nls.zh-tw.json +0 -3
  278. package/src/nodeMain.ts +0 -21
  279. package/src/nodeServer.ts +0 -30
  280. package/src/parser/characterStream.ts +0 -145
  281. package/src/parser/characters.ts +0 -285
  282. package/src/parser/parseNodes.ts +0 -2338
  283. package/src/parser/parser.ts +0 -4859
  284. package/src/parser/stringTokenUtils.ts +0 -564
  285. package/src/parser/tokenizer.ts +0 -1379
  286. package/src/parser/tokenizerTypes.ts +0 -420
  287. package/src/parser/unicode.ts +0 -2917
  288. package/src/pyright.ts +0 -824
  289. package/src/pyrightFileSystem.ts +0 -237
  290. package/src/readonlyAugmentedFileSystem.ts +0 -204
  291. package/src/server.ts +0 -298
  292. package/src/tests/chainedSourceFiles.test.ts +0 -183
  293. package/src/tests/checker.test.ts +0 -445
  294. package/src/tests/collectionUtils.test.ts +0 -178
  295. package/src/tests/common.test.ts +0 -117
  296. package/src/tests/config.test.ts +0 -291
  297. package/src/tests/debug.test.ts +0 -120
  298. package/src/tests/deferred.test.ts +0 -54
  299. package/src/tests/diagnosticOverrides.test.ts +0 -104
  300. package/src/tests/docStringConversion.test.ts +0 -823
  301. package/src/tests/docStringUtils.test.ts +0 -57
  302. package/src/tests/documentSymbolCollector.test.ts +0 -735
  303. package/src/tests/filesystem.test.ts +0 -215
  304. package/src/tests/fourSlashParser.test.ts +0 -330
  305. package/src/tests/fourSlashRunner.test.ts +0 -36
  306. package/src/tests/fourslash/completions.autoimport.Lib.Found.Type.fourslash.ts +0 -33
  307. package/src/tests/fourslash/completions.autoimport.Lib.Found.duplication.fourslash.ts +0 -47
  308. package/src/tests/fourslash/completions.autoimport.Lib.NotFound.fourslash.ts +0 -14
  309. package/src/tests/fourslash/completions.autoimport.disabled.fourslash.ts +0 -25
  310. package/src/tests/fourslash/completions.autoimport.duplicates.fourslash.ts +0 -36
  311. package/src/tests/fourslash/completions.autoimport.fourslash.ts +0 -29
  312. package/src/tests/fourslash/completions.autoimport.fromImport.fourslash.ts +0 -130
  313. package/src/tests/fourslash/completions.autoimport.plainText.fourslash.ts +0 -29
  314. package/src/tests/fourslash/completions.autoimport.shadow.fourslash.ts +0 -48
  315. package/src/tests/fourslash/completions.autoimport.submodule.fourslash.ts +0 -31
  316. package/src/tests/fourslash/completions.autoimport.topLevel.fourslash.ts +0 -57
  317. package/src/tests/fourslash/completions.builtinDocstrings.fourslash.ts +0 -117
  318. package/src/tests/fourslash/completions.builtinOverride.fourslash.ts +0 -22
  319. package/src/tests/fourslash/completions.call.stringLiteral.fourslash.ts +0 -55
  320. package/src/tests/fourslash/completions.call.typedDict.fourslash.ts +0 -247
  321. package/src/tests/fourslash/completions.call.typedDict.list.fourslash.ts +0 -163
  322. package/src/tests/fourslash/completions.call.typedDict.states.fourslash.ts +0 -135
  323. package/src/tests/fourslash/completions.classVariable.fourslash.ts +0 -37
  324. package/src/tests/fourslash/completions.comment.fourslash.ts +0 -28
  325. package/src/tests/fourslash/completions.declNames.class.fourslash.ts +0 -35
  326. package/src/tests/fourslash/completions.declNames.exception.fourslash.ts +0 -18
  327. package/src/tests/fourslash/completions.declNames.for.fourslash.ts +0 -30
  328. package/src/tests/fourslash/completions.declNames.importAlias.fourslash.ts +0 -15
  329. package/src/tests/fourslash/completions.declNames.lambda.fourslash.ts +0 -45
  330. package/src/tests/fourslash/completions.declNames.method.fourslash.ts +0 -71
  331. package/src/tests/fourslash/completions.declNames.overload.fourslash.ts +0 -156
  332. package/src/tests/fourslash/completions.declNames.topLevelOverload.fourslash.ts +0 -141
  333. package/src/tests/fourslash/completions.dictionary.keys.complex.fourslash.ts +0 -76
  334. package/src/tests/fourslash/completions.dictionary.keys.expression.fourslash.ts +0 -63
  335. package/src/tests/fourslash/completions.dictionary.keys.literalTypes.fourslash.ts +0 -161
  336. package/src/tests/fourslash/completions.dictionary.keys.simple.fourslash.ts +0 -151
  337. package/src/tests/fourslash/completions.dictionary.keys.stringLiterals.fourslash.ts +0 -116
  338. package/src/tests/fourslash/completions.dictionary.keys.symbols.fourslash.ts +0 -53
  339. package/src/tests/fourslash/completions.enums.members.fourslash.ts +0 -44
  340. package/src/tests/fourslash/completions.excluded.fourslash.ts +0 -12
  341. package/src/tests/fourslash/completions.fourslash.ts +0 -51
  342. package/src/tests/fourslash/completions.fstring.fourslash.ts +0 -33
  343. package/src/tests/fourslash/completions.fstring.stringLiteral.fourslash.ts +0 -96
  344. package/src/tests/fourslash/completions.fuzzyMatching.fourslash.ts +0 -30
  345. package/src/tests/fourslash/completions.importDunderNames.fourslash.ts +0 -31
  346. package/src/tests/fourslash/completions.importSubmodule.fourslash.ts +0 -26
  347. package/src/tests/fourslash/completions.importsDuplicates.fourslash.ts +0 -23
  348. package/src/tests/fourslash/completions.inList.fourslash.ts +0 -33
  349. package/src/tests/fourslash/completions.included.fourslash.ts +0 -12
  350. package/src/tests/fourslash/completions.indexer.keys.getitem.fourslash.ts +0 -57
  351. package/src/tests/fourslash/completions.inherited.function.docFromStub.fourslash.ts +0 -28
  352. package/src/tests/fourslash/completions.inherited.overload.docFromScrWithStub.fourslash.ts +0 -52
  353. package/src/tests/fourslash/completions.inherited.overload.docFromStub.fourslash.ts +0 -53
  354. package/src/tests/fourslash/completions.inherited.property.docFromSrc.fourslash.ts +0 -104
  355. package/src/tests/fourslash/completions.inherited.property.docFromStub.fourslash.ts +0 -108
  356. package/src/tests/fourslash/completions.keywords.pythonVersion.fourslash.ts +0 -72
  357. package/src/tests/fourslash/completions.libCodeAndStub.fourslash.ts +0 -79
  358. package/src/tests/fourslash/completions.libCodeNoStub.fourslash.ts +0 -69
  359. package/src/tests/fourslash/completions.libStub.fourslash.ts +0 -69
  360. package/src/tests/fourslash/completions.literals.fourslash.ts +0 -33
  361. package/src/tests/fourslash/completions.localCode.fourslash.ts +0 -74
  362. package/src/tests/fourslash/completions.moduleContext.UnknownMemberOnInstance.fourslash.ts +0 -17
  363. package/src/tests/fourslash/completions.moduleContext.UnknownStaticFunctionOnClass.fourslash.ts +0 -57
  364. package/src/tests/fourslash/completions.moduleContext.libCodeNoStub.fourslash.ts +0 -30
  365. package/src/tests/fourslash/completions.overloads.fourslash.ts +0 -40
  366. package/src/tests/fourslash/completions.override.default.fourslash.ts +0 -47
  367. package/src/tests/fourslash/completions.override.default.importStub.ts +0 -50
  368. package/src/tests/fourslash/completions.override.default.imported.fourslash.ts +0 -61
  369. package/src/tests/fourslash/completions.override.default.stub.fourslash.ts +0 -47
  370. package/src/tests/fourslash/completions.override.fourslash.ts +0 -47
  371. package/src/tests/fourslash/completions.override.property.fourslash.ts +0 -31
  372. package/src/tests/fourslash/completions.override.property.stub.fourslash.ts +0 -31
  373. package/src/tests/fourslash/completions.override.staticAndClassmethod.fourslash.ts +0 -64
  374. package/src/tests/fourslash/completions.override.stub.fourslash.ts +0 -47
  375. package/src/tests/fourslash/completions.override2.fourslash.ts +0 -71
  376. package/src/tests/fourslash/completions.parameters.fourslash.ts +0 -23
  377. package/src/tests/fourslash/completions.params.fourslash.ts +0 -24
  378. package/src/tests/fourslash/completions.parentFolder.fourslash.ts +0 -17
  379. package/src/tests/fourslash/completions.parentFolders.fourslash.ts +0 -77
  380. package/src/tests/fourslash/completions.plainText.fourslash.ts +0 -34
  381. package/src/tests/fourslash/completions.private.fourslash.ts +0 -64
  382. package/src/tests/fourslash/completions.property.fourslash.ts +0 -28
  383. package/src/tests/fourslash/completions.propertyDocStrings.fourslash.ts +0 -64
  384. package/src/tests/fourslash/completions.self.fourslash.ts +0 -43
  385. package/src/tests/fourslash/completions.stringLiteral.escape.fourslash.ts +0 -71
  386. package/src/tests/fourslash/completions.stringLiteral.fourslash.ts +0 -79
  387. package/src/tests/fourslash/completions.typeAlias.fourslash.ts +0 -29
  388. package/src/tests/fourslash/completions.typeshed.fourslash.ts +0 -9
  389. package/src/tests/fourslash/completions.vardecls.fourslash.ts +0 -40
  390. package/src/tests/fourslash/completions.variableDocStrings.fourslash.ts +0 -69
  391. package/src/tests/fourslash/completions.wildcardimports.fourslash.ts +0 -116
  392. package/src/tests/fourslash/completions.with.fourslash.ts +0 -26
  393. package/src/tests/fourslash/diagnostics.missingModuleSource.fourslash.ts +0 -69
  394. package/src/tests/fourslash/findDefinitions.builtinClass.fourslash.ts +0 -29
  395. package/src/tests/fourslash/findDefinitions.classes.fourslash.ts +0 -101
  396. package/src/tests/fourslash/findDefinitions.definitionFilter.preferSource.fourslash.ts +0 -29
  397. package/src/tests/fourslash/findDefinitions.definitionFilter.preferSource.onlyStubs.ts +0 -24
  398. package/src/tests/fourslash/findDefinitions.definitionFilter.preferStub.fourslash.ts +0 -29
  399. package/src/tests/fourslash/findDefinitions.definitionFilter.preferStub.onlySource.fourslash.ts +0 -25
  400. package/src/tests/fourslash/findDefinitions.fields.fourslash.ts +0 -131
  401. package/src/tests/fourslash/findDefinitions.functions.fourslash.ts +0 -87
  402. package/src/tests/fourslash/findDefinitions.methods.fourslash.ts +0 -162
  403. package/src/tests/fourslash/findDefinitions.modules.fourslash.ts +0 -50
  404. package/src/tests/fourslash/findDefinitions.namespaceImport.fourslash.ts +0 -40
  405. package/src/tests/fourslash/findDefinitions.overloads.fourslash.ts +0 -223
  406. package/src/tests/fourslash/findDefinitions.parameters.fourslash.ts +0 -162
  407. package/src/tests/fourslash/findDefinitions.sourceAndStub.function.fourslash.ts +0 -26
  408. package/src/tests/fourslash/findDefinitions.sourceAndStub.innerClass.fourslash.ts +0 -32
  409. package/src/tests/fourslash/findDefinitions.sourceAndStub.innerClassMethod.fourslash.ts +0 -33
  410. package/src/tests/fourslash/findDefinitions.sourceAndStub.outerClass.fourslash.ts +0 -28
  411. package/src/tests/fourslash/findDefinitions.sourceAndStub.outerClassMethod.fourslash.ts +0 -29
  412. package/src/tests/fourslash/findDefinitions.sourceAndStub.outerClassPropertyReadOnly.fourslash.ts +0 -31
  413. package/src/tests/fourslash/findDefinitions.sourceAndStub.outerClassPropertyReadWrite.fourslash.ts +0 -36
  414. package/src/tests/fourslash/findDefinitions.sourceOnly.class.fourslash.ts +0 -29
  415. package/src/tests/fourslash/findDefinitions.sourceOnly.function1.fourslash.ts +0 -28
  416. package/src/tests/fourslash/findDefinitions.sourceOnly.function2.fourslash.ts +0 -28
  417. package/src/tests/fourslash/findDefinitions.sourceOnly.relativeImport1.fourslash.ts +0 -22
  418. package/src/tests/fourslash/findDefinitions.sourceOnly.relativeImport2.fourslash.ts +0 -22
  419. package/src/tests/fourslash/findDefinitions.stubOnly.fourslash.ts +0 -61
  420. package/src/tests/fourslash/findDefinitions.stubPackages.fourslash.ts +0 -71
  421. package/src/tests/fourslash/findDefinitions.typedDict.keys.fourslash.ts +0 -99
  422. package/src/tests/fourslash/findDefinitions.variables.fourslash.ts +0 -88
  423. package/src/tests/fourslash/findDefinitions.wildcardimports.fourslash.ts +0 -117
  424. package/src/tests/fourslash/findTypeDefinitions.builtinClass.fourslash.ts +0 -26
  425. package/src/tests/fourslash/findTypeDefinitions.classes.fourslash.ts +0 -72
  426. package/src/tests/fourslash/findTypeDefinitions.unions.fourslash.ts +0 -26
  427. package/src/tests/fourslash/findallreferences.classPropertyReadWrite.ts +0 -39
  428. package/src/tests/fourslash/findallreferences.fourslash.ts +0 -34
  429. package/src/tests/fourslash/findallreferences.importalias.fourslash.ts +0 -34
  430. package/src/tests/fourslash/findallreferences.invokedFromLibrary.fourslash.ts +0 -52
  431. package/src/tests/fourslash/findallreferences.module.nested.fourslash.ts +0 -67
  432. package/src/tests/fourslash/findallreferences.modules.duplicated.fourslash.ts +0 -59
  433. package/src/tests/fourslash/findallreferences.modules.fourslash.ts +0 -46
  434. package/src/tests/fourslash/findallreferences.modules.shadow.fourslash.ts +0 -95
  435. package/src/tests/fourslash/findallreferences.openFiles.fourslash.ts +0 -37
  436. package/src/tests/fourslash/findallreferences.parameter.fourslash.ts +0 -24
  437. package/src/tests/fourslash/findallreferences.sourceAndStub.class.fourslash.ts +0 -33
  438. package/src/tests/fourslash/findallreferences.sourceAndStub.classMethod.fourslash.ts +0 -37
  439. package/src/tests/fourslash/findallreferences.sourceAndStub.classPropertyReadOnly.fourslash.ts +0 -40
  440. package/src/tests/fourslash/findallreferences.sourceAndStub.classPropertyReadWrite.fourslash.skip.ts +0 -48
  441. package/src/tests/fourslash/findallreferences.sourceAndStub.function.fourslash.ts +0 -35
  442. package/src/tests/fourslash/findallreferences.variable.fourslash.ts +0 -24
  443. package/src/tests/fourslash/fourslash.ts +0 -411
  444. package/src/tests/fourslash/highlightreferences.attributes.fourslash.ts +0 -31
  445. package/src/tests/fourslash/hover.builtinDocstrings.fourslash.ts +0 -64
  446. package/src/tests/fourslash/hover.classNoInit.fourslash.ts +0 -14
  447. package/src/tests/fourslash/hover.docFromScr.stringFormat.fourslash.ts +0 -52
  448. package/src/tests/fourslash/hover.docFromSrc.fourslash.ts +0 -83
  449. package/src/tests/fourslash/hover.docFromSrc.pkg-vs-module1.fourslash.ts +0 -26
  450. package/src/tests/fourslash/hover.docFromSrc.pkg-vs-module2.fourslash.ts +0 -26
  451. package/src/tests/fourslash/hover.docFromSrc.relativeImport1.fourslash.ts +0 -23
  452. package/src/tests/fourslash/hover.docFromSrc.relativeImport2.fourslash.ts +0 -22
  453. package/src/tests/fourslash/hover.docFromSrc.relativeImport3.fourslash.ts +0 -46
  454. package/src/tests/fourslash/hover.docFromSrc.stubs-package.fourslash.ts +0 -29
  455. package/src/tests/fourslash/hover.docFromSrc.typeshed.fourslash.ts +0 -20
  456. package/src/tests/fourslash/hover.docstring.links.fourslash.ts +0 -12
  457. package/src/tests/fourslash/hover.docstring.overloads.fourslash.ts +0 -41
  458. package/src/tests/fourslash/hover.docstring.split.fourslash.ts +0 -24
  459. package/src/tests/fourslash/hover.fourslash.ts +0 -20
  460. package/src/tests/fourslash/hover.import.django.view.fourslash.ts +0 -27
  461. package/src/tests/fourslash/hover.import.fourslash.ts +0 -11
  462. package/src/tests/fourslash/hover.inherited.docFromSrc.fourslash.ts +0 -63
  463. package/src/tests/fourslash/hover.inherited.docFromSrcWithStub.fourslash.ts +0 -54
  464. package/src/tests/fourslash/hover.inherited.docFromStub.fourslash.ts +0 -42
  465. package/src/tests/fourslash/hover.inherited.overload.docFromSrcWithStub.fourslash.ts +0 -46
  466. package/src/tests/fourslash/hover.inherited.overload.docFromStub.fourslash.ts +0 -47
  467. package/src/tests/fourslash/hover.inherited.property.docFromSrcWithStub.fourslash.ts +0 -87
  468. package/src/tests/fourslash/hover.inherited.property.docFromStub.fourslash.ts +0 -91
  469. package/src/tests/fourslash/hover.init.fourslash.ts +0 -39
  470. package/src/tests/fourslash/hover.libCodeAndStub.fourslash.ts +0 -52
  471. package/src/tests/fourslash/hover.libCodeNoStub.fourslash.ts +0 -41
  472. package/src/tests/fourslash/hover.libStub.fourslash.ts +0 -41
  473. package/src/tests/fourslash/hover.optionalAliasParameter.fourslash.ts +0 -14
  474. package/src/tests/fourslash/hover.plainText.fourslash.ts +0 -21
  475. package/src/tests/fourslash/hover.typedDict.key.fourslash.ts +0 -51
  476. package/src/tests/fourslash/hover.variable.docString.fourslash.ts +0 -41
  477. package/src/tests/fourslash/hover.wildcardimports.fourslash.ts +0 -80
  478. package/src/tests/fourslash/import.publicSymbols.fourslash.ts +0 -65
  479. package/src/tests/fourslash/import.pytyped.dunderAll.fourslash.ts +0 -77
  480. package/src/tests/fourslash/import.pytyped.privateSymbols.fourslash.ts +0 -65
  481. package/src/tests/fourslash/import.pytyped.typeCheckingBasic.fourslash.ts +0 -38
  482. package/src/tests/fourslash/import.pytyped.typeCheckingOff.fourslash.ts +0 -38
  483. package/src/tests/fourslash/import.wildcard.fourslash.ts +0 -27
  484. package/src/tests/fourslash/importnotresolved.fourslash.ts +0 -13
  485. package/src/tests/fourslash/missingModuleSource.disablingInStrictMode.fourslash.ts +0 -20
  486. package/src/tests/fourslash/missingModuleSource.fourslash.ts +0 -14
  487. package/src/tests/fourslash/missingTypeStub.codeAction.fourslash.ts +0 -33
  488. package/src/tests/fourslash/missingTypeStub.command.multipart.fourslash.ts +0 -48
  489. package/src/tests/fourslash/missingTypeStub.command.singlefile.fourslash.ts +0 -38
  490. package/src/tests/fourslash/missingTypeStub.command.singlepart.fourslash.ts +0 -38
  491. package/src/tests/fourslash/missingTypeStub.fourslash.ts +0 -20
  492. package/src/tests/fourslash/missingTypeStub.invokeCodeAction.fourslash.ts +0 -36
  493. package/src/tests/fourslash/noerrors.fourslash.ts +0 -9
  494. package/src/tests/fourslash/orderImports1.command.fourslash.ts +0 -20
  495. package/src/tests/fourslash/orderImports2.command.fourslash.ts +0 -24
  496. package/src/tests/fourslash/rename.externallyHidden.fourslash.ts +0 -24
  497. package/src/tests/fourslash/rename.externallyHidden.params.fourslash.ts +0 -24
  498. package/src/tests/fourslash/rename.fourslash.ts +0 -29
  499. package/src/tests/fourslash/rename.library.fourslash.ts +0 -29
  500. package/src/tests/fourslash/rename.library.sourceAndStub.fourslash.ts +0 -33
  501. package/src/tests/fourslash/rename.multipleDecl.fourslash.ts +0 -21
  502. package/src/tests/fourslash/rename.sourceAndStub.fourslash.ts +0 -37
  503. package/src/tests/fourslash/rename.string.excluded.fourslash.ts +0 -43
  504. package/src/tests/fourslash/rename.string.fourslash.ts +0 -26
  505. package/src/tests/fourslash/signature.builtinDocstrings.fourslash.ts +0 -63
  506. package/src/tests/fourslash/signature.complicated.fourslash.ts +0 -100
  507. package/src/tests/fourslash/signature.cornercases.fourslash.ts +0 -23
  508. package/src/tests/fourslash/signature.docstrings.fourslash.ts +0 -43
  509. package/src/tests/fourslash/signature.docstrings.overloaded.fourslash.ts +0 -50
  510. package/src/tests/fourslash/signature.docstrings.wildcardimports.fourslash.ts +0 -122
  511. package/src/tests/fourslash/signature.overload.fourslash.ts +0 -64
  512. package/src/tests/fourslash/signature.simple.fourslash.ts +0 -104
  513. package/src/tests/harness/fourslash/fourSlashParser.ts +0 -441
  514. package/src/tests/harness/fourslash/fourSlashTypes.ts +0 -134
  515. package/src/tests/harness/fourslash/runner.ts +0 -99
  516. package/src/tests/harness/fourslash/testLanguageService.ts +0 -142
  517. package/src/tests/harness/fourslash/testState.Consts.ts +0 -29
  518. package/src/tests/harness/fourslash/testState.ts +0 -1993
  519. package/src/tests/harness/testAccessHost.ts +0 -23
  520. package/src/tests/harness/testHost.ts +0 -177
  521. package/src/tests/harness/utils.ts +0 -355
  522. package/src/tests/harness/vfs/factory.ts +0 -199
  523. package/src/tests/harness/vfs/filesystem.ts +0 -1893
  524. package/src/tests/harness/vfs/pathValidation.ts +0 -154
  525. package/src/tests/importAdder.test.ts +0 -1361
  526. package/src/tests/importResolver.test.ts +0 -534
  527. package/src/tests/importStatementUtils.test.ts +0 -526
  528. package/src/tests/indentationUtils.ptvs.test.ts +0 -388
  529. package/src/tests/indentationUtils.reindent.test.ts +0 -403
  530. package/src/tests/indentationUtils.test.ts +0 -455
  531. package/src/tests/ipythonMode.test.ts +0 -365
  532. package/src/tests/localizer.test.ts +0 -47
  533. package/src/tests/parseTreeUtils.test.ts +0 -281
  534. package/src/tests/parser.test.ts +0 -99
  535. package/src/tests/pathUtils.test.ts +0 -321
  536. package/src/tests/pyrightFileSystem.test.ts +0 -183
  537. package/src/tests/renameModule.folder.test.ts +0 -261
  538. package/src/tests/renameModule.fromImports.test.ts +0 -952
  539. package/src/tests/renameModule.imports.test.ts +0 -450
  540. package/src/tests/renameModule.misc.test.ts +0 -765
  541. package/src/tests/renameModule.relativePath.test.ts +0 -277
  542. package/src/tests/renameModuleTestUtils.ts +0 -210
  543. package/src/tests/samples/abstractClass1.py +0 -51
  544. package/src/tests/samples/abstractClass2.py +0 -25
  545. package/src/tests/samples/abstractClass3.py +0 -30
  546. package/src/tests/samples/abstractClass4.py +0 -30
  547. package/src/tests/samples/abstractClass5.py +0 -42
  548. package/src/tests/samples/abstractClass6.py +0 -25
  549. package/src/tests/samples/abstractClass7.py +0 -22
  550. package/src/tests/samples/abstractClass8.py +0 -27
  551. package/src/tests/samples/annotated1.py +0 -72
  552. package/src/tests/samples/annotatedVar1.py +0 -22
  553. package/src/tests/samples/annotatedVar2.py +0 -28
  554. package/src/tests/samples/annotatedVar3.py +0 -54
  555. package/src/tests/samples/annotatedVar4.py +0 -24
  556. package/src/tests/samples/annotatedVar5.py +0 -37
  557. package/src/tests/samples/annotatedVar6.py +0 -22
  558. package/src/tests/samples/annotatedVar7.py +0 -13
  559. package/src/tests/samples/annotatedVar8.py +0 -29
  560. package/src/tests/samples/annotations1.py +0 -98
  561. package/src/tests/samples/annotations2.py +0 -33
  562. package/src/tests/samples/annotations3.py +0 -43
  563. package/src/tests/samples/annotations4.py +0 -54
  564. package/src/tests/samples/annotations5.py +0 -9
  565. package/src/tests/samples/annotations6.py +0 -29
  566. package/src/tests/samples/assert1.py +0 -22
  567. package/src/tests/samples/assertType1.py +0 -46
  568. package/src/tests/samples/assignment1.py +0 -58
  569. package/src/tests/samples/assignment10.py +0 -14
  570. package/src/tests/samples/assignment2.py +0 -40
  571. package/src/tests/samples/assignment3.py +0 -46
  572. package/src/tests/samples/assignment4.py +0 -20
  573. package/src/tests/samples/assignment5.py +0 -16
  574. package/src/tests/samples/assignment6.py +0 -25
  575. package/src/tests/samples/assignment7.py +0 -13
  576. package/src/tests/samples/assignment8.py +0 -40
  577. package/src/tests/samples/assignment9.py +0 -25
  578. package/src/tests/samples/assignmentExpr1.py +0 -23
  579. package/src/tests/samples/assignmentExpr2.py +0 -49
  580. package/src/tests/samples/assignmentExpr3.py +0 -27
  581. package/src/tests/samples/assignmentExpr4.py +0 -49
  582. package/src/tests/samples/assignmentExpr5.py +0 -15
  583. package/src/tests/samples/assignmentExpr6.py +0 -10
  584. package/src/tests/samples/assignmentExpr7.py +0 -13
  585. package/src/tests/samples/assignmentExpr8.py +0 -11
  586. package/src/tests/samples/assignmentExpr9.py +0 -28
  587. package/src/tests/samples/async1.py +0 -49
  588. package/src/tests/samples/augmentedAssignment1.py +0 -62
  589. package/src/tests/samples/augmentedAssignment2.py +0 -23
  590. package/src/tests/samples/augmentedAssignment3.py +0 -8
  591. package/src/tests/samples/await1.py +0 -23
  592. package/src/tests/samples/await2.py +0 -25
  593. package/src/tests/samples/badToken1.py +0 -6
  594. package/src/tests/samples/builtins1.py +0 -2
  595. package/src/tests/samples/call1.py +0 -93
  596. package/src/tests/samples/call2.py +0 -118
  597. package/src/tests/samples/call3.py +0 -168
  598. package/src/tests/samples/call4.py +0 -13
  599. package/src/tests/samples/call5.py +0 -95
  600. package/src/tests/samples/call6.py +0 -35
  601. package/src/tests/samples/call7.py +0 -57
  602. package/src/tests/samples/callSite1.py +0 -6
  603. package/src/tests/samples/callSite2.py +0 -12
  604. package/src/tests/samples/callable1.py +0 -53
  605. package/src/tests/samples/callable2.py +0 -58
  606. package/src/tests/samples/callable3.py +0 -28
  607. package/src/tests/samples/callable4.py +0 -32
  608. package/src/tests/samples/callable5.py +0 -40
  609. package/src/tests/samples/callable6.py +0 -83
  610. package/src/tests/samples/callbackProtocol1.py +0 -119
  611. package/src/tests/samples/callbackProtocol2.py +0 -29
  612. package/src/tests/samples/callbackProtocol3.py +0 -23
  613. package/src/tests/samples/callbackProtocol4.py +0 -73
  614. package/src/tests/samples/callbackProtocol5.py +0 -66
  615. package/src/tests/samples/callbackProtocol6.py +0 -66
  616. package/src/tests/samples/callbackProtocol7.py +0 -16
  617. package/src/tests/samples/callbackProtocol8.py +0 -16
  618. package/src/tests/samples/capturedVariable1.py +0 -106
  619. package/src/tests/samples/circular1.py +0 -16
  620. package/src/tests/samples/circular2.py +0 -38
  621. package/src/tests/samples/circularBaseClass.py +0 -17
  622. package/src/tests/samples/classGetItem1.py +0 -30
  623. package/src/tests/samples/classVar1.py +0 -41
  624. package/src/tests/samples/classVar2.py +0 -29
  625. package/src/tests/samples/classVar3.py +0 -46
  626. package/src/tests/samples/classVar4.py +0 -36
  627. package/src/tests/samples/classes1.py +0 -50
  628. package/src/tests/samples/classes3.py +0 -48
  629. package/src/tests/samples/classes4.py +0 -15
  630. package/src/tests/samples/classes5.py +0 -260
  631. package/src/tests/samples/classes6.py +0 -16
  632. package/src/tests/samples/classes7.py +0 -18
  633. package/src/tests/samples/classes8.py +0 -47
  634. package/src/tests/samples/codeFlow1.py +0 -65
  635. package/src/tests/samples/codeFlow2.py +0 -26
  636. package/src/tests/samples/codeFlow3.py +0 -8
  637. package/src/tests/samples/codeFlow4.py +0 -133
  638. package/src/tests/samples/codeFlow5.py +0 -10
  639. package/src/tests/samples/codeFlow6.py +0 -35
  640. package/src/tests/samples/codeFlow7.py +0 -35
  641. package/src/tests/samples/comparison1.py +0 -77
  642. package/src/tests/samples/comparison2.py +0 -37
  643. package/src/tests/samples/complex1.py +0 -17
  644. package/src/tests/samples/constant1.py +0 -40
  645. package/src/tests/samples/constants1.py +0 -64
  646. package/src/tests/samples/constructor1.py +0 -30
  647. package/src/tests/samples/constructor10.py +0 -19
  648. package/src/tests/samples/constructor11.py +0 -32
  649. package/src/tests/samples/constructor12.py +0 -20
  650. package/src/tests/samples/constructor13.py +0 -15
  651. package/src/tests/samples/constructor2.py +0 -180
  652. package/src/tests/samples/constructor3.py +0 -18
  653. package/src/tests/samples/constructor4.py +0 -25
  654. package/src/tests/samples/constructor5.py +0 -25
  655. package/src/tests/samples/constructor6.py +0 -70
  656. package/src/tests/samples/constructor7.py +0 -11
  657. package/src/tests/samples/constructor8.py +0 -99
  658. package/src/tests/samples/constructor9.py +0 -19
  659. package/src/tests/samples/coroutines1.py +0 -60
  660. package/src/tests/samples/coroutines2.py +0 -20
  661. package/src/tests/samples/coroutines3.py +0 -37
  662. package/src/tests/samples/dataclass1.py +0 -44
  663. package/src/tests/samples/dataclass10.py +0 -45
  664. package/src/tests/samples/dataclass11.py +0 -53
  665. package/src/tests/samples/dataclass12.py +0 -32
  666. package/src/tests/samples/dataclass13.py +0 -42
  667. package/src/tests/samples/dataclass14.py +0 -38
  668. package/src/tests/samples/dataclass15.py +0 -58
  669. package/src/tests/samples/dataclass16.py +0 -21
  670. package/src/tests/samples/dataclass17.py +0 -46
  671. package/src/tests/samples/dataclass18.py +0 -57
  672. package/src/tests/samples/dataclass19.py +0 -44
  673. package/src/tests/samples/dataclass2.py +0 -30
  674. package/src/tests/samples/dataclass20.py +0 -71
  675. package/src/tests/samples/dataclass21.py +0 -13
  676. package/src/tests/samples/dataclass3.py +0 -18
  677. package/src/tests/samples/dataclass4.py +0 -64
  678. package/src/tests/samples/dataclass5.py +0 -81
  679. package/src/tests/samples/dataclass6.py +0 -29
  680. package/src/tests/samples/dataclass7.py +0 -93
  681. package/src/tests/samples/dataclass8.py +0 -22
  682. package/src/tests/samples/dataclass9.py +0 -24
  683. package/src/tests/samples/dataclassPostInit1.py +0 -61
  684. package/src/tests/samples/dataclassTransform1.py +0 -71
  685. package/src/tests/samples/dataclassTransform2.py +0 -78
  686. package/src/tests/samples/dataclassTransform3.py +0 -83
  687. package/src/tests/samples/dataclassTransform4.py +0 -87
  688. package/src/tests/samples/decorator1.py +0 -20
  689. package/src/tests/samples/decorator2.py +0 -31
  690. package/src/tests/samples/decorator3.py +0 -27
  691. package/src/tests/samples/decorator4.py +0 -37
  692. package/src/tests/samples/decorator5.py +0 -29
  693. package/src/tests/samples/decorator6.py +0 -34
  694. package/src/tests/samples/defaultInitializer1.py +0 -26
  695. package/src/tests/samples/deprecated1.py +0 -37
  696. package/src/tests/samples/descriptor1.py +0 -134
  697. package/src/tests/samples/descriptor2.py +0 -29
  698. package/src/tests/samples/dictionary1.py +0 -42
  699. package/src/tests/samples/dictionary2.py +0 -14
  700. package/src/tests/samples/dictionary3.py +0 -30
  701. package/src/tests/samples/dictionary4.py +0 -106
  702. package/src/tests/samples/dunderAll1.py +0 -32
  703. package/src/tests/samples/dunderAll2.py +0 -16
  704. package/src/tests/samples/dunderAll3.pyi +0 -16
  705. package/src/tests/samples/duplicateDeclaration1.py +0 -115
  706. package/src/tests/samples/duplicateDeclaration2.py +0 -45
  707. package/src/tests/samples/duplicateImports1.py +0 -13
  708. package/src/tests/samples/ellipsis1.pyi +0 -48
  709. package/src/tests/samples/emptyContainers1.py +0 -89
  710. package/src/tests/samples/enums1.py +0 -52
  711. package/src/tests/samples/enums2.py +0 -15
  712. package/src/tests/samples/enums3.py +0 -24
  713. package/src/tests/samples/enums4.py +0 -23
  714. package/src/tests/samples/enums5.py +0 -16
  715. package/src/tests/samples/enums6.py +0 -33
  716. package/src/tests/samples/enums7.py +0 -54
  717. package/src/tests/samples/enums8.py +0 -14
  718. package/src/tests/samples/expressions1.py +0 -54
  719. package/src/tests/samples/expressions2.py +0 -29
  720. package/src/tests/samples/expressions3.py +0 -26
  721. package/src/tests/samples/expressions4.py +0 -23
  722. package/src/tests/samples/expressions5.py +0 -70
  723. package/src/tests/samples/expressions6.py +0 -14
  724. package/src/tests/samples/expressions7.py +0 -40
  725. package/src/tests/samples/expressions8.py +0 -26
  726. package/src/tests/samples/expressions9.py +0 -14
  727. package/src/tests/samples/final1.py +0 -14
  728. package/src/tests/samples/final2.py +0 -86
  729. package/src/tests/samples/final3.py +0 -179
  730. package/src/tests/samples/final4.pyi +0 -21
  731. package/src/tests/samples/final5.py +0 -18
  732. package/src/tests/samples/forLoop1.py +0 -88
  733. package/src/tests/samples/forLoop2.py +0 -48
  734. package/src/tests/samples/fstring1.py +0 -66
  735. package/src/tests/samples/fstring2.py +0 -12
  736. package/src/tests/samples/fstring3.py +0 -35
  737. package/src/tests/samples/fstring4.py +0 -17
  738. package/src/tests/samples/fstring5.py +0 -17
  739. package/src/tests/samples/fstring6.py +0 -14
  740. package/src/tests/samples/function1.py +0 -12
  741. package/src/tests/samples/function10.py +0 -20
  742. package/src/tests/samples/function11.py +0 -36
  743. package/src/tests/samples/function2.py +0 -7
  744. package/src/tests/samples/function3.py +0 -82
  745. package/src/tests/samples/function4.py +0 -13
  746. package/src/tests/samples/function6.py +0 -24
  747. package/src/tests/samples/function7.py +0 -13
  748. package/src/tests/samples/function8.py +0 -38
  749. package/src/tests/samples/function9.py +0 -75
  750. package/src/tests/samples/functionAnnotation1.py +0 -61
  751. package/src/tests/samples/functionAnnotation2.py +0 -26
  752. package/src/tests/samples/functionAnnotation3.py +0 -37
  753. package/src/tests/samples/functionAnnotation4.py +0 -22
  754. package/src/tests/samples/functionMember1.py +0 -18
  755. package/src/tests/samples/functionMember2.py +0 -45
  756. package/src/tests/samples/generators1.py +0 -122
  757. package/src/tests/samples/generators10.py +0 -18
  758. package/src/tests/samples/generators11.py +0 -27
  759. package/src/tests/samples/generators12.py +0 -25
  760. package/src/tests/samples/generators13.py +0 -65
  761. package/src/tests/samples/generators14.py +0 -19
  762. package/src/tests/samples/generators15.py +0 -26
  763. package/src/tests/samples/generators2.py +0 -31
  764. package/src/tests/samples/generators3.py +0 -42
  765. package/src/tests/samples/generators4.py +0 -33
  766. package/src/tests/samples/generators5.py +0 -24
  767. package/src/tests/samples/generators6.py +0 -14
  768. package/src/tests/samples/generators7.py +0 -18
  769. package/src/tests/samples/generators8.py +0 -12
  770. package/src/tests/samples/generators9.py +0 -19
  771. package/src/tests/samples/generic1.py +0 -41
  772. package/src/tests/samples/genericTypes1.py +0 -12
  773. package/src/tests/samples/genericTypes10.py +0 -38
  774. package/src/tests/samples/genericTypes11.py +0 -26
  775. package/src/tests/samples/genericTypes12.py +0 -14
  776. package/src/tests/samples/genericTypes13.py +0 -27
  777. package/src/tests/samples/genericTypes14.py +0 -22
  778. package/src/tests/samples/genericTypes15.py +0 -13
  779. package/src/tests/samples/genericTypes16.py +0 -15
  780. package/src/tests/samples/genericTypes17.py +0 -24
  781. package/src/tests/samples/genericTypes18.py +0 -135
  782. package/src/tests/samples/genericTypes19.py +0 -32
  783. package/src/tests/samples/genericTypes2.py +0 -40
  784. package/src/tests/samples/genericTypes20.py +0 -44
  785. package/src/tests/samples/genericTypes21.py +0 -29
  786. package/src/tests/samples/genericTypes22.py +0 -23
  787. package/src/tests/samples/genericTypes23.py +0 -27
  788. package/src/tests/samples/genericTypes24.py +0 -32
  789. package/src/tests/samples/genericTypes25.py +0 -37
  790. package/src/tests/samples/genericTypes26.py +0 -31
  791. package/src/tests/samples/genericTypes27.py +0 -14
  792. package/src/tests/samples/genericTypes28.py +0 -51
  793. package/src/tests/samples/genericTypes29.py +0 -24
  794. package/src/tests/samples/genericTypes3.py +0 -13
  795. package/src/tests/samples/genericTypes30.py +0 -32
  796. package/src/tests/samples/genericTypes31.py +0 -30
  797. package/src/tests/samples/genericTypes32.py +0 -25
  798. package/src/tests/samples/genericTypes33.py +0 -46
  799. package/src/tests/samples/genericTypes34.py +0 -54
  800. package/src/tests/samples/genericTypes35.py +0 -45
  801. package/src/tests/samples/genericTypes36.py +0 -35
  802. package/src/tests/samples/genericTypes37.py +0 -26
  803. package/src/tests/samples/genericTypes38.py +0 -15
  804. package/src/tests/samples/genericTypes39.py +0 -82
  805. package/src/tests/samples/genericTypes4.py +0 -37
  806. package/src/tests/samples/genericTypes40.py +0 -38
  807. package/src/tests/samples/genericTypes41.py +0 -16
  808. package/src/tests/samples/genericTypes42.py +0 -32
  809. package/src/tests/samples/genericTypes43.py +0 -24
  810. package/src/tests/samples/genericTypes44.py +0 -33
  811. package/src/tests/samples/genericTypes45.py +0 -43
  812. package/src/tests/samples/genericTypes46.py +0 -66
  813. package/src/tests/samples/genericTypes47.py +0 -39
  814. package/src/tests/samples/genericTypes48.py +0 -18
  815. package/src/tests/samples/genericTypes49.py +0 -41
  816. package/src/tests/samples/genericTypes5.py +0 -42
  817. package/src/tests/samples/genericTypes50.py +0 -62
  818. package/src/tests/samples/genericTypes51.py +0 -55
  819. package/src/tests/samples/genericTypes52.py +0 -34
  820. package/src/tests/samples/genericTypes53.py +0 -42
  821. package/src/tests/samples/genericTypes54.py +0 -31
  822. package/src/tests/samples/genericTypes55.py +0 -61
  823. package/src/tests/samples/genericTypes56.py +0 -19
  824. package/src/tests/samples/genericTypes57.py +0 -30
  825. package/src/tests/samples/genericTypes58.py +0 -52
  826. package/src/tests/samples/genericTypes59.py +0 -71
  827. package/src/tests/samples/genericTypes6.py +0 -49
  828. package/src/tests/samples/genericTypes60.py +0 -27
  829. package/src/tests/samples/genericTypes61.py +0 -34
  830. package/src/tests/samples/genericTypes62.py +0 -26
  831. package/src/tests/samples/genericTypes63.py +0 -32
  832. package/src/tests/samples/genericTypes64.py +0 -16
  833. package/src/tests/samples/genericTypes65.py +0 -15
  834. package/src/tests/samples/genericTypes66.py +0 -30
  835. package/src/tests/samples/genericTypes67.py +0 -57
  836. package/src/tests/samples/genericTypes68.py +0 -14
  837. package/src/tests/samples/genericTypes69.py +0 -45
  838. package/src/tests/samples/genericTypes7.py +0 -24
  839. package/src/tests/samples/genericTypes70.py +0 -31
  840. package/src/tests/samples/genericTypes71.py +0 -72
  841. package/src/tests/samples/genericTypes72.py +0 -24
  842. package/src/tests/samples/genericTypes73.py +0 -14
  843. package/src/tests/samples/genericTypes74.py +0 -23
  844. package/src/tests/samples/genericTypes75.py +0 -45
  845. package/src/tests/samples/genericTypes76.py +0 -107
  846. package/src/tests/samples/genericTypes77.py +0 -26
  847. package/src/tests/samples/genericTypes78.py +0 -23
  848. package/src/tests/samples/genericTypes79.py +0 -37
  849. package/src/tests/samples/genericTypes8.py +0 -26
  850. package/src/tests/samples/genericTypes80.py +0 -10
  851. package/src/tests/samples/genericTypes81.py +0 -32
  852. package/src/tests/samples/genericTypes82.py +0 -19
  853. package/src/tests/samples/genericTypes83.py +0 -28
  854. package/src/tests/samples/genericTypes84.py +0 -11
  855. package/src/tests/samples/genericTypes85.py +0 -20
  856. package/src/tests/samples/genericTypes86.py +0 -15
  857. package/src/tests/samples/genericTypes87.py +0 -21
  858. package/src/tests/samples/genericTypes88.py +0 -25
  859. package/src/tests/samples/genericTypes89.py +0 -17
  860. package/src/tests/samples/genericTypes9.py +0 -109
  861. package/src/tests/samples/genericTypes90.py +0 -12
  862. package/src/tests/samples/genericTypes91.py +0 -20
  863. package/src/tests/samples/import1.py +0 -7
  864. package/src/tests/samples/import10.py +0 -11
  865. package/src/tests/samples/import11.py +0 -11
  866. package/src/tests/samples/import12.py +0 -5
  867. package/src/tests/samples/import13.py +0 -6
  868. package/src/tests/samples/import14.py +0 -10
  869. package/src/tests/samples/import2.py +0 -27
  870. package/src/tests/samples/import3.py +0 -8
  871. package/src/tests/samples/import4.py +0 -15
  872. package/src/tests/samples/import5.py +0 -6
  873. package/src/tests/samples/import6.py +0 -17
  874. package/src/tests/samples/import7.py +0 -14
  875. package/src/tests/samples/import8.py +0 -7
  876. package/src/tests/samples/import9.py +0 -7
  877. package/src/tests/samples/inconsistentConstructor1.py +0 -23
  878. package/src/tests/samples/inconsistentSpaceTab1.py +0 -9
  879. package/src/tests/samples/inconsistentSpaceTab2.py +0 -10
  880. package/src/tests/samples/index1.py +0 -97
  881. package/src/tests/samples/inferredTypes1.py +0 -25
  882. package/src/tests/samples/initVar1.py +0 -23
  883. package/src/tests/samples/initsubclass1.py +0 -46
  884. package/src/tests/samples/initsubclass2.py +0 -16
  885. package/src/tests/samples/isinstance1.py +0 -57
  886. package/src/tests/samples/isinstance10.py +0 -15
  887. package/src/tests/samples/isinstance2.py +0 -28
  888. package/src/tests/samples/isinstance3.py +0 -59
  889. package/src/tests/samples/isinstance4.py +0 -57
  890. package/src/tests/samples/isinstance5.py +0 -8
  891. package/src/tests/samples/isinstance6.py +0 -19
  892. package/src/tests/samples/isinstance7.py +0 -42
  893. package/src/tests/samples/isinstance9.py +0 -26
  894. package/src/tests/samples/kwargsUnpack1.py +0 -116
  895. package/src/tests/samples/lambda1.py +0 -77
  896. package/src/tests/samples/lambda2.py +0 -26
  897. package/src/tests/samples/lambda3.py +0 -34
  898. package/src/tests/samples/lambda4.py +0 -70
  899. package/src/tests/samples/lambda5.py +0 -23
  900. package/src/tests/samples/lambda6.py +0 -15
  901. package/src/tests/samples/lines1.py +0 -14
  902. package/src/tests/samples/list1.py +0 -90
  903. package/src/tests/samples/listComprehension1.py +0 -45
  904. package/src/tests/samples/listComprehension2.py +0 -17
  905. package/src/tests/samples/listComprehension3.py +0 -12
  906. package/src/tests/samples/listComprehension4.py +0 -15
  907. package/src/tests/samples/listComprehension5.py +0 -20
  908. package/src/tests/samples/listComprehension6.py +0 -14
  909. package/src/tests/samples/listComprehension7.py +0 -15
  910. package/src/tests/samples/listComprehension8.py +0 -15
  911. package/src/tests/samples/literalString1.py +0 -43
  912. package/src/tests/samples/literals1.py +0 -48
  913. package/src/tests/samples/literals2.py +0 -30
  914. package/src/tests/samples/literals3.py +0 -40
  915. package/src/tests/samples/literals4.py +0 -10
  916. package/src/tests/samples/literals5.py +0 -28
  917. package/src/tests/samples/literals6.py +0 -90
  918. package/src/tests/samples/literals7.py +0 -38
  919. package/src/tests/samples/loops1.py +0 -45
  920. package/src/tests/samples/loops10.py +0 -11
  921. package/src/tests/samples/loops11.py +0 -22
  922. package/src/tests/samples/loops12.py +0 -18
  923. package/src/tests/samples/loops13.py +0 -13
  924. package/src/tests/samples/loops14.py +0 -22
  925. package/src/tests/samples/loops15.py +0 -22
  926. package/src/tests/samples/loops16.py +0 -322
  927. package/src/tests/samples/loops17.py +0 -9
  928. package/src/tests/samples/loops18.py +0 -23
  929. package/src/tests/samples/loops19.py +0 -14
  930. package/src/tests/samples/loops2.py +0 -25
  931. package/src/tests/samples/loops20.py +0 -41
  932. package/src/tests/samples/loops21.py +0 -18
  933. package/src/tests/samples/loops22.py +0 -21
  934. package/src/tests/samples/loops23.py +0 -16
  935. package/src/tests/samples/loops24.py +0 -12
  936. package/src/tests/samples/loops25.py +0 -45
  937. package/src/tests/samples/loops26.py +0 -12
  938. package/src/tests/samples/loops3.py +0 -11
  939. package/src/tests/samples/loops4.py +0 -17
  940. package/src/tests/samples/loops5.py +0 -14
  941. package/src/tests/samples/loops6.py +0 -25
  942. package/src/tests/samples/loops7.py +0 -14
  943. package/src/tests/samples/loops8.py +0 -17
  944. package/src/tests/samples/loops9.py +0 -25
  945. package/src/tests/samples/match1.py +0 -190
  946. package/src/tests/samples/match10.py +0 -67
  947. package/src/tests/samples/match2.py +0 -340
  948. package/src/tests/samples/match3.py +0 -364
  949. package/src/tests/samples/match4.py +0 -100
  950. package/src/tests/samples/match5.py +0 -70
  951. package/src/tests/samples/match6.py +0 -64
  952. package/src/tests/samples/match7.py +0 -65
  953. package/src/tests/samples/match8.py +0 -19
  954. package/src/tests/samples/match9.py +0 -53
  955. package/src/tests/samples/maxParseDepth1.py +0 -499
  956. package/src/tests/samples/maxParseDepth2.py +0 -16
  957. package/src/tests/samples/memberAccess1.py +0 -70
  958. package/src/tests/samples/memberAccess10.py +0 -65
  959. package/src/tests/samples/memberAccess11.py +0 -37
  960. package/src/tests/samples/memberAccess12.py +0 -36
  961. package/src/tests/samples/memberAccess13.py +0 -17
  962. package/src/tests/samples/memberAccess14.py +0 -63
  963. package/src/tests/samples/memberAccess15.py +0 -20
  964. package/src/tests/samples/memberAccess16.py +0 -12
  965. package/src/tests/samples/memberAccess17.py +0 -31
  966. package/src/tests/samples/memberAccess18.py +0 -31
  967. package/src/tests/samples/memberAccess2.py +0 -45
  968. package/src/tests/samples/memberAccess3.py +0 -64
  969. package/src/tests/samples/memberAccess4.py +0 -91
  970. package/src/tests/samples/memberAccess5.py +0 -26
  971. package/src/tests/samples/memberAccess6.py +0 -52
  972. package/src/tests/samples/memberAccess7.py +0 -36
  973. package/src/tests/samples/memberAccess8.py +0 -75
  974. package/src/tests/samples/memberAccess9.py +0 -11
  975. package/src/tests/samples/metaclass1.py +0 -7
  976. package/src/tests/samples/metaclass2.py +0 -35
  977. package/src/tests/samples/metaclass3.py +0 -43
  978. package/src/tests/samples/metaclass4.py +0 -26
  979. package/src/tests/samples/metaclass5.py +0 -33
  980. package/src/tests/samples/metaclass6.py +0 -15
  981. package/src/tests/samples/metaclass7.py +0 -38
  982. package/src/tests/samples/metaclass8.py +0 -20
  983. package/src/tests/samples/metaclass9.py +0 -77
  984. package/src/tests/samples/methodOverride1.py +0 -507
  985. package/src/tests/samples/methodOverride2.py +0 -74
  986. package/src/tests/samples/methodOverride3.py +0 -111
  987. package/src/tests/samples/methodOverride4.py +0 -36
  988. package/src/tests/samples/missingSuper1.py +0 -73
  989. package/src/tests/samples/module1.py +0 -13
  990. package/src/tests/samples/module2.py +0 -7
  991. package/src/tests/samples/mro1.py +0 -16
  992. package/src/tests/samples/mro2.py +0 -45
  993. package/src/tests/samples/mro3.py +0 -30
  994. package/src/tests/samples/mro4.py +0 -30
  995. package/src/tests/samples/nameBindings1.py +0 -48
  996. package/src/tests/samples/nameBindings2.py +0 -9
  997. package/src/tests/samples/nameBindings3.py +0 -36
  998. package/src/tests/samples/nameBindings4.py +0 -10
  999. package/src/tests/samples/nameBindings5.py +0 -53
  1000. package/src/tests/samples/namedTuples1.py +0 -103
  1001. package/src/tests/samples/namedTuples2.py +0 -56
  1002. package/src/tests/samples/namedTuples3.py +0 -15
  1003. package/src/tests/samples/namedTuples4.py +0 -24
  1004. package/src/tests/samples/namedTuples5.py +0 -15
  1005. package/src/tests/samples/namedTuples6.py +0 -31
  1006. package/src/tests/samples/namedTuples7.py +0 -27
  1007. package/src/tests/samples/never1.py +0 -12
  1008. package/src/tests/samples/never2.py +0 -43
  1009. package/src/tests/samples/newType1.py +0 -34
  1010. package/src/tests/samples/newType2.py +0 -25
  1011. package/src/tests/samples/newType3.py +0 -34
  1012. package/src/tests/samples/newType4.py +0 -8
  1013. package/src/tests/samples/none1.py +0 -29
  1014. package/src/tests/samples/none2.py +0 -22
  1015. package/src/tests/samples/noreturn1.py +0 -78
  1016. package/src/tests/samples/noreturn2.py +0 -37
  1017. package/src/tests/samples/noreturn3.py +0 -16
  1018. package/src/tests/samples/noreturn4.py +0 -29
  1019. package/src/tests/samples/operators1.py +0 -101
  1020. package/src/tests/samples/operators2.py +0 -30
  1021. package/src/tests/samples/operators3.py +0 -8
  1022. package/src/tests/samples/operators4.py +0 -22
  1023. package/src/tests/samples/operators5.py +0 -5
  1024. package/src/tests/samples/operators6.py +0 -10
  1025. package/src/tests/samples/operators7.py +0 -24
  1026. package/src/tests/samples/operators8.py +0 -125
  1027. package/src/tests/samples/optional1.py +0 -77
  1028. package/src/tests/samples/optional2.py +0 -23
  1029. package/src/tests/samples/overload1.py +0 -50
  1030. package/src/tests/samples/overload10.py +0 -48
  1031. package/src/tests/samples/overload2.py +0 -37
  1032. package/src/tests/samples/overload3.py +0 -29
  1033. package/src/tests/samples/overload4.py +0 -46
  1034. package/src/tests/samples/overload5.py +0 -333
  1035. package/src/tests/samples/overload6.py +0 -64
  1036. package/src/tests/samples/overload7.py +0 -376
  1037. package/src/tests/samples/overload8.py +0 -89
  1038. package/src/tests/samples/overload9.py +0 -19
  1039. package/src/tests/samples/package1/__init__.py +0 -3
  1040. package/src/tests/samples/package1/psyche/pysche.py +0 -4
  1041. package/src/tests/samples/package1/psyche.py +0 -4
  1042. package/src/tests/samples/package1/sub/__init__.py +0 -5
  1043. package/src/tests/samples/package1/sub.py +0 -4
  1044. package/src/tests/samples/package1/sub.pyi +0 -2
  1045. package/src/tests/samples/paramInference1.py +0 -27
  1046. package/src/tests/samples/paramNames1.py +0 -39
  1047. package/src/tests/samples/paramSpec1.py +0 -64
  1048. package/src/tests/samples/paramSpec10.py +0 -57
  1049. package/src/tests/samples/paramSpec11.py +0 -36
  1050. package/src/tests/samples/paramSpec12.py +0 -88
  1051. package/src/tests/samples/paramSpec13.py +0 -112
  1052. package/src/tests/samples/paramSpec14.py +0 -30
  1053. package/src/tests/samples/paramSpec15.py +0 -28
  1054. package/src/tests/samples/paramSpec16.py +0 -28
  1055. package/src/tests/samples/paramSpec17.py +0 -34
  1056. package/src/tests/samples/paramSpec18.py +0 -43
  1057. package/src/tests/samples/paramSpec19.py +0 -93
  1058. package/src/tests/samples/paramSpec2.py +0 -29
  1059. package/src/tests/samples/paramSpec20.py +0 -87
  1060. package/src/tests/samples/paramSpec21.py +0 -58
  1061. package/src/tests/samples/paramSpec22.py +0 -26
  1062. package/src/tests/samples/paramSpec23.py +0 -21
  1063. package/src/tests/samples/paramSpec24.py +0 -67
  1064. package/src/tests/samples/paramSpec25.py +0 -36
  1065. package/src/tests/samples/paramSpec26.py +0 -25
  1066. package/src/tests/samples/paramSpec27.py +0 -57
  1067. package/src/tests/samples/paramSpec28.py +0 -39
  1068. package/src/tests/samples/paramSpec29.py +0 -37
  1069. package/src/tests/samples/paramSpec3.py +0 -71
  1070. package/src/tests/samples/paramSpec30.py +0 -49
  1071. package/src/tests/samples/paramSpec31.py +0 -16
  1072. package/src/tests/samples/paramSpec32.py +0 -57
  1073. package/src/tests/samples/paramSpec33.py +0 -29
  1074. package/src/tests/samples/paramSpec34.py +0 -29
  1075. package/src/tests/samples/paramSpec35.py +0 -24
  1076. package/src/tests/samples/paramSpec36.py +0 -43
  1077. package/src/tests/samples/paramSpec37.py +0 -25
  1078. package/src/tests/samples/paramSpec4.py +0 -109
  1079. package/src/tests/samples/paramSpec5.py +0 -29
  1080. package/src/tests/samples/paramSpec6.py +0 -17
  1081. package/src/tests/samples/paramSpec7.py +0 -22
  1082. package/src/tests/samples/paramSpec8.py +0 -45
  1083. package/src/tests/samples/paramSpec9.py +0 -57
  1084. package/src/tests/samples/paramType1.py +0 -71
  1085. package/src/tests/samples/parameters1.py +0 -16
  1086. package/src/tests/samples/partial1.py +0 -163
  1087. package/src/tests/samples/partial2.py +0 -31
  1088. package/src/tests/samples/private1.py +0 -55
  1089. package/src/tests/samples/private2.py +0 -11
  1090. package/src/tests/samples/project1/pyrightconfig.json +0 -5
  1091. package/src/tests/samples/project1/sample1.py +0 -0
  1092. package/src/tests/samples/project1/subfolder1/sample2.py +0 -0
  1093. package/src/tests/samples/project1/subfolder1/subfolder1-1/sample3.py +0 -0
  1094. package/src/tests/samples/project2/pyrightconfig.json +0 -3
  1095. package/src/tests/samples/project3/pyrightconfig.json +0 -7
  1096. package/src/tests/samples/project4/presentfile.py +0 -0
  1097. package/src/tests/samples/project4/pyrightconfig.json +0 -11
  1098. package/src/tests/samples/project4/subfolder/presentfile2.py +0 -0
  1099. package/src/tests/samples/project4/subfolder/presentfile3.py +0 -0
  1100. package/src/tests/samples/project5/pyrightconfig.json +0 -4
  1101. package/src/tests/samples/project6/app1.py +0 -0
  1102. package/src/tests/samples/project6/app2.py +0 -0
  1103. package/src/tests/samples/project6/projectA/foo/__init__.py +0 -0
  1104. package/src/tests/samples/project6/projectA/foo/bar/__init__.py +0 -0
  1105. package/src/tests/samples/project6/projectB/foo/__init__.py +0 -0
  1106. package/src/tests/samples/project6/projectB/foo/baz/__init__.py +0 -0
  1107. package/src/tests/samples/project_src/src/module1.py +0 -0
  1108. package/src/tests/samples/project_src_is_pkg/src/__init__.py +0 -0
  1109. package/src/tests/samples/project_src_is_pkg/src/module1.py +0 -0
  1110. package/src/tests/samples/project_src_with_config_extra_paths/pyrightconfig.json +0 -3
  1111. package/src/tests/samples/project_src_with_config_extra_paths/src/module1.py +0 -0
  1112. package/src/tests/samples/project_src_with_config_no_extra_paths/pyrightconfig.json +0 -2
  1113. package/src/tests/samples/project_src_with_config_no_extra_paths/src/module1.py +0 -0
  1114. package/src/tests/samples/project_src_with_extra_paths/src/_vendored/vendored1.py +0 -1
  1115. package/src/tests/samples/project_src_with_extra_paths/src/module1.py +0 -2
  1116. package/src/tests/samples/project_with_pyproject_toml/pyproject.toml +0 -7
  1117. package/src/tests/samples/project_with_venv_auto_detect_exclude/myvenv/Lib/site-packages/library1.py +0 -0
  1118. package/src/tests/samples/project_with_venv_auto_detect_exclude/myvenv/pyvenv.cfg +0 -0
  1119. package/src/tests/samples/project_with_venv_auto_detect_exclude/pyrightconfig.json +0 -2
  1120. package/src/tests/samples/project_with_venv_auto_detect_exclude/sample1.py +0 -0
  1121. package/src/tests/samples/project_with_venv_auto_detect_exclude/subfolder1/sample2.py +0 -0
  1122. package/src/tests/samples/project_with_venv_auto_detect_exclude/subfolder1/subfolder1-1/sample3.py +0 -0
  1123. package/src/tests/samples/project_with_venv_auto_detect_include/excluded/excluded1.py +0 -0
  1124. package/src/tests/samples/project_with_venv_auto_detect_include/myvenv/Lib/site-packages/library1.py +0 -0
  1125. package/src/tests/samples/project_with_venv_auto_detect_include/myvenv/pyvenv.cfg +0 -0
  1126. package/src/tests/samples/project_with_venv_auto_detect_include/pyrightconfig.json +0 -3
  1127. package/src/tests/samples/project_with_venv_auto_detect_include/sample1.py +0 -0
  1128. package/src/tests/samples/project_with_venv_auto_detect_include/subfolder1/sample2.py +0 -0
  1129. package/src/tests/samples/project_with_venv_auto_detect_include/subfolder1/subfolder1-1/sample3.py +0 -0
  1130. package/src/tests/samples/properties1.py +0 -64
  1131. package/src/tests/samples/properties10.py +0 -19
  1132. package/src/tests/samples/properties11.py +0 -45
  1133. package/src/tests/samples/properties12.py +0 -23
  1134. package/src/tests/samples/properties13.py +0 -15
  1135. package/src/tests/samples/properties2.py +0 -34
  1136. package/src/tests/samples/properties3.py +0 -93
  1137. package/src/tests/samples/properties4.py +0 -17
  1138. package/src/tests/samples/properties5.py +0 -29
  1139. package/src/tests/samples/properties6.py +0 -35
  1140. package/src/tests/samples/properties7.py +0 -30
  1141. package/src/tests/samples/properties8.py +0 -26
  1142. package/src/tests/samples/properties9.py +0 -24
  1143. package/src/tests/samples/protocol1.py +0 -132
  1144. package/src/tests/samples/protocol10.py +0 -36
  1145. package/src/tests/samples/protocol11.py +0 -32
  1146. package/src/tests/samples/protocol12.py +0 -12
  1147. package/src/tests/samples/protocol13.py +0 -26
  1148. package/src/tests/samples/protocol14.py +0 -27
  1149. package/src/tests/samples/protocol15.py +0 -27
  1150. package/src/tests/samples/protocol16.py +0 -22
  1151. package/src/tests/samples/protocol17.py +0 -94
  1152. package/src/tests/samples/protocol18.py +0 -27
  1153. package/src/tests/samples/protocol19.py +0 -39
  1154. package/src/tests/samples/protocol2.py +0 -38
  1155. package/src/tests/samples/protocol20.py +0 -22
  1156. package/src/tests/samples/protocol21.py +0 -26
  1157. package/src/tests/samples/protocol22.py +0 -43
  1158. package/src/tests/samples/protocol23.py +0 -41
  1159. package/src/tests/samples/protocol24.py +0 -74
  1160. package/src/tests/samples/protocol25.py +0 -31
  1161. package/src/tests/samples/protocol26.py +0 -40
  1162. package/src/tests/samples/protocol27.py +0 -76
  1163. package/src/tests/samples/protocol28.py +0 -32
  1164. package/src/tests/samples/protocol29.py +0 -26
  1165. package/src/tests/samples/protocol3.py +0 -110
  1166. package/src/tests/samples/protocol30.py +0 -30
  1167. package/src/tests/samples/protocol31.py +0 -22
  1168. package/src/tests/samples/protocol32.py +0 -67
  1169. package/src/tests/samples/protocol33.py +0 -39
  1170. package/src/tests/samples/protocol34.py +0 -21
  1171. package/src/tests/samples/protocol4.py +0 -22
  1172. package/src/tests/samples/protocol5.py +0 -25
  1173. package/src/tests/samples/protocol6.py +0 -65
  1174. package/src/tests/samples/protocol7.py +0 -24
  1175. package/src/tests/samples/protocol8.py +0 -34
  1176. package/src/tests/samples/protocol9.py +0 -35
  1177. package/src/tests/samples/protocolModule1.py +0 -15
  1178. package/src/tests/samples/protocolModule2.py +0 -83
  1179. package/src/tests/samples/protocolModule3.py +0 -14
  1180. package/src/tests/samples/protocolModule4.py +0 -26
  1181. package/src/tests/samples/pseudoGeneric1.py +0 -20
  1182. package/src/tests/samples/pyrightIgnore1.py +0 -11
  1183. package/src/tests/samples/pyrightIgnore2.py +0 -24
  1184. package/src/tests/samples/python2.py +0 -31
  1185. package/src/tests/samples/recursiveTypeAlias1.py +0 -79
  1186. package/src/tests/samples/recursiveTypeAlias2.py +0 -32
  1187. package/src/tests/samples/recursiveTypeAlias3.py +0 -26
  1188. package/src/tests/samples/recursiveTypeAlias4.py +0 -55
  1189. package/src/tests/samples/recursiveTypeAlias5.pyi +0 -10
  1190. package/src/tests/samples/recursiveTypeAlias6.py +0 -25
  1191. package/src/tests/samples/recursiveTypeAlias7.py +0 -15
  1192. package/src/tests/samples/recursiveTypeAlias8.py +0 -38
  1193. package/src/tests/samples/recursiveTypeAlias9.py +0 -22
  1194. package/src/tests/samples/required1.py +0 -47
  1195. package/src/tests/samples/required2.py +0 -56
  1196. package/src/tests/samples/required3.py +0 -22
  1197. package/src/tests/samples/returnTypes1.py +0 -26
  1198. package/src/tests/samples/revealedType1.py +0 -30
  1199. package/src/tests/samples/sample1.py +0 -6
  1200. package/src/tests/samples/self1.py +0 -93
  1201. package/src/tests/samples/self2.py +0 -195
  1202. package/src/tests/samples/self3.py +0 -9
  1203. package/src/tests/samples/self4.py +0 -18
  1204. package/src/tests/samples/self5.py +0 -26
  1205. package/src/tests/samples/setComprehension1.py +0 -34
  1206. package/src/tests/samples/slots1.py +0 -63
  1207. package/src/tests/samples/slots2.py +0 -38
  1208. package/src/tests/samples/slots3.py +0 -35
  1209. package/src/tests/samples/specialization1.py +0 -78
  1210. package/src/tests/samples/specialization2.py +0 -51
  1211. package/src/tests/samples/staticExpressions1.py +0 -52
  1212. package/src/tests/samples/strings1.py +0 -22
  1213. package/src/tests/samples/subscript1.py +0 -74
  1214. package/src/tests/samples/subscript2.py +0 -55
  1215. package/src/tests/samples/subscript3.py +0 -135
  1216. package/src/tests/samples/suiteExpectedColon1.py +0 -4
  1217. package/src/tests/samples/suiteExpectedColon2.py +0 -2
  1218. package/src/tests/samples/suiteExpectedColon3.py +0 -2
  1219. package/src/tests/samples/super1.py +0 -57
  1220. package/src/tests/samples/super2.py +0 -29
  1221. package/src/tests/samples/super3.py +0 -10
  1222. package/src/tests/samples/super4.py +0 -24
  1223. package/src/tests/samples/super5.py +0 -28
  1224. package/src/tests/samples/super6.py +0 -17
  1225. package/src/tests/samples/super7.py +0 -52
  1226. package/src/tests/samples/super8.py +0 -7
  1227. package/src/tests/samples/super9.py +0 -36
  1228. package/src/tests/samples/test_file1.py +0 -0
  1229. package/src/tests/samples/threePartVersion1.py +0 -33
  1230. package/src/tests/samples/totalOrdering1.py +0 -52
  1231. package/src/tests/samples/tryExcept1.py +0 -39
  1232. package/src/tests/samples/tryExcept10.py +0 -12
  1233. package/src/tests/samples/tryExcept2.py +0 -16
  1234. package/src/tests/samples/tryExcept3.py +0 -12
  1235. package/src/tests/samples/tryExcept4.py +0 -28
  1236. package/src/tests/samples/tryExcept5.py +0 -30
  1237. package/src/tests/samples/tryExcept6.py +0 -27
  1238. package/src/tests/samples/tryExcept7.py +0 -17
  1239. package/src/tests/samples/tryExcept8.py +0 -69
  1240. package/src/tests/samples/tryExcept9.py +0 -42
  1241. package/src/tests/samples/tupleUnpack1.py +0 -63
  1242. package/src/tests/samples/tupleUnpack2.py +0 -56
  1243. package/src/tests/samples/tupleUnpack3.py +0 -28
  1244. package/src/tests/samples/tuples1.py +0 -185
  1245. package/src/tests/samples/tuples10.py +0 -30
  1246. package/src/tests/samples/tuples11.py +0 -21
  1247. package/src/tests/samples/tuples12.py +0 -31
  1248. package/src/tests/samples/tuples13.py +0 -26
  1249. package/src/tests/samples/tuples15.py +0 -16
  1250. package/src/tests/samples/tuples16.py +0 -14
  1251. package/src/tests/samples/tuples2.py +0 -23
  1252. package/src/tests/samples/tuples3.py +0 -15
  1253. package/src/tests/samples/tuples4.py +0 -21
  1254. package/src/tests/samples/tuples5.py +0 -16
  1255. package/src/tests/samples/tuples6.py +0 -56
  1256. package/src/tests/samples/tuples7.py +0 -61
  1257. package/src/tests/samples/tuples8.py +0 -98
  1258. package/src/tests/samples/tuples9.py +0 -17
  1259. package/src/tests/samples/typeAlias1.py +0 -37
  1260. package/src/tests/samples/typeAlias10.py +0 -45
  1261. package/src/tests/samples/typeAlias11.py +0 -37
  1262. package/src/tests/samples/typeAlias12.py +0 -20
  1263. package/src/tests/samples/typeAlias13.py +0 -53
  1264. package/src/tests/samples/typeAlias14.py +0 -29
  1265. package/src/tests/samples/typeAlias15.py +0 -24
  1266. package/src/tests/samples/typeAlias16.py +0 -24
  1267. package/src/tests/samples/typeAlias2.py +0 -26
  1268. package/src/tests/samples/typeAlias3.py +0 -35
  1269. package/src/tests/samples/typeAlias4.py +0 -68
  1270. package/src/tests/samples/typeAlias5.py +0 -56
  1271. package/src/tests/samples/typeAlias6.py +0 -51
  1272. package/src/tests/samples/typeAlias7.py +0 -50
  1273. package/src/tests/samples/typeAlias8.py +0 -24
  1274. package/src/tests/samples/typeAlias9.py +0 -35
  1275. package/src/tests/samples/typeGuard1.py +0 -68
  1276. package/src/tests/samples/typeGuard2.py +0 -58
  1277. package/src/tests/samples/typeGuard3.py +0 -98
  1278. package/src/tests/samples/typeIgnore1.py +0 -10
  1279. package/src/tests/samples/typeIgnore2.py +0 -20
  1280. package/src/tests/samples/typeIgnore3.py +0 -22
  1281. package/src/tests/samples/typeIgnore4.py +0 -10
  1282. package/src/tests/samples/typeIgnore5.py +0 -7
  1283. package/src/tests/samples/typeNarrowing1.py +0 -56
  1284. package/src/tests/samples/typeNarrowing2.py +0 -14
  1285. package/src/tests/samples/typeNarrowing3.py +0 -47
  1286. package/src/tests/samples/typeNarrowing4.py +0 -24
  1287. package/src/tests/samples/typeNarrowing5.py +0 -19
  1288. package/src/tests/samples/typeNarrowing6.py +0 -27
  1289. package/src/tests/samples/typeNarrowing7.py +0 -71
  1290. package/src/tests/samples/typeNarrowingAssert1.py +0 -24
  1291. package/src/tests/samples/typeNarrowingCallable1.py +0 -78
  1292. package/src/tests/samples/typeNarrowingEnum1.py +0 -58
  1293. package/src/tests/samples/typeNarrowingEnum2.py +0 -71
  1294. package/src/tests/samples/typeNarrowingFalsy1.py +0 -50
  1295. package/src/tests/samples/typeNarrowingIn1.py +0 -97
  1296. package/src/tests/samples/typeNarrowingIsNone1.py +0 -56
  1297. package/src/tests/samples/typeNarrowingIsNone2.py +0 -8
  1298. package/src/tests/samples/typeNarrowingIsNoneTuple1.py +0 -42
  1299. package/src/tests/samples/typeNarrowingIsNoneTuple2.py +0 -35
  1300. package/src/tests/samples/typeNarrowingIsinstance1.py +0 -162
  1301. package/src/tests/samples/typeNarrowingIsinstance2.py +0 -14
  1302. package/src/tests/samples/typeNarrowingIsinstance3.py +0 -78
  1303. package/src/tests/samples/typeNarrowingIsinstance4.py +0 -50
  1304. package/src/tests/samples/typeNarrowingIsinstance5.py +0 -39
  1305. package/src/tests/samples/typeNarrowingIsinstance6.py +0 -77
  1306. package/src/tests/samples/typeNarrowingIsinstance7.py +0 -19
  1307. package/src/tests/samples/typeNarrowingIsinstance8.py +0 -19
  1308. package/src/tests/samples/typeNarrowingLiteral1.py +0 -35
  1309. package/src/tests/samples/typeNarrowingLiteral2.py +0 -63
  1310. package/src/tests/samples/typeNarrowingLiteralMember1.py +0 -140
  1311. package/src/tests/samples/typeNarrowingLocalConst1.py +0 -136
  1312. package/src/tests/samples/typeNarrowingNoneMember1.py +0 -102
  1313. package/src/tests/samples/typeNarrowingTuple1.py +0 -23
  1314. package/src/tests/samples/typeNarrowingTupleLength1.py +0 -47
  1315. package/src/tests/samples/typeNarrowingTypeIs1.py +0 -95
  1316. package/src/tests/samples/typeNarrowingTypedDict1.py +0 -99
  1317. package/src/tests/samples/typeNarrowingTypedDict2.py +0 -35
  1318. package/src/tests/samples/typeNarrowingTypedDict3.py +0 -45
  1319. package/src/tests/samples/typePromotions1.py +0 -30
  1320. package/src/tests/samples/typeVar1.py +0 -23
  1321. package/src/tests/samples/typeVar10.py +0 -21
  1322. package/src/tests/samples/typeVar11.py +0 -12
  1323. package/src/tests/samples/typeVar2.py +0 -26
  1324. package/src/tests/samples/typeVar3.py +0 -73
  1325. package/src/tests/samples/typeVar4.py +0 -45
  1326. package/src/tests/samples/typeVar5.py +0 -75
  1327. package/src/tests/samples/typeVar6.py +0 -115
  1328. package/src/tests/samples/typeVar7.py +0 -171
  1329. package/src/tests/samples/typeVar8.py +0 -30
  1330. package/src/tests/samples/typeVar9.py +0 -118
  1331. package/src/tests/samples/typedDict1.py +0 -63
  1332. package/src/tests/samples/typedDict10.py +0 -34
  1333. package/src/tests/samples/typedDict11.py +0 -12
  1334. package/src/tests/samples/typedDict12.py +0 -103
  1335. package/src/tests/samples/typedDict13.py +0 -14
  1336. package/src/tests/samples/typedDict14.py +0 -25
  1337. package/src/tests/samples/typedDict15.py +0 -53
  1338. package/src/tests/samples/typedDict16.py +0 -103
  1339. package/src/tests/samples/typedDict17.py +0 -24
  1340. package/src/tests/samples/typedDict18.py +0 -43
  1341. package/src/tests/samples/typedDict2.py +0 -56
  1342. package/src/tests/samples/typedDict3.py +0 -40
  1343. package/src/tests/samples/typedDict4.py +0 -68
  1344. package/src/tests/samples/typedDict5.py +0 -50
  1345. package/src/tests/samples/typedDict6.py +0 -77
  1346. package/src/tests/samples/typedDict7.py +0 -22
  1347. package/src/tests/samples/typedDict8.py +0 -19
  1348. package/src/tests/samples/typedDict9.py +0 -22
  1349. package/src/tests/samples/unbound1.py +0 -18
  1350. package/src/tests/samples/unbound2.py +0 -12
  1351. package/src/tests/samples/unbound3.py +0 -13
  1352. package/src/tests/samples/unbound4.py +0 -25
  1353. package/src/tests/samples/unicode1.py +0 -39
  1354. package/src/tests/samples/uninitializedVariable1.py +0 -27
  1355. package/src/tests/samples/unions1.py +0 -79
  1356. package/src/tests/samples/unions2.py +0 -15
  1357. package/src/tests/samples/unions3.py +0 -48
  1358. package/src/tests/samples/unions4.py +0 -20
  1359. package/src/tests/samples/unions5.py +0 -43
  1360. package/src/tests/samples/unnecessaryCast1.py +0 -13
  1361. package/src/tests/samples/unnecessaryIsInstance1.py +0 -91
  1362. package/src/tests/samples/unnecessaryIsSubclass1.py +0 -22
  1363. package/src/tests/samples/unpack1.py +0 -56
  1364. package/src/tests/samples/unpack2.py +0 -27
  1365. package/src/tests/samples/unpack3.py +0 -16
  1366. package/src/tests/samples/unpack4.py +0 -15
  1367. package/src/tests/samples/unreachable1.py +0 -112
  1368. package/src/tests/samples/unusedCallResult1.py +0 -67
  1369. package/src/tests/samples/unusedCoroutine1.py +0 -23
  1370. package/src/tests/samples/unusedExpression1.py +0 -34
  1371. package/src/tests/samples/unusedVariable1.py +0 -21
  1372. package/src/tests/samples/variadicTypeVar1.py +0 -51
  1373. package/src/tests/samples/variadicTypeVar10.py +0 -65
  1374. package/src/tests/samples/variadicTypeVar11.py +0 -72
  1375. package/src/tests/samples/variadicTypeVar12.py +0 -26
  1376. package/src/tests/samples/variadicTypeVar13.py +0 -35
  1377. package/src/tests/samples/variadicTypeVar14.py +0 -72
  1378. package/src/tests/samples/variadicTypeVar2.py +0 -63
  1379. package/src/tests/samples/variadicTypeVar3.py +0 -86
  1380. package/src/tests/samples/variadicTypeVar4.py +0 -71
  1381. package/src/tests/samples/variadicTypeVar5.py +0 -131
  1382. package/src/tests/samples/variadicTypeVar6.py +0 -78
  1383. package/src/tests/samples/variadicTypeVar7.py +0 -59
  1384. package/src/tests/samples/variadicTypeVar8.py +0 -116
  1385. package/src/tests/samples/variadicTypeVar9.py +0 -38
  1386. package/src/tests/samples/with1.py +0 -117
  1387. package/src/tests/samples/with2.py +0 -63
  1388. package/src/tests/samples/with3.py +0 -66
  1389. package/src/tests/samples/with4.py +0 -24
  1390. package/src/tests/samples/with5.py +0 -33
  1391. package/src/tests/samples/zipfs/bad.egg +0 -1
  1392. package/src/tests/samples/zipfs/bad.zip +0 -1
  1393. package/src/tests/samples/zipfs/basic.egg +0 -0
  1394. package/src/tests/samples/zipfs/basic.zip +0 -0
  1395. package/src/tests/samples/zipfs/corrupt.egg +0 -0
  1396. package/src/tests/samples/zipfs/corrupt.zip +0 -0
  1397. package/src/tests/sourceFile.test.ts +0 -25
  1398. package/src/tests/stringUtils.test.ts +0 -63
  1399. package/src/tests/symbolNameUtils.test.ts +0 -77
  1400. package/src/tests/testState.test.ts +0 -579
  1401. package/src/tests/testUtils.ts +0 -251
  1402. package/src/tests/tokenizer.test.ts +0 -1534
  1403. package/src/tests/typeEvaluator1.test.ts +0 -1372
  1404. package/src/tests/typeEvaluator2.test.ts +0 -1253
  1405. package/src/tests/typeEvaluator3.test.ts +0 -1279
  1406. package/src/tests/typeEvaluator4.test.ts +0 -1178
  1407. package/src/tests/updateSymbolReference.test.ts +0 -1107
  1408. package/src/tests/zipfs.test.ts +0 -116
  1409. package/src/workspaceMap.ts +0 -76
@@ -1,4081 +0,0 @@
1
- /*
2
- * binder.ts
3
- * Copyright (c) Microsoft Corporation.
4
- * Licensed under the MIT license.
5
- * Author: Eric Traut
6
- *
7
- * A parse tree walker that performs basic name binding (creation of
8
- * scopes and associated symbol tables).
9
- * The binder walks the parse tree by scopes starting at the module
10
- * level. When a new scope is detected, it is pushed onto a list and
11
- * walked separately at a later time. (The exception is a class scope,
12
- * which is immediately walked.) Walking the tree in this manner
13
- * simulates the order in which execution normally occurs in a Python
14
- * file. The binder attempts to statically detect runtime errors that
15
- * would be reported by the python interpreter when executing the code.
16
- * This binder doesn't perform any static type checking.
17
- */
18
-
19
- import { Commands } from '../commands/commands';
20
- import { appendArray } from '../common/collectionUtils';
21
- import { DiagnosticLevel } from '../common/configOptions';
22
- import { assert, assertNever, fail } from '../common/debug';
23
- import { CreateTypeStubFileAction, Diagnostic } from '../common/diagnostic';
24
- import { DiagnosticRule } from '../common/diagnosticRules';
25
- import { getFileName, stripFileExtension } from '../common/pathUtils';
26
- import { convertOffsetsToRange } from '../common/positionUtils';
27
- import { getEmptyRange } from '../common/textRange';
28
- import { TextRange } from '../common/textRange';
29
- import { Localizer } from '../localization/localize';
30
- import {
31
- ArgumentCategory,
32
- AssertNode,
33
- AssignmentExpressionNode,
34
- AssignmentNode,
35
- AugmentedAssignmentNode,
36
- AwaitNode,
37
- BinaryOperationNode,
38
- BreakNode,
39
- CallNode,
40
- CaseNode,
41
- ClassNode,
42
- ContinueNode,
43
- DelNode,
44
- ExceptNode,
45
- ExpressionNode,
46
- ForNode,
47
- FunctionNode,
48
- GlobalNode,
49
- IfNode,
50
- ImportAsNode,
51
- ImportFromNode,
52
- IndexNode,
53
- LambdaNode,
54
- ListComprehensionNode,
55
- MatchNode,
56
- MemberAccessNode,
57
- ModuleNameNode,
58
- ModuleNode,
59
- NameNode,
60
- NonlocalNode,
61
- ParseNode,
62
- ParseNodeType,
63
- PatternAsNode,
64
- PatternCaptureNode,
65
- PatternMappingExpandEntryNode,
66
- RaiseNode,
67
- ReturnNode,
68
- StatementNode,
69
- StringListNode,
70
- StringNode,
71
- SuiteNode,
72
- TernaryNode,
73
- TryNode,
74
- TypeAnnotationNode,
75
- UnaryOperationNode,
76
- WhileNode,
77
- WithNode,
78
- YieldFromNode,
79
- YieldNode,
80
- } from '../parser/parseNodes';
81
- import { KeywordType, OperatorType } from '../parser/tokenizerTypes';
82
- import { AnalyzerFileInfo, ImportLookupResult, isAnnotationEvaluationPostponed } from './analyzerFileInfo';
83
- import * as AnalyzerNodeInfo from './analyzerNodeInfo';
84
- import {
85
- CodeFlowReferenceExpressionNode,
86
- createKeyForReference,
87
- FlowAssignment,
88
- FlowBranchLabel,
89
- FlowCall,
90
- FlowCondition,
91
- FlowExhaustedMatch,
92
- FlowFlags,
93
- FlowLabel,
94
- FlowNarrowForPattern,
95
- FlowNode,
96
- FlowPostContextManagerLabel,
97
- FlowPostFinally,
98
- FlowPreFinallyGate,
99
- FlowVariableAnnotation,
100
- FlowWildcardImport,
101
- getUniqueFlowNodeId,
102
- isCodeFlowSupportedForReference,
103
- } from './codeFlowTypes';
104
- import {
105
- AliasDeclaration,
106
- ClassDeclaration,
107
- DeclarationType,
108
- FunctionDeclaration,
109
- IntrinsicType,
110
- ModuleLoaderActions,
111
- ParameterDeclaration,
112
- VariableDeclaration,
113
- } from './declaration';
114
- import { ImplicitImport, ImportResult, ImportType } from './importResult';
115
- import * as ParseTreeUtils from './parseTreeUtils';
116
- import { ParseTreeWalker } from './parseTreeWalker';
117
- import { NameBindingType, Scope, ScopeType } from './scope';
118
- import * as StaticExpressions from './staticExpressions';
119
- import { indeterminateSymbolId, Symbol, SymbolFlags } from './symbol';
120
- import { isConstantName, isPrivateName, isPrivateOrProtectedName } from './symbolNameUtils';
121
-
122
- interface MemberAccessInfo {
123
- classNode: ClassNode;
124
- methodNode: FunctionNode;
125
- classScope: Scope;
126
- isInstanceMember: boolean;
127
- }
128
-
129
- interface DeferredBindingTask {
130
- scope: Scope;
131
- codeFlowExpressions: Set<string>;
132
- callback: () => void;
133
- }
134
-
135
- interface FinalInfo {
136
- isFinal: boolean;
137
- finalTypeNode: ExpressionNode | undefined;
138
- }
139
-
140
- interface ClassVarInfo {
141
- isClassVar: boolean;
142
- classVarTypeNode: ExpressionNode | undefined;
143
- }
144
-
145
- // For each flow node within an execution context, we'll add a small
146
- // amount to the complexity factor. Without this, the complexity
147
- // calculation fails to take into account large numbers of non-cyclical
148
- // flow nodes. This number is somewhat arbitrary and is tuned empirically.
149
- const flowNodeComplexityFactor = 0.05;
150
-
151
- export class Binder extends ParseTreeWalker {
152
- private readonly _fileInfo: AnalyzerFileInfo;
153
-
154
- // A queue of deferred analysis operations.
155
- private _deferredBindingTasks: DeferredBindingTask[] = [];
156
-
157
- // The current scope in effect.
158
- private _currentScope!: Scope;
159
-
160
- // Current control-flow node.
161
- private _currentFlowNode: FlowNode | undefined;
162
-
163
- // Current target function declaration, if currently binding
164
- // a function. This allows return and yield statements to be
165
- // added to the function declaration.
166
- private _targetFunctionDeclaration: FunctionDeclaration | undefined;
167
-
168
- // Flow node label that is the target of a "break" statement.
169
- private _currentBreakTarget: FlowLabel | undefined;
170
-
171
- // Flow node label that is the target of a "continue" statement.
172
- private _currentContinueTarget: FlowLabel | undefined;
173
-
174
- // Flow nodes used for if/else and while/else statements.
175
- private _currentTrueTarget: FlowLabel | undefined;
176
- private _currentFalseTarget: FlowLabel | undefined;
177
-
178
- // Flow nodes used within try blocks.
179
- private _currentExceptTargets: FlowLabel[] = [];
180
-
181
- // Flow nodes used within try/finally flows.
182
- private _finallyTargets: FlowLabel[] = [];
183
-
184
- // Flow nodes used for return statements.
185
- private _currentReturnTarget: FlowLabel | undefined;
186
-
187
- // Set of expressions within the current execution scope
188
- // and require code flow analysis to resolve.
189
- private _currentScopeCodeFlowExpressions: Set<string> | undefined;
190
-
191
- // Aliases of "typing" and "typing_extensions".
192
- private _typingImportAliases: string[] = [];
193
-
194
- // Aliases of "sys".
195
- private _sysImportAliases: string[] = [];
196
-
197
- // Aliases of "dataclasses".
198
- private _dataclassesImportAliases: string[] = [];
199
-
200
- // Map of imports of specific symbols imported from "typing" and "typing_extensions"
201
- // and the names they alias to.
202
- private _typingSymbolAliases: Map<string, string> = new Map<string, string>();
203
-
204
- // Map of imports of specific symbols imported from "dataclasses"
205
- // and the names they alias to.
206
- private _dataclassesSymbolAliases: Map<string, string> = new Map<string, string>();
207
-
208
- // List of names statically assigned to __all__ symbol.
209
- private _dunderAllNames: string[] | undefined;
210
-
211
- // List of string nodes associated with the "__all__" symbol.
212
- private _dunderAllStringNodes: StringNode[] = [];
213
-
214
- // One or more statements are manipulating __all__ in a manner that a
215
- // static analyzer doesn't understand.
216
- private _usesUnsupportedDunderAllForm = false;
217
-
218
- // Are we currently binding code located within an except block?
219
- private _isInExceptSuite = false;
220
-
221
- // A list of names assigned to __slots__ within a class.
222
- private _dunderSlotsEntries: StringListNode[] | undefined;
223
-
224
- // Flow node that is used for unreachable code.
225
- private static _unreachableFlowNode: FlowNode = {
226
- flags: FlowFlags.Unreachable,
227
- id: getUniqueFlowNodeId(),
228
- };
229
-
230
- // Map of symbols at the module level that may be externally
231
- // hidden depending on whether they are listed in the __all__ list.
232
- private _potentialHiddenSymbols = new Map<string, Symbol>();
233
-
234
- // Map of symbols at the module level that may be private depending
235
- // on whether they are listed in the __all__ list.
236
- private _potentialPrivateSymbols = new Map<string, Symbol>();
237
-
238
- // Estimates the overall complexity of the code flow graph for
239
- // the current function.
240
- private _codeFlowComplexity = 0;
241
-
242
- constructor(fileInfo: AnalyzerFileInfo, private _moduleSymbolOnly = false) {
243
- super();
244
-
245
- this._fileInfo = fileInfo;
246
- }
247
-
248
- bindModule(node: ModuleNode): void {
249
- // We'll assume that if there is no builtins scope provided, we must be
250
- // binding the builtins module itself.
251
- const isBuiltInModule = this._fileInfo.builtinsScope === undefined;
252
-
253
- this._createNewScope(
254
- isBuiltInModule ? ScopeType.Builtin : ScopeType.Module,
255
- this._fileInfo.builtinsScope,
256
- () => {
257
- AnalyzerNodeInfo.setScope(node, this._currentScope);
258
- AnalyzerNodeInfo.setFlowNode(node, this._currentFlowNode!);
259
-
260
- // Bind implicit names.
261
- // List taken from https://docs.python.org/3/reference/import.html#__name__
262
- this._addImplicitSymbolToCurrentScope('__doc__', node, 'str | None');
263
- this._addImplicitSymbolToCurrentScope('__name__', node, 'str');
264
- this._addImplicitSymbolToCurrentScope('__qualname__', node, 'str');
265
- this._addImplicitSymbolToCurrentScope('__loader__', node, 'Any');
266
- this._addImplicitSymbolToCurrentScope('__package__', node, 'str');
267
- this._addImplicitSymbolToCurrentScope('__spec__', node, 'Any');
268
- this._addImplicitSymbolToCurrentScope('__path__', node, 'Iterable[str]');
269
- this._addImplicitSymbolToCurrentScope('__file__', node, 'str');
270
- this._addImplicitSymbolToCurrentScope('__cached__', node, 'str');
271
- this._addImplicitSymbolToCurrentScope('__dict__', node, 'Dict[str, Any]');
272
- this._addImplicitSymbolToCurrentScope('__annotations__', node, 'Dict[str, Any]');
273
- this._addImplicitSymbolToCurrentScope('__builtins__', node, 'Any');
274
-
275
- // Create a start node for the module.
276
- this._currentFlowNode = this._createStartFlowNode();
277
-
278
- this._walkStatementsAndReportUnreachable(node.statements);
279
-
280
- // Associate the code flow node at the end of the module with the module.
281
- AnalyzerNodeInfo.setAfterFlowNode(node, this._currentFlowNode);
282
-
283
- AnalyzerNodeInfo.setCodeFlowExpressions(node, this._currentScopeCodeFlowExpressions!);
284
- AnalyzerNodeInfo.setCodeFlowComplexity(node, this._codeFlowComplexity);
285
- }
286
- );
287
-
288
- // Perform all analysis that was deferred during the first pass.
289
- this._bindDeferred();
290
-
291
- // Use the __all__ list to determine whether any potential private
292
- // symbols should be made externally hidden or private.
293
- this._potentialHiddenSymbols.forEach((symbol, name) => {
294
- if (!this._dunderAllNames?.some((sym) => sym === name)) {
295
- if (this._fileInfo.isStubFile) {
296
- symbol.setIsExternallyHidden();
297
- } else {
298
- symbol.setPrivatePyTypedImport();
299
- }
300
- }
301
- });
302
-
303
- this._potentialPrivateSymbols.forEach((symbol, name) => {
304
- if (!this._dunderAllNames?.some((sym) => sym === name)) {
305
- symbol.setIsPrivateMember();
306
- }
307
- });
308
-
309
- if (this._dunderAllNames) {
310
- AnalyzerNodeInfo.setDunderAllInfo(node, {
311
- names: this._dunderAllNames,
312
- stringNodes: this._dunderAllStringNodes,
313
- usesUnsupportedDunderAllForm: this._usesUnsupportedDunderAllForm,
314
- });
315
- } else {
316
- AnalyzerNodeInfo.setDunderAllInfo(node, /* names */ undefined);
317
- }
318
-
319
- // Set __all__ flags on the module symbols.
320
- const scope = AnalyzerNodeInfo.getScope(node);
321
- if (scope && this._dunderAllNames) {
322
- for (const name of this._dunderAllNames) {
323
- scope.symbolTable.get(name)?.setIsInDunderAll();
324
- }
325
- }
326
- }
327
-
328
- override visitModule(node: ModuleNode): boolean {
329
- // Tree walking should start with the children of
330
- // the node, so we should never get here.
331
- fail('We should never get here');
332
- return false;
333
- }
334
-
335
- override visitSuite(node: SuiteNode): boolean {
336
- this._walkStatementsAndReportUnreachable(node.statements);
337
- return false;
338
- }
339
-
340
- override visitModuleName(node: ModuleNameNode): boolean {
341
- const importResult = AnalyzerNodeInfo.getImportInfo(node);
342
- assert(importResult !== undefined);
343
-
344
- if (importResult.isNativeLib) {
345
- return true;
346
- }
347
-
348
- if (!importResult.isImportFound) {
349
- this._addDiagnostic(
350
- this._fileInfo.diagnosticRuleSet.reportMissingImports,
351
- DiagnosticRule.reportMissingImports,
352
- Localizer.Diagnostic.importResolveFailure().format({ importName: importResult.importName }),
353
- node
354
- );
355
- return true;
356
- }
357
-
358
- // Source found, but type stub is missing
359
- if (
360
- !importResult.isStubFile &&
361
- importResult.importType === ImportType.ThirdParty &&
362
- !importResult.pyTypedInfo
363
- ) {
364
- const diagnostic = this._addDiagnostic(
365
- this._fileInfo.diagnosticRuleSet.reportMissingTypeStubs,
366
- DiagnosticRule.reportMissingTypeStubs,
367
- Localizer.Diagnostic.stubFileMissing().format({ importName: importResult.importName }),
368
- node
369
- );
370
- if (diagnostic) {
371
- // Add a diagnostic action for resolving this diagnostic.
372
- const createTypeStubAction: CreateTypeStubFileAction = {
373
- action: Commands.createTypeStub,
374
- moduleName: importResult.importName,
375
- };
376
- diagnostic.addAction(createTypeStubAction);
377
- }
378
- }
379
-
380
- return true;
381
- }
382
-
383
- override visitClass(node: ClassNode): boolean {
384
- this.walkMultiple(node.decorators);
385
-
386
- const classDeclaration: ClassDeclaration = {
387
- type: DeclarationType.Class,
388
- node,
389
- path: this._fileInfo.filePath,
390
- range: convertOffsetsToRange(node.name.start, TextRange.getEnd(node.name), this._fileInfo.lines),
391
- moduleName: this._fileInfo.moduleName,
392
- isInExceptSuite: this._isInExceptSuite,
393
- };
394
-
395
- const symbol = this._bindNameToScope(this._currentScope, node.name.value);
396
- if (symbol) {
397
- symbol.addDeclaration(classDeclaration);
398
- }
399
-
400
- // Stash the declaration in the parse node for later access.
401
- AnalyzerNodeInfo.setDeclaration(node, classDeclaration);
402
-
403
- this.walkMultiple(node.arguments);
404
-
405
- this._createNewScope(ScopeType.Class, this._getNonClassParentScope(), () => {
406
- AnalyzerNodeInfo.setScope(node, this._currentScope);
407
-
408
- this._addImplicitSymbolToCurrentScope('__doc__', node, 'str | None');
409
- this._addImplicitSymbolToCurrentScope('__module__', node, 'str');
410
-
411
- this._dunderSlotsEntries = undefined;
412
- if (!this._moduleSymbolOnly) {
413
- // Analyze the suite.
414
- this.walk(node.suite);
415
- }
416
-
417
- if (this._dunderSlotsEntries) {
418
- this._addSlotsToCurrentScope(this._dunderSlotsEntries);
419
- }
420
- this._dunderSlotsEntries = undefined;
421
- });
422
-
423
- this._createAssignmentTargetFlowNodes(node.name, /* walkTargets */ false, /* unbound */ false);
424
-
425
- return false;
426
- }
427
-
428
- override visitFunction(node: FunctionNode): boolean {
429
- this._createVariableAnnotationFlowNode();
430
- AnalyzerNodeInfo.setFlowNode(node, this._currentFlowNode!);
431
-
432
- const symbol = this._bindNameToScope(this._currentScope, node.name.value);
433
- const containingClassNode = ParseTreeUtils.getEnclosingClass(node, /* stopAtFunction */ true);
434
- const functionDeclaration: FunctionDeclaration = {
435
- type: DeclarationType.Function,
436
- node,
437
- isMethod: !!containingClassNode,
438
- isGenerator: false,
439
- path: this._fileInfo.filePath,
440
- range: convertOffsetsToRange(node.name.start, TextRange.getEnd(node.name), this._fileInfo.lines),
441
- moduleName: this._fileInfo.moduleName,
442
- isInExceptSuite: this._isInExceptSuite,
443
- };
444
-
445
- if (symbol) {
446
- symbol.addDeclaration(functionDeclaration);
447
- }
448
-
449
- // Stash the declaration in the parse node for later access.
450
- AnalyzerNodeInfo.setDeclaration(node, functionDeclaration);
451
-
452
- this.walkMultiple(node.decorators);
453
- node.parameters.forEach((param) => {
454
- if (param.defaultValue) {
455
- this.walk(param.defaultValue);
456
- }
457
-
458
- if (param.typeAnnotation) {
459
- this.walk(param.typeAnnotation);
460
- }
461
-
462
- if (param.typeAnnotationComment) {
463
- this.walk(param.typeAnnotationComment);
464
- }
465
- });
466
-
467
- if (node.returnTypeAnnotation) {
468
- this.walk(node.returnTypeAnnotation);
469
- }
470
-
471
- if (node.functionAnnotationComment) {
472
- this.walk(node.functionAnnotationComment);
473
- }
474
-
475
- // Don't walk the body of the function until we're done analyzing
476
- // the current scope.
477
- this._createNewScope(ScopeType.Function, this._getNonClassParentScope(), () => {
478
- AnalyzerNodeInfo.setScope(node, this._currentScope);
479
-
480
- const enclosingClass = ParseTreeUtils.getEnclosingClass(node);
481
- if (enclosingClass) {
482
- // Add the implicit "__class__" symbol described in PEP 3135.
483
- this._addImplicitSymbolToCurrentScope('__class__', node, 'class');
484
- }
485
-
486
- this._deferBinding(() => {
487
- // Create a start node for the function.
488
- this._currentFlowNode = this._createStartFlowNode();
489
- this._codeFlowComplexity = 0;
490
-
491
- node.parameters.forEach((paramNode) => {
492
- if (paramNode.name) {
493
- const symbol = this._bindNameToScope(this._currentScope, paramNode.name.value);
494
- if (symbol) {
495
- const paramDeclaration: ParameterDeclaration = {
496
- type: DeclarationType.Parameter,
497
- node: paramNode,
498
- path: this._fileInfo.filePath,
499
- range: convertOffsetsToRange(
500
- paramNode.start,
501
- TextRange.getEnd(paramNode),
502
- this._fileInfo.lines
503
- ),
504
- moduleName: this._fileInfo.moduleName,
505
- isInExceptSuite: this._isInExceptSuite,
506
- };
507
-
508
- symbol.addDeclaration(paramDeclaration);
509
- AnalyzerNodeInfo.setDeclaration(paramNode.name, paramDeclaration);
510
- }
511
-
512
- this._createFlowAssignment(paramNode.name);
513
- }
514
- });
515
-
516
- this._targetFunctionDeclaration = functionDeclaration;
517
- this._currentReturnTarget = this._createBranchLabel();
518
-
519
- // Walk the statements that make up the function.
520
- this.walk(node.suite);
521
-
522
- // Associate the code flow node at the end of the suite with
523
- // the suite.
524
- AnalyzerNodeInfo.setAfterFlowNode(node.suite, this._currentFlowNode);
525
-
526
- // Compute the final return flow node and associate it with
527
- // the function's parse node. If this node is unreachable, then
528
- // the function never returns.
529
- this._addAntecedent(this._currentReturnTarget, this._currentFlowNode);
530
- const returnFlowNode = this._finishFlowLabel(this._currentReturnTarget);
531
-
532
- AnalyzerNodeInfo.setAfterFlowNode(node, returnFlowNode);
533
-
534
- AnalyzerNodeInfo.setCodeFlowExpressions(node, this._currentScopeCodeFlowExpressions!);
535
- AnalyzerNodeInfo.setCodeFlowComplexity(node, this._codeFlowComplexity);
536
- });
537
- });
538
-
539
- this._createAssignmentTargetFlowNodes(node.name, /* walkTargets */ false, /* unbound */ false);
540
-
541
- // We'll walk the child nodes in a deferred manner, so don't walk them now.
542
- return false;
543
- }
544
-
545
- override visitLambda(node: LambdaNode): boolean {
546
- this._createVariableAnnotationFlowNode();
547
- AnalyzerNodeInfo.setFlowNode(node, this._currentFlowNode!);
548
-
549
- // Analyze the parameter defaults in the context of the parent's scope
550
- // before we add any names from the function's scope.
551
- node.parameters.forEach((param) => {
552
- if (param.defaultValue) {
553
- this.walk(param.defaultValue);
554
- }
555
- });
556
-
557
- this._createNewScope(ScopeType.Function, this._getNonClassParentScope(), () => {
558
- AnalyzerNodeInfo.setScope(node, this._currentScope);
559
-
560
- this._deferBinding(() => {
561
- // Create a start node for the lambda.
562
- this._currentFlowNode = this._createStartFlowNode();
563
-
564
- node.parameters.forEach((paramNode) => {
565
- if (paramNode.name) {
566
- const symbol = this._bindNameToScope(this._currentScope, paramNode.name.value);
567
- if (symbol) {
568
- const paramDeclaration: ParameterDeclaration = {
569
- type: DeclarationType.Parameter,
570
- node: paramNode,
571
- path: this._fileInfo.filePath,
572
- range: convertOffsetsToRange(
573
- paramNode.start,
574
- TextRange.getEnd(paramNode),
575
- this._fileInfo.lines
576
- ),
577
- moduleName: this._fileInfo.moduleName,
578
- isInExceptSuite: this._isInExceptSuite,
579
- };
580
-
581
- symbol.addDeclaration(paramDeclaration);
582
- AnalyzerNodeInfo.setDeclaration(paramNode.name, paramDeclaration);
583
- }
584
-
585
- this._createFlowAssignment(paramNode.name);
586
- this.walk(paramNode.name);
587
- }
588
- });
589
-
590
- // Walk the expression that make up the lambda body.
591
- this.walk(node.expression);
592
-
593
- AnalyzerNodeInfo.setCodeFlowExpressions(node, this._currentScopeCodeFlowExpressions!);
594
- });
595
- });
596
-
597
- // We'll walk the child nodes in a deferred manner.
598
- return false;
599
- }
600
-
601
- override visitCall(node: CallNode): boolean {
602
- this._disableTrueFalseTargets(() => {
603
- this.walk(node.leftExpression);
604
- node.arguments.forEach((argNode) => {
605
- if (this._currentFlowNode) {
606
- AnalyzerNodeInfo.setFlowNode(argNode, this._currentFlowNode);
607
- }
608
- this.walk(argNode);
609
- });
610
- });
611
-
612
- // Create a call flow node. We'll skip this if the call is part of
613
- // a decorator. We assume that decorators are not NoReturn functions.
614
- // There are libraries that make extensive use of unannotated decorators,
615
- // and this can lead to a performance issue when walking the control
616
- // flow graph if we need to evaluate every decorator.
617
- if (!ParseTreeUtils.isNodeContainedWithinNodeType(node, ParseNodeType.Decorator)) {
618
- this._createCallFlowNode(node);
619
- }
620
-
621
- // Is this an manipulation of dunder all?
622
- if (
623
- this._currentScope.type === ScopeType.Module &&
624
- node.leftExpression.nodeType === ParseNodeType.MemberAccess &&
625
- node.leftExpression.leftExpression.nodeType === ParseNodeType.Name &&
626
- node.leftExpression.leftExpression.value === '__all__'
627
- ) {
628
- let emitDunderAllWarning = true;
629
-
630
- // Is this a call to "__all__.extend()"?
631
- if (node.leftExpression.memberName.value === 'extend' && node.arguments.length === 1) {
632
- const argExpr = node.arguments[0].valueExpression;
633
-
634
- // Is this a call to "__all__.extend([<list>])"?
635
- if (argExpr.nodeType === ParseNodeType.List) {
636
- argExpr.entries.forEach((listEntryNode) => {
637
- if (
638
- listEntryNode.nodeType === ParseNodeType.StringList &&
639
- listEntryNode.strings.length === 1 &&
640
- listEntryNode.strings[0].nodeType === ParseNodeType.String
641
- ) {
642
- this._dunderAllNames?.push(listEntryNode.strings[0].value);
643
- this._dunderAllStringNodes?.push(listEntryNode.strings[0]);
644
- emitDunderAllWarning = false;
645
- }
646
- });
647
- } else if (
648
- argExpr.nodeType === ParseNodeType.MemberAccess &&
649
- argExpr.leftExpression.nodeType === ParseNodeType.Name &&
650
- argExpr.memberName.value === '__all__'
651
- ) {
652
- // Is this a call to "__all__.extend(<mod>.__all__)"?
653
- const namesToAdd = this._getDunderAllNamesFromImport(argExpr.leftExpression.value);
654
- if (namesToAdd && namesToAdd.length > 0) {
655
- namesToAdd.forEach((name) => {
656
- this._dunderAllNames?.push(name);
657
- });
658
- emitDunderAllWarning = false;
659
- }
660
- }
661
- } else if (node.leftExpression.memberName.value === 'remove' && node.arguments.length === 1) {
662
- // Is this a call to "__all__.remove()"?
663
- const argExpr = node.arguments[0].valueExpression;
664
- if (
665
- argExpr.nodeType === ParseNodeType.StringList &&
666
- argExpr.strings.length === 1 &&
667
- argExpr.strings[0].nodeType === ParseNodeType.String &&
668
- this._dunderAllNames
669
- ) {
670
- this._dunderAllNames = this._dunderAllNames.filter((name) => name !== argExpr.strings[0].value);
671
- this._dunderAllStringNodes = this._dunderAllStringNodes.filter(
672
- (node) => node.value !== argExpr.strings[0].value
673
- );
674
- emitDunderAllWarning = false;
675
- }
676
- } else if (node.leftExpression.memberName.value === 'append' && node.arguments.length === 1) {
677
- // Is this a call to "__all__.append()"?
678
- const argExpr = node.arguments[0].valueExpression;
679
- if (
680
- argExpr.nodeType === ParseNodeType.StringList &&
681
- argExpr.strings.length === 1 &&
682
- argExpr.strings[0].nodeType === ParseNodeType.String
683
- ) {
684
- this._dunderAllNames?.push(argExpr.strings[0].value);
685
- this._dunderAllStringNodes?.push(argExpr.strings[0]);
686
- emitDunderAllWarning = false;
687
- }
688
- }
689
-
690
- if (emitDunderAllWarning) {
691
- this._usesUnsupportedDunderAllForm = true;
692
-
693
- this._addDiagnostic(
694
- this._fileInfo.diagnosticRuleSet.reportUnsupportedDunderAll,
695
- DiagnosticRule.reportUnsupportedDunderAll,
696
- Localizer.Diagnostic.unsupportedDunderAllOperation(),
697
- node
698
- );
699
- }
700
- }
701
-
702
- return false;
703
- }
704
-
705
- override visitAssignment(node: AssignmentNode): boolean {
706
- if (this._handleTypingStubAssignmentOrAnnotation(node)) {
707
- return false;
708
- }
709
-
710
- this._bindPossibleTupleNamedTarget(node.leftExpression);
711
-
712
- if (node.typeAnnotationComment) {
713
- this.walk(node.typeAnnotationComment);
714
- this._addTypeDeclarationForVariable(node.leftExpression, node.typeAnnotationComment);
715
- }
716
-
717
- // If there is a type annotation associated with the assignment and annotation evaluations are
718
- // not deferred, the Python interpreter creates an entry in the local symbol table (presumably
719
- // to store the __annotation__ attribute) before it evaluates the RHS of the assignment. This
720
- // can affect the evaluation of the RHS if the name of the symbol is the same as a name that
721
- // is defined in an outer scope.
722
- let createdAssignmentTargetFlowNodes = false;
723
- if (
724
- node.leftExpression.nodeType === ParseNodeType.TypeAnnotation &&
725
- !isAnnotationEvaluationPostponed(this._fileInfo)
726
- ) {
727
- this._createAssignmentTargetFlowNodes(node.leftExpression, /* walkTargets */ true, /* unbound */ false);
728
- createdAssignmentTargetFlowNodes = true;
729
- }
730
-
731
- this.walk(node.rightExpression);
732
-
733
- let isPossibleTypeAlias = true;
734
- if (ParseTreeUtils.getEnclosingFunction(node)) {
735
- // We will assume that type aliases are defined only at the module level
736
- // or as class variables, not as local variables within a function.
737
- isPossibleTypeAlias = false;
738
- } else if (node.rightExpression.nodeType === ParseNodeType.Call && this._fileInfo.isTypingStubFile) {
739
- // Some special built-in types defined in typing.pyi use
740
- // assignments of the form List = _Alias(). We don't want to
741
- // treat these as type aliases.
742
- isPossibleTypeAlias = false;
743
- } else if (ParseTreeUtils.isWithinLoop(node)) {
744
- // Assume that it's not a type alias if it's within a loop.
745
- isPossibleTypeAlias = false;
746
- }
747
-
748
- this._addInferredTypeAssignmentForVariable(node.leftExpression, node.rightExpression, isPossibleTypeAlias);
749
-
750
- // If we didn't create assignment target flow nodes above, do so now.
751
- if (!createdAssignmentTargetFlowNodes) {
752
- this._createAssignmentTargetFlowNodes(node.leftExpression, /* walkTargets */ true, /* unbound */ false);
753
- }
754
-
755
- // Is this an assignment to dunder all?
756
- if (this._currentScope.type === ScopeType.Module) {
757
- if (
758
- (node.leftExpression.nodeType === ParseNodeType.Name && node.leftExpression.value === '__all__') ||
759
- (node.leftExpression.nodeType === ParseNodeType.TypeAnnotation &&
760
- node.leftExpression.valueExpression.nodeType === ParseNodeType.Name &&
761
- node.leftExpression.valueExpression.value === '__all__')
762
- ) {
763
- const expr = node.rightExpression;
764
- this._dunderAllNames = [];
765
- let emitDunderAllWarning = false;
766
-
767
- if (expr.nodeType === ParseNodeType.List) {
768
- expr.entries.forEach((listEntryNode) => {
769
- if (
770
- listEntryNode.nodeType === ParseNodeType.StringList &&
771
- listEntryNode.strings.length === 1 &&
772
- listEntryNode.strings[0].nodeType === ParseNodeType.String
773
- ) {
774
- this._dunderAllNames!.push(listEntryNode.strings[0].value);
775
- this._dunderAllStringNodes.push(listEntryNode.strings[0]);
776
- } else {
777
- emitDunderAllWarning = true;
778
- }
779
- });
780
- } else if (expr.nodeType === ParseNodeType.Tuple) {
781
- expr.expressions.forEach((tupleEntryNode) => {
782
- if (
783
- tupleEntryNode.nodeType === ParseNodeType.StringList &&
784
- tupleEntryNode.strings.length === 1 &&
785
- tupleEntryNode.strings[0].nodeType === ParseNodeType.String
786
- ) {
787
- this._dunderAllNames!.push(tupleEntryNode.strings[0].value);
788
- this._dunderAllStringNodes.push(tupleEntryNode.strings[0]);
789
- } else {
790
- emitDunderAllWarning = true;
791
- }
792
- });
793
- } else {
794
- emitDunderAllWarning = true;
795
- }
796
-
797
- if (emitDunderAllWarning) {
798
- this._usesUnsupportedDunderAllForm = true;
799
-
800
- this._addDiagnostic(
801
- this._fileInfo.diagnosticRuleSet.reportUnsupportedDunderAll,
802
- DiagnosticRule.reportUnsupportedDunderAll,
803
- Localizer.Diagnostic.unsupportedDunderAllOperation(),
804
- node
805
- );
806
- }
807
- }
808
- }
809
-
810
- // Is this an assignment to dunder slots?
811
- if (this._currentScope.type === ScopeType.Class) {
812
- if (
813
- (node.leftExpression.nodeType === ParseNodeType.Name && node.leftExpression.value === '__slots__') ||
814
- (node.leftExpression.nodeType === ParseNodeType.TypeAnnotation &&
815
- node.leftExpression.valueExpression.nodeType === ParseNodeType.Name &&
816
- node.leftExpression.valueExpression.value === '__slots__')
817
- ) {
818
- const expr = node.rightExpression;
819
- this._dunderSlotsEntries = [];
820
- let isExpressionUnderstood = true;
821
-
822
- if (expr.nodeType === ParseNodeType.StringList) {
823
- this._dunderSlotsEntries.push(expr);
824
- } else if (expr.nodeType === ParseNodeType.List) {
825
- expr.entries.forEach((listEntryNode) => {
826
- if (
827
- listEntryNode.nodeType === ParseNodeType.StringList &&
828
- listEntryNode.strings.length === 1 &&
829
- listEntryNode.strings[0].nodeType === ParseNodeType.String
830
- ) {
831
- this._dunderSlotsEntries!.push(listEntryNode);
832
- } else {
833
- isExpressionUnderstood = false;
834
- }
835
- });
836
- } else if (expr.nodeType === ParseNodeType.Tuple) {
837
- expr.expressions.forEach((tupleEntryNode) => {
838
- if (
839
- tupleEntryNode.nodeType === ParseNodeType.StringList &&
840
- tupleEntryNode.strings.length === 1 &&
841
- tupleEntryNode.strings[0].nodeType === ParseNodeType.String
842
- ) {
843
- this._dunderSlotsEntries!.push(tupleEntryNode);
844
- } else {
845
- isExpressionUnderstood = false;
846
- }
847
- });
848
- } else {
849
- isExpressionUnderstood = false;
850
- }
851
-
852
- if (!isExpressionUnderstood) {
853
- this._dunderSlotsEntries = undefined;
854
- }
855
- }
856
- }
857
-
858
- return false;
859
- }
860
-
861
- override visitAssignmentExpression(node: AssignmentExpressionNode) {
862
- // Temporarily disable true/false targets in case this assignment
863
- // expression is located within an if/else conditional.
864
- this._disableTrueFalseTargets(() => {
865
- // Evaluate the operand expression.
866
- this.walk(node.rightExpression);
867
- });
868
-
869
- const evaluationNode = ParseTreeUtils.getEvaluationNodeForAssignmentExpression(node);
870
- if (!evaluationNode) {
871
- this._addError(Localizer.Diagnostic.assignmentExprContext(), node);
872
- this.walk(node.name);
873
- } else {
874
- // Bind the name to the containing scope. This special logic is required
875
- // because of the behavior defined in PEP 572. Targets of assignment
876
- // expressions don't bind to a list comprehension's scope but instead
877
- // bind to its containing scope.
878
- const containerScope = AnalyzerNodeInfo.getScope(evaluationNode)!;
879
-
880
- // If we're in a list comprehension (possibly nested), make sure that
881
- // local for targets don't collide with the target of the assignment
882
- // expression.
883
- let curScope: Scope | undefined = this._currentScope;
884
- while (curScope && curScope !== containerScope) {
885
- const localSymbol = curScope.lookUpSymbol(node.name.value);
886
- if (localSymbol) {
887
- this._addError(
888
- Localizer.Diagnostic.assignmentExprComprehension().format({ name: node.name.value }),
889
- node.name
890
- );
891
- break;
892
- }
893
-
894
- curScope = curScope.parent;
895
- }
896
-
897
- this._bindNameToScope(containerScope, node.name.value);
898
- this._addInferredTypeAssignmentForVariable(node.name, node.rightExpression);
899
- this._createAssignmentTargetFlowNodes(node.name, /* walkTargets */ true, /* unbound */ false);
900
- }
901
-
902
- return false;
903
- }
904
-
905
- override visitAugmentedAssignment(node: AugmentedAssignmentNode) {
906
- this.walk(node.leftExpression);
907
- this.walk(node.rightExpression);
908
-
909
- this._bindPossibleTupleNamedTarget(node.destExpression);
910
- this._createAssignmentTargetFlowNodes(node.destExpression, /* walkTargets */ false, /* unbound */ false);
911
-
912
- // Is this an assignment to dunder all of the form
913
- // __all__ += <expression>?
914
- if (
915
- node.operator === OperatorType.AddEqual &&
916
- this._currentScope.type === ScopeType.Module &&
917
- node.leftExpression.nodeType === ParseNodeType.Name &&
918
- node.leftExpression.value === '__all__'
919
- ) {
920
- const expr = node.rightExpression;
921
- let emitDunderAllWarning = true;
922
-
923
- if (expr.nodeType === ParseNodeType.List) {
924
- // Is this the form __all__ += ["a", "b"]?
925
- expr.entries.forEach((listEntryNode) => {
926
- if (
927
- listEntryNode.nodeType === ParseNodeType.StringList &&
928
- listEntryNode.strings.length === 1 &&
929
- listEntryNode.strings[0].nodeType === ParseNodeType.String
930
- ) {
931
- this._dunderAllNames?.push(listEntryNode.strings[0].value);
932
- this._dunderAllStringNodes.push(listEntryNode.strings[0]);
933
- }
934
- });
935
- emitDunderAllWarning = false;
936
- } else if (
937
- expr.nodeType === ParseNodeType.MemberAccess &&
938
- expr.leftExpression.nodeType === ParseNodeType.Name &&
939
- expr.memberName.value === '__all__'
940
- ) {
941
- // Is this using the form "__all__ += <mod>.__all__"?
942
- const namesToAdd = this._getDunderAllNamesFromImport(expr.leftExpression.value);
943
- if (namesToAdd) {
944
- namesToAdd.forEach((name) => {
945
- this._dunderAllNames?.push(name);
946
- });
947
-
948
- emitDunderAllWarning = false;
949
- }
950
- }
951
-
952
- if (emitDunderAllWarning) {
953
- this._usesUnsupportedDunderAllForm = true;
954
-
955
- this._addDiagnostic(
956
- this._fileInfo.diagnosticRuleSet.reportUnsupportedDunderAll,
957
- DiagnosticRule.reportUnsupportedDunderAll,
958
- Localizer.Diagnostic.unsupportedDunderAllOperation(),
959
- node
960
- );
961
- }
962
- }
963
-
964
- return false;
965
- }
966
-
967
- override visitDel(node: DelNode) {
968
- node.expressions.forEach((expr) => {
969
- this._bindPossibleTupleNamedTarget(expr);
970
- this.walk(expr);
971
- this._createAssignmentTargetFlowNodes(expr, /* walkTargets */ false, /* unbound */ true);
972
- });
973
-
974
- return false;
975
- }
976
-
977
- override visitTypeAnnotation(node: TypeAnnotationNode): boolean {
978
- if (this._handleTypingStubAssignmentOrAnnotation(node)) {
979
- return false;
980
- }
981
-
982
- // Walk the type annotation first so it is "before" the target
983
- // in the code flow graph.
984
- this.walk(node.typeAnnotation);
985
- this._createVariableAnnotationFlowNode();
986
-
987
- this._bindPossibleTupleNamedTarget(node.valueExpression);
988
- this._addTypeDeclarationForVariable(node.valueExpression, node.typeAnnotation);
989
-
990
- // For type annotations that are not part of assignments (e.g. simple variable
991
- // annotations), we need to populate the reference map. Otherwise the type
992
- // analyzer's code flow engine won't run and detect cases where the variable
993
- // is unbound.
994
- const expressionList: CodeFlowReferenceExpressionNode[] = [];
995
- if (this._isNarrowingExpression(node.valueExpression, expressionList)) {
996
- expressionList.forEach((expr) => {
997
- const referenceKey = createKeyForReference(expr);
998
- this._currentScopeCodeFlowExpressions!.add(referenceKey);
999
- });
1000
- }
1001
-
1002
- this.walk(node.valueExpression);
1003
- return false;
1004
- }
1005
-
1006
- override visitFor(node: ForNode) {
1007
- this._bindPossibleTupleNamedTarget(node.targetExpression);
1008
- this._addInferredTypeAssignmentForVariable(node.targetExpression, node);
1009
-
1010
- this.walk(node.iterableExpression);
1011
-
1012
- const preForLabel = this._createLoopLabel();
1013
- const preElseLabel = this._createBranchLabel();
1014
- const postForLabel = this._createBranchLabel();
1015
-
1016
- this._addAntecedent(preForLabel, this._currentFlowNode!);
1017
- this._currentFlowNode = preForLabel;
1018
- this._addAntecedent(preElseLabel, this._currentFlowNode);
1019
- this._createAssignmentTargetFlowNodes(node.targetExpression, /* walkTargets */ true, /* unbound */ false);
1020
-
1021
- this._bindLoopStatement(preForLabel, postForLabel, () => {
1022
- this.walk(node.forSuite);
1023
- this._addAntecedent(preForLabel, this._currentFlowNode!);
1024
- });
1025
-
1026
- this._currentFlowNode = this._finishFlowLabel(preElseLabel);
1027
- if (node.elseSuite) {
1028
- this.walk(node.elseSuite);
1029
- }
1030
- this._addAntecedent(postForLabel, this._currentFlowNode);
1031
-
1032
- this._currentFlowNode = this._finishFlowLabel(postForLabel);
1033
-
1034
- if (node.asyncToken) {
1035
- const enclosingFunction = ParseTreeUtils.getEnclosingFunction(node);
1036
- if (!enclosingFunction || !enclosingFunction.isAsync) {
1037
- this._addError(Localizer.Diagnostic.asyncNotInAsyncFunction(), node.asyncToken);
1038
- }
1039
- }
1040
-
1041
- return false;
1042
- }
1043
-
1044
- override visitContinue(node: ContinueNode): boolean {
1045
- if (this._currentContinueTarget) {
1046
- this._addAntecedent(this._currentContinueTarget, this._currentFlowNode!);
1047
- }
1048
- this._currentFlowNode = Binder._unreachableFlowNode;
1049
-
1050
- // Continue nodes don't have any children.
1051
- return false;
1052
- }
1053
-
1054
- override visitBreak(node: BreakNode): boolean {
1055
- if (this._currentBreakTarget) {
1056
- this._addAntecedent(this._currentBreakTarget, this._currentFlowNode!);
1057
- }
1058
- this._currentFlowNode = Binder._unreachableFlowNode;
1059
-
1060
- // Break nodes don't have any children.
1061
- return false;
1062
- }
1063
-
1064
- override visitReturn(node: ReturnNode): boolean {
1065
- if (this._targetFunctionDeclaration) {
1066
- if (!this._targetFunctionDeclaration.returnStatements) {
1067
- this._targetFunctionDeclaration.returnStatements = [];
1068
- }
1069
- this._targetFunctionDeclaration.returnStatements.push(node);
1070
- }
1071
-
1072
- if (node.returnExpression) {
1073
- this.walk(node.returnExpression);
1074
- }
1075
-
1076
- AnalyzerNodeInfo.setFlowNode(node, this._currentFlowNode!);
1077
- if (this._currentReturnTarget) {
1078
- this._addAntecedent(this._currentReturnTarget, this._currentFlowNode!);
1079
- }
1080
- this._finallyTargets.forEach((target) => {
1081
- this._addAntecedent(target, this._currentFlowNode!);
1082
- });
1083
- this._currentFlowNode = Binder._unreachableFlowNode;
1084
- return false;
1085
- }
1086
-
1087
- override visitYield(node: YieldNode): boolean {
1088
- if (this._isInListComprehension(node, /* ignoreOutermostIterable */ true)) {
1089
- this._addError(Localizer.Diagnostic.yieldWithinListCompr(), node);
1090
- }
1091
-
1092
- this._bindYield(node);
1093
- return false;
1094
- }
1095
-
1096
- override visitYieldFrom(node: YieldFromNode): boolean {
1097
- if (this._isInListComprehension(node, /* ignoreOutermostIterable */ true)) {
1098
- this._addError(Localizer.Diagnostic.yieldWithinListCompr(), node);
1099
- }
1100
-
1101
- this._bindYield(node);
1102
- return false;
1103
- }
1104
-
1105
- override visitMemberAccess(node: MemberAccessNode): boolean {
1106
- this.walk(node.leftExpression);
1107
- AnalyzerNodeInfo.setFlowNode(node, this._currentFlowNode!);
1108
- return false;
1109
- }
1110
-
1111
- override visitName(node: NameNode): boolean {
1112
- AnalyzerNodeInfo.setFlowNode(node, this._currentFlowNode!);
1113
-
1114
- // Name nodes have no children.
1115
- return false;
1116
- }
1117
-
1118
- override visitIndex(node: IndexNode): boolean {
1119
- AnalyzerNodeInfo.setFlowNode(node, this._currentFlowNode!);
1120
- return true;
1121
- }
1122
-
1123
- override visitIf(node: IfNode): boolean {
1124
- const preIfFlowNode = this._currentFlowNode!;
1125
- const thenLabel = this._createBranchLabel();
1126
- const elseLabel = this._createBranchLabel();
1127
- const postIfLabel = this._createBranchLabel(preIfFlowNode);
1128
-
1129
- postIfLabel.affectedExpressions = this._trackCodeFlowExpressions(() => {
1130
- // Determine if the test condition is always true or always false. If so,
1131
- // we can treat either the then or the else clause as unconditional.
1132
- const constExprValue = StaticExpressions.evaluateStaticBoolLikeExpression(
1133
- node.testExpression,
1134
- this._fileInfo.executionEnvironment,
1135
- this._fileInfo.definedConstants,
1136
- this._typingImportAliases,
1137
- this._sysImportAliases
1138
- );
1139
-
1140
- this._bindConditional(node.testExpression, thenLabel, elseLabel);
1141
-
1142
- // Handle the if clause.
1143
- this._currentFlowNode =
1144
- constExprValue === false ? Binder._unreachableFlowNode : this._finishFlowLabel(thenLabel);
1145
- this.walk(node.ifSuite);
1146
- this._addAntecedent(postIfLabel, this._currentFlowNode);
1147
-
1148
- // Now handle the else clause if it's present. If there
1149
- // are chained "else if" statements, they'll be handled
1150
- // recursively here.
1151
- this._currentFlowNode =
1152
- constExprValue === true ? Binder._unreachableFlowNode : this._finishFlowLabel(elseLabel);
1153
- if (node.elseSuite) {
1154
- this.walk(node.elseSuite);
1155
- } else {
1156
- this._bindNeverCondition(node.testExpression, postIfLabel, /* isPositiveTest */ false);
1157
- }
1158
- this._addAntecedent(postIfLabel, this._currentFlowNode);
1159
- this._currentFlowNode = this._finishFlowLabel(postIfLabel);
1160
- });
1161
-
1162
- return false;
1163
- }
1164
-
1165
- override visitWhile(node: WhileNode): boolean {
1166
- const thenLabel = this._createBranchLabel();
1167
- const elseLabel = this._createBranchLabel();
1168
- const postWhileLabel = this._createBranchLabel();
1169
-
1170
- // Determine if the test condition is always true or always false. If so,
1171
- // we can treat either the while or the else clause as unconditional.
1172
- const constExprValue = StaticExpressions.evaluateStaticBoolLikeExpression(
1173
- node.testExpression,
1174
- this._fileInfo.executionEnvironment,
1175
- this._fileInfo.definedConstants,
1176
- this._typingImportAliases,
1177
- this._sysImportAliases
1178
- );
1179
-
1180
- const preLoopLabel = this._createLoopLabel();
1181
- this._addAntecedent(preLoopLabel, this._currentFlowNode!);
1182
- this._currentFlowNode = preLoopLabel;
1183
-
1184
- this._bindConditional(node.testExpression, thenLabel, elseLabel);
1185
-
1186
- // Handle the while clause.
1187
- this._currentFlowNode =
1188
- constExprValue === false ? Binder._unreachableFlowNode : this._finishFlowLabel(thenLabel);
1189
- this._bindLoopStatement(preLoopLabel, postWhileLabel, () => {
1190
- this.walk(node.whileSuite);
1191
- });
1192
- this._addAntecedent(preLoopLabel, this._currentFlowNode);
1193
-
1194
- this._currentFlowNode =
1195
- constExprValue === true ? Binder._unreachableFlowNode : this._finishFlowLabel(elseLabel);
1196
- if (node.elseSuite) {
1197
- this.walk(node.elseSuite);
1198
- }
1199
- this._addAntecedent(postWhileLabel, this._currentFlowNode);
1200
- this._currentFlowNode = this._finishFlowLabel(postWhileLabel);
1201
- return false;
1202
- }
1203
-
1204
- override visitAssert(node: AssertNode): boolean {
1205
- const assertTrueLabel = this._createBranchLabel();
1206
- const assertFalseLabel = this._createBranchLabel();
1207
-
1208
- this._bindConditional(node.testExpression, assertTrueLabel, assertFalseLabel);
1209
-
1210
- if (node.exceptionExpression) {
1211
- this._currentFlowNode = this._finishFlowLabel(assertFalseLabel);
1212
- this.walk(node.exceptionExpression);
1213
- }
1214
-
1215
- this._currentFlowNode = this._finishFlowLabel(assertTrueLabel);
1216
- return false;
1217
- }
1218
-
1219
- override visitExcept(node: ExceptNode): boolean {
1220
- if (node.typeExpression) {
1221
- this.walk(node.typeExpression);
1222
- }
1223
-
1224
- if (node.name) {
1225
- this.walk(node.name);
1226
- const symbol = this._bindNameToScope(this._currentScope, node.name.value);
1227
- this._createAssignmentTargetFlowNodes(node.name, /* walkTargets */ true, /* unbound */ false);
1228
-
1229
- if (symbol) {
1230
- const declaration: VariableDeclaration = {
1231
- type: DeclarationType.Variable,
1232
- node: node.name,
1233
- isConstant: isConstantName(node.name.value),
1234
- inferredTypeSource: node,
1235
- path: this._fileInfo.filePath,
1236
- range: convertOffsetsToRange(node.name.start, TextRange.getEnd(node.name), this._fileInfo.lines),
1237
- moduleName: this._fileInfo.moduleName,
1238
- isInExceptSuite: this._isInExceptSuite,
1239
- };
1240
- symbol.addDeclaration(declaration);
1241
- }
1242
- }
1243
-
1244
- const wasInExceptSuite = this._isInExceptSuite;
1245
- this._isInExceptSuite = true;
1246
- this.walk(node.exceptSuite);
1247
- this._isInExceptSuite = wasInExceptSuite;
1248
-
1249
- if (node.name) {
1250
- // The exception name is implicitly unbound at the end of
1251
- // the except block.
1252
- this._createFlowAssignment(node.name, /* unbound */ true);
1253
- }
1254
-
1255
- return false;
1256
- }
1257
-
1258
- override visitRaise(node: RaiseNode): boolean {
1259
- if (this._targetFunctionDeclaration) {
1260
- if (!this._targetFunctionDeclaration.raiseStatements) {
1261
- this._targetFunctionDeclaration.raiseStatements = [];
1262
- }
1263
- this._targetFunctionDeclaration.raiseStatements.push(node);
1264
- }
1265
-
1266
- if (node.typeExpression) {
1267
- this.walk(node.typeExpression);
1268
- }
1269
- if (node.valueExpression) {
1270
- this.walk(node.valueExpression);
1271
- }
1272
- if (node.tracebackExpression) {
1273
- this.walk(node.tracebackExpression);
1274
- }
1275
-
1276
- this._finallyTargets.forEach((target) => {
1277
- this._addAntecedent(target, this._currentFlowNode!);
1278
- });
1279
-
1280
- this._currentFlowNode = Binder._unreachableFlowNode;
1281
- return false;
1282
- }
1283
-
1284
- override visitTry(node: TryNode): boolean {
1285
- // The try/except/else/finally statement is tricky to model using static code
1286
- // flow rules because the finally clause is executed regardless of whether an
1287
- // exception is raised or a return statement is executed. Code within the finally
1288
- // clause needs to be reachable always, and we conservatively assume that any
1289
- // statement within the try block can generate an exception, so we assume that its
1290
- // antecedent is the pre-try flow. We implement this with a "gate" node in the
1291
- // control flow graph. If analysis starts within the finally clause, the gate is
1292
- // opened, and all raise/return statements within try/except/else blocks are
1293
- // considered antecedents. If analysis starts outside (after) the finally clause,
1294
- // the gate is closed, and only paths that don't hit a raise/return statement
1295
- // in try/except/else blocks are considered.
1296
- //
1297
- //
1298
- // 1. PostElse
1299
- // ^
1300
- // |
1301
- // 3. TryExceptElseReturnOrExcept |
1302
- // ^ |
1303
- // | | 2. PostExcept (for each except)
1304
- // | | ^
1305
- // 4. ReturnOrRaiseLabel | |
1306
- // ^ | |
1307
- // | | |---------
1308
- // 5. PreFinallyGate | |
1309
- // ^ | |
1310
- // |------------------ | |
1311
- // | | |
1312
- // 6. PreFinallyLabel
1313
- // ^
1314
- // (finally block)
1315
- // ^
1316
- // 7. PostFinally
1317
- // ^ (only if isAfterElseAndExceptsReachable)
1318
- // (after finally)
1319
-
1320
- // Create one flow label for every except clause.
1321
- const preTryFlowNode = this._currentFlowNode!;
1322
- const curExceptTargets = node.exceptClauses.map(() => this._createBranchLabel());
1323
- const preFinallyLabel = this._createBranchLabel(preTryFlowNode);
1324
- let isAfterElseAndExceptsReachable = false;
1325
-
1326
- // Create a label for all of the return or raise labels that are
1327
- // encountered within the try/except/else blocks. This conditionally
1328
- // connects the return/raise statement to the finally clause.
1329
- const preFinallyReturnOrRaiseLabel = this._createBranchLabel(preTryFlowNode);
1330
-
1331
- const preFinallyGate: FlowPreFinallyGate = {
1332
- flags: FlowFlags.PreFinallyGate,
1333
- id: this._getUniqueFlowNodeId(),
1334
- antecedent: preFinallyReturnOrRaiseLabel,
1335
- isGateClosed: false,
1336
- };
1337
-
1338
- preFinallyLabel.affectedExpressions = this._trackCodeFlowExpressions(() => {
1339
- if (node.finallySuite) {
1340
- this._addAntecedent(preFinallyLabel, preFinallyGate);
1341
- }
1342
-
1343
- // Add the finally target as an exception target unless there is
1344
- // a "bare" except clause that accepts all exception types.
1345
- const hasBareExceptClause = node.exceptClauses.some((except) => !except.typeExpression);
1346
- if (!hasBareExceptClause) {
1347
- curExceptTargets.push(preFinallyReturnOrRaiseLabel);
1348
- }
1349
-
1350
- // An exception may be generated before the first flow node
1351
- // added by the try block, so all of the exception targets
1352
- // must have the pre-try flow node as an antecedent.
1353
- curExceptTargets.forEach((exceptLabel) => {
1354
- this._addAntecedent(exceptLabel, this._currentFlowNode!);
1355
- });
1356
-
1357
- // We don't perfectly handle nested finally clauses, which are not
1358
- // possible to model fully within a static analyzer, but we do handle
1359
- // a single level of finally statements, and we handle most cases
1360
- // involving nesting. Returns or raises within the try/except/raise
1361
- // block will execute the finally target(s).
1362
- if (node.finallySuite) {
1363
- this._finallyTargets.push(preFinallyReturnOrRaiseLabel);
1364
- }
1365
-
1366
- // Handle the try block.
1367
- this._useExceptTargets(curExceptTargets, () => {
1368
- this.walk(node.trySuite);
1369
- });
1370
-
1371
- // Handle the else block, which is executed only if
1372
- // execution falls through the try block.
1373
- if (node.elseSuite) {
1374
- this.walk(node.elseSuite);
1375
- }
1376
- this._addAntecedent(preFinallyLabel, this._currentFlowNode!);
1377
- if (!this._isCodeUnreachable()) {
1378
- isAfterElseAndExceptsReachable = true;
1379
- }
1380
-
1381
- // Handle the except blocks.
1382
- node.exceptClauses.forEach((exceptNode, index) => {
1383
- this._currentFlowNode = this._finishFlowLabel(curExceptTargets[index]);
1384
- this.walk(exceptNode);
1385
- this._addAntecedent(preFinallyLabel, this._currentFlowNode);
1386
- if (!this._isCodeUnreachable()) {
1387
- isAfterElseAndExceptsReachable = true;
1388
- }
1389
- });
1390
-
1391
- if (node.finallySuite) {
1392
- this._finallyTargets.pop();
1393
- }
1394
-
1395
- // Handle the finally block.
1396
- this._currentFlowNode = this._finishFlowLabel(preFinallyLabel);
1397
- });
1398
-
1399
- if (node.finallySuite) {
1400
- this.walk(node.finallySuite);
1401
-
1402
- // Add a post-finally node at the end. If we traverse this node,
1403
- // we'll set the "ignore" flag in the pre-finally node.
1404
- const postFinallyNode: FlowPostFinally = {
1405
- flags: FlowFlags.PostFinally,
1406
- id: this._getUniqueFlowNodeId(),
1407
- finallyNode: node.finallySuite,
1408
- antecedent: this._currentFlowNode!,
1409
- preFinallyGate,
1410
- };
1411
- this._currentFlowNode = isAfterElseAndExceptsReachable ? postFinallyNode : Binder._unreachableFlowNode;
1412
- }
1413
-
1414
- return false;
1415
- }
1416
-
1417
- override visitAwait(node: AwaitNode) {
1418
- // Make sure this is within an async lambda or function.
1419
- const enclosingFunction = ParseTreeUtils.getEnclosingFunction(node);
1420
- if (enclosingFunction === undefined || !enclosingFunction.isAsync) {
1421
- if (this._fileInfo.isIPythonMode && enclosingFunction === undefined) {
1422
- // Top level await is allowed in ipython mode.
1423
- return true;
1424
- }
1425
-
1426
- // Allow if it's within a generator expression. Execution of
1427
- // generator expressions is deferred and therefore can be
1428
- // run within the context of an async function later.
1429
- if (node.parent?.nodeType !== ParseNodeType.ListComprehension) {
1430
- this._addError(Localizer.Diagnostic.awaitNotInAsync(), node);
1431
- }
1432
- }
1433
-
1434
- return true;
1435
- }
1436
-
1437
- override visitGlobal(node: GlobalNode): boolean {
1438
- const globalScope = this._currentScope.getGlobalScope().scope;
1439
-
1440
- node.nameList.forEach((name) => {
1441
- const nameValue = name.value;
1442
-
1443
- // Is the binding inconsistent?
1444
- if (this._currentScope.getBindingType(nameValue) === NameBindingType.Nonlocal) {
1445
- this._addError(Localizer.Diagnostic.nonLocalRedefinition().format({ name: nameValue }), name);
1446
- }
1447
-
1448
- const valueWithScope = this._currentScope.lookUpSymbolRecursive(nameValue);
1449
-
1450
- // Was the name already assigned within this scope before it was declared global?
1451
- if (valueWithScope && valueWithScope.scope === this._currentScope) {
1452
- this._addError(Localizer.Diagnostic.globalReassignment().format({ name: nameValue }), name);
1453
- }
1454
-
1455
- // Add it to the global scope if it's not already added.
1456
- this._bindNameToScope(globalScope, nameValue);
1457
-
1458
- if (this._currentScope !== globalScope) {
1459
- this._currentScope.setBindingType(nameValue, NameBindingType.Global);
1460
- }
1461
- });
1462
-
1463
- return true;
1464
- }
1465
-
1466
- override visitNonlocal(node: NonlocalNode): boolean {
1467
- const globalScope = this._currentScope.getGlobalScope().scope;
1468
-
1469
- if (this._currentScope === globalScope) {
1470
- this._addError(Localizer.Diagnostic.nonLocalInModule(), node);
1471
- } else {
1472
- node.nameList.forEach((name) => {
1473
- const nameValue = name.value;
1474
-
1475
- // Is the binding inconsistent?
1476
- if (this._currentScope.getBindingType(nameValue) === NameBindingType.Global) {
1477
- this._addError(Localizer.Diagnostic.globalRedefinition().format({ name: nameValue }), name);
1478
- }
1479
-
1480
- const valueWithScope = this._currentScope.lookUpSymbolRecursive(nameValue);
1481
-
1482
- // Was the name already assigned within this scope before it was declared nonlocal?
1483
- if (valueWithScope && valueWithScope.scope === this._currentScope) {
1484
- this._addError(Localizer.Diagnostic.nonLocalReassignment().format({ name: nameValue }), name);
1485
- } else if (!valueWithScope || valueWithScope.scope === globalScope) {
1486
- this._addError(Localizer.Diagnostic.nonLocalNoBinding().format({ name: nameValue }), name);
1487
- }
1488
-
1489
- if (valueWithScope) {
1490
- this._currentScope.setBindingType(nameValue, NameBindingType.Nonlocal);
1491
- }
1492
- });
1493
- }
1494
-
1495
- return true;
1496
- }
1497
-
1498
- override visitImportAs(node: ImportAsNode): boolean {
1499
- if (node.module.nameParts.length > 0) {
1500
- const firstNamePartValue = node.module.nameParts[0].value;
1501
-
1502
- let symbolName: string | undefined;
1503
- if (node.alias) {
1504
- // The symbol name is defined by the alias.
1505
- symbolName = node.alias.value;
1506
- } else {
1507
- // There was no alias, so we need to use the first element of
1508
- // the name parts as the symbol.
1509
- symbolName = firstNamePartValue;
1510
- }
1511
-
1512
- const symbol = this._bindNameToScope(this._currentScope, symbolName);
1513
- if (
1514
- symbol &&
1515
- (this._currentScope.type === ScopeType.Module || this._currentScope.type === ScopeType.Builtin) &&
1516
- (!node.alias ||
1517
- node.module.nameParts.length !== 1 ||
1518
- node.module.nameParts[0].value !== node.alias.value)
1519
- ) {
1520
- if (this._fileInfo.isStubFile || this._fileInfo.isInPyTypedPackage) {
1521
- // PEP 484 indicates that imported symbols should not be
1522
- // considered "reexported" from a type stub file unless
1523
- // they are imported using the "as" form and the aliased
1524
- // name is entirely redundant.
1525
- this._potentialHiddenSymbols.set(symbolName, symbol);
1526
- }
1527
- }
1528
-
1529
- const importInfo = AnalyzerNodeInfo.getImportInfo(node.module);
1530
- assert(importInfo !== undefined);
1531
-
1532
- if (symbol) {
1533
- this._createAliasDeclarationForMultipartImportName(node, node.alias, importInfo, symbol);
1534
- }
1535
-
1536
- this._createFlowAssignment(node.alias ? node.alias : node.module.nameParts[0]);
1537
-
1538
- if (node.module.nameParts.length === 1) {
1539
- if (firstNamePartValue === 'typing' || firstNamePartValue === 'typing_extensions') {
1540
- this._typingImportAliases.push(node.alias?.value ?? firstNamePartValue);
1541
- } else if (firstNamePartValue === 'sys') {
1542
- this._sysImportAliases.push(node.alias?.value ?? firstNamePartValue);
1543
- } else if (firstNamePartValue === 'dataclasses') {
1544
- this._dataclassesImportAliases.push(node.alias?.value ?? firstNamePartValue);
1545
- }
1546
- }
1547
- }
1548
-
1549
- return true;
1550
- }
1551
-
1552
- override visitImportFrom(node: ImportFromNode): boolean {
1553
- const typingSymbolsOfInterest = ['Final', 'TypeAlias', 'ClassVar', 'Required', 'NotRequired', 'Annotated'];
1554
- const dataclassesSymbolsOfInterest = ['InitVar'];
1555
- const importInfo = AnalyzerNodeInfo.getImportInfo(node.module);
1556
-
1557
- let resolvedPath = '';
1558
- if (importInfo && importInfo.isImportFound && !importInfo.isNativeLib) {
1559
- resolvedPath = importInfo.resolvedPaths[importInfo.resolvedPaths.length - 1];
1560
- }
1561
-
1562
- // If this file is a module __init__.py(i), relative imports of submodules
1563
- // using the syntax "from .x import y" introduce a symbol x into the
1564
- // module namespace. We do this first (before adding the individual imported
1565
- // symbols below) in case one of the imported symbols is the same name as the
1566
- // submodule. In that case, we want to the symbol to appear later in the
1567
- // declaration list because it should "win" when resolving the alias.
1568
- const fileName = stripFileExtension(getFileName(this._fileInfo.filePath));
1569
- const isModuleInitFile =
1570
- fileName === '__init__' && node.module.leadingDots === 1 && node.module.nameParts.length === 1;
1571
-
1572
- let isTypingImport = false;
1573
- let isDataclassesImport = false;
1574
-
1575
- if (node.module.nameParts.length === 1) {
1576
- const firstNamePartValue = node.module.nameParts[0].value;
1577
- if (firstNamePartValue === 'typing' || firstNamePartValue === 'typing_extensions') {
1578
- isTypingImport = true;
1579
- }
1580
-
1581
- if (firstNamePartValue === 'dataclasses') {
1582
- isDataclassesImport = true;
1583
- }
1584
- }
1585
-
1586
- if (node.isWildcardImport) {
1587
- if (ParseTreeUtils.getEnclosingClass(node) || ParseTreeUtils.getEnclosingFunction(node)) {
1588
- this._addError(Localizer.Diagnostic.wildcardInFunction(), node);
1589
- }
1590
-
1591
- if (importInfo) {
1592
- const names: string[] = [];
1593
-
1594
- const lookupInfo = this._fileInfo.importLookup(resolvedPath);
1595
- if (lookupInfo) {
1596
- const wildcardNames = this._getWildcardImportNames(lookupInfo);
1597
-
1598
- if (isModuleInitFile) {
1599
- // If the symbol is going to be immediately replaced with a same-named
1600
- // imported symbol, skip this.
1601
- const isImmediatelyReplaced = wildcardNames.some((name) => {
1602
- return name === node.module.nameParts[0].value;
1603
- });
1604
-
1605
- if (!isImmediatelyReplaced) {
1606
- this._addImplicitFromImport(node, importInfo);
1607
- }
1608
- }
1609
-
1610
- wildcardNames.forEach((name) => {
1611
- const localSymbol = this._bindNameToScope(this._currentScope, name);
1612
-
1613
- if (localSymbol) {
1614
- const importedSymbol = lookupInfo.symbolTable.get(name)!;
1615
-
1616
- // Is the symbol in the target module's symbol table? If so,
1617
- // alias it.
1618
- if (importedSymbol) {
1619
- const aliasDecl: AliasDeclaration = {
1620
- type: DeclarationType.Alias,
1621
- node,
1622
- path: resolvedPath,
1623
- loadSymbolsFromPath: true,
1624
- range: getEmptyRange(),
1625
- usesLocalName: false,
1626
- symbolName: name,
1627
- moduleName: this._fileInfo.moduleName,
1628
- isInExceptSuite: this._isInExceptSuite,
1629
- };
1630
- localSymbol.addDeclaration(aliasDecl);
1631
- names.push(name);
1632
- } else {
1633
- // The symbol wasn't in the target module's symbol table. It's probably
1634
- // an implicitly-imported submodule referenced by __all__.
1635
- if (importInfo && importInfo.filteredImplicitImports) {
1636
- const implicitImport = importInfo.filteredImplicitImports.find(
1637
- (imp) => imp.name === name
1638
- );
1639
-
1640
- if (implicitImport) {
1641
- const submoduleFallback: AliasDeclaration = {
1642
- type: DeclarationType.Alias,
1643
- node,
1644
- path: implicitImport.path,
1645
- loadSymbolsFromPath: true,
1646
- range: getEmptyRange(),
1647
- usesLocalName: false,
1648
- moduleName: this._fileInfo.moduleName,
1649
- isInExceptSuite: this._isInExceptSuite,
1650
- };
1651
-
1652
- const aliasDecl: AliasDeclaration = {
1653
- type: DeclarationType.Alias,
1654
- node,
1655
- path: resolvedPath,
1656
- loadSymbolsFromPath: true,
1657
- usesLocalName: false,
1658
- symbolName: name,
1659
- submoduleFallback,
1660
- range: getEmptyRange(),
1661
- moduleName: this._fileInfo.moduleName,
1662
- isInExceptSuite: this._isInExceptSuite,
1663
- };
1664
-
1665
- localSymbol.addDeclaration(aliasDecl);
1666
- }
1667
- }
1668
- }
1669
- }
1670
- });
1671
- }
1672
-
1673
- this._createFlowWildcardImport(node, names);
1674
-
1675
- if (isTypingImport) {
1676
- typingSymbolsOfInterest.forEach((s) => {
1677
- this._typingSymbolAliases.set(s, s);
1678
- });
1679
- }
1680
-
1681
- if (isDataclassesImport) {
1682
- dataclassesSymbolsOfInterest.forEach((s) => {
1683
- this._dataclassesSymbolAliases.set(s, s);
1684
- });
1685
- }
1686
- }
1687
- } else {
1688
- if (isModuleInitFile) {
1689
- this._addImplicitFromImport(node, importInfo);
1690
- }
1691
-
1692
- node.imports.forEach((importSymbolNode) => {
1693
- const importedName = importSymbolNode.name.value;
1694
- const nameNode = importSymbolNode.alias || importSymbolNode.name;
1695
- const symbol = this._bindNameToScope(this._currentScope, nameNode.value);
1696
-
1697
- if (symbol) {
1698
- // All import statements of the form `from . import x` treat x
1699
- // as an externally-visible (not hidden) symbol.
1700
- if (node.module.nameParts.length > 0) {
1701
- if (
1702
- this._currentScope.type === ScopeType.Module ||
1703
- this._currentScope.type === ScopeType.Builtin
1704
- ) {
1705
- if (
1706
- !importSymbolNode.alias ||
1707
- importSymbolNode.alias.value !== importSymbolNode.name.value
1708
- ) {
1709
- if (this._fileInfo.isStubFile || this._fileInfo.isInPyTypedPackage) {
1710
- // PEP 484 indicates that imported symbols should not be
1711
- // considered "reexported" from a type stub file unless
1712
- // they are imported using the "as" form using a redundant form.
1713
- // Py.typed packages follow the same rule as PEP 484.
1714
- this._potentialHiddenSymbols.set(nameNode.value, symbol);
1715
- }
1716
- }
1717
- }
1718
- }
1719
-
1720
- // Is the import referring to an implicitly-imported module?
1721
- let implicitImport: ImplicitImport | undefined;
1722
- if (importInfo && importInfo.filteredImplicitImports) {
1723
- implicitImport = importInfo.filteredImplicitImports.find((imp) => imp.name === importedName);
1724
- }
1725
-
1726
- let submoduleFallback: AliasDeclaration | undefined;
1727
- let loadSymbolsFromPath = true;
1728
- if (implicitImport) {
1729
- submoduleFallback = {
1730
- type: DeclarationType.Alias,
1731
- node: importSymbolNode,
1732
- path: implicitImport.path,
1733
- loadSymbolsFromPath: true,
1734
- range: getEmptyRange(),
1735
- usesLocalName: false,
1736
- moduleName: this._fileInfo.moduleName,
1737
- isInExceptSuite: this._isInExceptSuite,
1738
- };
1739
-
1740
- // Handle the case of "from . import X" within an __init__ file.
1741
- // In this case, we want to always resolve to the submodule rather
1742
- // than the resolved path.
1743
- if (
1744
- fileName === '__init__' &&
1745
- node.module.leadingDots === 1 &&
1746
- node.module.nameParts.length === 0
1747
- ) {
1748
- loadSymbolsFromPath = false;
1749
- }
1750
- }
1751
-
1752
- const aliasDecl: AliasDeclaration = {
1753
- type: DeclarationType.Alias,
1754
- node: importSymbolNode,
1755
- path: resolvedPath,
1756
- loadSymbolsFromPath,
1757
- usesLocalName: !!importSymbolNode.alias,
1758
- symbolName: importedName,
1759
- submoduleFallback,
1760
- range: getEmptyRange(),
1761
- moduleName: this._fileInfo.moduleName,
1762
- isInExceptSuite: this._isInExceptSuite,
1763
- isNativeLib: importInfo?.isNativeLib,
1764
- };
1765
-
1766
- symbol.addDeclaration(aliasDecl);
1767
- this._createFlowAssignment(importSymbolNode.alias || importSymbolNode.name);
1768
-
1769
- if (isTypingImport) {
1770
- if (typingSymbolsOfInterest.some((s) => s === importSymbolNode.name.value)) {
1771
- this._typingSymbolAliases.set(nameNode.value, importSymbolNode.name.value);
1772
- }
1773
- }
1774
-
1775
- if (isDataclassesImport) {
1776
- if (dataclassesSymbolsOfInterest.some((s) => s === importSymbolNode.name.value)) {
1777
- this._dataclassesSymbolAliases.set(nameNode.value, importSymbolNode.name.value);
1778
- }
1779
- }
1780
- }
1781
- });
1782
- }
1783
-
1784
- return true;
1785
- }
1786
-
1787
- override visitWith(node: WithNode): boolean {
1788
- node.withItems.forEach((item) => {
1789
- this.walk(item.expression);
1790
- if (item.target) {
1791
- this._bindPossibleTupleNamedTarget(item.target);
1792
- this._addInferredTypeAssignmentForVariable(item.target, item);
1793
- this._createAssignmentTargetFlowNodes(item.target, /* walkTargets */ true, /* unbound */ false);
1794
- }
1795
- });
1796
-
1797
- // We need to treat the "with" body as though it is wrapped in a try/except
1798
- // block because some context managers catch and suppress exceptions.
1799
- // We'll make use of a special "context manager label" which acts like
1800
- // a regular branch label in most respects except that it is disabled
1801
- // if none of the context managers support exception suppression. We won't
1802
- // be able to determine whether any context managers support exception
1803
- // processing until the type evaluation phase.
1804
- //
1805
- // (pre with suite)
1806
- // ^
1807
- // |<--------------------|
1808
- // (with suite)<--------------|
1809
- // ^ |
1810
- // | ContextManagerSwallowExceptionTarget
1811
- // | ^
1812
- // | PostContextManagerLabel
1813
- // | ^
1814
- // |---------------------|
1815
- // |
1816
- // (after with)
1817
- //
1818
- // In addition to the ContextManagerSwallowExceptionTarget, we'll create
1819
- // a second target called ContextManagerForwardExceptionTarget that forwards
1820
- // exceptions to existing exception targets if they exist.
1821
-
1822
- const contextManagerSwallowExceptionTarget = this._createContextManagerLabel(
1823
- node.withItems.map((item) => item.expression),
1824
- !!node.isAsync,
1825
- /* blockIfSwallowsExceptions */ false
1826
- );
1827
- this._addAntecedent(contextManagerSwallowExceptionTarget, this._currentFlowNode!);
1828
-
1829
- const contextManagerForwardExceptionTarget = this._createContextManagerLabel(
1830
- node.withItems.map((item) => item.expression),
1831
- !!node.isAsync,
1832
- /* blockIfSwallowsExceptions */ true
1833
- );
1834
- this._currentExceptTargets.forEach((exceptionTarget) => {
1835
- this._addAntecedent(exceptionTarget, contextManagerForwardExceptionTarget);
1836
- });
1837
-
1838
- const preWithSuiteNode = this._currentFlowNode!;
1839
- const postContextManagerLabel = this._createBranchLabel(preWithSuiteNode);
1840
- this._addAntecedent(postContextManagerLabel, contextManagerSwallowExceptionTarget!);
1841
-
1842
- postContextManagerLabel.affectedExpressions = this._trackCodeFlowExpressions(() => {
1843
- this._useExceptTargets([contextManagerSwallowExceptionTarget, contextManagerForwardExceptionTarget], () => {
1844
- this.walk(node.suite);
1845
- });
1846
-
1847
- this._addAntecedent(postContextManagerLabel, this._currentFlowNode!);
1848
- this._currentFlowNode = postContextManagerLabel;
1849
-
1850
- // Model the call to `__exit__` as a potential exception generator.
1851
- if (!this._isCodeUnreachable()) {
1852
- this._addExceptTargets(this._currentFlowNode!);
1853
- }
1854
-
1855
- if (node.asyncToken) {
1856
- const enclosingFunction = ParseTreeUtils.getEnclosingFunction(node);
1857
- if (!enclosingFunction || !enclosingFunction.isAsync) {
1858
- this._addError(Localizer.Diagnostic.asyncNotInAsyncFunction(), node.asyncToken);
1859
- }
1860
- }
1861
- });
1862
-
1863
- return false;
1864
- }
1865
-
1866
- override visitTernary(node: TernaryNode): boolean {
1867
- const preTernaryFlowNode = this._currentFlowNode!;
1868
- const trueLabel = this._createBranchLabel();
1869
- const falseLabel = this._createBranchLabel();
1870
- const postExpressionLabel = this._createBranchLabel(preTernaryFlowNode);
1871
-
1872
- postExpressionLabel.affectedExpressions = this._trackCodeFlowExpressions(() => {
1873
- // Handle the test expression.
1874
- this._bindConditional(node.testExpression, trueLabel, falseLabel);
1875
-
1876
- // Handle the "true" portion (the "if" expression).
1877
- this._currentFlowNode = this._finishFlowLabel(trueLabel);
1878
- this.walk(node.ifExpression);
1879
- this._addAntecedent(postExpressionLabel, this._currentFlowNode);
1880
-
1881
- // Handle the "false" portion (the "else" expression).
1882
- this._currentFlowNode = this._finishFlowLabel(falseLabel);
1883
- this.walk(node.elseExpression);
1884
- this._addAntecedent(postExpressionLabel, this._currentFlowNode);
1885
-
1886
- this._currentFlowNode = this._finishFlowLabel(postExpressionLabel);
1887
- });
1888
-
1889
- return false;
1890
- }
1891
-
1892
- override visitUnaryOperation(node: UnaryOperationNode): boolean {
1893
- if (node.operator === OperatorType.Not && this._currentFalseTarget && this._currentTrueTarget) {
1894
- // Swap the existing true/false targets.
1895
- this._bindConditional(node.expression, this._currentFalseTarget, this._currentTrueTarget);
1896
- } else {
1897
- // Temporarily set the true/false targets to undefined because
1898
- // this unary operation is not part of a chain of logical expressions
1899
- // (AND/OR/NOT subexpressions).
1900
- this._disableTrueFalseTargets(() => {
1901
- // Evaluate the operand expression.
1902
- this.walk(node.expression);
1903
- });
1904
- }
1905
-
1906
- return false;
1907
- }
1908
-
1909
- override visitBinaryOperation(node: BinaryOperationNode): boolean {
1910
- if (node.operator === OperatorType.And || node.operator === OperatorType.Or) {
1911
- let trueTarget = this._currentTrueTarget;
1912
- let falseTarget = this._currentFalseTarget;
1913
- let postRightLabel: FlowLabel | undefined;
1914
-
1915
- if (!trueTarget || !falseTarget) {
1916
- postRightLabel = this._createBranchLabel();
1917
- trueTarget = falseTarget = postRightLabel;
1918
- }
1919
-
1920
- const preRightLabel = this._createBranchLabel();
1921
- if (node.operator === OperatorType.And) {
1922
- this._bindConditional(node.leftExpression, preRightLabel, falseTarget);
1923
- } else {
1924
- this._bindConditional(node.leftExpression, trueTarget, preRightLabel);
1925
- }
1926
- this._currentFlowNode = this._finishFlowLabel(preRightLabel);
1927
- this._bindConditional(node.rightExpression, trueTarget, falseTarget);
1928
- if (postRightLabel) {
1929
- this._currentFlowNode = this._finishFlowLabel(postRightLabel);
1930
- }
1931
- } else {
1932
- // Temporarily set the true/false targets to undefined because
1933
- // this binary operation is not part of a chain of logical expressions
1934
- // (AND/OR/NOT subexpressions).
1935
- this._disableTrueFalseTargets(() => {
1936
- this.walk(node.leftExpression);
1937
- this.walk(node.rightExpression);
1938
- });
1939
- }
1940
-
1941
- return false;
1942
- }
1943
-
1944
- override visitListComprehension(node: ListComprehensionNode): boolean {
1945
- const enclosingFunction = ParseTreeUtils.getEnclosingFunction(node);
1946
-
1947
- this._createNewScope(ScopeType.ListComprehension, this._getNonClassParentScope(), () => {
1948
- AnalyzerNodeInfo.setScope(node, this._currentScope);
1949
-
1950
- const falseLabel = this._createBranchLabel();
1951
-
1952
- // We'll walk the forIfNodes list twice. The first time we'll
1953
- // bind targets of for statements. The second time we'll walk
1954
- // expressions and create the control flow graph.
1955
- for (let i = 0; i < node.forIfNodes.length; i++) {
1956
- const compr = node.forIfNodes[i];
1957
- const addedSymbols = new Map<string, Symbol>();
1958
- if (compr.nodeType === ParseNodeType.ListComprehensionFor) {
1959
- this._bindPossibleTupleNamedTarget(compr.targetExpression, addedSymbols);
1960
- this._addInferredTypeAssignmentForVariable(compr.targetExpression, compr);
1961
-
1962
- // Async for is not allowed outside of an async function.
1963
- if (compr.asyncToken) {
1964
- if (!enclosingFunction || !enclosingFunction.isAsync) {
1965
- // Allow if it's within a generator expression. Execution of
1966
- // generator expressions is deferred and therefore can be
1967
- // run within the context of an async function later.
1968
- if (node.parent?.nodeType === ParseNodeType.List) {
1969
- this._addError(Localizer.Diagnostic.asyncNotInAsyncFunction(), compr.asyncToken);
1970
- }
1971
- }
1972
- }
1973
- }
1974
- }
1975
-
1976
- for (let i = 0; i < node.forIfNodes.length; i++) {
1977
- const compr = node.forIfNodes[i];
1978
- if (compr.nodeType === ParseNodeType.ListComprehensionFor) {
1979
- this.walk(compr.iterableExpression);
1980
-
1981
- this._createAssignmentTargetFlowNodes(
1982
- compr.targetExpression,
1983
- /* walkTargets */ true,
1984
- /* unbound */ false
1985
- );
1986
- } else {
1987
- const trueLabel = this._createBranchLabel();
1988
- this._bindConditional(compr.testExpression, trueLabel, falseLabel);
1989
- this._currentFlowNode = this._finishFlowLabel(trueLabel);
1990
- }
1991
- }
1992
-
1993
- this.walk(node.expression);
1994
- this._addAntecedent(falseLabel, this._currentFlowNode!);
1995
- this._currentFlowNode = this._finishFlowLabel(falseLabel);
1996
- });
1997
-
1998
- return false;
1999
- }
2000
-
2001
- override visitMatch(node: MatchNode) {
2002
- // Evaluate the subject expression.
2003
- this.walk(node.subjectExpression);
2004
-
2005
- const expressionList: CodeFlowReferenceExpressionNode[] = [];
2006
- const isSubjectNarrowable = this._isNarrowingExpression(node.subjectExpression, expressionList);
2007
- if (isSubjectNarrowable) {
2008
- expressionList.forEach((expr) => {
2009
- const referenceKey = createKeyForReference(expr);
2010
- this._currentScopeCodeFlowExpressions!.add(referenceKey);
2011
- });
2012
- }
2013
-
2014
- const postMatchLabel = this._createBranchLabel();
2015
- let foundIrrefutableCase = false;
2016
-
2017
- // Model the match statement as a series of if/elif clauses
2018
- // each of which tests for the specified pattern (and optionally
2019
- // for the guard condition).
2020
- node.cases.forEach((caseStatement) => {
2021
- const postCaseLabel = this._createBranchLabel();
2022
- const preGuardLabel = this._createBranchLabel();
2023
- const preSuiteLabel = this._createBranchLabel();
2024
-
2025
- // Evaluate the pattern.
2026
- this._addAntecedent(preGuardLabel, this._currentFlowNode!);
2027
-
2028
- if (!caseStatement.isIrrefutable) {
2029
- this._addAntecedent(postCaseLabel, this._currentFlowNode!);
2030
- } else if (!caseStatement.guardExpression) {
2031
- foundIrrefutableCase = true;
2032
- }
2033
-
2034
- this._currentFlowNode = this._finishFlowLabel(preGuardLabel);
2035
-
2036
- // Bind the pattern.
2037
- this.walk(caseStatement.pattern);
2038
-
2039
- if (isSubjectNarrowable) {
2040
- this._createFlowNarrowForPattern(node.subjectExpression, caseStatement);
2041
- }
2042
-
2043
- // Apply the guard expression.
2044
- if (caseStatement.guardExpression) {
2045
- this._bindConditional(caseStatement.guardExpression, preSuiteLabel, postCaseLabel);
2046
- } else {
2047
- this._addAntecedent(preSuiteLabel, this._currentFlowNode);
2048
- }
2049
-
2050
- this._currentFlowNode = this._finishFlowLabel(preSuiteLabel);
2051
-
2052
- // Bind the body of the case statement.
2053
- this.walk(caseStatement.suite);
2054
- this._addAntecedent(postMatchLabel, this._currentFlowNode);
2055
-
2056
- this._currentFlowNode = this._finishFlowLabel(postCaseLabel);
2057
- });
2058
-
2059
- // Add a final narrowing step for the subject expression for the entire
2060
- // match statement. This will compute the narrowed type if no case
2061
- // statements are matched.
2062
- if (isSubjectNarrowable) {
2063
- this._createFlowNarrowForPattern(node.subjectExpression, node);
2064
- }
2065
-
2066
- // Create an "implied else" to conditionally gate code flow based on
2067
- // whether the narrowed type of the subject expression is Never at this point.
2068
- if (!foundIrrefutableCase) {
2069
- this._createFlowExhaustedMatch(node);
2070
- }
2071
-
2072
- this._addAntecedent(postMatchLabel, this._currentFlowNode!);
2073
- this._currentFlowNode = this._finishFlowLabel(postMatchLabel);
2074
-
2075
- return false;
2076
- }
2077
-
2078
- override visitPatternAs(node: PatternAsNode) {
2079
- const postOrLabel = this._createBranchLabel();
2080
-
2081
- node.orPatterns.forEach((orPattern) => {
2082
- this.walk(orPattern);
2083
- this._addAntecedent(postOrLabel, this._currentFlowNode!);
2084
- });
2085
-
2086
- this._currentFlowNode = this._finishFlowLabel(postOrLabel);
2087
-
2088
- if (node.target) {
2089
- this.walk(node.target);
2090
- const symbol = this._bindNameToScope(this._currentScope, node.target.value);
2091
- this._createAssignmentTargetFlowNodes(node.target, /* walkTargets */ false, /* unbound */ false);
2092
-
2093
- if (symbol) {
2094
- const declaration: VariableDeclaration = {
2095
- type: DeclarationType.Variable,
2096
- node: node.target,
2097
- isConstant: isConstantName(node.target.value),
2098
- inferredTypeSource: node,
2099
- path: this._fileInfo.filePath,
2100
- range: convertOffsetsToRange(
2101
- node.target.start,
2102
- TextRange.getEnd(node.target),
2103
- this._fileInfo.lines
2104
- ),
2105
- moduleName: this._fileInfo.moduleName,
2106
- isInExceptSuite: this._isInExceptSuite,
2107
- };
2108
- symbol.addDeclaration(declaration);
2109
- }
2110
- }
2111
-
2112
- return false;
2113
- }
2114
-
2115
- override visitPatternCapture(node: PatternCaptureNode) {
2116
- if (!node.isWildcard) {
2117
- this._addPatternCaptureTarget(node.target);
2118
- }
2119
-
2120
- return true;
2121
- }
2122
-
2123
- override visitPatternMappingExpandEntry(node: PatternMappingExpandEntryNode) {
2124
- if (node.target.value !== '_') {
2125
- this._addPatternCaptureTarget(node.target);
2126
- }
2127
-
2128
- return true;
2129
- }
2130
-
2131
- private _getNonClassParentScope() {
2132
- // We may not be able to use the current scope if it's a class scope.
2133
- // Walk up until we find a non-class scope instead.
2134
- let parentScope = this._currentScope;
2135
- while (parentScope.type === ScopeType.Class) {
2136
- parentScope = parentScope.parent!;
2137
- }
2138
-
2139
- return parentScope;
2140
- }
2141
-
2142
- private _addSlotsToCurrentScope(slotNameNodes: StringListNode[]) {
2143
- assert(this._currentScope.type === ScopeType.Class);
2144
-
2145
- let slotsContainsDict = false;
2146
-
2147
- for (const slotNameNode of slotNameNodes) {
2148
- const slotName = slotNameNode.strings[0].value;
2149
-
2150
- if (slotName === '__dict__') {
2151
- slotsContainsDict = true;
2152
- continue;
2153
- }
2154
-
2155
- let symbol = this._currentScope.lookUpSymbol(slotName);
2156
- if (!symbol) {
2157
- symbol = this._currentScope.addSymbol(slotName, SymbolFlags.InitiallyUnbound | SymbolFlags.ClassMember);
2158
- const honorPrivateNaming = this._fileInfo.diagnosticRuleSet.reportPrivateUsage !== 'none';
2159
- if (isPrivateOrProtectedName(slotName) && honorPrivateNaming) {
2160
- symbol.setIsPrivateMember();
2161
- }
2162
- }
2163
-
2164
- const declaration: VariableDeclaration = {
2165
- type: DeclarationType.Variable,
2166
- node: slotNameNode,
2167
- isConstant: isConstantName(slotName),
2168
- isDefinedBySlots: true,
2169
- path: this._fileInfo.filePath,
2170
- range: convertOffsetsToRange(
2171
- slotNameNode.start,
2172
- slotNameNode.start + slotNameNode.length,
2173
- this._fileInfo.lines
2174
- ),
2175
- moduleName: this._fileInfo.moduleName,
2176
- isInExceptSuite: this._isInExceptSuite,
2177
- };
2178
- symbol.addDeclaration(declaration);
2179
- }
2180
-
2181
- if (!slotsContainsDict) {
2182
- this._currentScope.setSlotsNames(slotNameNodes.map((node) => node.strings[0].value));
2183
- }
2184
- }
2185
-
2186
- private _isInListComprehension(node: ParseNode, ignoreOutermostIterable = false) {
2187
- let curNode: ParseNode | undefined = node;
2188
- let prevNode: ParseNode | undefined;
2189
- let prevPrevNode: ParseNode | undefined;
2190
-
2191
- while (curNode) {
2192
- if (curNode.nodeType === ParseNodeType.ListComprehension) {
2193
- if (ignoreOutermostIterable && curNode.forIfNodes.length > 0) {
2194
- const outermostCompr = curNode.forIfNodes[0];
2195
- if (prevNode === outermostCompr && outermostCompr.nodeType === ParseNodeType.ListComprehensionFor) {
2196
- if (prevPrevNode === outermostCompr.iterableExpression) {
2197
- return false;
2198
- }
2199
- }
2200
- }
2201
-
2202
- return true;
2203
- }
2204
-
2205
- prevPrevNode = prevNode;
2206
- prevNode = curNode;
2207
- curNode = curNode.parent;
2208
- }
2209
- return false;
2210
- }
2211
-
2212
- private _addPatternCaptureTarget(target: NameNode) {
2213
- const symbol = this._bindNameToScope(this._currentScope, target.value);
2214
- this._createAssignmentTargetFlowNodes(target, /* walkTargets */ false, /* unbound */ false);
2215
-
2216
- if (symbol) {
2217
- const declaration: VariableDeclaration = {
2218
- type: DeclarationType.Variable,
2219
- node: target,
2220
- isConstant: isConstantName(target.value),
2221
- inferredTypeSource: target.parent,
2222
- path: this._fileInfo.filePath,
2223
- range: convertOffsetsToRange(target.start, TextRange.getEnd(target), this._fileInfo.lines),
2224
- moduleName: this._fileInfo.moduleName,
2225
- isInExceptSuite: this._isInExceptSuite,
2226
- };
2227
- symbol.addDeclaration(declaration);
2228
- }
2229
- }
2230
-
2231
- private _useExceptTargets(targets: FlowLabel[], callback: () => void) {
2232
- const prevExceptTargets = this._currentExceptTargets;
2233
- this._currentExceptTargets = targets;
2234
- callback();
2235
- this._currentExceptTargets = prevExceptTargets;
2236
- }
2237
-
2238
- // Attempts to resolve the module name, import it, and return
2239
- // its __all__ symbols.
2240
- private _getDunderAllNamesFromImport(varName: string): string[] | undefined {
2241
- const varSymbol = this._currentScope.lookUpSymbol(varName);
2242
- if (!varSymbol) {
2243
- return undefined;
2244
- }
2245
-
2246
- // There should be only one declaration for the variable.
2247
- const aliasDecl = varSymbol.getDeclarations().find((decl) => decl.type === DeclarationType.Alias) as
2248
- | AliasDeclaration
2249
- | undefined;
2250
- const resolvedPath =
2251
- aliasDecl?.path && aliasDecl.loadSymbolsFromPath
2252
- ? aliasDecl.path
2253
- : aliasDecl?.submoduleFallback?.path && aliasDecl.submoduleFallback.loadSymbolsFromPath
2254
- ? aliasDecl.submoduleFallback.path
2255
- : undefined;
2256
- if (!resolvedPath) {
2257
- return undefined;
2258
- }
2259
-
2260
- const lookupInfo = this._fileInfo.importLookup(resolvedPath);
2261
- if (!lookupInfo) {
2262
- return undefined;
2263
- }
2264
-
2265
- return lookupInfo.dunderAllNames;
2266
- }
2267
-
2268
- private _addImplicitFromImport(node: ImportFromNode, importInfo?: ImportResult) {
2269
- const symbolName = node.module.nameParts[0].value;
2270
- const symbol = this._bindNameToScope(this._currentScope, symbolName);
2271
- if (symbol) {
2272
- this._createAliasDeclarationForMultipartImportName(node, /* importAlias */ undefined, importInfo, symbol);
2273
- }
2274
-
2275
- this._createFlowAssignment(node.module.nameParts[0]);
2276
- }
2277
-
2278
- private _createAliasDeclarationForMultipartImportName(
2279
- node: ImportAsNode | ImportFromNode,
2280
- importAlias: NameNode | undefined,
2281
- importInfo: ImportResult | undefined,
2282
- symbol: Symbol
2283
- ) {
2284
- const firstNamePartValue = node.module.nameParts[0].value;
2285
-
2286
- // See if there's already a matching alias declaration for this import.
2287
- // if so, we'll update it rather than creating a new one. This is required
2288
- // to handle cases where multiple import statements target the same
2289
- // starting symbol such as "import a.b.c" and "import a.d". In this case,
2290
- // we'll build a single declaration that describes the combined actions
2291
- // of both import statements, thus reflecting the behavior of the
2292
- // python module loader.
2293
- const existingDecl = symbol
2294
- .getDeclarations()
2295
- .find((decl) => decl.type === DeclarationType.Alias && decl.firstNamePart === firstNamePartValue);
2296
- let newDecl: AliasDeclaration;
2297
- let pathOfLastSubmodule: string;
2298
- if (importInfo && importInfo.isImportFound && !importInfo.isNativeLib && importInfo.resolvedPaths.length > 0) {
2299
- pathOfLastSubmodule = importInfo.resolvedPaths[importInfo.resolvedPaths.length - 1];
2300
- } else {
2301
- pathOfLastSubmodule = '*** unresolved ***';
2302
- }
2303
-
2304
- const isResolved =
2305
- importInfo && importInfo.isImportFound && !importInfo.isNativeLib && importInfo.resolvedPaths.length > 0;
2306
-
2307
- if (existingDecl) {
2308
- newDecl = existingDecl as AliasDeclaration;
2309
- } else if (isResolved) {
2310
- newDecl = {
2311
- type: DeclarationType.Alias,
2312
- node,
2313
- path: pathOfLastSubmodule,
2314
- loadSymbolsFromPath: false,
2315
- range: getEmptyRange(),
2316
- usesLocalName: !!importAlias,
2317
- moduleName: importInfo.importName,
2318
- firstNamePart: firstNamePartValue,
2319
- isInExceptSuite: this._isInExceptSuite,
2320
- };
2321
- } else {
2322
- // If we couldn't resolve the import, create a dummy declaration with a
2323
- // bogus path so it gets an unknown type (rather than an unbound type) at
2324
- // analysis time.
2325
- newDecl = {
2326
- type: DeclarationType.Alias,
2327
- node,
2328
- path: pathOfLastSubmodule,
2329
- loadSymbolsFromPath: true,
2330
- range: getEmptyRange(),
2331
- usesLocalName: !!importAlias,
2332
- moduleName: importInfo?.importName ?? '',
2333
- firstNamePart: firstNamePartValue,
2334
- isUnresolved: true,
2335
- isInExceptSuite: this._isInExceptSuite,
2336
- };
2337
- }
2338
-
2339
- // Add the implicit imports for this module if it's the last
2340
- // name part we're resolving.
2341
- if (importAlias || node.module.nameParts.length === 1) {
2342
- newDecl.path = pathOfLastSubmodule;
2343
- newDecl.loadSymbolsFromPath = true;
2344
- newDecl.isUnresolved = false;
2345
-
2346
- if (importInfo) {
2347
- this._addImplicitImportsToLoaderActions(importInfo, newDecl);
2348
- }
2349
- } else {
2350
- // Fill in the remaining name parts.
2351
- let curLoaderActions: ModuleLoaderActions = newDecl;
2352
-
2353
- for (let i = 1; i < node.module.nameParts.length; i++) {
2354
- const namePartValue = node.module.nameParts[i].value;
2355
-
2356
- // Is there an existing loader action for this name?
2357
- let loaderActions = curLoaderActions.implicitImports
2358
- ? curLoaderActions.implicitImports.get(namePartValue)
2359
- : undefined;
2360
- if (!loaderActions) {
2361
- const loaderActionPath =
2362
- importInfo && i < importInfo.resolvedPaths.length
2363
- ? importInfo.resolvedPaths[i]
2364
- : '*** unresolved ***';
2365
-
2366
- // Allocate a new loader action.
2367
- loaderActions = {
2368
- path: loaderActionPath,
2369
- loadSymbolsFromPath: false,
2370
- implicitImports: new Map<string, ModuleLoaderActions>(),
2371
- isUnresolved: !isResolved,
2372
- };
2373
- if (!curLoaderActions.implicitImports) {
2374
- curLoaderActions.implicitImports = new Map<string, ModuleLoaderActions>();
2375
- }
2376
- curLoaderActions.implicitImports.set(namePartValue, loaderActions);
2377
- }
2378
-
2379
- // If this is the last name part we're resolving, add in the
2380
- // implicit imports as well.
2381
- if (i === node.module.nameParts.length - 1) {
2382
- if (importInfo && i < importInfo.resolvedPaths.length) {
2383
- loaderActions.path = importInfo.resolvedPaths[i];
2384
- loaderActions.loadSymbolsFromPath = true;
2385
- this._addImplicitImportsToLoaderActions(importInfo, loaderActions);
2386
- }
2387
- }
2388
-
2389
- curLoaderActions = loaderActions;
2390
- }
2391
- }
2392
-
2393
- if (!existingDecl) {
2394
- symbol.addDeclaration(newDecl);
2395
- }
2396
- }
2397
-
2398
- private _getWildcardImportNames(lookupInfo: ImportLookupResult): string[] {
2399
- const namesToImport: string[] = [];
2400
-
2401
- // If a dunder all symbol is defined, it takes precedence.
2402
- if (lookupInfo.dunderAllNames) {
2403
- if (!lookupInfo.usesUnsupportedDunderAllForm) {
2404
- return lookupInfo.dunderAllNames;
2405
- }
2406
-
2407
- appendArray(namesToImport, lookupInfo.dunderAllNames);
2408
- }
2409
-
2410
- lookupInfo.symbolTable.forEach((symbol, name) => {
2411
- if (!symbol.isExternallyHidden() && !isPrivateOrProtectedName(name)) {
2412
- namesToImport!.push(name);
2413
- }
2414
- });
2415
-
2416
- return namesToImport;
2417
- }
2418
-
2419
- private _walkStatementsAndReportUnreachable(statements: StatementNode[]) {
2420
- let foundUnreachableStatement = false;
2421
-
2422
- for (const statement of statements) {
2423
- AnalyzerNodeInfo.setFlowNode(statement, this._currentFlowNode!);
2424
-
2425
- if (!foundUnreachableStatement) {
2426
- foundUnreachableStatement = this._isCodeUnreachable();
2427
- }
2428
-
2429
- if (!foundUnreachableStatement) {
2430
- this.walk(statement);
2431
- } else {
2432
- // If we're within a function, we need to look for unreachable yield
2433
- // statements because they affect the behavior of the function (making
2434
- // it a generator) even if they're never executed.
2435
- if (this._targetFunctionDeclaration && !this._targetFunctionDeclaration.isGenerator) {
2436
- const yieldFinder = new YieldFinder();
2437
- if (yieldFinder.checkContainsYield(statement)) {
2438
- this._targetFunctionDeclaration.isGenerator = true;
2439
- }
2440
- }
2441
- }
2442
- }
2443
-
2444
- return false;
2445
- }
2446
-
2447
- private _createStartFlowNode() {
2448
- const flowNode: FlowNode = {
2449
- flags: FlowFlags.Start,
2450
- id: this._getUniqueFlowNodeId(),
2451
- };
2452
- return flowNode;
2453
- }
2454
-
2455
- private _createBranchLabel(preBranchAntecedent?: FlowNode) {
2456
- const flowNode: FlowBranchLabel = {
2457
- flags: FlowFlags.BranchLabel,
2458
- id: this._getUniqueFlowNodeId(),
2459
- antecedents: [],
2460
- preBranchAntecedent,
2461
- affectedExpressions: undefined,
2462
- };
2463
- return flowNode;
2464
- }
2465
-
2466
- // Create a flow node that narrows the type of the subject expression for
2467
- // a specified case statement or the entire match statement (if the flow
2468
- // falls through the bottom of all cases).
2469
- private _createFlowNarrowForPattern(subjectExpression: ExpressionNode, statement: CaseNode | MatchNode) {
2470
- const flowNode: FlowNarrowForPattern = {
2471
- flags: FlowFlags.NarrowForPattern,
2472
- id: this._getUniqueFlowNodeId(),
2473
- subjectExpression,
2474
- statement,
2475
- antecedent: this._currentFlowNode!,
2476
- };
2477
-
2478
- this._currentFlowNode! = flowNode;
2479
- }
2480
-
2481
- private _createContextManagerLabel(
2482
- expressions: ExpressionNode[],
2483
- isAsync: boolean,
2484
- blockIfSwallowsExceptions: boolean
2485
- ) {
2486
- const flowNode: FlowPostContextManagerLabel = {
2487
- flags: FlowFlags.PostContextManager | FlowFlags.BranchLabel,
2488
- id: this._getUniqueFlowNodeId(),
2489
- antecedents: [],
2490
- expressions,
2491
- affectedExpressions: undefined,
2492
- isAsync,
2493
- blockIfSwallowsExceptions,
2494
- };
2495
- return flowNode;
2496
- }
2497
-
2498
- private _createLoopLabel() {
2499
- const flowNode: FlowLabel = {
2500
- flags: FlowFlags.LoopLabel,
2501
- id: this._getUniqueFlowNodeId(),
2502
- antecedents: [],
2503
- affectedExpressions: undefined,
2504
- };
2505
-
2506
- return flowNode;
2507
- }
2508
-
2509
- private _finishFlowLabel(node: FlowLabel) {
2510
- // If there were no antecedents, this is unreachable.
2511
- if (node.antecedents.length === 0) {
2512
- return Binder._unreachableFlowNode;
2513
- }
2514
-
2515
- // If there was only one antecedent and this is a simple
2516
- // branch label, there's no need for a label to exist.
2517
- if (node.antecedents.length === 1 && node.flags === FlowFlags.BranchLabel) {
2518
- return node.antecedents[0];
2519
- }
2520
-
2521
- // The cyclomatic complexity is the number of edges minus the
2522
- // number of nodes in the graph. Add n-1 where n is the number
2523
- // of antecedents (edges) and 1 represents the label node.
2524
- this._codeFlowComplexity += node.antecedents.length - 1;
2525
-
2526
- return node;
2527
- }
2528
-
2529
- // Creates a node that creates a "gate" that is closed (doesn't allow for code
2530
- // flow) if the specified expression is never once it is narrowed (in either the
2531
- // positive or negative case).
2532
- private _bindNeverCondition(node: ExpressionNode, target: FlowLabel, isPositiveTest: boolean) {
2533
- const expressionList: CodeFlowReferenceExpressionNode[] = [];
2534
-
2535
- if (node.nodeType === ParseNodeType.UnaryOperation && node.operator === OperatorType.Not) {
2536
- this._bindNeverCondition(node.expression, target, !isPositiveTest);
2537
- } else if (
2538
- node.nodeType === ParseNodeType.BinaryOperation &&
2539
- (node.operator === OperatorType.And || node.operator === OperatorType.Or)
2540
- ) {
2541
- let isAnd = node.operator === OperatorType.And;
2542
- if (isPositiveTest) {
2543
- isAnd = !isAnd;
2544
- }
2545
-
2546
- if (isAnd) {
2547
- // In the And case, we need to gate the synthesized else clause if both
2548
- // of the operands evaluate to never once they are narrowed.
2549
- const savedCurrentFlowNode = this._currentFlowNode;
2550
- this._bindNeverCondition(node.leftExpression, target, isPositiveTest);
2551
- this._currentFlowNode = savedCurrentFlowNode;
2552
- this._bindNeverCondition(node.rightExpression, target, isPositiveTest);
2553
- } else {
2554
- const initialCurrentFlowNode = this._currentFlowNode;
2555
-
2556
- // In the Or case, we need to gate the synthesized else clause if either
2557
- // of the operands evaluate to never.
2558
- const afterLabel = this._createBranchLabel();
2559
- this._bindNeverCondition(node.leftExpression, afterLabel, isPositiveTest);
2560
-
2561
- // If the condition didn't result in any new flow nodes, we can skip
2562
- // checking the other condition.
2563
- if (initialCurrentFlowNode !== this._currentFlowNode) {
2564
- this._currentFlowNode = this._finishFlowLabel(afterLabel);
2565
-
2566
- const prevCurrentNode = this._currentFlowNode;
2567
- this._bindNeverCondition(node.rightExpression, target, isPositiveTest);
2568
-
2569
- // If the second condition resulted in no new control flow node, we can
2570
- // eliminate this entire subgraph.
2571
- if (prevCurrentNode === this._currentFlowNode) {
2572
- this._currentFlowNode = initialCurrentFlowNode;
2573
- }
2574
- }
2575
- }
2576
- } else {
2577
- // Limit only to expressions that contain a narrowable subexpression
2578
- // that is a name. This avoids complexities with composite expressions like
2579
- // member access or index expressions.
2580
- if (this._isNarrowingExpression(node, expressionList, /* neverNarrowingExpressions */ true)) {
2581
- const filteredExprList = expressionList.filter((expr) => expr.nodeType === ParseNodeType.Name);
2582
- if (filteredExprList.length > 0) {
2583
- this._currentFlowNode = this._createFlowConditional(
2584
- isPositiveTest ? FlowFlags.TrueNeverCondition : FlowFlags.FalseNeverCondition,
2585
- this._currentFlowNode!,
2586
- node
2587
- );
2588
- }
2589
- }
2590
-
2591
- this._addAntecedent(target, this._currentFlowNode!);
2592
- }
2593
- }
2594
-
2595
- private _bindConditional(node: ExpressionNode, trueTarget: FlowLabel, falseTarget: FlowLabel) {
2596
- this._setTrueFalseTargets(trueTarget, falseTarget, () => {
2597
- this.walk(node);
2598
- });
2599
-
2600
- if (!this._isLogicalExpression(node)) {
2601
- this._addAntecedent(
2602
- trueTarget,
2603
- this._createFlowConditional(FlowFlags.TrueCondition, this._currentFlowNode!, node)
2604
- );
2605
- this._addAntecedent(
2606
- falseTarget,
2607
- this._createFlowConditional(FlowFlags.FalseCondition, this._currentFlowNode!, node)
2608
- );
2609
- }
2610
- }
2611
-
2612
- private _disableTrueFalseTargets(callback: () => void): void {
2613
- this._setTrueFalseTargets(/* trueTarget */ undefined, /* falseTarget */ undefined, callback);
2614
- }
2615
-
2616
- private _setTrueFalseTargets(
2617
- trueTarget: FlowLabel | undefined,
2618
- falseTarget: FlowLabel | undefined,
2619
- callback: () => void
2620
- ) {
2621
- const savedTrueTarget = this._currentTrueTarget;
2622
- const savedFalseTarget = this._currentFalseTarget;
2623
- this._currentTrueTarget = trueTarget;
2624
- this._currentFalseTarget = falseTarget;
2625
-
2626
- callback();
2627
-
2628
- this._currentTrueTarget = savedTrueTarget;
2629
- this._currentFalseTarget = savedFalseTarget;
2630
- }
2631
-
2632
- private _createFlowConditional(flags: FlowFlags, antecedent: FlowNode, expression: ExpressionNode): FlowNode {
2633
- if (antecedent.flags & FlowFlags.Unreachable) {
2634
- return antecedent;
2635
- }
2636
- const staticValue = StaticExpressions.evaluateStaticBoolLikeExpression(
2637
- expression,
2638
- this._fileInfo.executionEnvironment,
2639
- this._fileInfo.definedConstants,
2640
- this._typingImportAliases,
2641
- this._sysImportAliases
2642
- );
2643
- if (
2644
- (staticValue === true && flags & FlowFlags.FalseCondition) ||
2645
- (staticValue === false && flags & FlowFlags.TrueCondition)
2646
- ) {
2647
- return Binder._unreachableFlowNode;
2648
- }
2649
-
2650
- const expressionList: CodeFlowReferenceExpressionNode[] = [];
2651
- if (!this._isNarrowingExpression(expression, expressionList)) {
2652
- return antecedent;
2653
- }
2654
-
2655
- expressionList.forEach((expr) => {
2656
- const referenceKey = createKeyForReference(expr);
2657
- this._currentScopeCodeFlowExpressions!.add(referenceKey);
2658
- });
2659
-
2660
- // Select the first name expression.
2661
- const filteredExprList = expressionList.filter((expr) => expr.nodeType === ParseNodeType.Name);
2662
-
2663
- const conditionalFlowNode: FlowCondition = {
2664
- flags,
2665
- id: this._getUniqueFlowNodeId(),
2666
- reference: filteredExprList.length > 0 ? (filteredExprList[0] as NameNode) : undefined,
2667
- expression,
2668
- antecedent,
2669
- };
2670
-
2671
- this._addExceptTargets(conditionalFlowNode);
2672
-
2673
- return conditionalFlowNode;
2674
- }
2675
-
2676
- // Indicates whether the expression is a NOT, AND or OR expression.
2677
- private _isLogicalExpression(expression: ExpressionNode): boolean {
2678
- switch (expression.nodeType) {
2679
- case ParseNodeType.UnaryOperation: {
2680
- return expression.operator === OperatorType.Not;
2681
- }
2682
-
2683
- case ParseNodeType.BinaryOperation: {
2684
- return expression.operator === OperatorType.And || expression.operator === OperatorType.Or;
2685
- }
2686
- }
2687
-
2688
- return false;
2689
- }
2690
-
2691
- // Determines whether the specified expression can be used for conditional
2692
- // type narrowing. The expression atoms (names, member accesses and index)
2693
- // are provided as an output in the expressionList.
2694
- // If filterForNeverNarrowing is true, we limit some types of narrowing
2695
- // expressions for performance reasons.
2696
- // The isComplexExpression parameter is used internally to determine whether
2697
- // the call is an atom (name, member access, index - plus a "not" form of
2698
- // these) or something more complex (binary operator, call, etc.).
2699
- private _isNarrowingExpression(
2700
- expression: ExpressionNode,
2701
- expressionList: CodeFlowReferenceExpressionNode[],
2702
- filterForNeverNarrowing = false,
2703
- isComplexExpression = false
2704
- ): boolean {
2705
- switch (expression.nodeType) {
2706
- case ParseNodeType.Name:
2707
- case ParseNodeType.MemberAccess:
2708
- case ParseNodeType.Index: {
2709
- if (filterForNeverNarrowing) {
2710
- // Never narrowing doesn't support member access or index
2711
- // expressions.
2712
- if (expression.nodeType !== ParseNodeType.Name) {
2713
- return false;
2714
- }
2715
-
2716
- // Never narrowing doesn't support simple names (falsy
2717
- // or truthy narrowing) because it's too expensive and
2718
- // provides relatively little utility.
2719
- if (!isComplexExpression) {
2720
- return false;
2721
- }
2722
- }
2723
-
2724
- if (isCodeFlowSupportedForReference(expression)) {
2725
- expressionList.push(expression);
2726
- return true;
2727
- }
2728
-
2729
- return false;
2730
- }
2731
-
2732
- case ParseNodeType.AssignmentExpression: {
2733
- expressionList.push(expression.name);
2734
- this._isNarrowingExpression(
2735
- expression.rightExpression,
2736
- expressionList,
2737
- filterForNeverNarrowing,
2738
- /* isComplexExpression */ true
2739
- );
2740
- return true;
2741
- }
2742
-
2743
- case ParseNodeType.BinaryOperation: {
2744
- const isOrIsNotOperator =
2745
- expression.operator === OperatorType.Is || expression.operator === OperatorType.IsNot;
2746
- const equalsOrNotEqualsOperator =
2747
- expression.operator === OperatorType.Equals || expression.operator === OperatorType.NotEquals;
2748
-
2749
- if (isOrIsNotOperator || equalsOrNotEqualsOperator) {
2750
- // Look for "X is None", "X is not None", "X == None", "X != None".
2751
- // These are commonly-used patterns used in control flow.
2752
- if (
2753
- expression.rightExpression.nodeType === ParseNodeType.Constant &&
2754
- expression.rightExpression.constType === KeywordType.None
2755
- ) {
2756
- return this._isNarrowingExpression(
2757
- expression.leftExpression,
2758
- expressionList,
2759
- filterForNeverNarrowing,
2760
- /* isComplexExpression */ true
2761
- );
2762
- }
2763
-
2764
- // Look for "type(X) is Y" or "type(X) is not Y".
2765
- if (
2766
- isOrIsNotOperator &&
2767
- expression.leftExpression.nodeType === ParseNodeType.Call &&
2768
- expression.leftExpression.leftExpression.nodeType === ParseNodeType.Name &&
2769
- expression.leftExpression.leftExpression.value === 'type' &&
2770
- expression.leftExpression.arguments.length === 1 &&
2771
- expression.leftExpression.arguments[0].argumentCategory === ArgumentCategory.Simple
2772
- ) {
2773
- return this._isNarrowingExpression(
2774
- expression.leftExpression.arguments[0].valueExpression,
2775
- expressionList,
2776
- filterForNeverNarrowing,
2777
- /* isComplexExpression */ true
2778
- );
2779
- }
2780
-
2781
- const isLeftNarrowing = this._isNarrowingExpression(
2782
- expression.leftExpression,
2783
- expressionList,
2784
- filterForNeverNarrowing,
2785
- /* isComplexExpression */ true
2786
- );
2787
-
2788
- // Look for "X is Y" or "X is not Y".
2789
- if (isOrIsNotOperator) {
2790
- return isLeftNarrowing;
2791
- }
2792
-
2793
- // Look for X == <literal>, X != <literal> or <literal> == X, <literal> != X
2794
- if (equalsOrNotEqualsOperator) {
2795
- const isRightNarrowing = this._isNarrowingExpression(
2796
- expression.rightExpression,
2797
- expressionList,
2798
- filterForNeverNarrowing,
2799
- /* isComplexExpression */ true
2800
- );
2801
- return isLeftNarrowing || isRightNarrowing;
2802
- }
2803
- }
2804
-
2805
- // Look for "<string> in Y" or "<string> not in Y".
2806
- if (expression.operator === OperatorType.In || expression.operator === OperatorType.NotIn) {
2807
- if (
2808
- expression.leftExpression.nodeType === ParseNodeType.StringList &&
2809
- this._isNarrowingExpression(
2810
- expression.rightExpression,
2811
- expressionList,
2812
- filterForNeverNarrowing,
2813
- /* isComplexExpression */ true
2814
- )
2815
- ) {
2816
- return true;
2817
- }
2818
- }
2819
-
2820
- // Look for "X in Y" or "X not in Y".
2821
- if (expression.operator === OperatorType.In || expression.operator === OperatorType.NotIn) {
2822
- return this._isNarrowingExpression(
2823
- expression.leftExpression,
2824
- expressionList,
2825
- filterForNeverNarrowing,
2826
- /* isComplexExpression */ true
2827
- );
2828
- }
2829
-
2830
- return false;
2831
- }
2832
-
2833
- case ParseNodeType.UnaryOperation: {
2834
- return (
2835
- expression.operator === OperatorType.Not &&
2836
- this._isNarrowingExpression(
2837
- expression.expression,
2838
- expressionList,
2839
- filterForNeverNarrowing,
2840
- /* isComplexExpression */ false
2841
- )
2842
- );
2843
- }
2844
-
2845
- case ParseNodeType.AugmentedAssignment: {
2846
- return this._isNarrowingExpression(
2847
- expression.rightExpression,
2848
- expressionList,
2849
- filterForNeverNarrowing,
2850
- /* isComplexExpression */ true
2851
- );
2852
- }
2853
-
2854
- case ParseNodeType.Call: {
2855
- if (
2856
- expression.leftExpression.nodeType === ParseNodeType.Name &&
2857
- (expression.leftExpression.value === 'isinstance' ||
2858
- expression.leftExpression.value === 'issubclass') &&
2859
- expression.arguments.length === 2
2860
- ) {
2861
- return this._isNarrowingExpression(
2862
- expression.arguments[0].valueExpression,
2863
- expressionList,
2864
- filterForNeverNarrowing,
2865
- /* isComplexExpression */ true
2866
- );
2867
- }
2868
-
2869
- if (
2870
- expression.leftExpression.nodeType === ParseNodeType.Name &&
2871
- expression.leftExpression.value === 'callable' &&
2872
- expression.arguments.length === 1
2873
- ) {
2874
- return this._isNarrowingExpression(
2875
- expression.arguments[0].valueExpression,
2876
- expressionList,
2877
- filterForNeverNarrowing,
2878
- /* isComplexExpression */ true
2879
- );
2880
- }
2881
-
2882
- // Is this potentially a call to a user-defined type guard function?
2883
- if (expression.arguments.length >= 1) {
2884
- // Never narrowing doesn't support type guards because they do not
2885
- // offer negative narrowing.
2886
- if (filterForNeverNarrowing) {
2887
- return false;
2888
- }
2889
-
2890
- return this._isNarrowingExpression(
2891
- expression.arguments[0].valueExpression,
2892
- expressionList,
2893
- filterForNeverNarrowing,
2894
- /* isComplexExpression */ true
2895
- );
2896
- }
2897
- }
2898
- }
2899
-
2900
- return false;
2901
- }
2902
-
2903
- private _createAssignmentTargetFlowNodes(target: ExpressionNode, walkTargets: boolean, unbound: boolean) {
2904
- switch (target.nodeType) {
2905
- case ParseNodeType.Name:
2906
- case ParseNodeType.MemberAccess: {
2907
- this._createFlowAssignment(target, unbound);
2908
- if (walkTargets) {
2909
- this.walk(target);
2910
- }
2911
- break;
2912
- }
2913
-
2914
- case ParseNodeType.Index: {
2915
- this._createFlowAssignment(target, unbound);
2916
- if (walkTargets) {
2917
- this.walk(target);
2918
- }
2919
- break;
2920
- }
2921
-
2922
- case ParseNodeType.Tuple: {
2923
- target.expressions.forEach((expr) => {
2924
- this._createAssignmentTargetFlowNodes(expr, walkTargets, unbound);
2925
- });
2926
- break;
2927
- }
2928
-
2929
- case ParseNodeType.TypeAnnotation: {
2930
- this._createAssignmentTargetFlowNodes(target.valueExpression, /* walkTargets */ false, unbound);
2931
- if (walkTargets) {
2932
- this.walk(target);
2933
- }
2934
- break;
2935
- }
2936
-
2937
- case ParseNodeType.Unpack: {
2938
- this._createAssignmentTargetFlowNodes(target.expression, /* walkTargets */ false, unbound);
2939
- if (walkTargets) {
2940
- this.walk(target);
2941
- }
2942
- break;
2943
- }
2944
-
2945
- case ParseNodeType.List: {
2946
- target.entries.forEach((entry) => {
2947
- this._createAssignmentTargetFlowNodes(entry, walkTargets, unbound);
2948
- });
2949
- break;
2950
- }
2951
-
2952
- default: {
2953
- if (walkTargets) {
2954
- this.walk(target);
2955
- }
2956
- }
2957
- }
2958
- }
2959
-
2960
- private _createCallFlowNode(node: CallNode) {
2961
- if (!this._isCodeUnreachable()) {
2962
- const flowNode: FlowCall = {
2963
- flags: FlowFlags.Call,
2964
- id: this._getUniqueFlowNodeId(),
2965
- node,
2966
- antecedent: this._currentFlowNode!,
2967
- };
2968
-
2969
- this._currentFlowNode = flowNode;
2970
- }
2971
-
2972
- AnalyzerNodeInfo.setFlowNode(node, this._currentFlowNode!);
2973
-
2974
- if (!this._isCodeUnreachable()) {
2975
- this._addExceptTargets(this._currentFlowNode!);
2976
- }
2977
- }
2978
-
2979
- private _createVariableAnnotationFlowNode() {
2980
- if (!this._isCodeUnreachable()) {
2981
- const flowNode: FlowVariableAnnotation = {
2982
- flags: FlowFlags.VariableAnnotation,
2983
- id: this._getUniqueFlowNodeId(),
2984
- antecedent: this._currentFlowNode!,
2985
- };
2986
-
2987
- this._currentFlowNode = flowNode;
2988
- }
2989
- }
2990
-
2991
- private _createFlowAssignment(node: CodeFlowReferenceExpressionNode, unbound = false) {
2992
- let targetSymbolId = indeterminateSymbolId;
2993
- if (node.nodeType === ParseNodeType.Name) {
2994
- const symbolWithScope = this._currentScope.lookUpSymbolRecursive(node.value);
2995
- assert(symbolWithScope !== undefined);
2996
- targetSymbolId = symbolWithScope!.symbol.id;
2997
- }
2998
-
2999
- const prevFlowNode = this._currentFlowNode!;
3000
- if (!this._isCodeUnreachable() && isCodeFlowSupportedForReference(node)) {
3001
- const flowNode: FlowAssignment = {
3002
- flags: FlowFlags.Assignment,
3003
- id: this._getUniqueFlowNodeId(),
3004
- node,
3005
- antecedent: this._currentFlowNode!,
3006
- targetSymbolId,
3007
- };
3008
-
3009
- const referenceKey = createKeyForReference(node);
3010
- this._currentScopeCodeFlowExpressions!.add(referenceKey);
3011
-
3012
- if (unbound) {
3013
- flowNode.flags |= FlowFlags.Unbind;
3014
- }
3015
-
3016
- // Assume that an assignment to a member access expression
3017
- // can potentially generate an exception.
3018
- if (node.nodeType === ParseNodeType.MemberAccess) {
3019
- this._addExceptTargets(flowNode);
3020
- }
3021
- this._currentFlowNode = flowNode;
3022
- }
3023
-
3024
- // If we're marking the node as unbound and there is already a flow node
3025
- // associated with the node, don't replace it. This case applies for symbols
3026
- // introduced in except clauses. If there is no use the previous flow node
3027
- // associated, use the previous flow node (applies in the del case).
3028
- // Otherwise, the node will be evaluated as unbound at this point in the flow.
3029
- if (!unbound || AnalyzerNodeInfo.getFlowNode(node) === undefined) {
3030
- AnalyzerNodeInfo.setFlowNode(node, unbound ? prevFlowNode : this._currentFlowNode!);
3031
- }
3032
- }
3033
-
3034
- private _createFlowWildcardImport(node: ImportFromNode, names: string[]) {
3035
- if (!this._isCodeUnreachable()) {
3036
- const flowNode: FlowWildcardImport = {
3037
- flags: FlowFlags.WildcardImport,
3038
- id: this._getUniqueFlowNodeId(),
3039
- node,
3040
- names,
3041
- antecedent: this._currentFlowNode!,
3042
- };
3043
-
3044
- this._addExceptTargets(flowNode);
3045
- this._currentFlowNode = flowNode;
3046
- }
3047
-
3048
- AnalyzerNodeInfo.setFlowNode(node, this._currentFlowNode!);
3049
- }
3050
-
3051
- private _createFlowExhaustedMatch(node: MatchNode) {
3052
- if (!this._isCodeUnreachable()) {
3053
- const flowNode: FlowExhaustedMatch = {
3054
- flags: FlowFlags.ExhaustedMatch,
3055
- id: this._getUniqueFlowNodeId(),
3056
- node,
3057
- antecedent: this._currentFlowNode!,
3058
- };
3059
-
3060
- this._currentFlowNode = flowNode;
3061
- }
3062
-
3063
- AnalyzerNodeInfo.setAfterFlowNode(node, this._currentFlowNode!);
3064
- }
3065
-
3066
- private _isCodeUnreachable() {
3067
- return !!(this._currentFlowNode!.flags & FlowFlags.Unreachable);
3068
- }
3069
-
3070
- private _addExceptTargets(flowNode: FlowNode) {
3071
- // If there are any except targets, then we're in a try block, and we
3072
- // have to assume that an exception can be raised after every assignment.
3073
- if (this._currentExceptTargets) {
3074
- this._currentExceptTargets.forEach((label) => {
3075
- this._addAntecedent(label, flowNode);
3076
- });
3077
- }
3078
- }
3079
-
3080
- private _trackCodeFlowExpressions(callback: () => void): Set<string> {
3081
- const savedExpressions = this._currentScopeCodeFlowExpressions;
3082
- this._currentScopeCodeFlowExpressions = new Set<string>();
3083
- callback();
3084
-
3085
- const scopedExpressions = this._currentScopeCodeFlowExpressions;
3086
-
3087
- if (savedExpressions) {
3088
- this._currentScopeCodeFlowExpressions.forEach((value) => {
3089
- savedExpressions.add(value);
3090
- });
3091
- }
3092
-
3093
- this._currentScopeCodeFlowExpressions = savedExpressions;
3094
-
3095
- return scopedExpressions;
3096
- }
3097
-
3098
- private _bindLoopStatement(preLoopLabel: FlowLabel, postLoopLabel: FlowLabel, callback: () => void) {
3099
- const savedContinueTarget = this._currentContinueTarget;
3100
- const savedBreakTarget = this._currentBreakTarget;
3101
-
3102
- this._currentContinueTarget = preLoopLabel;
3103
- this._currentBreakTarget = postLoopLabel;
3104
-
3105
- preLoopLabel.affectedExpressions = this._trackCodeFlowExpressions(callback);
3106
-
3107
- this._currentContinueTarget = savedContinueTarget;
3108
- this._currentBreakTarget = savedBreakTarget;
3109
- }
3110
-
3111
- private _addAntecedent(label: FlowLabel, antecedent: FlowNode) {
3112
- if (!(this._currentFlowNode!.flags & FlowFlags.Unreachable)) {
3113
- // Don't add the same antecedent twice.
3114
- if (!label.antecedents.some((existing) => existing.id === antecedent.id)) {
3115
- label.antecedents.push(antecedent);
3116
- }
3117
- }
3118
- }
3119
-
3120
- private _bindNameToScope(scope: Scope, name: string, addedSymbols?: Map<string, Symbol>) {
3121
- // Is this name already bound to a scope other than the local one?
3122
- const bindingType = this._currentScope.getBindingType(name);
3123
-
3124
- if (bindingType !== undefined) {
3125
- const scopeToUse =
3126
- bindingType === NameBindingType.Nonlocal
3127
- ? this._currentScope.parent!
3128
- : this._currentScope.getGlobalScope().scope;
3129
- const symbolWithScope = scopeToUse.lookUpSymbolRecursive(name);
3130
- if (symbolWithScope) {
3131
- return symbolWithScope.symbol;
3132
- }
3133
- } else {
3134
- // Don't overwrite an existing symbol.
3135
- let symbol = scope.lookUpSymbol(name);
3136
- if (!symbol) {
3137
- symbol = scope.addSymbol(name, SymbolFlags.InitiallyUnbound | SymbolFlags.ClassMember);
3138
-
3139
- if (this._currentScope.type === ScopeType.Module || this._currentScope.type === ScopeType.Builtin) {
3140
- if (isPrivateOrProtectedName(name)) {
3141
- if (isPrivateName(name)) {
3142
- // Private names are obscured, so they are always externally hidden.
3143
- symbol.setIsExternallyHidden();
3144
- } else if (this._fileInfo.isStubFile || this._fileInfo.isInPyTypedPackage) {
3145
- if (this._currentScope.type === ScopeType.Builtin) {
3146
- // Don't include private-named symbols in the builtin scope.
3147
- symbol.setIsExternallyHidden();
3148
- } else {
3149
- this._potentialPrivateSymbols.set(name, symbol);
3150
- }
3151
- } else {
3152
- symbol.setIsPrivateMember();
3153
- }
3154
- }
3155
- }
3156
-
3157
- if (addedSymbols) {
3158
- addedSymbols.set(name, symbol);
3159
- }
3160
- }
3161
-
3162
- return symbol;
3163
- }
3164
-
3165
- return undefined;
3166
- }
3167
-
3168
- private _bindPossibleTupleNamedTarget(target: ExpressionNode, addedSymbols?: Map<string, Symbol>) {
3169
- switch (target.nodeType) {
3170
- case ParseNodeType.Name: {
3171
- this._bindNameToScope(this._currentScope, target.value, addedSymbols);
3172
- break;
3173
- }
3174
-
3175
- case ParseNodeType.Tuple: {
3176
- target.expressions.forEach((expr) => {
3177
- this._bindPossibleTupleNamedTarget(expr, addedSymbols);
3178
- });
3179
- break;
3180
- }
3181
-
3182
- case ParseNodeType.List: {
3183
- target.entries.forEach((expr) => {
3184
- this._bindPossibleTupleNamedTarget(expr, addedSymbols);
3185
- });
3186
- break;
3187
- }
3188
-
3189
- case ParseNodeType.TypeAnnotation: {
3190
- this._bindPossibleTupleNamedTarget(target.valueExpression, addedSymbols);
3191
- break;
3192
- }
3193
-
3194
- case ParseNodeType.Unpack: {
3195
- this._bindPossibleTupleNamedTarget(target.expression, addedSymbols);
3196
- break;
3197
- }
3198
- }
3199
- }
3200
-
3201
- private _addImplicitSymbolToCurrentScope(
3202
- nameValue: string,
3203
- node: ModuleNode | ClassNode | FunctionNode,
3204
- type: IntrinsicType
3205
- ) {
3206
- const symbol = this._addSymbolToCurrentScope(nameValue, /* isInitiallyUnbound */ false);
3207
- if (symbol) {
3208
- symbol.addDeclaration({
3209
- type: DeclarationType.Intrinsic,
3210
- node,
3211
- intrinsicType: type,
3212
- path: this._fileInfo.filePath,
3213
- range: getEmptyRange(),
3214
- moduleName: this._fileInfo.moduleName,
3215
- isInExceptSuite: this._isInExceptSuite,
3216
- });
3217
- symbol.setIsIgnoredForProtocolMatch();
3218
- }
3219
- }
3220
-
3221
- // Adds a new symbol with the specified name if it doesn't already exist.
3222
- private _addSymbolToCurrentScope(nameValue: string, isInitiallyUnbound: boolean) {
3223
- let symbol = this._currentScope.lookUpSymbol(nameValue);
3224
-
3225
- if (!symbol) {
3226
- let symbolFlags = SymbolFlags.None;
3227
-
3228
- if (isInitiallyUnbound) {
3229
- symbolFlags |= SymbolFlags.InitiallyUnbound;
3230
- }
3231
-
3232
- if (this._currentScope.type === ScopeType.Class) {
3233
- symbolFlags |= SymbolFlags.ClassMember;
3234
- }
3235
-
3236
- if (this._fileInfo.isStubFile && isPrivateOrProtectedName(nameValue)) {
3237
- symbolFlags |= SymbolFlags.ExternallyHidden;
3238
- }
3239
-
3240
- // Add the symbol. Assume that symbols with a default type source ID
3241
- // are "implicit" symbols added to the scope. These are not initially unbound.
3242
- symbol = this._currentScope.addSymbol(nameValue, symbolFlags);
3243
- }
3244
-
3245
- return symbol;
3246
- }
3247
-
3248
- private _createNewScope(scopeType: ScopeType, parentScope: Scope | undefined, callback: () => void) {
3249
- const prevScope = this._currentScope;
3250
- const newScope = new Scope(scopeType, parentScope);
3251
- this._currentScope = newScope;
3252
-
3253
- // If this scope is an execution scope, allocate a new reference map.
3254
- const isExecutionScope =
3255
- scopeType === ScopeType.Builtin || scopeType === ScopeType.Module || scopeType === ScopeType.Function;
3256
- const prevExpressions = this._currentScopeCodeFlowExpressions;
3257
-
3258
- if (isExecutionScope) {
3259
- this._currentScopeCodeFlowExpressions = new Set<string>();
3260
- }
3261
-
3262
- callback();
3263
-
3264
- this._currentScopeCodeFlowExpressions = prevExpressions;
3265
- this._currentScope = prevScope;
3266
-
3267
- return newScope;
3268
- }
3269
-
3270
- private _addInferredTypeAssignmentForVariable(
3271
- target: ExpressionNode,
3272
- source: ParseNode,
3273
- isPossibleTypeAlias = false
3274
- ) {
3275
- switch (target.nodeType) {
3276
- case ParseNodeType.Name: {
3277
- const name = target;
3278
- const symbolWithScope = this._currentScope.lookUpSymbolRecursive(name.value);
3279
- if (symbolWithScope && symbolWithScope.symbol) {
3280
- const declaration: VariableDeclaration = {
3281
- type: DeclarationType.Variable,
3282
- node: target,
3283
- isConstant: isConstantName(target.value),
3284
- inferredTypeSource: source,
3285
- isInferenceAllowedInPyTyped: this._isInferenceAllowedInPyTyped(name.value),
3286
- typeAliasName: isPossibleTypeAlias ? target : undefined,
3287
- path: this._fileInfo.filePath,
3288
- range: convertOffsetsToRange(name.start, TextRange.getEnd(name), this._fileInfo.lines),
3289
- moduleName: this._fileInfo.moduleName,
3290
- isInExceptSuite: this._isInExceptSuite,
3291
- docString: this._getVariableDocString(target),
3292
- };
3293
- symbolWithScope.symbol.addDeclaration(declaration);
3294
- }
3295
- break;
3296
- }
3297
-
3298
- case ParseNodeType.MemberAccess: {
3299
- const memberAccessInfo = this._getMemberAccessInfo(target);
3300
- if (memberAccessInfo) {
3301
- const name = target.memberName;
3302
-
3303
- let symbol = memberAccessInfo.classScope.lookUpSymbol(name.value);
3304
- if (!symbol) {
3305
- symbol = memberAccessInfo.classScope.addSymbol(name.value, SymbolFlags.InitiallyUnbound);
3306
- const honorPrivateNaming = this._fileInfo.diagnosticRuleSet.reportPrivateUsage !== 'none';
3307
- if (isPrivateOrProtectedName(name.value) && honorPrivateNaming) {
3308
- symbol.setIsPrivateMember();
3309
- }
3310
- }
3311
-
3312
- if (memberAccessInfo.isInstanceMember) {
3313
- // If a method (which has a declared type) is being overwritten
3314
- // by an expression with no declared type, don't mark it as
3315
- // an instance member because the type evaluator will think
3316
- // that it doesn't need to perform object binding.
3317
- if (
3318
- !symbol.isClassMember() ||
3319
- !symbol
3320
- .getDeclarations()
3321
- .some((decl) => decl.type === DeclarationType.Function && decl.isMethod)
3322
- ) {
3323
- symbol.setIsInstanceMember();
3324
- }
3325
- } else {
3326
- symbol.setIsClassMember();
3327
- }
3328
-
3329
- const declaration: VariableDeclaration = {
3330
- type: DeclarationType.Variable,
3331
- node: target.memberName,
3332
- isConstant: isConstantName(name.value),
3333
- inferredTypeSource: source,
3334
- isDefinedByMemberAccess: true,
3335
- path: this._fileInfo.filePath,
3336
- range: convertOffsetsToRange(
3337
- target.memberName.start,
3338
- target.memberName.start + target.memberName.length,
3339
- this._fileInfo.lines
3340
- ),
3341
- moduleName: this._fileInfo.moduleName,
3342
- isInExceptSuite: this._isInExceptSuite,
3343
- docString: this._getVariableDocString(target),
3344
- };
3345
- symbol.addDeclaration(declaration);
3346
- }
3347
- break;
3348
- }
3349
-
3350
- case ParseNodeType.Tuple: {
3351
- target.expressions.forEach((expr) => {
3352
- this._addInferredTypeAssignmentForVariable(expr, source);
3353
- });
3354
- break;
3355
- }
3356
-
3357
- case ParseNodeType.TypeAnnotation: {
3358
- this._addInferredTypeAssignmentForVariable(target.valueExpression, source);
3359
- break;
3360
- }
3361
-
3362
- case ParseNodeType.Unpack: {
3363
- this._addInferredTypeAssignmentForVariable(target.expression, source);
3364
- break;
3365
- }
3366
-
3367
- case ParseNodeType.List: {
3368
- target.entries.forEach((entry) => {
3369
- this._addInferredTypeAssignmentForVariable(entry, source);
3370
- });
3371
- break;
3372
- }
3373
- }
3374
- }
3375
-
3376
- private _isInferenceAllowedInPyTyped(symbolName: string): boolean {
3377
- const exemptSymbols = ['__match_args__', '__slots__', '__all__'];
3378
- return exemptSymbols.some((name) => name === symbolName);
3379
- }
3380
-
3381
- private _addTypeDeclarationForVariable(target: ExpressionNode, typeAnnotation: ExpressionNode) {
3382
- let declarationHandled = false;
3383
-
3384
- switch (target.nodeType) {
3385
- case ParseNodeType.Name: {
3386
- const name = target;
3387
- const symbolWithScope = this._currentScope.lookUpSymbolRecursive(name.value);
3388
- if (symbolWithScope && symbolWithScope.symbol) {
3389
- const finalInfo = this._isAnnotationFinal(typeAnnotation);
3390
- const isExplicitTypeAlias = this._isAnnotationTypeAlias(typeAnnotation);
3391
-
3392
- let typeAnnotationNode: ExpressionNode | undefined = typeAnnotation;
3393
- let innerTypeAnnotationNode: ExpressionNode | undefined = typeAnnotation;
3394
- if (isExplicitTypeAlias) {
3395
- typeAnnotationNode = undefined;
3396
- innerTypeAnnotationNode = undefined;
3397
-
3398
- // Type aliases are allowed only in the global or class scope.
3399
- if (
3400
- this._currentScope.type !== ScopeType.Class &&
3401
- this._currentScope.type !== ScopeType.Module &&
3402
- this._currentScope.type !== ScopeType.Builtin
3403
- ) {
3404
- this._addError(Localizer.Diagnostic.typeAliasNotInModuleOrClass(), typeAnnotation);
3405
- }
3406
- } else if (finalInfo.isFinal) {
3407
- innerTypeAnnotationNode = finalInfo.finalTypeNode;
3408
- if (!finalInfo.finalTypeNode) {
3409
- typeAnnotationNode = undefined;
3410
- }
3411
- }
3412
-
3413
- // Is this annotation indicating that the variable is a "ClassVar"?
3414
- let classVarInfo = this._isAnnotationClassVar(typeAnnotation);
3415
-
3416
- if (classVarInfo.isClassVar) {
3417
- innerTypeAnnotationNode = classVarInfo.classVarTypeNode;
3418
-
3419
- if (!classVarInfo.classVarTypeNode) {
3420
- typeAnnotationNode = undefined;
3421
- }
3422
- }
3423
-
3424
- // PEP 591 indicates that a Final variable initialized within a class
3425
- // body should also be considered a ClassVar.
3426
- if (finalInfo.isFinal) {
3427
- const containingClass = ParseTreeUtils.getEnclosingClassOrFunction(target);
3428
- if (containingClass && containingClass.nodeType === ParseNodeType.Class) {
3429
- // Make sure it's part of an assignment.
3430
- if (
3431
- target.parent?.nodeType === ParseNodeType.Assignment ||
3432
- target.parent?.parent?.nodeType === ParseNodeType.Assignment
3433
- ) {
3434
- classVarInfo = {
3435
- isClassVar: true,
3436
- classVarTypeNode: undefined,
3437
- };
3438
- }
3439
- }
3440
- }
3441
-
3442
- const declaration: VariableDeclaration = {
3443
- type: DeclarationType.Variable,
3444
- node: target,
3445
- isConstant: isConstantName(name.value),
3446
- isFinal: finalInfo.isFinal,
3447
- isClassVar: classVarInfo.isClassVar,
3448
- isRequired: this._isRequiredAnnotation(innerTypeAnnotationNode),
3449
- isNotRequired: this._isNotRequiredAnnotation(innerTypeAnnotationNode),
3450
- typeAliasAnnotation: isExplicitTypeAlias ? typeAnnotation : undefined,
3451
- typeAliasName: isExplicitTypeAlias ? target : undefined,
3452
- path: this._fileInfo.filePath,
3453
- typeAnnotationNode,
3454
- range: convertOffsetsToRange(name.start, TextRange.getEnd(name), this._fileInfo.lines),
3455
- moduleName: this._fileInfo.moduleName,
3456
- isInExceptSuite: this._isInExceptSuite,
3457
- docString: this._getVariableDocString(target),
3458
- };
3459
- symbolWithScope.symbol.addDeclaration(declaration);
3460
-
3461
- if (classVarInfo.isClassVar) {
3462
- symbolWithScope.symbol.setIsClassVar();
3463
- } else {
3464
- symbolWithScope.symbol.setIsInstanceMember();
3465
- }
3466
-
3467
- // Look for an 'InitVar' either by itself or wrapped in an 'Annotated'.
3468
- if (typeAnnotation.nodeType === ParseNodeType.Index) {
3469
- if (this._isDataclassesAnnotation(typeAnnotation.baseExpression, 'InitVar')) {
3470
- symbolWithScope.symbol.setIsInitVar();
3471
- } else if (
3472
- this._isTypingAnnotation(typeAnnotation.baseExpression, 'Annotated') &&
3473
- typeAnnotation.items.length > 0
3474
- ) {
3475
- const item0Expr = typeAnnotation.items[0].valueExpression;
3476
- if (
3477
- item0Expr.nodeType === ParseNodeType.Index &&
3478
- this._isDataclassesAnnotation(item0Expr.baseExpression, 'InitVar')
3479
- ) {
3480
- symbolWithScope.symbol.setIsInitVar();
3481
- }
3482
- }
3483
- }
3484
- }
3485
-
3486
- declarationHandled = true;
3487
- break;
3488
- }
3489
-
3490
- case ParseNodeType.MemberAccess: {
3491
- // We need to determine whether this expression is declaring a class or
3492
- // instance variable. This is difficult because python doesn't provide
3493
- // a keyword for accessing "this". Instead, it uses naming conventions
3494
- // of "cls" and "self", but we don't want to rely on these naming
3495
- // conventions here. Instead, we'll apply some heuristics to determine
3496
- // whether the symbol on the LHS is a reference to the current class
3497
- // or an instance of the current class.
3498
-
3499
- const memberAccessInfo = this._getMemberAccessInfo(target);
3500
- if (memberAccessInfo) {
3501
- const name = target.memberName;
3502
-
3503
- let symbol = memberAccessInfo.classScope.lookUpSymbol(name.value);
3504
- if (!symbol) {
3505
- symbol = memberAccessInfo.classScope.addSymbol(name.value, SymbolFlags.InitiallyUnbound);
3506
- const honorPrivateNaming = this._fileInfo.diagnosticRuleSet.reportPrivateUsage !== 'none';
3507
- if (isPrivateOrProtectedName(name.value) && honorPrivateNaming) {
3508
- symbol.setIsPrivateMember();
3509
- }
3510
- }
3511
-
3512
- if (memberAccessInfo.isInstanceMember) {
3513
- symbol.setIsInstanceMember();
3514
- } else {
3515
- symbol.setIsClassMember();
3516
- }
3517
-
3518
- const finalInfo = this._isAnnotationFinal(typeAnnotation);
3519
- const declaration: VariableDeclaration = {
3520
- type: DeclarationType.Variable,
3521
- node: target.memberName,
3522
- isConstant: isConstantName(name.value),
3523
- isDefinedByMemberAccess: true,
3524
- isFinal: finalInfo.isFinal,
3525
- path: this._fileInfo.filePath,
3526
- typeAnnotationNode: finalInfo.isFinal && !finalInfo.finalTypeNode ? undefined : typeAnnotation,
3527
- range: convertOffsetsToRange(
3528
- target.memberName.start,
3529
- target.memberName.start + target.memberName.length,
3530
- this._fileInfo.lines
3531
- ),
3532
- moduleName: this._fileInfo.moduleName,
3533
- isInExceptSuite: this._isInExceptSuite,
3534
- docString: this._getVariableDocString(target),
3535
- };
3536
- symbol.addDeclaration(declaration);
3537
-
3538
- declarationHandled = true;
3539
- }
3540
- break;
3541
- }
3542
- }
3543
-
3544
- if (!declarationHandled) {
3545
- this._addError(Localizer.Diagnostic.annotationNotSupported(), typeAnnotation);
3546
- }
3547
- }
3548
-
3549
- // Determines whether the expression refers to a type exported by the typing
3550
- // or typing_extensions modules. We can directly evaluate the types at binding
3551
- // time. We assume here that the code isn't making use of some custom type alias
3552
- // to refer to the typing types.
3553
- private _isTypingAnnotation(typeAnnotation: ExpressionNode, name: string): boolean {
3554
- return this._isKnownAnnotation(typeAnnotation, name, this._typingImportAliases, this._typingSymbolAliases);
3555
- }
3556
-
3557
- private _isDataclassesAnnotation(typeAnnotation: ExpressionNode, name: string): boolean {
3558
- return this._isKnownAnnotation(
3559
- typeAnnotation,
3560
- name,
3561
- this._dataclassesImportAliases,
3562
- this._dataclassesSymbolAliases
3563
- );
3564
- }
3565
-
3566
- private _isKnownAnnotation(
3567
- typeAnnotation: ExpressionNode,
3568
- name: string,
3569
- importAliases: string[],
3570
- symbolAliases: Map<string, string>
3571
- ) {
3572
- if (typeAnnotation.nodeType === ParseNodeType.Name) {
3573
- const alias = symbolAliases.get(typeAnnotation.value);
3574
- if (alias === name) {
3575
- return true;
3576
- }
3577
- } else if (typeAnnotation.nodeType === ParseNodeType.MemberAccess) {
3578
- if (
3579
- typeAnnotation.leftExpression.nodeType === ParseNodeType.Name &&
3580
- typeAnnotation.memberName.value === name
3581
- ) {
3582
- const baseName = typeAnnotation.leftExpression.value;
3583
- return importAliases.some((alias) => alias === baseName);
3584
- }
3585
- }
3586
-
3587
- return false;
3588
- }
3589
-
3590
- private _getVariableDocString(node: ExpressionNode): string | undefined {
3591
- // Walk up the parse tree to find an assignment expression.
3592
- let curNode: ParseNode | undefined = node;
3593
- let annotationNode: TypeAnnotationNode | undefined;
3594
-
3595
- while (curNode) {
3596
- if (curNode.nodeType === ParseNodeType.Assignment) {
3597
- break;
3598
- }
3599
-
3600
- if (curNode.nodeType === ParseNodeType.TypeAnnotation && !annotationNode) {
3601
- annotationNode = curNode;
3602
- }
3603
-
3604
- curNode = curNode.parent;
3605
- }
3606
-
3607
- if (curNode?.nodeType !== ParseNodeType.Assignment) {
3608
- // Allow a simple annotation statement to have a docstring even
3609
- // though PEP 258 doesn't mention this case. This PEP pre-dated
3610
- // PEP 526, so it didn't contemplate this situation.
3611
- if (annotationNode) {
3612
- curNode = annotationNode;
3613
- } else {
3614
- return undefined;
3615
- }
3616
- }
3617
-
3618
- const parentNode = curNode.parent;
3619
- if (parentNode?.nodeType !== ParseNodeType.StatementList) {
3620
- return undefined;
3621
- }
3622
-
3623
- const suiteOrModule = parentNode.parent;
3624
- if (
3625
- !suiteOrModule ||
3626
- (suiteOrModule.nodeType !== ParseNodeType.Module && suiteOrModule.nodeType !== ParseNodeType.Suite)
3627
- ) {
3628
- return undefined;
3629
- }
3630
-
3631
- const assignmentIndex = suiteOrModule.statements.findIndex((node) => node === parentNode);
3632
- if (assignmentIndex < 0 || assignmentIndex === suiteOrModule.statements.length - 1) {
3633
- return undefined;
3634
- }
3635
-
3636
- const nextStatement = suiteOrModule.statements[assignmentIndex + 1];
3637
-
3638
- if (nextStatement.nodeType !== ParseNodeType.StatementList || !ParseTreeUtils.isDocString(nextStatement)) {
3639
- return undefined;
3640
- }
3641
-
3642
- // See if the assignment is within one of the contexts specified in PEP 258.
3643
- let isValidContext = false;
3644
- if (parentNode?.parent?.nodeType === ParseNodeType.Module) {
3645
- // If we're at the top level of a module, the attribute docstring is valid.
3646
- isValidContext = true;
3647
- } else if (
3648
- parentNode?.parent?.nodeType === ParseNodeType.Suite &&
3649
- parentNode?.parent?.parent?.nodeType === ParseNodeType.Class
3650
- ) {
3651
- // If we're at the top level of a class, the attribute docstring is valid.
3652
- isValidContext = true;
3653
- } else {
3654
- const func = ParseTreeUtils.getEnclosingFunction(parentNode);
3655
-
3656
- // If we're within an __init__ method, the attribute docstring is valid.
3657
- if (
3658
- func &&
3659
- func.name.value === '__init__' &&
3660
- ParseTreeUtils.getEnclosingClass(func, /* stopAtFunction */ true)
3661
- ) {
3662
- isValidContext = true;
3663
- }
3664
- }
3665
-
3666
- if (!isValidContext) {
3667
- return undefined;
3668
- }
3669
-
3670
- // A docstring can consist of multiple joined strings in a single expression.
3671
- const strings = (nextStatement.statements[0] as StringListNode).strings;
3672
- if (strings.length === 1) {
3673
- // Common case.
3674
- return strings[0].value;
3675
- }
3676
-
3677
- return strings.map((s) => s.value).join('');
3678
- }
3679
-
3680
- // Determines if the specified type annotation expression is a "Final".
3681
- // It returns a value indicating whether the expression is a "Final"
3682
- // expression and whether it's a "raw" Final with no type arguments.
3683
- private _isAnnotationFinal(typeAnnotation: ExpressionNode | undefined): FinalInfo {
3684
- let isFinal = false;
3685
- let finalTypeNode: ExpressionNode | undefined;
3686
-
3687
- if (typeAnnotation) {
3688
- if (this._isTypingAnnotation(typeAnnotation, 'Final')) {
3689
- isFinal = true;
3690
- } else if (typeAnnotation.nodeType === ParseNodeType.Index && typeAnnotation.items.length === 1) {
3691
- // Recursively call to see if the base expression is "Final".
3692
- const finalInfo = this._isAnnotationFinal(typeAnnotation.baseExpression);
3693
- if (
3694
- finalInfo.isFinal &&
3695
- typeAnnotation.items[0].argumentCategory === ArgumentCategory.Simple &&
3696
- !typeAnnotation.items[0].name &&
3697
- !typeAnnotation.trailingComma
3698
- ) {
3699
- isFinal = true;
3700
- finalTypeNode = typeAnnotation.items[0].valueExpression;
3701
- }
3702
- }
3703
- }
3704
-
3705
- return { isFinal, finalTypeNode };
3706
- }
3707
-
3708
- // Determines if the specified type annotation expression is a "ClassVar".
3709
- // It returns a value indicating whether the expression is a "ClassVar"
3710
- // expression and whether it's a "raw" ClassVar with no type arguments.
3711
- private _isAnnotationClassVar(typeAnnotation: ExpressionNode | undefined): ClassVarInfo {
3712
- let isClassVar = false;
3713
- let classVarTypeNode: ExpressionNode | undefined;
3714
-
3715
- while (typeAnnotation) {
3716
- if (
3717
- typeAnnotation.nodeType === ParseNodeType.Index &&
3718
- typeAnnotation.items.length > 0 &&
3719
- this._isTypingAnnotation(typeAnnotation.baseExpression, 'Annotated')
3720
- ) {
3721
- typeAnnotation = typeAnnotation.items[0].valueExpression;
3722
- } else if (this._isTypingAnnotation(typeAnnotation, 'ClassVar')) {
3723
- isClassVar = true;
3724
- break;
3725
- } else if (typeAnnotation.nodeType === ParseNodeType.Index && typeAnnotation.items.length === 1) {
3726
- // Recursively call to see if the base expression is "ClassVar".
3727
- const finalInfo = this._isAnnotationClassVar(typeAnnotation.baseExpression);
3728
- if (
3729
- finalInfo.isClassVar &&
3730
- typeAnnotation.items[0].argumentCategory === ArgumentCategory.Simple &&
3731
- !typeAnnotation.items[0].name &&
3732
- !typeAnnotation.trailingComma
3733
- ) {
3734
- isClassVar = true;
3735
- classVarTypeNode = typeAnnotation.items[0].valueExpression;
3736
- }
3737
- break;
3738
- } else {
3739
- break;
3740
- }
3741
- }
3742
-
3743
- return { isClassVar, classVarTypeNode };
3744
- }
3745
-
3746
- // Determines if the specified type annotation is wrapped in a "Required".
3747
- private _isRequiredAnnotation(typeAnnotation: ExpressionNode | undefined): boolean {
3748
- if (typeAnnotation && typeAnnotation.nodeType === ParseNodeType.Index && typeAnnotation.items.length === 1) {
3749
- if (this._isTypingAnnotation(typeAnnotation.baseExpression, 'Required')) {
3750
- return true;
3751
- }
3752
- }
3753
-
3754
- return false;
3755
- }
3756
-
3757
- // Determines if the specified type annotation is wrapped in a "NotRequired".
3758
- private _isNotRequiredAnnotation(typeAnnotation: ExpressionNode | undefined): boolean {
3759
- if (typeAnnotation && typeAnnotation.nodeType === ParseNodeType.Index && typeAnnotation.items.length === 1) {
3760
- if (this._isTypingAnnotation(typeAnnotation.baseExpression, 'NotRequired')) {
3761
- return true;
3762
- }
3763
- }
3764
-
3765
- return false;
3766
- }
3767
-
3768
- private _isAnnotationTypeAlias(typeAnnotation: ExpressionNode | undefined) {
3769
- if (!typeAnnotation) {
3770
- return false;
3771
- }
3772
-
3773
- return this._isTypingAnnotation(typeAnnotation, 'TypeAlias');
3774
- }
3775
-
3776
- // Determines whether a member access expression is referring to a
3777
- // member of a class (either a class or instance member). This will
3778
- // typically take the form "self.x" or "cls.x".
3779
- private _getMemberAccessInfo(node: MemberAccessNode): MemberAccessInfo | undefined {
3780
- // We handle only simple names on the left-hand side of the expression,
3781
- // not calls, nested member accesses, index expressions, etc.
3782
- if (node.leftExpression.nodeType !== ParseNodeType.Name) {
3783
- return undefined;
3784
- }
3785
-
3786
- const leftSymbolName = node.leftExpression.value;
3787
-
3788
- // Make sure the expression is within a function (i.e. a method) that's
3789
- // within a class definition.
3790
- const methodNode = ParseTreeUtils.getEnclosingFunction(node);
3791
- if (!methodNode) {
3792
- return undefined;
3793
- }
3794
-
3795
- const classNode = ParseTreeUtils.getEnclosingClass(methodNode, /* stopAtFunction */ true);
3796
- if (!classNode) {
3797
- return undefined;
3798
- }
3799
-
3800
- // Determine whether the left-hand side indicates a class or
3801
- // instance member.
3802
- let isInstanceMember = false;
3803
-
3804
- if (methodNode.parameters.length < 1 || !methodNode.parameters[0].name) {
3805
- return undefined;
3806
- }
3807
-
3808
- const className = classNode.name.value;
3809
- const firstParamName = methodNode.parameters[0].name.value;
3810
-
3811
- if (leftSymbolName === className) {
3812
- isInstanceMember = false;
3813
- } else {
3814
- if (leftSymbolName !== firstParamName) {
3815
- return undefined;
3816
- }
3817
-
3818
- // To determine whether the first parameter of the method
3819
- // refers to the class or the instance, we need to apply
3820
- // some heuristics.
3821
- if (methodNode.name.value === '__new__') {
3822
- // The __new__ method is special. It acts as a classmethod even
3823
- // though it doesn't have a @classmethod decorator.
3824
- isInstanceMember = false;
3825
- } else {
3826
- // Assume that it's an instance member unless we find
3827
- // a decorator that tells us otherwise.
3828
- isInstanceMember = true;
3829
- for (const decorator of methodNode.decorators) {
3830
- if (decorator.expression.nodeType === ParseNodeType.Name) {
3831
- const decoratorName = decorator.expression.value;
3832
-
3833
- if (decoratorName === 'staticmethod') {
3834
- // A static method doesn't have a "self" or "cls" parameter.
3835
- return undefined;
3836
- } else if (decoratorName === 'classmethod') {
3837
- // A classmethod implies that the first parameter is "cls".
3838
- isInstanceMember = false;
3839
- break;
3840
- }
3841
- }
3842
- }
3843
- }
3844
- }
3845
-
3846
- const classScope = AnalyzerNodeInfo.getScope(classNode)!;
3847
- assert(classScope !== undefined);
3848
-
3849
- return {
3850
- classNode,
3851
- methodNode,
3852
- classScope,
3853
- isInstanceMember,
3854
- };
3855
- }
3856
-
3857
- private _addImplicitImportsToLoaderActions(importResult: ImportResult, loaderActions: ModuleLoaderActions) {
3858
- importResult.filteredImplicitImports.forEach((implicitImport) => {
3859
- const existingLoaderAction = loaderActions.implicitImports
3860
- ? loaderActions.implicitImports.get(implicitImport.name)
3861
- : undefined;
3862
- if (existingLoaderAction) {
3863
- existingLoaderAction.path = implicitImport.path;
3864
- existingLoaderAction.loadSymbolsFromPath = true;
3865
- } else {
3866
- if (!loaderActions.implicitImports) {
3867
- loaderActions.implicitImports = new Map<string, ModuleLoaderActions>();
3868
- }
3869
- loaderActions.implicitImports.set(implicitImport.name, {
3870
- path: implicitImport.path,
3871
- loadSymbolsFromPath: true,
3872
- implicitImports: new Map<string, ModuleLoaderActions>(),
3873
- });
3874
- }
3875
- });
3876
- }
3877
-
3878
- // Handles some special-case assignment statements that are found
3879
- // within the typings.pyi file.
3880
- private _handleTypingStubAssignmentOrAnnotation(node: AssignmentNode | TypeAnnotationNode) {
3881
- if (!this._fileInfo.isTypingStubFile) {
3882
- return false;
3883
- }
3884
-
3885
- let annotationNode: TypeAnnotationNode;
3886
-
3887
- if (node.nodeType === ParseNodeType.TypeAnnotation) {
3888
- annotationNode = node;
3889
- } else {
3890
- if (node.leftExpression.nodeType !== ParseNodeType.TypeAnnotation) {
3891
- return false;
3892
- }
3893
-
3894
- annotationNode = node.leftExpression;
3895
- }
3896
-
3897
- if (annotationNode.valueExpression.nodeType !== ParseNodeType.Name) {
3898
- return false;
3899
- }
3900
-
3901
- const assignedNameNode = annotationNode.valueExpression;
3902
- const specialTypes: Map<string, boolean> = new Map([
3903
- ['Tuple', true],
3904
- ['Generic', true],
3905
- ['Protocol', true],
3906
- ['Callable', true],
3907
- ['Type', true],
3908
- ['ClassVar', true],
3909
- ['Final', true],
3910
- ['Literal', true],
3911
- ['TypedDict', true],
3912
- ['Union', true],
3913
- ['Optional', true],
3914
- ['Annotated', true],
3915
- ['TypeAlias', true],
3916
- ['OrderedDict', true],
3917
- ['Concatenate', true],
3918
- ['TypeGuard', true],
3919
- ['StrictTypeGuard', true],
3920
- ['Unpack', true],
3921
- ['Self', true],
3922
- ['NoReturn', true],
3923
- ['Never', true],
3924
- ['LiteralString', true],
3925
- ]);
3926
-
3927
- const assignedName = assignedNameNode.value;
3928
-
3929
- if (!specialTypes.has(assignedName)) {
3930
- return false;
3931
- }
3932
- const symbol = this._bindNameToScope(this._currentScope, assignedName);
3933
-
3934
- if (symbol) {
3935
- symbol.addDeclaration({
3936
- type: DeclarationType.SpecialBuiltInClass,
3937
- node: annotationNode,
3938
- path: this._fileInfo.filePath,
3939
- range: convertOffsetsToRange(
3940
- annotationNode.start,
3941
- TextRange.getEnd(annotationNode),
3942
- this._fileInfo.lines
3943
- ),
3944
- moduleName: this._fileInfo.moduleName,
3945
- isInExceptSuite: this._isInExceptSuite,
3946
- });
3947
- }
3948
- return true;
3949
- }
3950
-
3951
- private _deferBinding(callback: () => void) {
3952
- if (this._moduleSymbolOnly) {
3953
- return;
3954
- }
3955
-
3956
- this._deferredBindingTasks.push({
3957
- scope: this._currentScope,
3958
- codeFlowExpressions: this._currentScopeCodeFlowExpressions!,
3959
- callback,
3960
- });
3961
- }
3962
-
3963
- private _bindDeferred() {
3964
- while (this._deferredBindingTasks.length > 0) {
3965
- const nextItem = this._deferredBindingTasks.shift()!;
3966
-
3967
- // Reset the state
3968
- this._currentScope = nextItem.scope;
3969
- this._currentScopeCodeFlowExpressions = nextItem.codeFlowExpressions;
3970
-
3971
- nextItem.callback();
3972
- }
3973
- }
3974
-
3975
- private _bindYield(node: YieldNode | YieldFromNode) {
3976
- const functionNode = ParseTreeUtils.getEnclosingFunction(node);
3977
-
3978
- if (!functionNode) {
3979
- if (!ParseTreeUtils.getEnclosingLambda(node)) {
3980
- this._addError(Localizer.Diagnostic.yieldOutsideFunction(), node);
3981
- }
3982
- } else if (functionNode.isAsync && node.nodeType === ParseNodeType.YieldFrom) {
3983
- // PEP 525 indicates that 'yield from' is not allowed in an
3984
- // async function.
3985
- this._addError(Localizer.Diagnostic.yieldFromOutsideAsync(), node);
3986
- }
3987
-
3988
- if (this._targetFunctionDeclaration) {
3989
- if (!this._targetFunctionDeclaration.yieldStatements) {
3990
- this._targetFunctionDeclaration.yieldStatements = [];
3991
- }
3992
- this._targetFunctionDeclaration.yieldStatements.push(node);
3993
- this._targetFunctionDeclaration.isGenerator = true;
3994
- }
3995
-
3996
- if (node.expression) {
3997
- this.walk(node.expression);
3998
- }
3999
-
4000
- AnalyzerNodeInfo.setFlowNode(node, this._currentFlowNode!);
4001
- }
4002
-
4003
- private _getUniqueFlowNodeId() {
4004
- this._codeFlowComplexity += flowNodeComplexityFactor;
4005
- return getUniqueFlowNodeId();
4006
- }
4007
-
4008
- private _addDiagnostic(diagLevel: DiagnosticLevel, rule: string, message: string, textRange: TextRange) {
4009
- let diagnostic: Diagnostic | undefined;
4010
- switch (diagLevel) {
4011
- case 'error':
4012
- diagnostic = this._addError(message, textRange);
4013
- break;
4014
-
4015
- case 'warning':
4016
- diagnostic = this._addWarning(message, textRange);
4017
- break;
4018
-
4019
- case 'information':
4020
- diagnostic = this._addInformation(message, textRange);
4021
- break;
4022
-
4023
- case 'none':
4024
- break;
4025
-
4026
- default:
4027
- return assertNever(diagLevel, `${diagLevel} is not expected`);
4028
- }
4029
-
4030
- if (diagnostic) {
4031
- diagnostic.setRule(rule);
4032
- }
4033
-
4034
- return diagnostic;
4035
- }
4036
-
4037
- private _addError(message: string, textRange: TextRange) {
4038
- return this._fileInfo.diagnosticSink.addDiagnosticWithTextRange('error', message, textRange);
4039
- }
4040
-
4041
- private _addWarning(message: string, textRange: TextRange) {
4042
- return this._fileInfo.diagnosticSink.addDiagnosticWithTextRange('warning', message, textRange);
4043
- }
4044
-
4045
- private _addInformation(message: string, textRange: TextRange) {
4046
- return this._fileInfo.diagnosticSink.addDiagnosticWithTextRange('information', message, textRange);
4047
- }
4048
- }
4049
-
4050
- export class YieldFinder extends ParseTreeWalker {
4051
- private _containsYield = false;
4052
-
4053
- checkContainsYield(node: ParseNode) {
4054
- this.walk(node);
4055
- return this._containsYield;
4056
- }
4057
-
4058
- override visitYield(node: YieldNode): boolean {
4059
- this._containsYield = true;
4060
- return false;
4061
- }
4062
-
4063
- override visitYieldFrom(node: YieldFromNode): boolean {
4064
- this._containsYield = true;
4065
- return false;
4066
- }
4067
- }
4068
-
4069
- export class ReturnFinder extends ParseTreeWalker {
4070
- private _containsReturn = false;
4071
-
4072
- checkContainsReturn(node: ParseNode) {
4073
- this.walk(node);
4074
- return this._containsReturn;
4075
- }
4076
-
4077
- override visitReturn(node: ReturnNode): boolean {
4078
- this._containsReturn = true;
4079
- return false;
4080
- }
4081
- }