MCPcopy
hub / github.com/rocky/python-uncompyle6 / code_deparse_align

Function code_deparse_align

uncompyle6/semantics/aligner.py:128–206  ·  view source on GitHub ↗

ingests and deparses a given code block 'co'

(
    co,
    out=sys.stderr,
    version=None,
    is_pypy=None,
    debug_opts=DEFAULT_DEBUG_OPTS,
    code_objects={},
    compile_mode="exec",
)

Source from the content-addressed store, hash-verified

126
127
128def code_deparse_align(
129 co,
130 out=sys.stderr,
131 version=None,
132 is_pypy=None,
133 debug_opts=DEFAULT_DEBUG_OPTS,
134 code_objects={},
135 compile_mode="exec",
136):
137 """
138 ingests and deparses a given code block 'co'
139 """
140
141 assert iscode(co)
142
143 if version is None:
144 version = PYTHON_VERSION_TRIPLE
145 if is_pypy is None:
146 is_pypy = IS_PYPY
147
148 # store final output stream for case of error
149 scanner = get_scanner(version, is_pypy=is_pypy)
150
151 tokens, customize = scanner.ingest(co, code_objects=code_objects)
152 show_asm = debug_opts.get("asm", None)
153 maybe_show_asm(show_asm, tokens)
154
155 debug_parser = dict(PARSER_DEFAULT_DEBUG)
156 show_grammar = debug_opts.get("grammar", None)
157 show_grammar = debug_opts.get("grammar", None)
158 if show_grammar:
159 debug_parser["reduce"] = show_grammar
160 debug_parser["errorstack"] = True
161
162 # Build a parse tree from tokenized and massaged disassembly.
163 show_ast = debug_opts.get("ast", TREE_DEFAULT_DEBUG)
164 deparsed = AligningWalker(
165 version,
166 out,
167 scanner,
168 showast=show_ast,
169 debug_parser=debug_parser,
170 compile_mode=compile_mode,
171 is_pypy=is_pypy,
172 )
173
174 is_top_level_module = co.co_name == "<module>"
175 deparsed.ast = deparsed.build_ast(
176 tokens, customize, co, is_top_level_module=is_top_level_module
177 )
178
179 assert deparsed.ast == "stmts", "Should have parsed grammar start"
180
181 del tokens # save memory
182
183 (deparsed.mod_globs, _) = find_globals_and_nonlocals(
184 deparsed.ast, set(), set(), co, version
185 )

Callers 1

deparse_testFunction · 0.85

Calls 10

writeMethod · 0.95
get_scannerFunction · 0.90
maybe_show_asmFunction · 0.90
SourceWalkerErrorClass · 0.90
AligningWalkerClass · 0.85
ingestMethod · 0.45
getMethod · 0.45
build_astMethod · 0.45
gen_sourceMethod · 0.45

Tested by

no test coverage detected