Undo changes to the switch function. The new documentation left out the first parameter, in effect documenting the usage in single function mode.

This commit is contained in:
Charles Haley 2024-11-12 18:30:17 +00:00
parent 078e2a2654
commit 266be27bc3

View File

@ -768,8 +768,8 @@ class BuiltinSwitch(BuiltinFormatterFunction):
category = 'Iterating over values' category = 'Iterating over values'
__doc__ = doc = _( __doc__ = doc = _(
r''' r'''
``switch([pattern, value,]+ else_value)`` -- for each ``pattern, value`` pair, ``switch(value, [pattern, value,]+ else_value)`` -- for each ``pattern, value`` pair,
checks if the field matches the regular expression ``pattern`` and if so returns checks if the value matches the regular expression ``pattern`` and if so returns
the associated ``value``. If no ``pattern`` matches, then ``else_value`` is the associated ``value``. If no ``pattern`` matches, then ``else_value`` is
returned. You can have as many ``pattern, value`` pairs as you wish. The first returned. You can have as many ``pattern, value`` pairs as you wish. The first
match is returned. match is returned.
@ -777,7 +777,7 @@ match is returned.
def evaluate(self, formatter, kwargs, mi, locals, val, *args): def evaluate(self, formatter, kwargs, mi, locals, val, *args):
if (len(args) % 2) != 1: if (len(args) % 2) != 1:
raise ValueError(_('switch requires an odd number of arguments')) raise ValueError(_('switch requires an even number of arguments'))
i = 0 i = 0
while i < len(args): while i < len(args):
if i + 1 >= len(args): if i + 1 >= len(args):