Skip to content

Instantly share code, notes, and snippets.

@lmassaron
Created May 15, 2023 06:31
Show Gist options
  • Select an option

  • Save lmassaron/dac9f87bc190fd322233382f13daecda to your computer and use it in GitHub Desktop.

Select an option

Save lmassaron/dac9f87bc190fd322233382f13daecda to your computer and use it in GitHub Desktop.
An example about how to build a decorator
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