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

Method gen_source

uncompyle6/semantics/pysource.py:1175–1205  ·  view source on GitHub ↗

convert parse tree to Python source code

(
        self,
        ast,
        name,
        customize,
        is_lambda=False,
        returnNone=False,
        debug_opts=DEFAULT_DEBUG_OPTS,
    )

Source from the content-addressed store, hash-verified

1173 self.classes.pop(-1)
1174
1175 def gen_source(
1176 self,
1177 ast,
1178 name,
1179 customize,
1180 is_lambda=False,
1181 returnNone=False,
1182 debug_opts=DEFAULT_DEBUG_OPTS,
1183 ):
1184 """convert parse tree to Python source code"""
1185
1186 rn = self.return_none
1187 self.return_none = returnNone
1188 old_name = self.name
1189 self.name = name
1190 self.debug_opts = debug_opts
1191 # if code would be empty, append 'pass'
1192 if len(ast) == 0:
1193 self.println(self.indent, "pass")
1194 else:
1195 self.customize(customize)
1196 self.text = self.traverse(ast, is_lambda=is_lambda)
1197 # In a formatted string using "lambda", we should not add "\n".
1198 # For example in:
1199 # f'{(lambda x:x)("8")!r}'
1200 # Adding a "\n" after "lambda x: x" will give an error message:
1201 # SyntaxError: f-string expression part cannot include a backslash
1202 # So avoid \n after writing text
1203 self.write(self.text)
1204 self.name = old_name
1205 self.return_none = rn
1206
1207 def build_ast(
1208 self,

Callers 8

build_classMethod · 0.95
code_deparseFunction · 0.45
make_function2Function · 0.45
make_function3_annotateFunction · 0.45
make_function3Function · 0.45
make_function36Function · 0.45
code_deparse_alignFunction · 0.45
make_function1Function · 0.45

Calls 4

printlnMethod · 0.95
customizeMethod · 0.95
traverseMethod · 0.95
writeMethod · 0.95

Tested by

no test coverage detected