Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix semicolon detection with no history #14163

Merged
merged 1 commit into from
Sep 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 5 additions & 12 deletions IPython/core/displayhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -83,15 +83,9 @@ def check_for_underscore(self):

def quiet(self):
"""Should we silence the display hook because of ';'?"""
# 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)
if self.exec_result is not None:
return self.semicolon_at_end_of_expression(self.exec_result.info.raw_cell)
return False

@staticmethod
def semicolon_at_end_of_expression(expression):
Expand Down Expand Up @@ -280,13 +274,12 @@ 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:
Expand Down