mirror of https://github.com/scrapy/scrapy.git
equal_attributes function optimization
This commit is contained in:
parent
6ae8963256
commit
d022d3cb9e
|
|
@ -257,20 +257,14 @@ def equal_attributes(obj1, obj2, attributes):
|
|||
if not attributes:
|
||||
return False
|
||||
|
||||
temp1, temp2 = object(), object()
|
||||
for attr in attributes:
|
||||
# support callables like itemgetter
|
||||
if callable(attr):
|
||||
if not attr(obj1) == attr(obj2):
|
||||
return False
|
||||
else:
|
||||
# check that objects has attribute
|
||||
if not hasattr(obj1, attr):
|
||||
return False
|
||||
if not hasattr(obj2, attr):
|
||||
return False
|
||||
# compare object attributes
|
||||
if not getattr(obj1, attr) == getattr(obj2, attr):
|
||||
if attr(obj1) != attr(obj2):
|
||||
return False
|
||||
elif getattr(obj1, attr, temp1) != getattr(obj2, attr, temp2):
|
||||
return False
|
||||
# all attributes equal
|
||||
return True
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue