Skip to content

Commit 07c94ed

Browse files
prevent enter if syntax error
1 parent f7949d5 commit 07c94ed

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

bpython/curtsiesfrontend/repl.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -684,10 +684,16 @@ def readline_kill(self, e):
684684

685685
def on_enter(self, insert_into_history=True):
686686
# so the cursor isn't touching a paren TODO: necessary?
687-
self._set_cursor_offset(-1, update_completion=False)
688687

689-
self.history.append(self.current_line)
690-
self.push(self.current_line, insert_into_history=insert_into_history)
688+
try:
689+
self.interp.compile('\n'.join(self.buffer + [self.current_line]))
690+
except (ValueError, SyntaxError, OverflowError) as e:
691+
self.status_bar.message(str(e))
692+
else:
693+
self._set_cursor_offset(-1, update_completion=False)
694+
695+
self.history.append(self.current_line)
696+
self.push(self.current_line, insert_into_history=insert_into_history)
691697

692698
def on_tab(self, back=False):
693699
"""Do something on tab key

0 commit comments

Comments
 (0)