Overview
Function decorator to make argument passing saner.
I often have to write a function which runs a simulation/learning task which I need to run for several different parameters. This initially is manageable, but then slowly configuration creep starts to happen: I keep adding more and more parameters to the functions which run the simulations and keep making my old code more and more fragile.
I wrote decorated_options to decouple the arguments for different set of experiments.
In brief, decorated_options converts this:
def run(max_num_followers, num_segments, is_hawkes):
# ...
# ...
# tmp = run_multiple_followers(max_num_followers=10, num_segments=10, is_hawkes=True)
# tmp = run_multiple_followers(max_num_followers=100, num_segments=10, is_hawkes=False)
# tmp = run_multiple_followers(max_num_followers=10, num_segments=50, is_hawkes=True)
tmp = run_multiple_followers(max_num_followers=1000, num_segments=100, is_hawkes=False)
to:
from decorated_options import Options, optioned
@optioned('opts')
def run(max_num_followers, num_segments, is_hawkes):
# ...
# ...
opts = Options(max_num_followers=10, num_segments=10, is_hawkes=True)
# tmp = run_multiple_followers(opts=opts)
# tmp = run_multiple_followers(max_num_followers=100, is_hawkes=False, opts=opts)
# tmp = run_multiple_followers(num_segments=50, is_hawkes=False, opts=opts)
tmp = run_multiple_followers(max_num_followers=1000, num_segments=100, is_hawkes=False)
Benefits over **kwargs in receiving function:
Early reporting of errors at call-time.
No need to unpack the values.
Default values do not have to be hard-coded.
Allows progressive improvement, no need to change old code which uses positional arguments.
Benefits over **dict while calling:
Easier updating/overriding of values
Positional arguments also work
Guaranteed immutability (throws Exceptions on attempted violations.)
Benefits over default values in receiving function:
Options objects can save defaults for multiple settings.
De-couples default values from the functions themselves.
Installation
pip install git+https://github.com/musically-ut/decorated_options.git@master#egg=decorated_options
Development
To run the all tests run:
tox
Note, to combine the coverage data from all the tox environments run:
Windows |
set PYTEST_ADDOPTS=--cov-append tox |
|---|---|
Other |
PYTEST_ADDOPTS=--cov-append tox |
Changelog
0.1.0 (2016-07-24)
First release on PyPI.
Metadata
Release files for decorated_options 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| decorated_options-0.1.0.tar.gz | 11.5 kB | Without provenance | Details |
Release files / decorated_options-0.1.0.tar.gz
| Download URL | decorated_options-0.1.0.tar.gz |
|---|---|
| Size | 11.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d85586ac70e6e3f6aa82c2c89fcbd794595d3d88cd6acdaebedc29498d1b1d22
|
|
BLAKE2b-256 checksum How to use checksums |
ca3ab0be237ef9980bde57d1bc26050c746a56ed434375a76d45954c59e6c133
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for decorated_options 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.