summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2012-08-24 16:14:47 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2012-08-24 16:14:47 -0400
commit2c2c6a3fe8e4ee29026ba7016e3a5d5b2850ec6b (patch)
treef60ac600f584a33a9e6c16deaae48eccd4971fa5
parent17f9bc5735b021201c1800adc2236b3fe67262b2 (diff)
downloadsqlalchemy-2c2c6a3fe8e4ee29026ba7016e3a5d5b2850ec6b.tar.gz
- correct the argument signature for GenericFunction to be more predictable
-rw-r--r--lib/sqlalchemy/sql/functions.py21
-rw-r--r--test/sql/test_functions.py11
2 files changed, 18 insertions, 14 deletions
diff --git a/lib/sqlalchemy/sql/functions.py b/lib/sqlalchemy/sql/functions.py
index 79f1bcde2..fe64764b7 100644
--- a/lib/sqlalchemy/sql/functions.py
+++ b/lib/sqlalchemy/sql/functions.py
@@ -6,7 +6,7 @@
from .. import types as sqltypes, schema
from .expression import (
- ClauseList, Function, _literal_as_binds, text, _type_from_args
+ ClauseList, Function, _literal_as_binds, literal_column, _type_from_args
)
from . import operators
from .visitors import VisitableType
@@ -87,15 +87,14 @@ class GenericFunction(Function):
__metaclass__ = _GenericMeta
coerce_arguments = True
- def __init__(self, type_=None, args=(), **kwargs):
- args = [_literal_as_binds(c) for c in args]
+ def __init__(self, *args, **kwargs):
self.packagenames = []
self._bind = kwargs.get('bind', None)
self.clause_expr = ClauseList(
operator=operators.comma_op,
group_contents=True, *args).self_group()
self.type = sqltypes.to_instance(
- type_ or getattr(self, 'type', None))
+ kwargs.pop("type_", None) or getattr(self, 'type', None))
class next_value(GenericFunction):
@@ -130,7 +129,7 @@ class ReturnTypeFromArgs(GenericFunction):
def __init__(self, *args, **kwargs):
kwargs.setdefault('type_', _type_from_args(args))
- GenericFunction.__init__(self, args=args, **kwargs)
+ GenericFunction.__init__(self, *args, **kwargs)
class coalesce(ReturnTypeFromArgs):
pass
@@ -150,19 +149,15 @@ class now(GenericFunction):
class concat(GenericFunction):
type = sqltypes.String
- def __init__(self, *args, **kwargs):
- GenericFunction.__init__(self, args=args, **kwargs)
class char_length(GenericFunction):
type = sqltypes.Integer
def __init__(self, arg, **kwargs):
- GenericFunction.__init__(self, args=[arg], **kwargs)
+ GenericFunction.__init__(self, arg, **kwargs)
class random(GenericFunction):
- def __init__(self, *args, **kwargs):
- kwargs.setdefault('type_', None)
- GenericFunction.__init__(self, args=args, **kwargs)
+ pass
class count(GenericFunction):
"""The ANSI COUNT aggregate function. With no arguments, emits COUNT \*."""
@@ -171,8 +166,8 @@ class count(GenericFunction):
def __init__(self, expression=None, **kwargs):
if expression is None:
- expression = text('*')
- GenericFunction.__init__(self, args=(expression,), **kwargs)
+ expression = literal_column('*')
+ GenericFunction.__init__(self, expression, **kwargs)
class current_date(AnsiFunction):
type = sqltypes.Date
diff --git a/test/sql/test_functions.py b/test/sql/test_functions.py
index 5769e4a1a..b69f8f6ba 100644
--- a/test/sql/test_functions.py
+++ b/test/sql/test_functions.py
@@ -38,7 +38,7 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
__return_type__ = sqltypes.Integer
def __init__(self, arg, **kwargs):
- GenericFunction.__init__(self, args=[arg], **kwargs)
+ GenericFunction.__init__(self, arg, **kwargs)
self.assert_compile(
fake_func('foo'),
@@ -114,6 +114,15 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
assert isinstance(func.mypackage.myfunc(), f1)
assert isinstance(func.myotherpackage.myfunc(), f2)
+ def test_custom_args(self):
+ class myfunc(GenericFunction):
+ pass
+
+ self.assert_compile(
+ myfunc(1, 2, 3),
+ "myfunc(:param_1, :param_2, :param_3)"
+ )
+
def test_namespacing_conflicts(self):
self.assert_compile(func.text('foo'), 'text(:text_1)')