Skip to main content

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_lambda acts 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 ValueError is 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 or lambda: lambda: ....

How it works

  • extract_deps inspects 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. f in lambda: 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

lazy_args_resolve-0.1.0.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lazy_args_resolve-0.1.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

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

Hashes for lazy_args_resolve-0.1.0.tar.gz
Algorithm Hash digest
SHA256 49c03d3ae9c21cddc8bc8b23c8eacb7a0b860b7a7c223e0b971fbe968dea3b15
MD5 3ef554b601c72c3b91ab8c977b206d6e
BLAKE2b-256 e8ee98aeffce3cf1423cbb988d0d88480e686c802448664b9a31b16fead4ca6c

See more details on using hashes here.

Provenance

The following attestation bundles were made for lazy_args_resolve-0.1.0.tar.gz:

Publisher: publish.yml on Hocnonsense/lazy-args-resolve

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lazy_args_resolve-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for lazy_args_resolve-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8609c120af3c203a05eb2fb31255a73cb97a4d3e90876dd8586410d204196853
MD5 22af0504a628e43da3bb854da03c91d2
BLAKE2b-256 7a05d4b38fc9b7dbaf2cbb4abf259e048dc7838aabd5cca88751d47a6c7c5ac1

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page