]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
turned starargs conversion to a decorator, per jek's advice. select().order_by()...
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 29 Mar 2008 16:31:31 +0000 (16:31 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 29 Mar 2008 16:31:31 +0000 (16:31 +0000)
CHANGES
lib/sqlalchemy/orm/query.py
lib/sqlalchemy/util.py

diff --git a/CHANGES b/CHANGES
index d81c0a87b597a9fc476b3a85127864e5b1ecc1a4..5dea65f02b14364a3f9e8547a05a610cf99d4474 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -26,7 +26,8 @@ CHANGES
       more flexible approach.
 
     - query.order_by() and query.group_by() will accept
-      multiple arguments using *args.
+      multiple arguments using *args (like select() 
+      already does).
       
     - Fixed/covered case when using a False/0 value as a
       polymorphic discriminator.
index 8c0f1335ddcb3a883844d8c6501ba1566dbbe15a..1d4b24e0c58a7108fcbefc58123986561986355c 100644 (file)
@@ -529,24 +529,26 @@ class Query(object):
         q = self._no_statement("order_by")
 
         if self._aliases_tail:
-            criterion = [expression._literal_as_text(o) for o in util.starargs_as_list(*criterion)]
+            criterion = [expression._literal_as_text(o) for o in criterion]
             criterion = self._aliases_tail.adapt_list(criterion)
 
         if q._order_by is False:
-            q._order_by = util.starargs_as_list(*criterion)
+            q._order_by = criterion
         else:
-            q._order_by = q._order_by + util.starargs_as_list(*criterion)
+            q._order_by = q._order_by + criterion
         return q
-
+    order_by = util.array_as_starargs_decorator(order_by)
+    
     def group_by(self, *criterion):
         """apply one or more GROUP BY criterion to the query and return the newly resulting ``Query``"""
 
         q = self._no_statement("group_by")
         if q._group_by is False:
-            q._group_by = util.starargs_as_list(*criterion)
+            q._group_by = criterion
         else:
-            q._group_by = q._group_by + util.starargs_as_list(*criterion)
+            q._group_by = q._group_by + criterion
         return q
+    group_by = util.array_as_starargs_decorator(group_by)
     
     def having(self, criterion):
         """apply a HAVING criterion to the query and return the newly resulting ``Query``."""
index 6919d1557dc1b7e737b5e15a4d26263d41e0fe30..26b6dbe9a060bc3a56a57e9553ac4765e92fb969 100644 (file)
@@ -188,15 +188,17 @@ def to_list(x, default=None):
     else:
         return x
 
-def starargs_as_list(*args):
-    """interpret the given *args as either a list of *args, 
-    or detect if it's a single list and return that.
+def array_as_starargs_decorator(func):
+    """Interpret a single positional array argument as
+    *args for the decorated method.
     
     """
-    if len(args) == 1:
-        return to_list(args[0], [])
-    else:
-        return list(args)
+    def starargs_as_list(self, *args, **kwargs):
+        if len(args) == 1:
+            return func(self, *to_list(args[0], []), **kwargs)
+        else:
+            return func(self, *args, **kwargs)
+    return starargs_as_list
     
 def to_set(x):
     if x is None: