Skip to content

Instantly share code, notes, and snippets.

@bcattle
Created July 25, 2023 21:44
Show Gist options
  • Save bcattle/436a107e1abc821a76cf2a002dfa61ef to your computer and use it in GitHub Desktop.
Save bcattle/436a107e1abc821a76cf2a002dfa61ef to your computer and use it in GitHub Desktop.
Minimal working decorator example in the style of `flask.App.route()`
import functools
import numpy as np
class DataServiceManager:
def __init__(self) -> None:
pass
def service(self, **options):
print('service() called')
def decorator(func):
print('decorator() called')
@functools.wraps(func)
def wrapper():
print("Something is happening before the function is called.")
result = func()
print("Something is happening after the function is called.")
return result
return wrapper
return decorator
svcmgr = DataServiceManager()
@svcmgr.service()
def getData() -> np.ndarray:
""" Pointer to data """
print('get_data() called')
pass
getData()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment