Include filename in state

This commit is contained in:
Andrew Murray 2025-04-02 11:14:58 +11:00
parent 7c56b383ff
commit 1103e82d17
3 changed files with 6 additions and 1 deletions

View File

@ -81,6 +81,7 @@ def test_pickle_jpeg() -> None:
unpickled_image = pickle.loads(pickle.dumps(image))
# Assert
assert unpickled_image.filename == "Tests/images/hopper.jpg"
assert len(unpickled_image.layer) == 3
assert unpickled_image.layers == 3

View File

@ -252,8 +252,12 @@ class ImageFile(Image.Image):
return Image.MIME.get(self.format.upper())
return None
def __getstate__(self) -> list[Any]:
return super().__getstate__() + [self.filename]
def __setstate__(self, state: list[Any]) -> None:
self.tile = []
self.filename = state[5]
super().__setstate__(state)
def verify(self) -> None:

View File

@ -403,8 +403,8 @@ class JpegImageFile(ImageFile.ImageFile):
return super().__getstate__() + [self.layers, self.layer]
def __setstate__(self, state: list[Any]) -> None:
self.layers, self.layer = state[6:]
super().__setstate__(state)
self.layers, self.layer = state[5:]
def load_read(self, read_bytes: int) -> bytes:
"""