Skip to content

Instantly share code, notes, and snippets.

@DaelonSuzuka
Last active December 7, 2024 23:10
Show Gist options
  • Save DaelonSuzuka/fc625ec1b16561b5c6cd2c3a69d5991b to your computer and use it in GitHub Desktop.
Save DaelonSuzuka/fc625ec1b16561b5c6cd2c3a69d5991b to your computer and use it in GitHub Desktop.
class lmao:
toggle = True
def __init__(self, value=None):
print(f'lmao.init = {value}')
self.value = value
def __call__(self, func):
print(f'lmao.decorate = {self.value}')
def wrapper(*args, **kwargs):
print('\tlmao.wrapper')
if lmao.toggle:
print(f'\t\tlmao.value = {self.value}')
return func(*args, **kwargs)
return wrapper
def __enter__(self, *_):
print('lmao.enter')
lmao.toggle = False
return self
def __exit__(self, *_):
print('lmao.exit')
lmao.toggle = True
@lmao('lol')
def test1():
print('\t\ttest1')
@lmao('kek')
def test2():
print('\t\ttest2')
test1()
test2()
with lmao():
test1()
test2()
test1()
test2()
# lmao.init = lol
# lmao.decorate = lol
# lmao.init = kek
# lmao.decorate = kek
# lmao.wrapper
# lmao.value = lol
# test1
# lmao.wrapper
# lmao.value = kek
# test2
# lmao.init = None
# lmao.enter
# lmao.wrapper
# test1
# lmao.wrapper
# test2
# lmao.exit
# lmao.wrapper
# lmao.value = lol
# test1
# lmao.wrapper
# lmao.value = kek
# test2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment