summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMads Jensen <mje@inducks.org>2017-09-28 11:39:12 +0200
committerTim Graham <timograham@gmail.com>2017-09-28 09:18:37 -0400
commit4508fafe16e37960769bbe170fd9729910d7d2ce (patch)
treeb8b6abde678360b082235124e68a8d26c9ac1e3e
parent129f4900be086e373123f7d17ca0afb87fb91369 (diff)
Simplified various __eq__() methods.
-rw-r--r--django/contrib/gis/db/backends/base/adapter.py7
-rw-r--r--django/contrib/gis/db/backends/postgis/adapter.py4
-rw-r--r--django/contrib/gis/gdal/geometries.py5
-rw-r--r--django/db/migrations/migration.py8
-rw-r--r--django/db/models/query.py4
-rw-r--r--django/template/base.py4
-rw-r--r--django/template/context.py9
-rw-r--r--django/utils/tree.py10
8 files changed, 22 insertions, 29 deletions
diff --git a/django/contrib/gis/db/backends/base/adapter.py b/django/contrib/gis/db/backends/base/adapter.py
index 8f35909d28..604711eb6a 100644
--- a/django/contrib/gis/db/backends/base/adapter.py
+++ b/django/contrib/gis/db/backends/base/adapter.py
@@ -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))
diff --git a/django/contrib/gis/db/backends/postgis/adapter.py b/django/contrib/gis/db/backends/postgis/adapter.py
index 39867ebc61..84c19c7e3b 100644
--- a/django/contrib/gis/db/backends/postgis/adapter.py
+++ b/django/contrib/gis/db/backends/postgis/adapter.py
@@ -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)
diff --git a/django/contrib/gis/gdal/geometries.py b/django/contrib/gis/gdal/geometries.py
index 35ce8d5157..d111f8bc44 100644
--- a/django/contrib/gis/gdal/geometries.py
+++ b/django/contrib/gis/gdal/geometries.py
@@ -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."
diff --git a/django/db/migrations/migration.py b/django/db/migrations/migration.py
index ffe0b1fb3d..fe5e228c6c 100644
--- a/django/db/migrations/migration.py
+++ b/django/db/migrations/migration.py
@@ -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)
diff --git a/django/db/models/query.py b/django/db/models/query.py
index 3bfe0a6fb4..03de96ab2f 100644
--- a/django/db/models/query.py
+++ b/django/db/models/query.py
@@ -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)
diff --git a/django/template/base.py b/django/template/base.py
index 6572eae8ab..10a1f11464 100644
--- a/django/template/base.py
+++ b/django/template/base.py
@@ -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
)
diff --git a/django/template/context.py b/django/template/context.py
index 5292a0bb19..ec9abf7655 100644
--- a/django/template/context.py
+++ b/django/template/context.py
@@ -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):
diff --git a/django/utils/tree.py b/django/utils/tree.py
index 74612736f1..392838b482 100644
--- a/django/utils/tree.py
+++ b/django/utils/tree.py
@@ -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):
"""