Skip to content

ch_func_to_all_pk: unify the excess-keyword policy of the with-*args and without-*args paths #95

Description

@thorwhalen

Found while landing #92 and #93 (adversarial review of the fix-variadics-all-pk branch). Pre-existing, not introduced by either.

ch_func_to_all_pk has two policies for excess keyword arguments, depending on whether the function has *args:

from i2.signatures import ch_func_to_all_pk, tuple_the_args

def f4(a, b=2, **kwargs): return a, b, kwargs
def g(a, *args, **kwargs): return a, args, kwargs

ch_func_to_all_pk(f4)(1, x=3, q=4)              # (1, 2, {})                      extras DROPPED, though f4 has **kwargs
ch_func_to_all_pk(f4)(1, kwargs={'x': 3}, q=4)  # (1, 2, {'x': 3})                q dropped
ch_func_to_all_pk(g)(1, (2,), x=3, q=4)         # (1, (2,), {'x': 3, 'q': 4})     extras FORWARDED
tuple_the_args(g)(1, (2,), x=3, q=4)            # (1, (2,), {'x': 3, 'q': 4})     forwarded
ch_func_to_all_pk(f4)(1, 2, 3)                  # TypeError: dict() argument after ** must be a mapping, not int

The no-*args path keeps the 0.1.74 behaviour because meshed's hook_up calls it with a whole scope dict and relies on extras being dropped (#92 pinned that in a test). The *args path (#92) forwards extras. The last line is a sharp edge of the no-*args path: a third positional lands on the kwargs slot.

Both policies live inside ch_func_to_all_pk's wrapper, and the advertised signature would not change, so unifying them is a one-function edit that does not touch meshed / py2http / FlexFuncFanout: route the no-*args path through all_pk_sig.map_arguments(allow_excess=True) + _args_and_kwargs_from_all_pk_arguments against func_sig too, and pick one rule for extras (drop them, or forward them when the function has **kwargs). The decision is which rule; meshed's reliance on "drop" is the constraint.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions