summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/sqlalchemy/sql/expression.py11
-rw-r--r--lib/sqlalchemy/types.py19
2 files changed, 21 insertions, 9 deletions
diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py
index a7cba8161..eb36558ce 100644
--- a/lib/sqlalchemy/sql/expression.py
+++ b/lib/sqlalchemy/sql/expression.py
@@ -2131,15 +2131,10 @@ class _BindParamClause(ColumnElement):
return obj.type
def compare(self, other, **kw):
- """Compare this ``_BindParamClause`` to the given clause.
-
- Since ``compare()`` is meant to compare statement syntax, this
- method returns True if the two ``_BindParamClauses`` have just
- the same type.
-
- """
+ """Compare this ``_BindParamClause`` to the given clause."""
+
return isinstance(other, _BindParamClause) and \
- other.type.__class__ == self.type.__class__ and \
+ self.type._compare_type_affinity(other.type) and \
self.value == other.value
def __getstate__(self):
diff --git a/lib/sqlalchemy/types.py b/lib/sqlalchemy/types.py
index 66b90ce04..3c42de2b8 100644
--- a/lib/sqlalchemy/types.py
+++ b/lib/sqlalchemy/types.py
@@ -37,7 +37,7 @@ if util.jython:
import array
class AbstractType(Visitable):
-
+
def __init__(self, *args, **kwargs):
pass
@@ -103,6 +103,19 @@ class AbstractType(Visitable):
"""
return op
+
+ @util.memoized_property
+ def _type_affinity(self):
+ """Return a rudimental 'affinity' value expressing the general class of type."""
+
+ for i, t in enumerate(self.__class__.__mro__):
+ if t is TypeEngine or t is UserDefinedType:
+ return self.__class__.__mro__[i - 1]
+ else:
+ return self.__class__
+
+ def _compare_type_affinity(self, other):
+ return self._type_affinity is other._type_affinity
def __repr__(self):
return "%s(%s)" % (
@@ -270,6 +283,10 @@ class TypeDecorator(AbstractType):
self._impl_dict[dialect] = tt
return tt
+ @util.memoized_property
+ def _type_affinity(self):
+ return self.impl._type_affinity
+
def type_engine(self, dialect):
impl = self.dialect_impl(dialect)
if not isinstance(impl, TypeDecorator):