From 6f7620652d45869cf9a891c97fc03d9de33a033d Mon Sep 17 00:00:00 2001 From: matt Date: Sun, 19 Jun 2016 14:23:27 -0400 Subject: [PATCH] Changed equals method on Image class to short circuit. --- PIL/Image.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/PIL/Image.py b/PIL/Image.py index 4ab40620f..20a4d62ea 100644 --- a/PIL/Image.py +++ b/PIL/Image.py @@ -586,14 +586,17 @@ class Image(object): 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 + + properties = ['mode', 'size', 'info', 'category', 'readonly'] + + props_eq = all(self.__getattribute__(p) == other.__getattribute__(p) + for p in properties) + if not props_eq: + return False + + funcs_eq = (self.getpalette() == other.getpalette()) \ + and (self.tobytes() == other.tobytes()) + return funcs_eq def __ne__(self, other): eq = (self == other)