Skip to content

Instantly share code, notes, and snippets.

@marethyu
Created July 19, 2020 20:43
Show Gist options
  • Select an option

  • Save marethyu/ffca5129bce370635b1cfd4feb2b1700 to your computer and use it in GitHub Desktop.

Select an option

Save marethyu/ffca5129bce370635b1cfd4feb2b1700 to your computer and use it in GitHub Desktop.
def uhm(f):
class Wrapper:
def __getitem__(self, arg):
if arg is None:
return f()
elif isinstance(arg, tuple):
return f(*arg)
else:
return f(arg)
return Wrapper()
@uhm
def hello(name):
print(f'hello {name}!')
@uhm
def repeat(name, times):
for _ in range(times):
hello[name]
@uhm
def print_smth():
print('something')
@uhm
def sqrt(n, iterations):
guess = 10.0
for _ in range(iterations):
guess = guess - (guess * guess - n) / (2.0 * guess)
return guess
hello['jimmy']
repeat['bob', 10]
print_smth[None]
print(sqrt[25.0, 20])
print(sqrt[50.0, 15])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment