Decorator that returns a function named wrapper.

    When invoked, wrapper invokes func with default kwargs appended.

    Parameters
    ----------
    func : callable
        The function to append the default kwargs to
320040
def pass_defaults(func):
    
    @functools.wraps(func)
    def wrapper(self, *args, **kwargs):
        merged = {}
        merged.update(self.defaults)
        merged.update(kwargs)
        return func(self, *args, **merged)
    return wrapper
551309
def decorate(self, func):
		
		self.func = func
		self._set_implied_name()
		self.register()
		return func
1089237
def wrapped_help_text(wrapped_func):
    
    def decorator(wrapper_func):
        """The decorator.

        Parameters
        ----------
        f : callable
            The wrapped function.

        """
        wrapper_func.__doc__ = ('This method wraps the following method:\n\n' +
                                pydoc.text.document(wrapped_func))
        return wrapper_func
    return decorator
878450
def get_default(__func: Callable, __arg: str) -> str:
    
    return signature(__func).parameters[__arg].default
1171265
def indent(func):
    
    def wrapper(self, *args, **kwds):
        func(self, *args, **kwds)
        return Indent(self)
    return wrapper
1346547
def wrap(self, func):
        
        @six.wraps(func)
        def wrapper(*args, **kwargs):
            try:
                return self.aggregate()
            except KeyError:
                return func(*args, **kwargs)
        return wrapper
484606
def defaults(default=None):
    
    def _f(func):
        @functools.wraps(func)
        def __f(self, *args, **kwargs):
            try:
                return func(self, *args, **kwargs)
            except Exception:
                return default
        return __f
    return _f
291465
def call(func, args):
    
    assert hasattr(func, '__call__'), 'Cannot call func: {}'.format(
        func.__name__)
    raw_func = (
        func if isinstance(func, FunctionType) else func.__class__.__call__)
    hints = collections.defaultdict(lambda: Any, get_type_hints(raw_func))
    argspec = _getargspec(raw_func)
    named_args = {}
    varargs = ()
    for k, nk, v in _normalize(args):
        if nk == argspec.varargs:
            hints[nk] = Tuple[hints[nk], ...]
        elif nk not in argspec.args and argspec.varkw in hints:
            hints[nk] = hints[argspec.varkw]
        try:
            value = cast(hints[nk], v)
        except TypeError as e:
            _LOGGER.exception(e)
            six.raise_from(exc.InvalidCliValueError(k, v), e)
        if nk == argspec.varargs:
            varargs = value
        elif (nk in argspec.args or argspec.varkw) and (
                nk not in named_args or named_args[nk] is None):
            named_args[nk] = value
    return func(*varargs, **named_args)
1366039
def _enable_cleanup(func):
    

    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        self = args[0]
        result = func(*args, **kwargs)
        self.cleanup(self)
        return result

    return wrapper
606480
def allow_create(function):
    
    @wraps(function)
    def _wrapped_func(*args, **kwargs):
        form = args[0]
        # If this argument is not a form, there are a lot of chances that
        # you didn't decorate the right method.
        # This decorator is only to be used decorating "form_valid()"
        if isinstance(form, (Form, ModelForm)):
            # If the form is not valid, don't try to create new values
            if not form.is_valid():
                return function(*args, **kwargs)

            for k, field in form.fields.items():
                if getattr(field, 'create', False) \
                        and getattr(field, '_new_values', None):
                    new_values = field.create_new_values()
                    # update the field value
                    form.cleaned_data[k] = form.cleaned_data[k] | new_values

        return function(*args, **kwargs)
    return _wrapped_func
952150
def wrap_with(wrapper_cls):
    
    def wrapper(func):
        annotate(func, 'wrapper', [{'wrapper': wrapper_cls}])
        return activate(func)
    return wrapper
1212195
def call_decorator(cls, func):
        

        @wraps(func)
        def _wrap(self, *args, **kwargs):
            try:
                return func(self, *args, **kwargs)
            except Exception:
                self.logger.exception('While executing benchmark')
                if not (self.catch_child_exception or False):
                    raise

        return _wrap
792452
def exception(function):
    
    @functools.wraps(function)
    def wrapper(*exception, **kwargs):
        result = function(**kwargs)
        if exception:
            result.exception = exception[0]
        return result
    return wrapper
368144
def optional_args_func(func) -> callable:
    
    if getattr(func, '_optional_args_func', False):
        return func

    is_generator = inspect.isgeneratorfunction(func)
    func_sig = inspect.signature(func)
    expects_nothing = not func_sig.parameters

    if is_generator:
        @functools.wraps(func)
        def wrapped(*args, **kwargs):
            if expects_nothing:
                yield from func()
            else:
                bound_arguments = func_sig.bind(*args, **{k: v for k, v in kwargs.items() if k in func_sig.parameters})
                yield from func(*bound_arguments.args, **bound_arguments.kwargs)
    else:
        @functools.wraps(func)
        def wrapped(*args, **kwargs):
            if expects_nothing:
                return func()
            else:
                bound_arguments = func_sig.bind(*args, **{k: v for k, v in kwargs.items() if k in func_sig.parameters})
                return func(*bound_arguments.args, **bound_arguments.kwargs)

    # Mark it so that we don't double wrap our own
    setattr(wrapped, '_optional_args_func', True)

    return wrapped
548880
def argument(*args, **kwargs):
    

    def decorator(func):
        adaptor = ScriptAdaptor._get_adaptor(func)
        group = kwargs.pop('group', None)
        adaptor._add_argument(args, kwargs, group=group)
        return func
    return decorator
525861
def absorb_args(self, func):
        
        @wraps(func)
        def wrapper(*args, **kwargs):
            return func()
        return wrapper
496453
def method_name(func):
    
    @wraps(func)
    def _method_name(*args, **kwargs):
        name = to_pascal_case(func.__name__)
        return func(name=name, *args, **kwargs)
    return _method_name