keep IPython/Jupyter text/plain output stable

This commit is contained in:
Alexey Shamrin 2021-12-15 22:35:32 +02:00 committed by GitHub
parent 2a38670169
commit b3cb55f823
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -644,6 +644,19 @@ class Image:
id(self), 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): def _repr_png_(self):
"""iPython display hook support """iPython display hook support