mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 17:36:18 +03:00
Merge pull request #5891 from shamrin/stable-jupyter-text-output
Keep IPython/Jupyter text/plain output stable
This commit is contained in:
commit
0a49ec1cc0
|
@ -89,6 +89,17 @@ class TestImage:
|
|||
# with pytest.raises(MemoryError):
|
||||
# Image.new("L", (1000000, 1000000))
|
||||
|
||||
def test_repr_pretty(self):
|
||||
class Pretty:
|
||||
def text(self, text):
|
||||
self.pretty_output = text
|
||||
|
||||
im = Image.new("L", (100, 100))
|
||||
|
||||
p = Pretty()
|
||||
im._repr_pretty_(p, None)
|
||||
assert p.pretty_output == "<PIL.Image.Image image mode=L size=100x100>"
|
||||
|
||||
def test_open_formats(self):
|
||||
PNGFILE = "Tests/images/hopper.png"
|
||||
JPGFILE = "Tests/images/hopper.jpg"
|
||||
|
|
|
@ -641,6 +641,22 @@ class Image:
|
|||
id(self),
|
||||
)
|
||||
|
||||
def _repr_pretty_(self, p, cycle):
|
||||
"""IPython plain text display support"""
|
||||
|
||||
# Same as __repr__ but without unpredicatable id(self),
|
||||
# to keep Jupyter notebook `text/plain` output stable.
|
||||
p.text(
|
||||
"<%s.%s image mode=%s size=%dx%d>"
|
||||
% (
|
||||
self.__class__.__module__,
|
||||
self.__class__.__name__,
|
||||
self.mode,
|
||||
self.size[0],
|
||||
self.size[1],
|
||||
)
|
||||
)
|
||||
|
||||
def _repr_png_(self):
|
||||
"""iPython display hook support
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user