Do not assign new fp attribute to image when closing

This commit is contained in:
Andrew Murray 2023-11-17 08:32:25 +11:00
parent b25ece364b
commit 67e1253202
2 changed files with 5 additions and 6 deletions

View File

@ -1027,7 +1027,6 @@ class TestImage:
assert len(self._caplog.records) == 0
assert im.fp is None
assert copy.fp is None
class MockEncoder:

View File

@ -549,17 +549,17 @@ class Image:
:py:meth:`~PIL.Image.Image.load` method. See :ref:`file-handling` for
more information.
"""
try:
if hasattr(self, "fp"):
if hasattr(self, "fp"):
try:
if getattr(self, "_fp", False):
if self._fp != self.fp:
self._fp.close()
self._fp = DeferredError(ValueError("Operation on closed image"))
if self.fp:
self.fp.close()
self.fp = None
except Exception as msg:
logger.debug("Error closing: %s", msg)
self.fp = None
except Exception as msg:
logger.debug("Error closing: %s", msg)
if getattr(self, "map", None):
self.map = None