Deedee is a dependency inversion library
Project description
Dependency inversion for python, the easy way
Nutshell
Deedee provides an API which enables the developer to use late binding for default values in function definition.
Example:
import deedee
class Database:
def select(self, query):
print("select", query)
@deedee.resolve
def handler(param_a, param_b, database=deedee.context.database):
print(param_a, param_b) # param_a and param_b are unchanged
print(database) # this will print a database instance
database.select("select * from table order by id") # this call will be successful
def main():
# register the default value (which will be used when calling handler)
deedee.context.register("database", Database())
# call the handler, the 3rd parameter will be the previously registered value
handler("param_1", "param_2")
if __name__ == '__main__':
main()
In python the binding of the default value happens at the function defintion, so it is not possible to set the default parameter later on, the expression after the ‘=’ sign gets evaluated at the function definition.
With deedee this changes, so you can specify a reference instead, and later on, specify the value for that reference.
When the function is called later on, the decorator deedee.resolve will resolve the reference of the default value.
This can be used to implement dependency injection and dependency inversion patterns without using any boilerplate classes or functions.
Features
Lazy evaluation of the default parameters
Default value can be overriden by specifying it during the call (same behaviour as ‘normal’ default values)
It can be traced which function references to a given default parameter (soon)
It can be checked that all references can be resolved in the future, so it can be ensured that there will be no error with resolving during function calls
Context objects can be implemented by the user (it is not required to use deedee.context)
Annotations can be use freely, the library doesn’t use or change them
Nearly straightforward implementation, good test coverage
Name
According to urban dictionary, deedee is:
A person who is always there when you need them. A strong survivor who can make it through anything.
In deedee the values you are registering to a context behave like this – they are always there when you need them.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file deedee-0.1.tar.gz
.
File metadata
- Download URL: deedee-0.1.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25f1acaa45160402c0c8fcb45f1d88ae1a85526500ae997ba2eb5b24714a934b |
|
MD5 | 0ec8e3735ad3ca0de0366e3b0b218680 |
|
BLAKE2b-256 | c571be324239e2347f679a6686cbf0f45018ccb46f68b3eb7e7386255dc2de35 |
File details
Details for the file deedee-0.1-py3-none-any.whl
.
File metadata
- Download URL: deedee-0.1-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ded2b86b85623efecbac66ea3caa621349afc4305b0ca076e3d9144d92a8a33 |
|
MD5 | 8001e671b534c4fdaa23d1c3de78eea2 |
|
BLAKE2b-256 | 0b768b9b9ff9d814251c26ab8bf76e8bca224c510a7aa8c13ab70d2c70c7aec3 |