reg[name] = cls
super(_GenericMeta, cls).__init__(clsname, bases, clsdict)
- def __call__(cls, *args, **kwargs):
- if cls.coerce_arguments:
- args = [_literal_as_binds(c) for c in args]
- return type.__call__(cls, *args, **kwargs)
-
class GenericFunction(Function):
"""Define a 'generic' function.
coerce_arguments = True
def __init__(self, *args, **kwargs):
+ parsed_args = kwargs.pop('_parsed_args', None)
+ if parsed_args is None:
+ parsed_args = [_literal_as_binds(c) for c in args]
self.packagenames = []
self._bind = kwargs.get('bind', None)
self.clause_expr = ClauseList(
operator=operators.comma_op,
- group_contents=True, *args).self_group()
+ group_contents=True, *parsed_args).self_group()
self.type = sqltypes.to_instance(
kwargs.pop("type_", None) or getattr(self, 'type', None))
"""
type = sqltypes.Integer()
name = "next_value"
- coerce_arguments = False
def __init__(self, seq, **kw):
assert isinstance(seq, schema.Sequence), \
"""Define a function whose return type is the same as its arguments."""
def __init__(self, *args, **kwargs):
+ args = [_literal_as_binds(c) for c in args]
kwargs.setdefault('type_', _type_from_args(args))
+ kwargs['_parsed_args'] = args
GenericFunction.__init__(self, *args, **kwargs)
class coalesce(ReturnTypeFromArgs):
assert isinstance(func.mypackage.myfunc(), f1)
assert isinstance(func.myotherpackage.myfunc(), f2)
+ def test_custom_name(self):
+ class MyFunction(GenericFunction):
+ name = 'my_func'
+
+ def __init__(self, *args):
+ args = args + (3,)
+ super(MyFunction, self).__init__(*args)
+
+ self.assert_compile(
+ func.my_func(1, 2),
+ "my_func(:param_1, :param_2, :param_3)"
+ )
+
def test_custom_args(self):
class myfunc(GenericFunction):
pass