i2mint / i2

Python Mint creation, manipulation, and use
Apache License 2.0
1 stars 1 forks source link

Careful reordering when adding keyword-only params to a list that already has a variadic keyword. #17

Open thorwhalen opened 2 years ago

thorwhalen commented 2 years ago

To reproduce:

from i2 import partialx

@partialx(partialx, x=2, _allow_reordering=True)
def foo(x, y, z=0):
    return x + y * z

leads to:

ValueError: wrong parameter order: variadic keyword parameter before keyword-only parameter

We don't get the problem if we use functools.partial on the external partial:

import functools

@functools.partial(partialx, x=2, _allow_reordering=True)
...

The problem is that we find ourselves in this situation:

[<Parameter "func">, <Parameter "*args">, <Parameter "**kwargs">, <Parameter "__name__=None">, <Parameter "_rm_partialize=False">, <Parameter "_allow_reordering=False">]

Hypothesis: Somewhere in the process, the parameters should probably be loosely reordered. We don't want to allow complete reordering, but just enough to allow variadics to be in their proper place (the keyword arguments before the kwargs.

┆Issue is synchronized with this Asana task by Unito