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