-
Notifications
You must be signed in to change notification settings - Fork 231
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
Improve Documentation - To Convert Existing Decorators and Class Based Decorators #237
Comments
Here are a whole bunch of ways one can use a class object to hold state for the decorator. Should give you a few ideas. Key thing is ensuring that introspection still works. You cannot use the same structure as your method 2 uses if you want introspection to yield the correct results. As is, the prototype of
Not that you must use |
It would be profoundly helpful to provide a walkthrough, demonstrating how to convert common existing decorator patterns, to use the wrapt package.
Take a simple case, of a decorator that measures the execution time of the function it wraps, which may be implemented as either a function or class decorator. For brevity, I reuse the functional decorator to reduce duplicated code. See the following three typical patterns:
and each of these decorators may be used as follows...
From the current documentation, it shows us how to create decorators in the first case "Method 1" - Function as a decorator, as follows:
however, It isn't entirely clear, how we convert classes as Decorators? From the documentation, we have the following, which is another function:
In these simple cases, we could easily convert our class based method decorators, into functions as shown above, but in more complicated examples (where we need to manage more states of the class), this may not be so easy. Is there a way to create class based wrappers using wrapt?
The text was updated successfully, but these errors were encountered: