Clones the Callable optionally with new settings

        Args:
            callable: New callable function to wrap
            **overrides: Parameter overrides to apply

        Returns:
            Cloned Callable object
359431
def clone(self, callable=None, **overrides):
        
        old = {k: v for k, v in self.get_param_values()
               if k not in ['callable', 'name']}
        params = dict(old, **overrides)
        callable = self.callable if callable is None else callable
        return self.__class__(callable, **params)
1172193
def p_Callable(p):
    '''
    
    '''
    if len(p) <= 3:
        p[0] = Callable(p[1], None)
    else:
        p[0] = Callable(p[1], p[3])
1159511
def replace_all_calls(mod, orig, repl):
    
    rc = ReplaceCalls(orig, repl)
    rc.visit(mod)
    return rc.calls
330080
def recreate(cls, *args, **kwargs):
        """"""
        cls.check_arguments(kwargs)
        first_is_callable = True if any(args) and callable(args[0]) else False
        signature = cls.default_arguments()
        allowed_arguments = {k: v for k, v in kwargs.items() if k in signature}
        if (any(allowed_arguments) or any(args)) and not first_is_callable:
            if any(args) and not first_is_callable:
                return cls(args[0], **allowed_arguments)
            elif any(allowed_arguments):
                return cls(**allowed_arguments)

        return cls.instances[-1] if any(cls.instances) else cls()
224168
def clone_and_update(self, **kwargs):
        
        cloned = self.clone()
        cloned.update(**kwargs)
        return cloned
1275023
def _wrap(method: Callable, wrapper: Callable) -> Callable:
        
        def wrapped(*args, **kwargs):
            return wrapper(method, *args, **kwargs)
        return wrapped
1351141
def singleton(func):
    

    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        if wrapper.__call_state__ == CALLED:
            return
        ret = func(*args, **kwargs)
        wrapper.__call_state__ = CALLED
        return ret

    def reset():
        wrapper.__call_state__ = NOT_CALLED

    wrapper.reset = reset
    reset()

    # save original func to be able to patch and restore multiple times from
    # unit tests
    wrapper.__original_func = func
    return wrapper
896501
def mutable(function):
    ''''''

    def wrapper(self, *args, **kwargs):
        state = self._get_state()
        return function(self, state, *args, **kwargs)

    return wrapper
1033113
def _get_callargs(self, *args, **kwargs):
        
        callargs = getcallargs(self.func, *args, **kwargs)
        return callargs
394438
public static <V> Callable<V> wrap(final Callable<V> callable) {
		final String suffix = Log.suffix.get();
		// t.getCause() is atop t, see Log.concat() for more details
		final Throwable t = new Throwable(Log.throwable.get());
		return new Callable<V>() {
			@Override
			public V call() throws Exception {
				threadNum.incrementAndGet();
				Log.suffix.set(suffix);
				Log.throwable.set(t);
				try {
					return callable.call();
				} catch (Error e) {
					throw new Exception(e);
				} finally {
					Log.throwable.remove();
					Log.suffix.remove();
					threadNum.decrementAndGet();
				}
			}
		};
	}
305717
def extend(cls):
    
    def extender(func):
        setattr(cls, get_function_name(func), func)
        return func
    return extender
249536
def _compile_callable(self, schema):
        
        # Prepare self
        self.compiled_type = const.COMPILED_TYPE.CALLABLE
        self.name = get_callable_name(schema)

        # Error utils
        enrich_exception = lambda e, value: e.enrich(
            expected=self.name,
            provided=get_literal_name(value),
            path=self.path,
            validator=schema)

        # Validator
        def validate_with_callable(v):
            try:
                # Try this callable
                return schema(v)
            except Invalid as e:
                # Enrich & re-raise
                enrich_exception(e, v)
                raise
            except const.transformed_exceptions as e:
                message = _(u'{message}').format(
                    Exception=type(e).__name__,
                    message=six.text_type(e))
                e = Invalid(message)
                raise enrich_exception(e, v)

        # Matcher
        if self.matcher:
            def match_with_callable(v):
                try:
                    return True, validate_with_callable(v)
                except Invalid:
                    return False, v
            return match_with_callable

        return validate_with_callable
788812
def clone(self, opts):
        '''
        
        '''
        topt = self.opts.copy()
        topt.update(opts)
        return self.__class__(self.modl, self.name, self.info, topt)
936716
def callwith(context_manager):
    
    def decorator(func):
        @functools.wraps(func)
        def wrapper(*args, **kwds):
            with context_manager:
                return func(*args, **kwds)
        return wrapper
    return decorator
387811
public static <T> Callable<T> privilegedCallable(Callable<T> callable) {
        if (callable == null)
            throw new NullPointerException();
        return callable;
    }
368595
def _start_callables(self, row, callables):
        
        id_vals = {c: row[c] for c in self.ids}

        def callback(tab, cols, result):
            if isinstance(result, Mapping):
                pass
            elif isinstance(result, tuple):
                result = dict(zip(cols, result))
            elif len(cols) == 1:
                # Don't bother raising an exception if cols != 1
                # because it would be lost in the thread.
                result = {cols[0]: result}
            result.update(id_vals)
            tab._write(result)

        if self._pool is None:
            self._pool = Pool()
        if self._lock is None:
            self._lock = multiprocessing.Lock()

        for cols, fn in callables:
            cb_func = partial(callback, self, cols)

            gen = None
            if inspect.isgeneratorfunction(fn):
                gen = fn()
            elif inspect.isgenerator(fn):
                gen = fn

            if gen:
                def callback_for_each():
                    for i in gen:
                        cb_func(i)
                self._pool.apply_async(callback_for_each)
            else:
                self._pool.apply_async(fn, callback=cb_func)
33109
def _makes_clone(_func, *args, **kw):
    
    self = args[0]._clone()
    _func(self, *args[1:], **kw)
    return self