Load image before deepcopy(__getstate__)

Signed-off-by: bigcat88 <bigcat88@icloud.com>
This commit is contained in:
Alexander Piskun 2023-04-21 17:42:45 +03:00 committed by bigcat88
parent a405e8406b
commit b10379b3c1
No known key found for this signature in database
GPG Key ID: 1F0BF0EC3CF22721
2 changed files with 11 additions and 1 deletions

View File

@ -1,4 +1,5 @@
import warnings
from copy import deepcopy
import pytest
@ -226,6 +227,14 @@ def test_load_first():
assert a.shape == (88, 590)
@skip_unless_feature("libtiff")
def test_load_first_deepcopy():
with Image.open("Tests/images/g4_orientation_5.tif") as im:
im_deepcopy = deepcopy(im)
a = numpy.array(im_deepcopy)
assert a.shape == (88, 590)
def test_bool():
# https://github.com/python-pillow/Pillow/issues/2044
a = numpy.zeros((10, 2), dtype=bool)

View File

@ -672,7 +672,8 @@ class Image:
return new
def __getstate__(self):
return [self.info, self.mode, self.size, self.getpalette(), self.tobytes()]
im_data = self.tobytes() # load image first
return [self.info, self.mode, self.size, self.getpalette(), im_data]
def __setstate__(self, state):
Image.__init__(self)