Created
September 14, 2016 15:57
-
-
Save squeaky-pl/eccd621018283e057a1c5567c38fdc72 to your computer and use it in GitHub Desktop.
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
registry = { | |
'db': 'my database', | |
'redis': 'my redis', | |
'settings': 'my settings' | |
} | |
def inject(func): | |
def wrapper(*args, **kwargs): | |
injected = {k: registry[dep] for k, dep in func.__annotations__.items()} | |
bound = partial(func, **injected) | |
return bound(*args, **kwargs) | |
return wrapper | |
@inject | |
def my_func(value, fancy_db: 'db', useless_redis: 'redis'): | |
print(fancy_db, useless_redis, value) | |
my_func(5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment