Created
July 25, 2023 21:44
-
-
Save bcattle/436a107e1abc821a76cf2a002dfa61ef to your computer and use it in GitHub Desktop.
Minimal working decorator example in the style of `flask.App.route()`
This file contains 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 | |
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