From 13d64f9479a1b904caa7398407dac1283ef533a7 Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Mon, 2 Oct 2023 09:57:25 +0200 Subject: [PATCH] Backport PR #14198: Revert "fix semicolon detection with no history" --- IPython/core/displayhook.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/IPython/core/displayhook.py b/IPython/core/displayhook.py index 1ea8d8506f5..b411f116139 100644 --- a/IPython/core/displayhook.py +++ b/IPython/core/displayhook.py @@ -51,7 +51,7 @@ def __init__(self, shell=None, cache_size=1000, **kwargs): # we need a reference to the user-level namespace self.shell = shell - + self._,self.__,self.___ = '','','' # these are deliberately global: @@ -83,9 +83,15 @@ def check_for_underscore(self): def quiet(self): """Should we silence the display hook because of ';'?""" - if self.exec_result is not None: - return self.semicolon_at_end_of_expression(self.exec_result.info.raw_cell) - return False + # do not print output if input ends in ';' + + try: + cell = self.shell.history_manager.input_hist_parsed[-1] + except IndexError: + # some uses of ipshellembed may fail here + return False + + return self.semicolon_at_end_of_expression(cell) @staticmethod def semicolon_at_end_of_expression(expression): @@ -274,12 +280,13 @@ def cull_cache(self): cull_count = max(int(sz * self.cull_fraction), 2) warn('Output cache limit (currently {sz} entries) hit.\n' 'Flushing oldest {cull_count} entries.'.format(sz=sz, cull_count=cull_count)) - + for i, n in enumerate(sorted(oh)): if i >= cull_count: break self.shell.user_ns.pop('_%i' % n, None) oh.pop(n, None) + def flush(self): if not self.do_full_cache: