Skip to content

tuple_the_args: passing the tupled *args by keyword fails, and ch_func_to_all_pk can't handle a required keyword-only after *args #93

Description

@thorwhalen

Found while fixing #12 (PR #92). Neither is fixed there, because both need a design call.

1. tuple_the_args rejects its own signature. The wrapper advertises the tupled *args as a positional-or-keyword param, but giving it by keyword fails:

from i2.signatures import tuple_the_args, Sig

def foo(*pos, **kws):
    return pos, kws

f = tuple_the_args(foo)
Sig(f)               # <Sig (pos=(), **kws)>
f((1, 2), a=3)       # works
f(pos=(1, 2), a=3)   # FuncCallNotMatchingSignature: There should be only keyword arguments after the Variadic args

The cause is in ch_variadics_to_non_variadic_kind's inner function. It rebuilds positional args with mk_args_and_kwargs on the original signature, which unpacks the tuple, then indexes args[idx_of_vp] expecting the tuple. A fix has to fill any skipped defaults before *args, e.g. def g(a, b=1, *args) called as tupled(1, args=(2, 3)) must become g(1, 1, 2, 3). PR #92 adds a helper for exactly that (_args_and_kwargs_from_all_pk_arguments in signatures.py), which could be reused here.

2. ch_func_to_all_pk fails at decoration time for a required keyword-only param after *args:

from i2.signatures import ch_func_to_all_pk

def h(x, *y, z):
    ...

ch_func_to_all_pk(h)  # ValueError: non-default argument follows default argument

The all-PK signature would be (x, y=(), z), which isn't valid. The options are to drop y's default (making it required), to reorder, or to keep z keyword-only. Each changes what callers see, so this needs your decision.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions