Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comparing Image to None throws error #869

Closed
nakedible opened this issue Aug 25, 2014 · 3 comments
Closed

Comparing Image to None throws error #869

nakedible opened this issue Aug 25, 2014 · 3 comments

Comments

@nakedible
Copy link

In Image.py you have the following compare methods:

    def __eq__(self, other):
        a = (self.mode == other.mode)
        b = (self.size == other.size)
        c = (self.getpalette() == other.getpalette())
        d = (self.info == other.info)
        e = (self.category == other.category)
        f = (self.readonly == other.readonly)
        g = (self.tobytes() == other.tobytes())
        return a and b and c and d and e and f and g

    def __ne__(self, other):
        eq = (self == other)
        return not eq

If attempting to compare an image to None, this errors out with the error AttributeError: 'NoneType' object has no attribute 'mode'.

Please at least make comparisons against None safe. Preferably comparisons against all values as well.

@hugovk
Copy link
Member

hugovk commented Aug 25, 2014

This is a duplicate of #774 which was fixed in #775 on 7th July 2014, just missing the quarterly release, so it'll be in the next one be around the end of September.

     def __eq__(self, other):
+        if self.__class__.__name__ != other.__class__.__name__:
+            return False
         a = (self.mode == other.mode)
         b = (self.size == other.size)
         c = (self.getpalette() == other.getpalette())
         d = (self.info == other.info)
         e = (self.category == other.category)
         f = (self.readonly == other.readonly)
         g = (self.tobytes() == other.tobytes())
         return a and b and c and d and e and f and g

@hugovk hugovk closed this as completed Aug 25, 2014
@nakedible
Copy link
Author

Great! Sorry for the duplicate, forgot to search for already closed issues.

@hugovk
Copy link
Member

hugovk commented Aug 25, 2014

No problem, better reported twice than not at all!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants