Skip to content

Values support in call, callwith #86

Closed

Description

@Technologicat

For completeness, the call and callwith functions should support the Values abstraction, for unpacking multiple and/or named return values into function arguments. The function composition utilities already support this.

Instead of *a and **kw, if given exactly one positional argument x, and type(x) is Values, then unpack it, thus populating *a and **kw.

Activity

  1. added
    enhancement
    on Sep 20, 2023
  2. added this to the 2.2.0 milestone on Apr 24, 2026
  3. Technologicat commented on May 4, 2026

    @Technologicat
    OwnerAuthor

    Implemented in 2.2.0.

    —Technologicat

  4. Technologicat commented on May 4, 2026

    @Technologicat
    OwnerAuthor

    Implemented in 5bcf3d4, generalized in dfe73ee, for 2.2.0.

    call and callwith now unpack Values in their positional arguments. Each Values expands in place, left-to-right: its rets splice into the positional arguments, its kwrets merge into the keyword arguments. Across multiple Values and the explicit kwargs, rightmost wins per unique keyword name (explicit kwargs are syntactically last, so they always override).

    Mirrors Python's familiar spread/merge semantics — [*a, *b, c] for the positional side, {**a, **b} for the keyword side. The use case is taking a Values produced by one function and applying it as the arguments to another — including spread-and-override patterns where a Values carries defaults and explicit kwargs override individual keys.

    Trigger uses isinstance (not strict type is), matching the existing Values-output handling in unpythonic.fun's composition utilities (fun.py:908). The type is tuple check in valuify is qualitatively different: there it's recognising the pythonic tuple-as-multiple-return-values idiom, where exactness matters.

    The first iteration (5bcf3d4) was a leading-position-only unpack with trailing-args override, justified using a curry-passthrough scenario. On closer inspection (fun.py:361–437), curry has its own dedicated Values-merging logic with a callable-leftmost promotion that doesn't generalize, so the curry argument didn't actually motivate any special-casing in call/callwith. The follow-up (dfe73ee) drops the asymmetry and treats this as plain spread.

    Implementation factored into a private _maybe_unpack_values(args, kwargs) helper, shared by call and callwith. For callwith, the unpack runs at definition time (when args/kwargs are frozen), so the inner closure captures the already-expanded values.

    Logged under Changed in CHANGELOG; tests in unpythonic/tests/test_funutil.py.

    — Claude (Opus 4.7)

  5. added a commit that references this issue on May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions