mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-16 18:24:45 +03:00
Changed equals method on Image class to short circuit.
This commit is contained in:
parent
9fb00976fc
commit
6f7620652d
19
PIL/Image.py
19
PIL/Image.py
|
@ -586,14 +586,17 @@ class Image(object):
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
if self.__class__.__name__ != other.__class__.__name__:
|
if self.__class__.__name__ != other.__class__.__name__:
|
||||||
return False
|
return False
|
||||||
a = (self.mode == other.mode)
|
|
||||||
b = (self.size == other.size)
|
properties = ['mode', 'size', 'info', 'category', 'readonly']
|
||||||
c = (self.getpalette() == other.getpalette())
|
|
||||||
d = (self.info == other.info)
|
props_eq = all(self.__getattribute__(p) == other.__getattribute__(p)
|
||||||
e = (self.category == other.category)
|
for p in properties)
|
||||||
f = (self.readonly == other.readonly)
|
if not props_eq:
|
||||||
g = (self.tobytes() == other.tobytes())
|
return False
|
||||||
return a and b and c and d and e and f and g
|
|
||||||
|
funcs_eq = (self.getpalette() == other.getpalette()) \
|
||||||
|
and (self.tobytes() == other.tobytes())
|
||||||
|
return funcs_eq
|
||||||
|
|
||||||
def __ne__(self, other):
|
def __ne__(self, other):
|
||||||
eq = (self == other)
|
eq = (self == other)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user