def __new__(cls, priority, function, *args, **kwargs): """ Creates a Hook with the given: priority: some comparable object. only used if you place the hook in a HookList. function: can be any callable if the given argument for function is not a callable, it will be wrapped to a function which always returns that argument (a constant of sorts) args: arguments that will be passed to function when this hook is called Examples: h1 = Hook(0.0, lambda a, b: a + b, (1, 4)) h1() # 5 h2 = Hook(0.0, 27, ()) h2() # 27 h3 = Hook(7.2, lambda a, b, c: a + b + c, (1, 4)) h3(8) # 13 """ if not callable(function): function = util.always(function) self = partial.__new__(cls, function, *args, **kwargs) self.priority = priority return self
def __new__(cls, func, *args, **kw): assert not isinstance(func, Handler) obj = partial.__new__(cls, func, *args, **kw) obj._cancelled = False return obj
def __new__(cls, name, call, *args, **kwds): check = partial.__new__(cls, call, *args, **kwds) check.__name__ = name return check
def __new__(cls, name, typeobj): obj = partial.__new__(cls, typeobj.__instancecheck__) obj.__name__ = name or (typeobj.__name__ + "?") return obj
def __new__(cls, target, kwargs): """ Just pass the arguments to underlying ``functools.partial``. """ return partial.__new__(cls, target, **kwargs)
def __new__(cls, *funcs): funcs = (func if isinstance(func, cls) else [func] for func in funcs) funcs = tuple(itertools.chain(*funcs)) return partial.__new__(cls, *(funcs if len(funcs) == 1 else (pipe, funcs)))