Last active
August 16, 2022 04:27
-
-
Save josephsdavid/78c9e7b1a78b5a55bd1b137bc733732e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Magic: | |
def __init__(self): | |
pass | |
magic = Magic() | |
def setmagic(f): | |
magic.__dict__[f.func_name] = f | |
def magic_deco(f): | |
def wrapped(*args, **kwargs): | |
magic.__dict__[f.__name__] = f | |
return f(*args, **kwargs) | |
return wrapped | |
def delimit_str(start, delim=" "): | |
def out(*args): | |
return reduce(lambda x, y: f"{x}{delim}{y}", args, start) | |
out.func_name = start | |
return out | |
setmagic(print) | |
setmagic(sum) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from evil import magic, setmagic, magic_deco | |
magic.sum([1,23]) | |
magic.print("ok") | |
@magic_deco | |
def demo(a, b, c): | |
return a + b + c | |
magic.demo # errors | |
demo(1, 2, 3) | |
magic.demo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment