Skip to content

Instantly share code, notes, and snippets.

@ducva
Created May 28, 2020 03:50
Show Gist options
  • Select an option

  • Save ducva/7ff12016b76a660dcec02bf291740d05 to your computer and use it in GitHub Desktop.

Select an option

Save ducva/7ff12016b76a660dcec02bf291740d05 to your computer and use it in GitHub Desktop.
class Authed:
def __init__(self, func: typing.Callable[[str], None]):
self.func = func
self.checked_times = 0
def __call__(self, arg: str):
print('checking auth....OK')
self.checked_times += 1
if self.checked_times >= 5:
print('run out of time')
else:
self.func(arg)
print('post process....OK')
@Authed
def orig_func(arg1: str):
print(f"arg1: {arg1}")
if __name__ == "__main__":
orig_func("Hello World!")
orig_func("test: Hello World!")
orig_func("Hello World!")
orig_func("test: Hello World!")
orig_func("Hello World!")
orig_func("test: Hello World!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment