diff --git a/AUTHORS.md b/AUTHORS.md index efaced62..7ea041f5 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -19,3 +19,5 @@ José Ricardo [@josericardo](https://github.c Tom Prince [@tomprince](https://github.com/tomprince) Bart van Merriënboer [@bartvm](https://github.com/bartvm) + +Nikolaos-Digenis Karagiannis [@digenis](https://github.com/digenis/) diff --git a/toolz/functoolz.py b/toolz/functoolz.py index da19d07e..b1509944 100644 --- a/toolz/functoolz.py +++ b/toolz/functoolz.py @@ -152,7 +152,10 @@ class curry(object): toolz.curried - namespace of curried functions http://toolz.readthedocs.org/en/latest/curry.html """ - def __init__(self, func, *args, **kwargs): + def __init__(self, *args, **kwargs): + if not args: + raise TypeError('__init__() takes at least 2 arguments (1 given)') + func, args = args[0], args[1:] if not callable(func): raise TypeError("Input must be callable") diff --git a/toolz/tests/test_functoolz.py b/toolz/tests/test_functoolz.py index 5d42ba8f..66b1bed5 100644 --- a/toolz/tests/test_functoolz.py +++ b/toolz/tests/test_functoolz.py @@ -1,3 +1,6 @@ +import platform + + from toolz.functoolz import (thread_first, thread_last, memoize, curry, compose, pipe, complement, do, juxt) from toolz.functoolz import _num_required_args @@ -161,6 +164,7 @@ def test_curry_simple(): cmap = curry(map) assert list(cmap(inc)([1, 2, 3])) == [2, 3, 4] + assert raises(TypeError, lambda: curry()) assert raises(TypeError, lambda: curry({1: 2})) @@ -186,6 +190,16 @@ def g(a=1, b=10, c=0): assert cg(0) == 2 # pass "a" as arg, not kwarg assert raises(TypeError, lambda: cg(1, 2)) # pass "b" as arg AND kwarg + def h(x, func=int): + return func(x) + + if platform.python_implementation() != 'PyPy'\ + or platform.python_version_tuple()[0] != '3': # Bug on PyPy3<2.5 + # __init__ must not pick func as positional arg + assert curry(h)(0.0) == 0 + assert curry(h)(func=str)(0.0) == '0.0' + assert curry(h, func=str)(0.0) == '0.0' + def test_curry_passes_errors(): @curry