diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-05-24 14:35:28 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-05-24 14:35:28 -0400 |
commit | d1705a46fea6beb7a02d20b2bdc1518c214012ff (patch) | |
tree | e0f5fd316ad845ecd41aa8f4f395e00a26c65a39 /lib/sqlalchemy/sql/elements.py | |
parent | 931685bac9161056cda3337ca2515ae9add236d8 (diff) | |
download | sqlalchemy-d1705a46fea6beb7a02d20b2bdc1518c214012ff.tar.gz |
- Fixed bug where the :meth:`.Operators.__and__`,
:meth:`.Operators.__or__` and :meth:`.Operators.__invert__`
operator overload methods could not be overridden within a custom
:class:`.TypeEngine.Comparator` implementation.
fixes #3012
Diffstat (limited to 'lib/sqlalchemy/sql/elements.py')
-rw-r--r-- | lib/sqlalchemy/sql/elements.py | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py index 13cf9aa91..ce6056418 100644 --- a/lib/sqlalchemy/sql/elements.py +++ b/lib/sqlalchemy/sql/elements.py @@ -505,9 +505,21 @@ class ClauseElement(Visitable): return unicode(self.compile()).encode('ascii', 'backslashreplace') def __and__(self, other): + """'and' at the ClauseElement level. + + .. deprecated:: 0.9.5 - conjunctions are intended to be + at the :class:`.ColumnElement`. level + + """ return and_(self, other) def __or__(self, other): + """'or' at the ClauseElement level. + + .. deprecated:: 0.9.5 - conjunctions are intended to be + at the :class:`.ColumnElement`. level + + """ return or_(self, other) def __invert__(self): @@ -516,17 +528,18 @@ class ClauseElement(Visitable): else: return self._negate() - def __bool__(self): - raise TypeError("Boolean value of this clause is not defined") - - __nonzero__ = __bool__ - def _negate(self): return UnaryExpression( self.self_group(against=operators.inv), operator=operators.inv, negate=None) + def __bool__(self): + raise TypeError("Boolean value of this clause is not defined") + + __nonzero__ = __bool__ + + def __repr__(self): friendly = getattr(self, 'description', None) if friendly is None: @@ -536,8 +549,7 @@ class ClauseElement(Visitable): self.__module__, self.__class__.__name__, id(self), friendly) - -class ColumnElement(ClauseElement, operators.ColumnOperators): +class ColumnElement(operators.ColumnOperators, ClauseElement): """Represent a column-oriented SQL expression suitable for usage in the "columns" clause, WHERE clause etc. of a statement. @@ -1503,6 +1515,8 @@ class TextClause(Executable, ClauseElement): def get_children(self, **kwargs): return list(self._bindparams.values()) + def compare(self, other): + return isinstance(other, TextClause) and other.text == self.text class Null(ColumnElement): """Represent the NULL keyword in a SQL statement. |