Skip to content

Commit 1e1d6bf

Browse files
author
James William Pye
committed
Move the equality override into an isconsistent method.
1 parent cddf491 commit 1e1d6bf

3 files changed

Lines changed: 17 additions & 5 deletions

File tree

postgresql/api.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,20 @@ def details(self) -> dict:
101101
* 'internal_query'
102102
"""
103103

104+
@abstractmethod
105+
def isconsistent(self, other) -> bool:
106+
"""
107+
Whether the fields of the `other` Message object is consistent with the
108+
fields of `self`.
109+
110+
This *must* return the result of the comparison of code, source, message,
111+
and details.
112+
113+
This method is provided as the alternative to overriding equality;
114+
often, pointer equality is the desirable means for comparison, but
115+
equality of the fields is also necessary.
116+
"""
117+
104118
class Result(Element):
105119
"""
106120
A result is an object managing the results of a prepared statement.

postgresql/message.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ def _e_metas(self, get0 = itemgetter(0)):
4848
'CLIENT',
4949
)
5050

51-
def __eq__(self, other):
51+
def isconsistent(self, other):
5252
if not isinstance(other, self.__class__):
53-
return NotImplemented
53+
return False
5454
# creator is contextual information
5555
return (
5656
self.code == other.code and \
@@ -59,8 +59,6 @@ def __eq__(self, other):
5959
self.source == other.source
6060
)
6161

62-
__hash__ = object.__hash__
63-
6462
def __init__(self,
6563
message : "The primary information of the message",
6664
code : "Message code to attach (SQL state)" = None,

postgresql/test/test_driver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1512,7 +1512,7 @@ def add(x):
15121512
if last is None:
15131513
last = x
15141514
continue
1515-
self.failUnlessEqual(x, last)
1515+
self.failUnless(x.isconsistent(last))
15161516
last = x
15171517

15181518
if __name__ == '__main__':

0 commit comments

Comments
 (0)