Added coroutine decorator to helpers
This commit is contained in:
parent
665469ffff
commit
80d47ecae8
|
@ -4,4 +4,4 @@ from abots.helpers.numbers import clamp, randfloat, isnumeric
|
|||
from abots.helpers.general import eprint, deduce, noop, cast, get_digit, obtain
|
||||
from abots.helpers.general import utc_now, utc_now_timestamp
|
||||
from abots.helpers.logging import Logger
|
||||
from abots.helpers.black_magic import infinitedict
|
||||
from abots.helpers.black_magic import infinitedict, debugger, coroutine
|
||||
|
|
|
@ -1,5 +1,35 @@
|
|||
from collections import defaultdict
|
||||
from functools import wraps
|
||||
|
||||
def infinitedict():
|
||||
d = lambda: defaultdict(d)
|
||||
return defaultdict(d)
|
||||
return defaultdict(d)
|
||||
|
||||
# NOTE - Is this useful? I have no idea, but here it is!
|
||||
def decorator(wrapper):
|
||||
def wrapper_decorator(func):
|
||||
@wraps(func)
|
||||
def wrapper_wrapper(*args, **kwargs):
|
||||
return wrapper(*args, **kwargs)
|
||||
return wrapper_wrapper
|
||||
return wrapper_decorator
|
||||
|
||||
def debugger(func):
|
||||
@wraps(func)
|
||||
def wrapper_debug(*args, **kwargs):
|
||||
args_repr = [repr(arg) for arg in args]
|
||||
kwargs_repr = [f"{key}={value!r}" for key, value in kwargs.items()]
|
||||
signature = ", ".join(args_repr + kwargs_repr)
|
||||
print(f"[DEBUGGER]: Calling {func.__name__}({signature})")
|
||||
result = func(*args, **kwargs)
|
||||
print(f"[DEBUGGER]: {func.__name__!r} returned {value!r}")
|
||||
return value
|
||||
return wrapper_debug
|
||||
|
||||
def coroutine(func):
|
||||
@wraps(func)
|
||||
def wrapper_coroutine(*args, **kwargs):
|
||||
coro = func(*args, **kwargs)
|
||||
coro.send(None)
|
||||
return coro
|
||||
return wrapper_decorator
|
||||
|
|
Loading…
Reference in New Issue