pytoolz/toolz

flip bug with > 2 parameters

efagerberg opened this issue · 1 comments

from toolz.functoolz import flip

def foo(x, y):
    return x - y

flip(foo, 5, 2)
# -3, works fine

def foo(x, y, z):
    return x - y + z

flip(foo, 5, 4, 3)
# expected 2
    301     def __call__(self, *args, **kwargs):
    302         try:
--> 303             return self._partial(*args, **kwargs)
    304         except TypeError as exc:
    305             if self._should_curry(args, kwargs, exc):

TypeError: flip() takes 3 positional arguments but 4 were given

flip(foo, 5, 4)
# expect a function that takes x as a parameter
    301     def __call__(self, *args, **kwargs):
    302         try:
--> 303             return self._partial(*args, **kwargs)
    304         except TypeError as exc:
    305             if self._should_curry(args, kwargs, exc):

    728     [1, 2, 3]
    729     """
--> 730     return func(b, a)
    731 
    732 

TypeError: foo() missing 1 required positional argument: 'z'

Never-mind, I realize this is intended, the flip function does not take arbitrary amounts of args. And doing so might make the example of supplying the first and third params harder.