Skip to content

Commit

Permalink
Merge pull request #286 from ssanderson/set-__wrapped__-in-decorators
Browse files Browse the repository at this point in the history
ENH: Set __wrapped__ attribute on curry and memoize.
  • Loading branch information
mrocklin committed Dec 15, 2015
2 parents bf0f253 + d4ee0a5 commit 9262dd3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 2 additions & 0 deletions toolz/functoolz.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ def __init__(self, *args, **kwargs):
@property
def func(self):
return self._partial.func
__wrapped__ = func

@property
def args(self):
Expand Down Expand Up @@ -359,6 +360,7 @@ def memof(*args, **kwargs):
except AttributeError:
pass
memof.__doc__ = func.__doc__
memof.__wrapped__ = func
return memof


Expand Down
23 changes: 22 additions & 1 deletion toolz/tests/test_functoolz.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import platform


from toolz.functoolz import (thread_first, thread_last, memoize, curry,
compose, pipe, complement, do, juxt, flip)
from toolz.functoolz import _num_required_args
Expand Down Expand Up @@ -153,6 +152,17 @@ def f(x, y, *args, **kwargs):
assert f(1, 3) == 3


def test_memoize_wrapped():

def foo():
"""
Docstring
"""
pass
memoized_foo = memoize(foo)
assert memoized_foo.__wrapped__ is foo


def test_curry_simple():
cmul = curry(mul)
double = cmul(2)
Expand Down Expand Up @@ -413,6 +423,17 @@ def __hash__(self):
assert A.addstatic(3, 4) == 7


def test_curry_wrapped():

def foo(a):
"""
Docstring
"""
pass
curried_foo = curry(foo)
assert curried_foo.__wrapped__ is foo


def test__num_required_args():
assert _num_required_args(map) != 0
assert _num_required_args(lambda x: x) == 1
Expand Down

0 comments on commit 9262dd3

Please sign in to comment.