From 957db67d43844fd3576e1750a2943d01f6945bdf Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Mon, 9 Sep 2024 23:25:46 +1000 Subject: [PATCH] Use hasattr --- src/PIL/ImageFile.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PIL/ImageFile.py b/src/PIL/ImageFile.py index 6fdc9c7cb..7e148b919 100644 --- a/src/PIL/ImageFile.py +++ b/src/PIL/ImageFile.py @@ -173,8 +173,8 @@ class ImageFile(Image.Image): return self def _close_fp(self) -> None: - if getattr(self, "_fp", False): - if self._fp != self.fp and not isinstance(self._fp, DeferredError): + if hasattr(self, "_fp") and not isinstance(self._fp, DeferredError): + if self._fp != self.fp: self._fp.close() self._fp = DeferredError(ValueError("Operation on closed image")) if self.fp: