Пример #1
0
def wraps(wrapped, *args, **kwargs):
    """A wrap decorator which stores in the returned function a reference to
    the wrapped function (in member '__wrapped__')"""
    wrapper = _wraps(wrapped, *args, **kwargs)
    setattr(wrapper, __WRAPPED, weakref.ref(wrapped))
    setattr(wrapped, __WRAPPER, weakref.ref(wrapper))
    return wrapper
Пример #2
0
def _fix(
    f,
    what,
    re=_re.compile(r"Same as (?P<op>.+?(?=(,|\.$| \()))(?P<tail>[.,]?.*)")):
    out = _wraps(f)(what)
    if out.__doc__:
        doc = out.__doc__.strip().rstrip(".") + "."
        m = re.match(doc)
        if m:
            op, tail = m.group("op", "tail")
            out.__doc__ = f"Same as ``{op}``{tail}"
    return out
Пример #3
0
def no_op_wraps(function):
    """
    Replaces functools.wraps in order to undo wrapping when generating Sphinx
    documentation.
    """

    if function.__module__ is None or 'colour' not in function.__module__:
        return functools._wraps(function)

    def wrapper(*args):
        return function

    return wrapper
Пример #4
0
def no_op_wraps(function):
    """
    Replaces functools.wraps in order to undo wrapping when generating Sphinx
    documentation.
    """

    if function.__module__ is None or 'colour' not in function.__module__:
        return functools._wraps(function)

    def wrapper(*args):
        return function

    return wrapper
Пример #5
0
 def __init__(self, func):
     self._orig = func
     self._wrapper = _wraps(func)
Пример #6
0
 def decorate_func(func):
     return _wraps(func)(Converter(
         func,
         totype=totype,
         convertible_type_description=convertible_type_description,
         convertible_value_description=convertible_value_description))
Пример #7
0
 def wrapper(f):
     f = _wraps(wrapped, *args, **kwargs)(f)
     f.__wrapped__ = wrapped
     return f
Пример #8
0
 def dec(func):
     _wraps(f)(func)
     func.__wrapped__ = f
     return func
Пример #9
0
import builtins as _builtins
from functools import wraps as _wraps

from ..functions import fn

_execute_with = lambda **kwargs: lambda f: f(**kwargs) or f
_flipped = lambda f: _wraps(f)(lambda x, y: f(y, x))
_getattr = getattr
_dir = dir

# Arity-1 functions
# abs, all, any, ascii, bin, bool, callable, chr, classmethod, dict, dir, float
# frozenset, hash, help, hex, id, input, int, iter, len, list, memoryview
# next, oct, ord, repr, reversed, round, set, sorted, staticmethod, str, sum
# tuple, type, vars


@fn.curry(2)
def int_base(base, x):
    """
    Convert string x representing a number in some base to integer.
    """
    return _builtins.int(x, base)


@fn.curry(3)
def getattr_or(default, attr, obj):
    """
    Return given attribute of object or the default argument if attr is not
    given.
    """
 def dec(func):
     _wraps(f)(func)
     func.__wrapped__ = f
     return func