summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2010-03-11 16:18:37 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2010-03-11 16:18:37 -0500
commitec0fafc7b01839c2fac7f93cb2e0a92aa3e1c41a (patch)
tree6dcc9443fd67a2d118de8e48b730a70e64d5d939
parent3254699f8527cde0ecd4d806c72e34764899b26b (diff)
downloadsqlalchemy-ec0fafc7b01839c2fac7f93cb2e0a92aa3e1c41a.tar.gz
added better typing for integer expressions, since integer is implementing _DateAffinity
-rw-r--r--lib/sqlalchemy/types.py23
-rw-r--r--test/sql/test_types.py5
2 files changed, 27 insertions, 1 deletions
diff --git a/lib/sqlalchemy/types.py b/lib/sqlalchemy/types.py
index 5c4e2ca3f..bf06ec99b 100644
--- a/lib/sqlalchemy/types.py
+++ b/lib/sqlalchemy/types.py
@@ -33,6 +33,7 @@ from sqlalchemy.util import pickle
from sqlalchemy.sql.visitors import Visitable
from sqlalchemy import util
from sqlalchemy import processors
+import collections
NoneType = type(None)
if util.jython:
@@ -820,12 +821,32 @@ class Integer(_DateAffinity, TypeEngine):
@util.memoized_property
def _expression_adaptations(self):
+ # TODO: need a dictionary object that will
+ # handle operators generically here, this is incomplete
return {
operators.add:{
Date:Date,
+ Integer:Integer,
+ Numeric:Numeric,
},
operators.mul:{
- Interval:Interval
+ Interval:Interval,
+ Integer:Integer,
+ Numeric:Numeric,
+ },
+ # Py2K
+ operators.div:{
+ Integer:Integer,
+ Numeric:Numeric,
+ },
+ # end Py2K
+ operators.truediv:{
+ Integer:Integer,
+ Numeric:Numeric,
+ },
+ operators.sub:{
+ Integer:Integer,
+ Numeric:Numeric,
},
}
diff --git a/test/sql/test_types.py b/test/sql/test_types.py
index d56a7552e..fa8254a7a 100644
--- a/test/sql/test_types.py
+++ b/test/sql/test_types.py
@@ -909,6 +909,11 @@ class ExpressionTest(TestBase, AssertsExecutionResults, AssertsCompiledSQL):
expr = func.current_date() - column('foo', types.TIMESTAMP)
eq_(expr.type._type_affinity, types.Interval)
+
+ def test_expression_typing(self):
+ expr = column('bar', Integer) - 3
+
+ eq_(expr.type._type_affinity, Integer)
def test_distinct(self):
s = select([distinct(test_table.c.avalue)])