(
self,
tokens,
customize,
code,
is_lambda=False,
noneInNames=False,
is_top_level_module=False,
compile_mode="exec",
)
| 1205 | self.return_none = rn |
| 1206 | |
| 1207 | def build_ast( |
| 1208 | self, |
| 1209 | tokens, |
| 1210 | customize, |
| 1211 | code, |
| 1212 | is_lambda=False, |
| 1213 | noneInNames=False, |
| 1214 | is_top_level_module=False, |
| 1215 | compile_mode="exec", |
| 1216 | ) -> GenericASTTraversal: |
| 1217 | # FIXME: DRY with fragments.py |
| 1218 | |
| 1219 | # assert isinstance(tokens[0], Token) |
| 1220 | |
| 1221 | if is_lambda: |
| 1222 | for t in tokens: |
| 1223 | if t.kind == "RETURN_END_IF": |
| 1224 | t.kind = "RETURN_END_IF_LAMBDA" |
| 1225 | elif t.kind == "RETURN_VALUE": |
| 1226 | t.kind = "RETURN_VALUE_LAMBDA" |
| 1227 | tokens.append(Token("LAMBDA_MARKER")) |
| 1228 | try: |
| 1229 | # FIXME: have p.insts update in a better way |
| 1230 | # modularity is broken here |
| 1231 | p_insts = self.p.insts |
| 1232 | self.p.insts = self.scanner.insts |
| 1233 | self.p.offset2inst_index = self.scanner.offset2inst_index |
| 1234 | ast = parse(self.p, tokens, customize, code) |
| 1235 | self.customize(customize) |
| 1236 | self.p.insts = p_insts |
| 1237 | |
| 1238 | except (ParserError, AssertionError) as e: |
| 1239 | raise ParserError(e, tokens, self.p.debug["reduce"]) |
| 1240 | transform_tree = self.treeTransform.transform(ast, code) |
| 1241 | self.maybe_show_tree(ast, phase="after") |
| 1242 | del ast # Save memory |
| 1243 | return transform_tree |
| 1244 | |
| 1245 | # The bytecode for the end of the main routine has a "return |
| 1246 | # None". However, you can't issue a "return" statement in |
| 1247 | # main. So as the old cigarette slogan goes: I'd rather switch |
| 1248 | # (the token stream) than fight (with the grammar to not emit |
| 1249 | # "return None"). |
| 1250 | if self.hide_internal: |
| 1251 | if len(tokens) >= 2 and not noneInNames: |
| 1252 | if tokens[-1].kind in ("RETURN_VALUE", "RETURN_VALUE_LAMBDA"): |
| 1253 | # Python 3.4's classes can add a "return None" which is |
| 1254 | # invalid syntax. |
| 1255 | load_const = tokens[-2] |
| 1256 | # We should have: |
| 1257 | # LOAD_CONST None |
| 1258 | # with *no* line number associated the token. |
| 1259 | # A line number on the token or a non-None |
| 1260 | # token value a token based on user source |
| 1261 | # text. |
| 1262 | if ( |
| 1263 | load_const.kind == "LOAD_CONST" |
| 1264 | and load_const.linestart is None |
no test coverage detected