From 4c5da3858faad0cd82213aa26962742bd2ee04f8 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 15 Dec 2020 02:21:56 -0500 Subject: [PATCH] Rename a confusing variable. As noted in #19059, there is both a `buff` and `buf` in this function. The latter is a PNG file, so rename it to `png`. --- lib/matplotlib/backends/backend_webagg_core.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/matplotlib/backends/backend_webagg_core.py b/lib/matplotlib/backends/backend_webagg_core.py index 9d498c830b51..0c1b1e17268a 100644 --- a/lib/matplotlib/backends/backend_webagg_core.py +++ b/lib/matplotlib/backends/backend_webagg_core.py @@ -196,14 +196,15 @@ def get_diff_image(self): diff = buff != self._last_buff output = np.where(diff, buff, 0) - buf = BytesIO() - data = output.view(dtype=np.uint8).reshape((*output.shape, 4)) - Image.fromarray(data).save(buf, format="png") - # store the current buffer so we can compute the next diff + # Store the current buffer so we can compute the next diff. np.copyto(self._last_buff, buff) self._force_full = False self._png_is_old = False - return buf.getvalue() + + data = output.view(dtype=np.uint8).reshape((*output.shape, 4)) + with BytesIO() as png: + Image.fromarray(data).save(png, format="png") + return png.getvalue() def get_renderer(self, cleared=None): # Mirrors super.get_renderer, but caches the old one so that we can do