Moved get_child_images() to ImageFile#8689
Conversation
I wonder, are there some circumstances where this could be a breaking change? |
|
>>> from PIL import Image
>>> im = Image.new("RGB", (1, 1))
>>> im.get_child_images()
[]would start failing. >>> im.get_child_images()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'Image' object has no attribute 'get_child_images'However, I would suggest that is more helpful than an apparently-successful empty list, since an >>> from PIL import Image
>>> im = Image.open("Tests/images/flower.jpg")
>>> im.get_child_images()
[<PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=160x120 at 0x103ACA970>]
>>> im.copy().get_child_images()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "PIL/Image.py", line 1574, in get_child_images
current_offset = self.fp.tell()
AttributeError: 'Image' object has no attribute 'fp'That would now change to >>> im.copy().get_child_images()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'Image' object has no attribute 'get_child_images'which again, I think is more helpful. |
|
Yes okay, if you'd like to go ahead with this, I suggest a deprecation cycle, so we don't break things without warning. |
|
Ok, I've deprecated the functionality, to be removed in Pillow 13. |
|
Thanks! |
This is part of #8362 - I'm hoping to break down that PR into easier-to-review chunks.
get_child_images()relies onself.fp, and since that only exists for anImageFileand not anImage, I suggest moving it there. This isn't a strictly necessary change, so feel free to disagree.After that, I've also made changes to fix two mypy errors. One is asserting that
fpis notNone, like #8617. The other is asserting that an Exif tag is an integer, to fix