Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 43a01a2

Browse files
committed
Do not import from IPython.core.display and warn users.
1 parent 46ca535 commit 43a01a2

8 files changed

Lines changed: 65 additions & 14 deletions

File tree

IPython/core/display.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,38 @@
1717

1818
from IPython.utils.py3compat import cast_unicode
1919
from IPython.testing.skipdoctest import skip_doctest
20-
from .display_functions import display, clear_output, publish_display_data, update_display, DisplayHandle
20+
from . import display_functions
2121

22-
__all__ = ['display', 'display_pretty', 'display_html', 'display_markdown',
22+
23+
__all__ = ['display_pretty', 'display_html', 'display_markdown',
2324
'display_svg', 'display_png', 'display_jpeg', 'display_latex', 'display_json',
2425
'display_javascript', 'display_pdf', 'DisplayObject', 'TextDisplayObject',
2526
'Pretty', 'HTML', 'Markdown', 'Math', 'Latex', 'SVG', 'ProgressBar', 'JSON',
26-
'GeoJSON', 'Javascript', 'Image', 'clear_output', 'set_matplotlib_formats',
27-
'set_matplotlib_close', 'publish_display_data', 'update_display', 'DisplayHandle',
27+
'GeoJSON', 'Javascript', 'Image', 'set_matplotlib_formats',
28+
'set_matplotlib_close',
2829
'Video']
2930

31+
_deprecated_names = ["display", "clear_output", "publish_display_data", "update_display", "DisplayHandle"]
32+
33+
__all__ = __all__ + _deprecated_names
34+
35+
36+
# ----- warn to import from IPython.display -----
37+
38+
from warnings import warn
39+
40+
41+
def __getattr__(name):
42+
if name in _deprecated_names:
43+
warn(f"Importing {name} from IPython.core.display is deprecated since IPython 7.14, please import from IPython display", DeprecationWarning, stacklevel=2)
44+
return getattr(display_functions, name)
45+
46+
if name in globals().keys():
47+
return globals()[name]
48+
else:
49+
raise AttributeError(f"module {__name__} has no attribute {name}")
50+
51+
3052
#-----------------------------------------------------------------------------
3153
# utility functions
3254
#-----------------------------------------------------------------------------

IPython/core/displaypub.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from traitlets import List
2323

2424
# This used to be defined here - it is imported for backwards compatibility
25-
from .display import publish_display_data
25+
from .display_functions import publish_display_data
2626

2727
#-----------------------------------------------------------------------------
2828
# Main payload class

IPython/core/magics/display.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#-----------------------------------------------------------------------------
1313

1414
# Our own packages
15-
from IPython.core.display import display, Javascript, Latex, SVG, HTML, Markdown
15+
from IPython.display import display, Javascript, Latex, SVG, HTML, Markdown
1616
from IPython.core.magic import (
1717
Magics, magics_class, cell_magic
1818
)

IPython/core/page.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from io import UnsupportedOperation
2525

2626
from IPython import get_ipython
27-
from IPython.core.display import display
27+
from IPython.display import display
2828
from IPython.core.error import TryNext
2929
from IPython.utils.data import chop
3030
from IPython.utils.process import system

IPython/core/pylabtools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ def import_pylab(user_ns, import_all=True):
354354

355355
# IPython symbols to add
356356
user_ns['figsize'] = figsize
357-
from IPython.core.display import display
357+
from IPython.display import display
358358
# Add display and getfigs to the user's namespace
359359
user_ns['display'] = display
360360
user_ns['getfigs'] = getfigs

IPython/core/tests/test_display.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import nose.tools as nt
1111

12-
from IPython.core import display
12+
from IPython import display
1313
from IPython.core.getipython import get_ipython
1414
from IPython.utils.io import capture_output
1515
from IPython.utils.tempdir import NamedFileInTemporaryDirectory

IPython/display.py

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,44 @@
11
"""Public API for display tools in IPython.
22
"""
33

4-
#-----------------------------------------------------------------------------
4+
# -----------------------------------------------------------------------------
55
# Copyright (C) 2012 The IPython Development Team
66
#
77
# Distributed under the terms of the BSD License. The full license is in
88
# the file COPYING, distributed as part of this software.
9-
#-----------------------------------------------------------------------------
9+
# -----------------------------------------------------------------------------
1010

11-
#-----------------------------------------------------------------------------
11+
# -----------------------------------------------------------------------------
1212
# Imports
13-
#-----------------------------------------------------------------------------
13+
# -----------------------------------------------------------------------------
1414

15-
from IPython.core.display import *
15+
from IPython.core.display_functions import *
16+
from IPython.core.display import (
17+
display_pretty,
18+
display_html,
19+
display_markdown,
20+
display_svg,
21+
display_png,
22+
display_jpeg,
23+
display_latex,
24+
display_json,
25+
display_javascript,
26+
display_pdf,
27+
DisplayObject,
28+
TextDisplayObject,
29+
Pretty,
30+
HTML,
31+
Markdown,
32+
Math,
33+
Latex,
34+
SVG,
35+
ProgressBar,
36+
JSON,
37+
GeoJSON,
38+
Javascript,
39+
Image,
40+
set_matplotlib_formats,
41+
set_matplotlib_close,
42+
Video,
43+
)
1644
from IPython.lib.display import *

IPython/testing/iptest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
warnings.filterwarnings('error', message='.*disable_gui.*', category=DeprecationWarning, module='.*')
5858

5959
warnings.filterwarnings('error', message='.*ExceptionColors global is deprecated.*', category=DeprecationWarning, module='.*')
60+
warnings.filterwarnings('error', message='.*IPython.core.display.*', category=DeprecationWarning, module='.*')
6061

6162
# Jedi older versions
6263
warnings.filterwarnings(

0 commit comments

Comments
 (0)