lazy-args-resolve
Lazy argument evaluation for Python: the @resolve_lambda decorator defers evaluation of zero-argument lambda defaults until call time, resolving them automatically by their dependency relationships.
from lazy_args import resolve_lambda
@resolve_lambda
def f(a=lambda: b + 1, b=lambda: a * 2):
return a() + b()
f(10) # 30 -> b depends on a, a=10 resolved
f(b=1) # 3 -> a depends on b, b=1 resolved
Feature
resolve_lambdaacts as a decorator: it recognizes zero-argument lambdas in parameter defaults or passed as arguments, and resolves them iteratively by dependency ordering.- If resolution fails, e.g. on circular dependencies, a
ValueErroris raised. - Inside the function body, parameters whose defaults are zero-argument lambdas remain callable (
a()), preserving the original lambda semantics. To keep a lambda from being resolved, use a named function orlambda: lambda: ....
How it works
extract_depsinspects the bytecode (dis) of a lambda to collect its references to the enclosing scope as a dependency set.- Dependency extraction relies on bytecode instructions (
LOAD_GLOBAL/LOAD_DEREF/LOAD_NAME); indirect references inside the lambda body (e.g.finlambda: f(x)) are also collected and may be misidentified as dependencies if they collide with parameter names.
Testing
pixi run test # pytest, includes --doctest-modules automatically
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lazy_args_resolve-0.1.0.tar.gz.
File metadata
- Download URL: lazy_args_resolve-0.1.0.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
49c03d3ae9c21cddc8bc8b23c8eacb7a0b860b7a7c223e0b971fbe968dea3b15
|
|
| MD5 |
3ef554b601c72c3b91ab8c977b206d6e
|
|
| BLAKE2b-256 |
e8ee98aeffce3cf1423cbb988d0d88480e686c802448664b9a31b16fead4ca6c
|
Provenance
The following attestation bundles were made for lazy_args_resolve-0.1.0.tar.gz:
Publisher:
publish.yml on Hocnonsense/lazy-args-resolve
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lazy_args_resolve-0.1.0.tar.gz -
Subject digest:
49c03d3ae9c21cddc8bc8b23c8eacb7a0b860b7a7c223e0b971fbe968dea3b15 - Sigstore transparency entry: 2569528773
- Sigstore integration time:
-
Permalink:
Hocnonsense/lazy-args-resolve@60ebd8f69e89f392d823bfaf5fa7cc1a59ee9cf1 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Hocnonsense
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@60ebd8f69e89f392d823bfaf5fa7cc1a59ee9cf1 -
Trigger Event:
push
-
Statement type:
File details
Details for the file lazy_args_resolve-0.1.0-py3-none-any.whl.
File metadata
- Download URL: lazy_args_resolve-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8609c120af3c203a05eb2fb31255a73cb97a4d3e90876dd8586410d204196853
|
|
| MD5 |
22af0504a628e43da3bb854da03c91d2
|
|
| BLAKE2b-256 |
7a05d4b38fc9b7dbaf2cbb4abf259e048dc7838aabd5cca88751d47a6c7c5ac1
|
Provenance
The following attestation bundles were made for lazy_args_resolve-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on Hocnonsense/lazy-args-resolve
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lazy_args_resolve-0.1.0-py3-none-any.whl -
Subject digest:
8609c120af3c203a05eb2fb31255a73cb97a4d3e90876dd8586410d204196853 - Sigstore transparency entry: 2569528795
- Sigstore integration time:
-
Permalink:
Hocnonsense/lazy-args-resolve@60ebd8f69e89f392d823bfaf5fa7cc1a59ee9cf1 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Hocnonsense
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@60ebd8f69e89f392d823bfaf5fa7cc1a59ee9cf1 -
Trigger Event:
push
-
Statement type: