Applies a set of values to a function's optional parameters, if nothing was
passed to them.
In a typical function, the passed value takes precedence, and if no value is
passed it takes the default value specified in the parameter list is used.
This adds another layer between those two. So the precedence becomes:
1. Passed values, otherwise
2. The values specified by the decorator, otherwise
3. The default value.
The values can come from the bound object, or a configuration file.
`apply_self` applies attributes from the bound object ("self"):
```python
from apply_defaults import apply_self
class MyObject:
def __init__(self):
self.foo = "foo"
@apply_self
def method(self, foo=None):
return foo
>>> # If 'foo' is not passed, the param is assigned the value of self.foo.
>>> MyObject().method()
'foo'
>>> # Overriding @apply_self by specifying a value for 'foo'.
>>> MyObject().method(foo="bar")
'bar'
```
`apply_config` applies the options from a ConfigParser:
```python
from apply_defaults import apply_config
from configparser import ConfigParser
config = ConfigParser()
@apply_config(config)
def my_func(foo=None)
return foo
>>> # There is no configuration yet, so my_func returns the optional
>>> # parameter's default value.
>>> my_func()
None
>>> config.read_dict({"general": {"foo": "foo"}})
>>> # If 'foo' is not passed, the param is assigned the value of 'foo' in the
>>> # configuration.
>>> my_func()
'foo'
>>> # Override @apply_config by specifying a value for 'foo'.
>>> my_func(foo="bar")
'bar'
```
Metadata
Release files for apply-defaults 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 | |
|---|---|---|---|---|
| apply_defaults-0.1.0.tar.gz | 2.0 kB | Without provenance | Details |
Release files / apply_defaults-0.1.0.tar.gz
| Download URL | apply_defaults-0.1.0.tar.gz |
|---|---|
| Size | 2.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8325354bc10cbd5c570cd5112b1f887dd2f267bc2605b15adc2b16a2cef8f134
|
|
BLAKE2b-256 checksum How to use checksums |
8ee59dca6b7c4a63f18b2e0d5f8b0c6a016c0625a0ee0c0a929ab23e5ddeae76
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/28.8.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.5.2
|
Security for apply-defaults 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.