]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
added better typing for integer expressions, since integer is implementing _DateAffinity
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 11 Mar 2010 21:18:37 +0000 (16:18 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 11 Mar 2010 21:18:37 +0000 (16:18 -0500)
lib/sqlalchemy/types.py
test/sql/test_types.py

index 5c4e2ca3f58cb21a69c8d480870c9499c633be79..bf06ec99b7d8ff1cd2c5125a3c950a0499461ce6 100644 (file)
@@ -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,
             },
         }
 
index d56a7552ea5fc0f4c6104d09e4eb382b8ddc4c97..fa8254a7a4cefc5d811b8aa5ee51505bed325ee7 100644 (file)
@@ -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)])