Skip to content

Commit

Permalink
Merge pull request #217 from Digenis/master
Browse files Browse the repository at this point in the history
Remove positional arg "func" from curry.__init__
  • Loading branch information
eriknw committed Apr 22, 2015
2 parents e2f10e6 + 0fea472 commit 13f0c63
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
5 changes: 4 additions & 1 deletion toolz/functoolz.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
14 changes: 14 additions & 0 deletions toolz/tests/test_functoolz.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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}))


Expand All @@ -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
Expand Down

0 comments on commit 13f0c63

Please sign in to comment.