|
19 | 19 | * get_python_parser().parse(), or |
20 | 20 | * python_parser() which does the above |
21 | 21 |
|
22 | | -Note however all of this is imported from the __init__ module |
23 | 22 | """ |
24 | 23 |
|
25 | 24 | import sys |
|
53 | 52 | from decompyle3.show import maybe_show_asm |
54 | 53 |
|
55 | 54 |
|
56 | | -def parse(p, tokens, customize, is_lambda) -> SyntaxTree: |
| 55 | +def parse(p, tokens, customize, is_lambda: bool) -> SyntaxTree: |
57 | 56 | was_lambda = p.is_lambda |
58 | 57 | p.is_lambda = is_lambda |
59 | 58 | p.customize_grammar_rules(tokens, customize) |
@@ -150,22 +149,26 @@ def python_parser( |
150 | 149 | co, |
151 | 150 | version: tuple = PYTHON_VERSION_TRIPLE, |
152 | 151 | out=sys.stdout, |
153 | | - showasm=False, |
| 152 | + showasm: bool = False, |
154 | 153 | parser_debug=PARSER_DEFAULT_DEBUG, |
155 | | - compile_mode="exec", |
156 | | - is_pypy=False, |
157 | | - is_lambda=False, |
158 | | -): |
| 154 | + compile_mode: str = "exec", |
| 155 | + is_pypy: bool = False, |
| 156 | + is_lambda: bool = False, |
| 157 | +) -> SyntaxTree: |
159 | 158 | """ |
160 | 159 | Parse a code object to an abstract syntax tree representation. |
161 | 160 |
|
162 | | - :param version: The python version this code is from as a float, for |
163 | | - example 2.6, 2.7, 3.2, 3.3, 3.4, 3.5 etc. |
164 | 161 | :param co: The code object to parse. |
| 162 | + :param version: The python version of this code is from as a float, for |
| 163 | + example, 2.6, 2.7, 3.2, 3.3, 3.4, 3.5 etc. |
165 | 164 | :param out: File like object to write the output to. |
166 | 165 | :param showasm: Flag which determines whether the disassembled and |
167 | 166 | ingested code is written to sys.stdout or not. |
168 | 167 | :param parser_debug: dict containing debug flags for the spark parser. |
| 168 | + :param compile_mode: compile mode that we want to parse input `co` as. |
| 169 | + This is either "exec", "eval" or, "single". |
| 170 | + :param is_pypy: True if ``co`` comes is PyPy code |
| 171 | + :param is_lambda True if ``co`` is a lambda expression |
169 | 172 |
|
170 | 173 | :return: Abstract syntax tree representation of the code object. |
171 | 174 | """ |
@@ -196,7 +199,6 @@ def python_parser( |
196 | 199 | if __name__ == "__main__": |
197 | 200 |
|
198 | 201 | def parse_test(co) -> None: |
199 | | - from decompyle3 import IS_PYPY |
200 | 202 |
|
201 | 203 | tree = python_parser(co, (3, 8, 2), showasm=True, is_pypy=IS_PYPY) |
202 | 204 | print(tree) |
|
0 commit comments