mirror of
https://github.com/django/django.git
synced 2025-08-22 11:34:33 +00:00
Refs #25629 -- Added arity
class attribute to Func
expressions
This commit is contained in:
parent
03c6ad7ad4
commit
0a26121797
6 changed files with 27 additions and 10 deletions
|
@ -482,8 +482,18 @@ class Func(Expression):
|
|||
function = None
|
||||
template = '%(function)s(%(expressions)s)'
|
||||
arg_joiner = ', '
|
||||
arity = None # The number of arguments the function accepts.
|
||||
|
||||
def __init__(self, *expressions, **extra):
|
||||
if self.arity is not None and len(expressions) != self.arity:
|
||||
raise TypeError(
|
||||
"'%s' takes exactly %s %s (%s given)" % (
|
||||
self.__class__.__name__,
|
||||
self.arity,
|
||||
"argument" if self.arity == 1 else "arguments",
|
||||
len(expressions),
|
||||
)
|
||||
)
|
||||
output_field = extra.pop('output_field', None)
|
||||
super(Func, self).__init__(output_field=output_field)
|
||||
self.source_expressions = self._parse_expressions(*expressions)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue