diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-06-22 12:19:41 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-06-22 12:20:20 -0400 |
| commit | aa5cc5a2cca1131af7925f5bec1745571bfd5736 (patch) | |
| tree | 2b01fe0840dcd50eea910ce5d541267c03da0cc3 /lib/sqlalchemy/sql | |
| parent | 6bdeab2e4ccb0790882ece3f42ba370211658168 (diff) | |
| download | sqlalchemy-aa5cc5a2cca1131af7925f5bec1745571bfd5736.tar.gz | |
Provided a new attribute for :class:`.TypeDecorator`
called :attr:`.TypeDecorator.coerce_to_is_types`,
to make it easier to control how comparisons using
``==`` or ``!=`` to ``None`` and boolean types goes
about producing an ``IS`` expression, or a plain
equality expression with a bound parameter.
[ticket:2744]
Conflicts:
doc/build/changelog/changelog_09.rst
Diffstat (limited to 'lib/sqlalchemy/sql')
| -rw-r--r-- | lib/sqlalchemy/sql/expression.py | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index 3f9aef2b7..7e893db27 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -2013,8 +2013,10 @@ class _DefaultColumnComparator(operators.ColumnOperators): return op, other_comparator.type def _boolean_compare(self, expr, op, obj, negate=None, reverse=False, + _python_is_types=(util.NoneType, bool), **kwargs): - if isinstance(obj, (util.NoneType, bool, Null, True_, False_)): + + if isinstance(obj, _python_is_types + (Null, True_, False_)): # allow x ==/!= True/False to be treated as a literal. # this comes out to "== / != true/false" or "1/0" if those @@ -2056,7 +2058,8 @@ class _DefaultColumnComparator(operators.ColumnOperators): type_=sqltypes.BOOLEANTYPE, negate=negate, modifiers=kwargs) - def _binary_operate(self, expr, op, obj, reverse=False, result_type=None): + def _binary_operate(self, expr, op, obj, reverse=False, result_type=None, + **kw): obj = self._check_literal(expr, op, obj) if reverse: |
