convert parse tree to Python source code
(
self,
ast,
name,
customize,
is_lambda=False,
returnNone=False,
debug_opts=DEFAULT_DEBUG_OPTS,
)
| 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, |
no test coverage detected