Skip to content

Commit

Permalink
Do not assign new fp attribute to image when closing
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Nov 16, 2023
1 parent b25ece3 commit 67e1253
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
1 change: 0 additions & 1 deletion Tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,6 @@ def test_close_graceful(self):

assert len(self._caplog.records) == 0
assert im.fp is None
assert copy.fp is None


class MockEncoder:
Expand Down
10 changes: 5 additions & 5 deletions src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,17 +549,17 @@ def close(self):
: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
Expand Down

0 comments on commit 67e1253

Please sign in to comment.