Skip to content

Commit

Permalink
Backport PR ipython#12823: Added clear kwarg to display()
Browse files Browse the repository at this point in the history
  • Loading branch information
Carreau committed Apr 17, 2021
1 parent 197b993 commit 6ebff35
Show file tree
Hide file tree
Showing 2 changed files with 383 additions and 2 deletions.
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

0 comments on commit 6ebff35

Please sign in to comment.