Skip to content

Commit 29b9de4

Browse files
committed
Added __ne__ for DBRefs PYTHON-440
1 parent da6d73b commit 29b9de4

20 files changed

+126
-35
lines changed

bson/binary.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ def __getnewargs__(self):
154154

155155
def __eq__(self, other):
156156
if isinstance(other, Binary):
157-
return (self.__subtype, binary_type(self)) == (other.subtype, binary_type(other))
157+
return ((self.__subtype, binary_type(self)) ==
158+
(other.subtype, binary_type(other)))
158159
# We don't return NotImplemented here because if we did then
159160
# Binary("foo") == "foo" would return True, since Binary is a
160161
# subclass of str...

bson/dbref.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,16 @@ def __repr__(self):
115115

116116
def __eq__(self, other):
117117
if isinstance(other, DBRef):
118-
us = [self.__database, self.__collection,
119-
self.__id, self.__kwargs]
120-
them = [other.__database, other.__collection,
121-
other.__id, other.__kwargs]
118+
us = (self.__database, self.__collection,
119+
self.__id, self.__kwargs)
120+
them = (other.__database, other.__collection,
121+
other.__id, other.__kwargs)
122122
return us == them
123123
return NotImplemented
124124

125+
def __ne__(self, other):
126+
return not self == other
127+
125128
def __hash__(self):
126129
"""Get a hash value for this :class:`DBRef`.
127130

bson/objectid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ def __eq__(self, other):
254254
return self.__id == other.__id
255255
return NotImplemented
256256

257-
def __ne__(self,other):
257+
def __ne__(self, other):
258258
if isinstance(other, ObjectId):
259259
return self.__id != other.__id
260260
return NotImplemented

bson/son.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ def __eq__(self, other):
198198
dict(self.items()) == dict(other.items()))
199199
return dict(self.items()) == other
200200

201+
def __ne__(self, other):
202+
return not self == other
203+
201204
def __len__(self):
202205
return len(self.keys())
203206

pymongo/collection.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ def __eq__(self, other):
150150
return us == them
151151
return NotImplemented
152152

153+
def __ne__(self, other):
154+
return not self == other
155+
153156
@property
154157
def full_name(self):
155158
"""The full name of this :class:`Collection`.

pymongo/database.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ def __eq__(self, other):
183183
return us == them
184184
return NotImplemented
185185

186+
def __ne__(self, other):
187+
return not self == other
188+
186189
def __repr__(self):
187190
return "Database(%r, %r)" % (self.__connection, self.__name)
188191

pymongo/master_slave_connection.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@ def __eq__(self, other):
220220
return us == them
221221
return NotImplemented
222222

223+
def __ne__(self, other):
224+
return not self == other
225+
223226
def __repr__(self):
224227
return "MasterSlaveConnection(%r, %r)" % (self.__master, self.__slaves)
225228

pymongo/mongo_client.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,9 @@ def __eq__(self, other):
994994
return us == them
995995
return NotImplemented
996996

997+
def __ne__(self, other):
998+
return not self == other
999+
9971000
def __repr__(self):
9981001
if len(self.__nodes) == 1:
9991002
return "MongoClient(%r, %r)" % (self.__host, self.__port)

pymongo/mongo_replica_set_client.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,6 +1264,9 @@ def __eq__(self, other):
12641264
# XXX: Implement this?
12651265
return NotImplemented
12661266

1267+
def __ne__(self, other):
1268+
return NotImplemented
1269+
12671270
def __repr__(self):
12681271
return "MongoReplicaSetClient(%r)" % (["%s:%d" % n
12691272
for n in self.__hosts],)

pymongo/pool.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ def __eq__(self, other):
8686
# if its sock is the same as ours
8787
return hasattr(other, 'sock') and self.sock == other.sock
8888

89+
def __ne__(self, other):
90+
return not self == other
91+
8992
def __hash__(self):
9093
return hash(self.sock)
9194

0 commit comments

Comments
 (0)