Merge pull request #1 from radarhere/handle-repr-exceptions

Simplified code
This commit is contained in:
Matthew Treinish 2023-07-24 19:16:38 -04:00 committed by GitHub
commit 2a55b140b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -641,9 +641,8 @@ class Image:
b = io.BytesIO() b = io.BytesIO()
try: try:
self.save(b, image_format, **kwargs) self.save(b, image_format, **kwargs)
except Exception as e: except Exception:
msg = f"Could not save to {image_format} for display" return None
raise ValueError(msg) from e
return b.getvalue() return b.getvalue()
def _repr_png_(self): def _repr_png_(self):
@ -651,20 +650,14 @@ class Image:
:returns: PNG version of the image as bytes :returns: PNG version of the image as bytes
""" """
try: return self._repr_image("PNG", compress_level=1)
return self._repr_image("PNG", compress_level=1)
except Exception:
return None
def _repr_jpeg_(self): def _repr_jpeg_(self):
"""iPython display hook support for JPEG format. """iPython display hook support for JPEG format.
:returns: JPEG version of the image as bytes :returns: JPEG version of the image as bytes
""" """
try: return self._repr_image("JPEG")
return self._repr_image("JPEG")
except Exception:
return None
@property @property
def __array_interface__(self): def __array_interface__(self):