diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index d2125f6..71cb7db 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -144,23 +144,29 @@ class ReadlineNoRecord(object): def __enter__(self): if self._nested_level == 0: - self.orig_length = self.current_length() - self.readline_tail = self.get_readline_tail() + try: + self.orig_length = self.current_length() + self.readline_tail = self.get_readline_tail() + except (AttributeError, IndexError): # Can fail with pyreadline + self.orig_length, self.readline_tail = 999999, [] self._nested_level += 1 def __exit__(self, type, value, traceback): self._nested_level -= 1 if self._nested_level == 0: # Try clipping the end if it's got longer - e = self.current_length() - self.orig_length - if e > 0: - for _ in range(e): - self.shell.readline.remove_history_item(self.orig_length) - - # If it still doesn't match, just reload readline history. - if self.current_length() != self.orig_length \ - or self.get_readline_tail() != self.readline_tail: - self.shell.refill_readline_hist() + try: + e = self.current_length() - self.orig_length + if e > 0: + for _ in range(e): + self.shell.readline.remove_history_item(self.orig_length) + + # If it still doesn't match, just reload readline history. + if self.current_length() != self.orig_length \ + or self.get_readline_tail() != self.readline_tail: + self.shell.refill_readline_hist() + except (AttributeError, IndexError): + pass # Returning False will cause exceptions to propagate return False