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

Backport PR #12823: Added clear kwarg to display() #12919

Merged
merged 1 commit into from Apr 17, 2021
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
11 changes: 9 additions & 2 deletions IPython/core/display.py
Expand Up @@ -163,6 +163,9 @@ def display(*objs, include=None, exclude=None, metadata=None, transient=None, di
Set an id for the display.
This id can be used for updating this display area later via update_display.
If given as `True`, generate a new `display_id`
clear : bool, optional
Should the output area be cleared before displaying anything? If True,
this will wait for additional output before clearing. [default: False]
kwargs: additional keyword-args, optional
Additional keyword-arguments are passed through to the display publisher.

Expand Down Expand Up @@ -281,8 +284,9 @@ def display(*objs, include=None, exclude=None, metadata=None, transient=None, di
# Directly print objects.
print(*objs)
return

raw = kwargs.pop('raw', False)

raw = kwargs.pop("raw", False)
clear = kwargs.pop("clear", False)
if transient is None:
transient = {}
if metadata is None:
Expand All @@ -306,6 +310,9 @@ def display(*objs, include=None, exclude=None, metadata=None, transient=None, di
if not raw:
format = InteractiveShell.instance().display_formatter.format

if clear:
clear_output(wait=True)

for obj in objs:
if raw:
publish_display_data(data=obj, metadata=metadata, **kwargs)
Expand Down