Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use set up calls/period with class attributes #25

Open
sirhc78 opened this issue Oct 5, 2018 · 1 comment
Open

How to use set up calls/period with class attributes #25

sirhc78 opened this issue Oct 5, 2018 · 1 comment

Comments

@sirhc78
Copy link

sirhc78 commented Oct 5, 2018

Hi,

I am trying to use Ratelimit in a class.

class test : 
 def __init__(self,maxcalls,period)
    self.maxcalls =maxcalls
    self.period=period

 @limits(calls=self.maxcalls, period=self.period)
 def todo:
    pass

But I can't.
What can be my solutions ?

Thanks

@jonespm
Copy link

jonespm commented Oct 26, 2018

You can probably do it in the class constructor. I don't know how or if it's possible to do it on the class function. This is the only place you're defining these values anyway.

from ratelimit import limits

class test: 
    def __init__ (self, maxcalls, period):
        self.todo = limits(calls=maxcalls, period=period)(self._todo)

    def _todo(self):
        pass

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants