summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/engine
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2014-01-28 23:43:14 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2014-01-28 23:43:14 -0500
commitd4c908ded1e9a7923312f3b335835e7e40b6690e (patch)
tree8737395d3494ad31270c1dddb1ade580ceaf8a47 /lib/sqlalchemy/engine
parentd8d03011b8dafe48b71e9eb3bc756d05da54a7bf (diff)
downloadsqlalchemy-d4c908ded1e9a7923312f3b335835e7e40b6690e.tar.gz
- Fixed 0.9 regression where the new sortable support for :class:`.RowProxy`
would lead to ``TypeError`` when compared to non-tuple types as it attempted to apply tuple() to the "other" object unconditionally. The full range of Python comparison operators have now been implemented on :class:`.RowProxy`, using an approach that guarantees a comparison system that is equivalent to that of a tuple, and the "other" object is only coerced if it's an instance of RowProxy. [ticket:2924]
Diffstat (limited to 'lib/sqlalchemy/engine')
-rw-r--r--lib/sqlalchemy/engine/result.py21
1 files changed, 18 insertions, 3 deletions
diff --git a/lib/sqlalchemy/engine/result.py b/lib/sqlalchemy/engine/result.py
index f9e0ca0d2..6c98dae18 100644
--- a/lib/sqlalchemy/engine/result.py
+++ b/lib/sqlalchemy/engine/result.py
@@ -12,6 +12,7 @@ and :class:`.RowProxy."""
from .. import exc, util
from ..sql import expression, sqltypes
import collections
+import operator
# This reconstructor is necessary so that pickles with the C extension or
# without use the same Binary format.
@@ -125,14 +126,28 @@ class RowProxy(BaseRowProxy):
__hash__ = None
+ def _op(self, other, op):
+ return op(tuple(self), tuple(other)) \
+ if isinstance(other, RowProxy) \
+ else op(tuple(self), other)
+
def __lt__(self, other):
- return tuple(self) < tuple(other)
+ return self._op(other, operator.lt)
+
+ def __le__(self, other):
+ return self._op(other, operator.le)
+
+ def __ge__(self, other):
+ return self._op(other, operator.ge)
+
+ def __gt__(self, other):
+ return self._op(other, operator.gt)
def __eq__(self, other):
- return other is self or tuple(other) == tuple(self)
+ return self._op(other, operator.eq)
def __ne__(self, other):
- return not self.__eq__(other)
+ return self._op(other, operator.ne)
def __repr__(self):
return repr(tuple(self))