mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-28 01:42:52 +03:00
Do not assign new fp attribute to image when exiting context manager
This commit is contained in:
parent
04a4d54275
commit
5431b15bd2
|
@ -1015,6 +1015,11 @@ class TestImage:
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
assert str(e) == "buffer overrun when reading image file"
|
assert str(e) == "buffer overrun when reading image file"
|
||||||
|
|
||||||
|
def test_exit_fp(self):
|
||||||
|
with Image.new("L", (1, 1)) as im:
|
||||||
|
pass
|
||||||
|
assert not hasattr(im, "fp")
|
||||||
|
|
||||||
def test_close_graceful(self, caplog):
|
def test_close_graceful(self, caplog):
|
||||||
with Image.open("Tests/images/hopper.jpg") as im:
|
with Image.open("Tests/images/hopper.jpg") as im:
|
||||||
copy = im.copy()
|
copy = im.copy()
|
||||||
|
|
|
@ -528,7 +528,8 @@ class Image:
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __exit__(self, *args):
|
def __exit__(self, *args):
|
||||||
if hasattr(self, "fp") and getattr(self, "_exclusive_fp", False):
|
if hasattr(self, "fp"):
|
||||||
|
if getattr(self, "_exclusive_fp", False):
|
||||||
if getattr(self, "_fp", False):
|
if getattr(self, "_fp", False):
|
||||||
if self._fp != self.fp:
|
if self._fp != self.fp:
|
||||||
self._fp.close()
|
self._fp.close()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user