def new(expr, *args, **kwargs):
<EOL>current_args, current_var_args, current_kwargs = get_vars(expr)<EOL>new_kwargs = current_kwargs.copy()<EOL>recursive_arguments = {}<EOL>for key in tuple(kwargs):<EOL><INDENT>if "<STR_LIT>" in key:<EOL><INDENT>value = kwargs.pop(key)<EOL>key, _, subkey = key.partition("<STR_LIT>")<EOL>recursive_arguments.setdefault(key, []).append((subkey, value))<EOL><DEDENT><DEDENT>for key, pairs in recursive_arguments.items():<EOL><INDENT>recursed_object = current_args.get(key, current_kwargs.get(key))<EOL>if recursed_object is None:<EOL><INDENT>continue<EOL><DEDENT>kwargs[key] = new(recursed_object, **dict(pairs))<EOL><DEDENT>if args:<EOL><INDENT>current_var_args = args<EOL><DEDENT>for key, value in kwargs.items():<EOL><INDENT>if key in current_args:<EOL><INDENT>current_args[key] = value<EOL><DEDENT>else:<EOL><INDENT>new_kwargs[key] = value<EOL><DEDENT><DEDENT>new_args = list(current_args.values()) + list(current_var_args)<EOL>return type(expr)(*new_args, **new_kwargs)<EOL>
Template an object.

::

    >>> class MyObject:
    ...     def __init__(self, arg1, arg2, *var_args, foo=None, bar=None, **kwargs):
    ...         self.arg1 = arg1
    ...         self.arg2 = arg2
    ...         self.var_args = var_args
    ...         self.foo = foo
    ...         self.bar = bar
    ...         self.kwargs = kwargs
    ...
    >>> my_object = MyObject('a', 'b', 'c', 'd', foo='x', quux=['y', 'z'])

::

    >>> import uqbar
    >>> new_object = uqbar.objects.new(my_object, foo=666, bar=1234)
    >>> print(uqbar.objects.get_repr(new_object))
    MyObject(
        'a',
        'b',
        'c',
        'd',
        bar=1234,
        foo=666,
        quux=['y', 'z'],
        )

Original object is unchanged:

::

    >>> print(uqbar.objects.get_repr(my_object))
    MyObject(
        'a',
        'b',
        'c',
        'd',
        foo='x',
        quux=['y', 'z'],
        )