From 8f30ec94070ae2b2f94448c8ee1dbf79f8a54cc0 Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Thu, 15 Aug 2019 19:46:12 -0700 Subject: Use Pillow's Image context manager to close image file --- sphinx/util/images.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/sphinx/util/images.py b/sphinx/util/images.py index 8471e56df..dfc94d4b4 100644 --- a/sphinx/util/images.py +++ b/sphinx/util/images.py @@ -42,12 +42,8 @@ def get_image_size(filename: str) -> Tuple[int, int]: size = None if size is None and Image: # fallback to Pillow - im = Image.open(filename) - size = im.size - try: - im.fp.close() - except Exception: - pass + with Image.open(filename) as im: + size = im.size return size except Exception: -- cgit v1.2.1