diff --git a/IPython/core/display.py b/IPython/core/display.py
index 851016f..00fe85e 100644
--- a/IPython/core/display.py
+++ b/IPython/core/display.py
@@ -801,9 +801,20 @@ class Image(DisplayObject):
_FMT_GIF: 'image/gif',
}
- def __init__(self, data=None, url=None, filename=None, format=None,
- embed=None, width=None, height=None, retina=False,
- unconfined=False, metadata=None, alt=None):
+ def __init__(
+ self,
+ data=None,
+ url=None,
+ filename=None,
+ format=None,
+ embed=None,
+ width=None,
+ height=None,
+ retina=False,
+ unconfined=False,
+ metadata=None,
+ alt=None,
+ ):
"""Create a PNG/JPEG/GIF image object given raw data.
When this object is returned by an input cell or passed to the
@@ -937,8 +948,8 @@ class Image(DisplayObject):
if self.height is None and self.metadata.get('height', {}):
self.height = metadata['height']
- if self.alt is None and self.metadata.get('alt', {}):
- self.alt = metadata['alt']
+ if self.alt is None and self.metadata.get("alt", {}):
+ self.alt = metadata["alt"]
if retina:
self._retina_shape()
@@ -969,7 +980,7 @@ class Image(DisplayObject):
def _repr_html_(self):
if not self.embed:
- width = height = klass = alt = ''
+ width = height = klass = alt = ""
if self.width:
width = ' width="%d"' % self.width
if self.height:
@@ -978,7 +989,7 @@ class Image(DisplayObject):
klass = ' class="unconfined"'
if self.alt:
alt = ' alt="%s"' % html.escape(self.alt)
- return u''.format(
+ return ''.format(
url=self.url,
width=width,
height=height,
@@ -1017,7 +1028,7 @@ class Image(DisplayObject):
if self.unconfined:
md['unconfined'] = self.unconfined
if self.alt:
- md['alt'] = self.alt
+ md["alt"] = self.alt
if md or always_both:
return b64_data, md
else:
diff --git a/IPython/core/tests/test_display.py b/IPython/core/tests/test_display.py
index b7b4400..8deb11a 100644
--- a/IPython/core/tests/test_display.py
+++ b/IPython/core/tests/test_display.py
@@ -94,9 +94,9 @@ def test_embed_svg_url():
if args[0] == url:
return MockResponse(svg_data)
- elif args[0] == url + 'z':
- ret= MockResponse(gzip_svg)
- ret.headers['content-encoding']= 'gzip'
+ elif args[0] == url + "z":
+ ret = MockResponse(gzip_svg)
+ ret.headers["content-encoding"] = "gzip"
return ret
return MockResponse(None)
@@ -459,19 +459,24 @@ def test_display_handle():
def test_image_alt_tag():
"""Simple test for display.Image(args, alt=x,)"""
- thisurl = 'http://example.com/image.png'
- img = display.Image(url=thisurl, alt='an image')
+ thisurl = "http://example.com/image.png"
+ img = display.Image(url=thisurl, alt="an image")
nt.assert_equal(u'' % (thisurl), img._repr_html_())
- img = display.Image(url=thisurl, unconfined=True, alt='an image')
- nt.assert_equal(u'' % (thisurl), img._repr_html_())
+ img = display.Image(url=thisurl, unconfined=True, alt="an image")
+ nt.assert_equal(
+ u'' % (thisurl),
+ img._repr_html_(),
+ )
img = display.Image(url=thisurl, alt='>"& <')
- nt.assert_equal(u'' % (thisurl), img._repr_html_())
+ nt.assert_equal(
+ u'' % (thisurl), img._repr_html_()
+ )
- img = display.Image(url=thisurl, metadata={'alt':'an image'})
- nt.assert_equal(img.alt, 'an image')
+ img = display.Image(url=thisurl, metadata={"alt": "an image"})
+ nt.assert_equal(img.alt, "an image")
here = os.path.dirname(__file__)
- img = display.Image(os.path.join(here, "2x2.png"), alt='an image')
- nt.assert_equal(img.alt, 'an image')
+ img = display.Image(os.path.join(here, "2x2.png"), alt="an image")
+ nt.assert_equal(img.alt, "an image")
_, md = img._repr_png_()
- nt.assert_equal(md['alt'], 'an image')
+ nt.assert_equal(md["alt"], "an image")