def last_arg_decorator(func):
@wraps(func)<EOL>def decorator(*args, **kwargs):<EOL><INDENT>if signature_matches(func, args, kwargs):<EOL><INDENT>return func(*args, **kwargs)<EOL><DEDENT>else:<EOL><INDENT>return lambda last: func(*(args + (last,)), **kwargs)<EOL><DEDENT><DEDENT>return decorator<EOL>
Allows a function to be used as either a decorator with args, or called as
a normal function.

@last_arg_decorator
def register_a_thing(foo, func, bar=True):
    ..

# Called as a decorator
@register_a_thing("abc", bar=False)
def my_func():
    ...

# Called as a normal function call
def my_other_func():
    ...

register_a_thing("def", my_other_func, bar=True)