diff --git a/IPython/core/display_functions.py b/IPython/core/display_functions.py index aab2b7e..567cf3f 100644 --- a/IPython/core/display_functions.py +++ b/IPython/core/display_functions.py @@ -8,6 +8,7 @@ from binascii import b2a_hex import os import sys +import warnings __all__ = ['display', 'clear_output', 'publish_display_data', 'update_display', 'DisplayHandle'] @@ -33,9 +34,17 @@ def _merge(d1, d2): # Main functions #----------------------------------------------------------------------------- +class _Sentinel: + def __repr__(self): + return "" + + +_sentinel = _Sentinel() # use * to indicate transient is keyword-only -def publish_display_data(data, metadata=None, source=None, *, transient=None, **kwargs): +def publish_display_data( + data, metadata=None, source=_sentinel, *, transient=None, **kwargs +): """Publish data and metadata to all frontends. See the ``display_data`` message in the messaging documentation for @@ -65,6 +74,14 @@ def publish_display_data(data, metadata=None, source=None, *, transient=None, ** """ from IPython.core.interactiveshell import InteractiveShell + if source is not _sentinel: + warnings.warn( + "The `source` parameter emit a deprecation warning since" + " IPython 8.0, it had no effects for a long time and will " + " be removed in future versions.", + DeprecationWarning, + stacklevel=2, + ) display_pub = InteractiveShell.instance().display_pub # only pass transient if supplied, diff --git a/IPython/terminal/tests/test_interactivshell.py b/IPython/terminal/tests/test_interactivshell.py index 7a06cc3..68dbe37 100644 --- a/IPython/terminal/tests/test_interactivshell.py +++ b/IPython/terminal/tests/test_interactivshell.py @@ -191,26 +191,29 @@ class InteractiveShellTestCase(unittest.TestCase): class Test2(Test): def _ipython_display_(self): from IPython.display import display, HTML - display(HTML('')) + + display(HTML("")) # verify that mimehandlers are called called = False def handler(data, metadata): - print('Handler called') + print("Handler called") nonlocal called called = True ip.display_formatter.active_types.append("text/html") ip.display_formatter.formatters["text/html"].enabled = True ip.mime_renderers["text/html"] = handler - - - obj = Test() - display(obj) + try: + obj = Test() + display(obj) + finally: + ip.display_formatter.formatters["text/html"].enabled = False + del ip.mime_renderers["text/html"] assert called == True - + def syntax_error_transformer(lines): """Transformer that throws SyntaxError if 'syntaxerror' is in the code."""