Q:

What's the proper way to make a Python 3 function accept presets?

Consider a function that takes three arguments:
def foo(arg1, arg2, arg3):
    pass

and a class that provides presets in a tuple:
class Presets():
    preset1 = (1, 2, 3)
    preset2 = (3, 2, 1)

What's the proper way to make the function accept either three seperate arguments or one tuple of arguments?
Both should be valid function calls:
foo(1,1,1)
foo(Presets.preset2)

A:

One way to do it is by using a decorator.
from functools import wraps

def tupled_arguments(f):
    @wraps(f)  # keeps name, docstring etc. of f
    def accepts_tuple(tup, *args):
        if not args:  # only one argument given
            return f(*tup)
        return f(tup, *args)
    return accepts_tuple

@tupled_arguments
def foo(arg1, arg2, arg3):
    pass

Now the function can be called by either passing all arguments seperately or by passing them in a sequence.
foo(1,2,3)
foo((1,2,3))
foo([1,2,3])

are all equal calls.

A:

The simplest way is to just use an asterisk * to cause the arguments to be flattened when passed to foo:
foo(*Presets.preset2)

This is equivalent to:
foo(*(3, 2, 1))

which is equivalent to:
foo(3, 2, 1)

