def opt_arg_dec(decorated, is_method=False, valid_target=None, 
    allow_non_callable=False):
    """ 
    is_method: True if the function to become an opt_arg_dec is a 
        method or a classmethod (not a staticmethod).
    valid_target: A callable receiving a single object and returning True
        if it is a valid target for the decorator to decorate. 

        This is not used as error validation. This is to detect when the 
        decorator will only be called once (when no initial call to set 
        arguments is made or when it is not used in the form of a decorator.)
        If arguments were previously passed, the target will be sent through
        without any form of checking. You must still to error validation in
        your decorator if you need it.

        The target must be callable unless allow_non_callable is True.
        Special values:
        - None (default): the target must not be a type/class (but it can be
                an instance of a type/class).
                Use this for function decorator, unless you want to pass in
                a function to be more specific and only allow certain specific
                types.
        - "class": the target must be a class (not an instance of a class).
                However, builtin classes that are global to python will not
                be accepted. Meaning (int, float, str, set, dict, list, tuple
                and maybe a few more) since it is unlikely to want to decorate
                those.
                Use this for class decorators.
        - "type": same as "class", but builtin classes are also accepted.
        - "any": anything is allowed. (Must still be callable unless
                allow_non_callable is True)
        - "never": nothing will ever be accepted as target. This means the
                decorator must always be called before being applied to the
                real target, even if it means with no arguments.
    
    allow_non_callable: If False (the default), then the target to be
        decorated must be callable! See valid_target for more details,
        this check is done in the same conditions. Setting this to True means
        that valid_target must do more advanced check, otherwise almost
        anything will be considered a valid target and the first call to the
        function will be treated as a full call.
    """
    try:
        if valid_target in _valid_target_defaults:
            valid_target = _valid_target_defaults[valid_target]
    except:
        # valid_target is not hashable. So it's not one of the special values.
        pass

    is_method = bool(is_method)

    options = {"is_method": is_method,
               "valid_target": valid_target,
               "allow_non_callable": allow_non_callable}

    def opt_arg_dec_wrapped(*params, **kwargs):
        return _opt_arg_dec_used(decorated, options, params, kwargs)
    
    opt_arg_dec_wrapped.__name__ = decorated.__name__
    opt_arg_dec_wrapped.__doc__ = decorated.__doc__

    return opt_arg_dec_wrapped
 
    is_method: True if the function to become an opt_arg_dec is a 
        method or a classmethod (not a staticmethod).
    valid_target: A callable receiving a single object and returning True
        if it is a valid target for the decorator to decorate. 

        This is not used as error validation. This is to detect when the 
        decorator will only be called once (when no initial call to set 
        arguments is made or when it is not used in the form of a decorator.)
        If arguments were previously passed, the target will be sent through
        without any form of checking. You must still to error validation in
        your decorator if you need it.

        The target must be callable unless allow_non_callable is True.
        Special values:
        - None (default): the target must not be a type/class (but it can be
                an instance of a type/class).
                Use this for function decorator, unless you want to pass in
                a function to be more specific and only allow certain specific
                types.
        - "class": the target must be a class (not an instance of a class).
                However, builtin classes that are global to python will not
                be accepted. Meaning (int, float, str, set, dict, list, tuple
                and maybe a few more) since it is unlikely to want to decorate
                those.
                Use this for class decorators.
        - "type": same as "class", but builtin classes are also accepted.
        - "any": anything is allowed. (Must still be callable unless
                allow_non_callable is True)
        - "never": nothing will ever be accepted as target. This means the
                decorator must always be called before being applied to the
                real target, even if it means with no arguments.
    
    allow_non_callable: If False (the default), then the target to be
        decorated must be callable! See valid_target for more details,
        this check is done in the same conditions. Setting this to True means
        that valid_target must do more advanced check, otherwise almost
        anything will be considered a valid target and the first call to the
        function will be treated as a full call.
    
recipes/Python/578435_Optional_arguments_decorator/recipe-578435.py