Created
July 6, 2016 17:07
-
-
Save cablehead/7fc6d015a3a0c58d7ffdf50df9aaed0d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import functools | |
| def common(accepts): | |
| def wrap(f): | |
| f.__doc__ += """ | |
| *token* i take a token | |
| """ | |
| d = {} | |
| exec(""" | |
| def __(self, token=None): | |
| params = {} | |
| if token: | |
| params["token"] = token | |
| else: | |
| params["token"] = self.agent | |
| f(self, params) | |
| """, {'f': f}, d) | |
| functools.update_wrapper(d['__'], f) | |
| return d['__'] | |
| return wrap | |
| class C(object): | |
| agent = "agent default" | |
| @common(["token"]) | |
| def bar(self, params): | |
| """ | |
| My docstring! | |
| """ | |
| print params | |
| c = C() | |
| print c.bar | |
| print c.bar.__doc__ | |
| c.bar() | |
| c.bar(token="hi") |
Author
cablehead
commented
Jul 6, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment