Simplified various __eq__() methods.
This commit is contained in:
parent
129f4900be
commit
4508fafe16
|
@ -7,9 +7,10 @@ class WKTAdapter:
|
|||
self.srid = geom.srid
|
||||
|
||||
def __eq__(self, other):
|
||||
if not isinstance(other, WKTAdapter):
|
||||
return False
|
||||
return self.wkt == other.wkt and self.srid == other.srid
|
||||
return (
|
||||
isinstance(other, WKTAdapter) and
|
||||
self.wkt == other.wkt and self.srid == other.srid
|
||||
)
|
||||
|
||||
def __hash__(self):
|
||||
return hash((self.wkt, self.srid))
|
||||
|
|
|
@ -34,9 +34,7 @@ class PostGISAdapter:
|
|||
raise Exception('Error implementing psycopg2 protocol. Is psycopg2 installed?')
|
||||
|
||||
def __eq__(self, other):
|
||||
if not isinstance(other, PostGISAdapter):
|
||||
return False
|
||||
return self.ewkb == other.ewkb
|
||||
return isinstance(other, PostGISAdapter) and self.ewkb == other.ewkb
|
||||
|
||||
def __hash__(self):
|
||||
return hash(self.ewkb)
|
||||
|
|
|
@ -190,10 +190,7 @@ class OGRGeometry(GDALBase):
|
|||
|
||||
def __eq__(self, other):
|
||||
"Is this Geometry equal to the other?"
|
||||
if isinstance(other, OGRGeometry):
|
||||
return self.equals(other)
|
||||
else:
|
||||
return False
|
||||
return isinstance(other, OGRGeometry) and self.equals(other)
|
||||
|
||||
def __str__(self):
|
||||
"WKT is used for the string representation."
|
||||
|
|
|
@ -58,9 +58,11 @@ class Migration:
|
|||
self.replaces = list(self.__class__.replaces)
|
||||
|
||||
def __eq__(self, other):
|
||||
if not isinstance(other, Migration):
|
||||
return False
|
||||
return (self.name == other.name) and (self.app_label == other.app_label)
|
||||
return (
|
||||
isinstance(other, Migration) and
|
||||
self.name == other.name and
|
||||
self.app_label == other.app_label
|
||||
)
|
||||
|
||||
def __repr__(self):
|
||||
return "<Migration %s.%s>" % (self.app_label, self.name)
|
||||
|
|
|
@ -1413,9 +1413,7 @@ class Prefetch:
|
|||
return None
|
||||
|
||||
def __eq__(self, other):
|
||||
if isinstance(other, Prefetch):
|
||||
return self.prefetch_to == other.prefetch_to
|
||||
return False
|
||||
return isinstance(other, Prefetch) and self.prefetch_to == other.prefetch_to
|
||||
|
||||
def __hash__(self):
|
||||
return hash(self.__class__) ^ hash(self.prefetch_to)
|
||||
|
|
|
@ -126,10 +126,8 @@ class Origin:
|
|||
return self.name
|
||||
|
||||
def __eq__(self, other):
|
||||
if not isinstance(other, Origin):
|
||||
return False
|
||||
|
||||
return (
|
||||
isinstance(other, Origin) and
|
||||
self.name == other.name and
|
||||
self.loader == other.loader
|
||||
)
|
||||
|
|
|
@ -127,13 +127,12 @@ class BaseContext:
|
|||
"""
|
||||
Compare two contexts by comparing theirs 'dicts' attributes.
|
||||
"""
|
||||
if isinstance(other, BaseContext):
|
||||
return (
|
||||
isinstance(other, BaseContext) and
|
||||
# because dictionaries can be put in different order
|
||||
# we have to flatten them like in templates
|
||||
return self.flatten() == other.flatten()
|
||||
|
||||
# if it's not comparable return false
|
||||
return False
|
||||
self.flatten() == other.flatten()
|
||||
)
|
||||
|
||||
|
||||
class Context(BaseContext):
|
||||
|
|
|
@ -64,11 +64,11 @@ class Node:
|
|||
return other in self.children
|
||||
|
||||
def __eq__(self, other):
|
||||
if self.__class__ != other.__class__:
|
||||
return False
|
||||
if (self.connector, self.negated) == (other.connector, other.negated):
|
||||
return self.children == other.children
|
||||
return False
|
||||
return (
|
||||
self.__class__ == other.__class__ and
|
||||
(self.connector, self.negated) == (other.connector, other.negated) and
|
||||
self.children == other.children
|
||||
)
|
||||
|
||||
def add(self, data, conn_type, squash=True):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue