Created
May 15, 2023 06:31
-
-
Save lmassaron/dac9f87bc190fd322233382f13daecda to your computer and use it in GitHub Desktop.
An example about how to build a decorator
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 decorator(func_to_decorate): | |
| """ | |
| @wraps | |
| (func) updates .__name__ and .__doc__ so that code completion | |
| works in editors and you can pull up documentation. | |
| """ | |
| @functools.wraps(func_to_decorate) | |
| def wrapper(*args, **kwargs): | |
| # Do something | |
| result = func_to_decorate(*args, **kwargs) | |
| # Do something | |
| return result | |
| return wrapper |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment