Show More
@@ -8,6 +8,7 b'' | |||||
8 | from binascii import b2a_hex |
|
8 | from binascii import b2a_hex | |
9 | import os |
|
9 | import os | |
10 | import sys |
|
10 | import sys | |
|
11 | import warnings | |||
11 |
|
12 | |||
12 | __all__ = ['display', 'clear_output', 'publish_display_data', 'update_display', 'DisplayHandle'] |
|
13 | __all__ = ['display', 'clear_output', 'publish_display_data', 'update_display', 'DisplayHandle'] | |
13 |
|
14 | |||
@@ -33,9 +34,17 b' def _merge(d1, d2):' | |||||
33 | # Main functions |
|
34 | # Main functions | |
34 | #----------------------------------------------------------------------------- |
|
35 | #----------------------------------------------------------------------------- | |
35 |
|
36 | |||
|
37 | class _Sentinel: | |||
|
38 | def __repr__(self): | |||
|
39 | return "<deprecated>" | |||
|
40 | ||||
|
41 | ||||
|
42 | _sentinel = _Sentinel() | |||
36 |
|
43 | |||
37 | # use * to indicate transient is keyword-only |
|
44 | # use * to indicate transient is keyword-only | |
38 | def publish_display_data(data, metadata=None, source=None, *, transient=None, **kwargs): |
|
45 | def publish_display_data( | |
|
46 | data, metadata=None, source=_sentinel, *, transient=None, **kwargs | |||
|
47 | ): | |||
39 | """Publish data and metadata to all frontends. |
|
48 | """Publish data and metadata to all frontends. | |
40 |
|
49 | |||
41 | See the ``display_data`` message in the messaging documentation for |
|
50 | See the ``display_data`` message in the messaging documentation for | |
@@ -65,6 +74,14 b' def publish_display_data(data, metadata=None, source=None, *, transient=None, **' | |||||
65 | """ |
|
74 | """ | |
66 | from IPython.core.interactiveshell import InteractiveShell |
|
75 | from IPython.core.interactiveshell import InteractiveShell | |
67 |
|
76 | |||
|
77 | if source is not _sentinel: | |||
|
78 | warnings.warn( | |||
|
79 | "The `source` parameter emit a deprecation warning since" | |||
|
80 | " IPython 8.0, it had no effects for a long time and will " | |||
|
81 | " be removed in future versions.", | |||
|
82 | DeprecationWarning, | |||
|
83 | stacklevel=2, | |||
|
84 | ) | |||
68 | display_pub = InteractiveShell.instance().display_pub |
|
85 | display_pub = InteractiveShell.instance().display_pub | |
69 |
|
86 | |||
70 | # only pass transient if supplied, |
|
87 | # only pass transient if supplied, |
@@ -191,26 +191,29 b' class InteractiveShellTestCase(unittest.TestCase):' | |||||
191 | class Test2(Test): |
|
191 | class Test2(Test): | |
192 | def _ipython_display_(self): |
|
192 | def _ipython_display_(self): | |
193 | from IPython.display import display, HTML |
|
193 | from IPython.display import display, HTML | |
194 | display(HTML('<custom>')) |
|
194 | ||
|
195 | display(HTML("<custom>")) | |||
195 |
|
196 | |||
196 | # verify that mimehandlers are called |
|
197 | # verify that mimehandlers are called | |
197 | called = False |
|
198 | called = False | |
198 |
|
199 | |||
199 | def handler(data, metadata): |
|
200 | def handler(data, metadata): | |
200 |
print( |
|
201 | print("Handler called") | |
201 | nonlocal called |
|
202 | nonlocal called | |
202 | called = True |
|
203 | called = True | |
203 |
|
204 | |||
204 | ip.display_formatter.active_types.append("text/html") |
|
205 | ip.display_formatter.active_types.append("text/html") | |
205 | ip.display_formatter.formatters["text/html"].enabled = True |
|
206 | ip.display_formatter.formatters["text/html"].enabled = True | |
206 | ip.mime_renderers["text/html"] = handler |
|
207 | ip.mime_renderers["text/html"] = handler | |
207 |
|
208 | try: | ||
208 |
|
209 | obj = Test() | ||
209 | obj = Test() |
|
210 | display(obj) | |
210 |
|
|
211 | finally: | |
|
212 | ip.display_formatter.formatters["text/html"].enabled = False | |||
|
213 | del ip.mime_renderers["text/html"] | |||
211 |
|
214 | |||
212 | assert called == True |
|
215 | assert called == True | |
213 |
|
216 | |||
214 |
|
217 | |||
215 | def syntax_error_transformer(lines): |
|
218 | def syntax_error_transformer(lines): | |
216 | """Transformer that throws SyntaxError if 'syntaxerror' is in the code.""" |
|
219 | """Transformer that throws SyntaxError if 'syntaxerror' is in the code.""" |
General Comments 0
You need to be logged in to leave comments.
Login now