Push a line of code onto the buffer, start running the buffer If the interpreter successfully runs the code, clear the buffer
(self, line, insert_into_history=True)
| 1245 | return indent |
| 1246 | |
| 1247 | def push(self, line, insert_into_history=True) -> bool: |
| 1248 | """Push a line of code onto the buffer, start running the buffer |
| 1249 | |
| 1250 | If the interpreter successfully runs the code, clear the buffer |
| 1251 | """ |
| 1252 | # Note that push() overrides its parent without calling it, unlike |
| 1253 | # urwid and cli which implement custom behavior and call repl.Repl.push |
| 1254 | if self.paste_mode: |
| 1255 | self.saved_indent = 0 |
| 1256 | else: |
| 1257 | self.saved_indent = self.predicted_indent(line) |
| 1258 | |
| 1259 | if self.config.syntax: |
| 1260 | display_line = bpythonparse( |
| 1261 | pygformat(self.tokenize(line), self.formatter) |
| 1262 | ) |
| 1263 | # self.tokenize requires that the line not be in self.buffer yet |
| 1264 | |
| 1265 | logger.debug( |
| 1266 | "display line being pushed to buffer: %r -> %r", |
| 1267 | line, |
| 1268 | display_line, |
| 1269 | ) |
| 1270 | self.display_buffer.append(display_line) |
| 1271 | else: |
| 1272 | self.display_buffer.append(fmtstr(line)) |
| 1273 | |
| 1274 | if insert_into_history: |
| 1275 | self.insert_into_history(line) |
| 1276 | self.buffer.append(line) |
| 1277 | |
| 1278 | code_to_run = "\n".join(self.buffer) |
| 1279 | |
| 1280 | logger.debug("running %r in interpreter", self.buffer) |
| 1281 | c, code_will_parse = code_finished_will_parse( |
| 1282 | "\n".join(self.buffer), self.interp.compile |
| 1283 | ) |
| 1284 | self.saved_predicted_parse_error = not code_will_parse |
| 1285 | if c: |
| 1286 | logger.debug("finished - buffer cleared") |
| 1287 | self.cursor_offset = 0 |
| 1288 | self.display_lines.extend(self.display_buffer_lines) |
| 1289 | self.display_buffer = [] |
| 1290 | self.buffer = [] |
| 1291 | |
| 1292 | self.coderunner.load_code(code_to_run) |
| 1293 | self.run_code_and_maybe_finish() |
| 1294 | return not code_will_parse |
| 1295 | |
| 1296 | def run_code_and_maybe_finish(self, for_code=None): |
| 1297 | r = self.coderunner.run_code(for_code=for_code) |
no test coverage detected