Skip to content

Instantly share code, notes, and snippets.

@dword4
Created August 24, 2022 18:45
Show Gist options
  • Save dword4/c44fcb3bb07a4e447808d0535925a2d3 to your computer and use it in GitHub Desktop.
Save dword4/c44fcb3bb07a4e447808d0535925a2d3 to your computer and use it in GitHub Desktop.
decorator problems
#!/usr/bin/env python3
class command(object):
def ratelimit(*args, **kwargs):
limit = args[0]
def ratelimit_wrapper(func):
print(f"rate: {limit}")
print("begin: ratelimit_wrapper")
# some stuff
print("end: ratelimit_wrapper")
return func
return ratelimit_wrapper
class animals(object):
@command.ratelimit(10)
def cat(self):
print("meow")
@command.ratelimit(5)
def dog(self):
print("woof")
zoo = animals()
zoo.cat()
zoo.dog()
zoo.cat()
./dec.py
rate: 10
begin: ratelimit_wrapper
end: ratelimit_wrapper
rate: 5
begin: ratelimit_wrapper
end: ratelimit_wrapper
meow
woof
meow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment