[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#932578: PATCH



The release notes for PILlow 6.1 (https://pillow.readthedocs.io/en/stable/releasenotes/6.0.0.html#backwards-incompatible-changes) indicate that Image.VERSION has been dropped in favour of using Image.__version__. VERSION was fossilised at '1.1.7' 9 years ago to avoid confusing legacy users of the original PIL library.

The only usage of this attribute is to check to see if the version is 1.1.7 (which it hasn't been for some time) in order to work around a bug. The relevant code is

## BEGIN CODE

if Image.VERSION == '1.1.7':

    def split(image):
        """Work around for bug in Pil 1.1.7

        :param image: input image
        :type image: PIL image object
        :returns: the different color bands of the image (eg R, G, B)
        :rtype: tuple
        """
        image.load()
        return image.split()
else:

    def split(image):
        """Work around for bug in Pil 1.1.7

        :param image: input image
        :type image: PIL image object
        :returns: the different color bands of the image (eg R, G, B)
        :rtype: tuple
        """
        return image.split()

## END CODE

Given that the workaround is long irrelevant, we should probably just define split() according to the else clause. The docstring should also probably be updated.

The safer alternative is to replace the condition of the if statement with

if hasattr(Image, 'VERSION') and Image.VERSION == '1.1.7':

which works for me and seems like it should work for anyone else, too, even if they're using the long abandoned original PIL library, though I don't fancy testing that.

## BEGIN PATCH
--- bin/imtools.py        2018-08-07 13:51:47.000000000 +0100
+++ bin/imtools.py      2019-08-16 22:05:05.018603503 +0100
@@ -620,7 +620,7 @@
         has_alpha(image)


-if Image.VERSION == '1.1.7':
+if hasattr(Image, '"VERSION') and Image.VERSION == '1.1.7':

     def split(image):
         """Work around for bug in Pil 1.1.7
## END PATCH


Reply to: