Fixed partials (Issue #398)

This commit is contained in:
Erez Shinan 2019-08-20 11:34:48 +02:00 committed by Erez Sh
parent 59f3a5707b
commit def1d2931c
2 changed files with 6 additions and 6 deletions

View File

@ -160,7 +160,7 @@ def smart_decorator(f, create_decorator):
elif isinstance(f, partial):
# wraps does not work for partials in 2.7: https://bugs.python.org/issue3445
return wraps(f.func)(create_decorator(f.func, True))
return wraps(f.func)(create_decorator(lambda *args, **kw: f(*args[1:], **kw), True))
else:
return create_decorator(f.__func__.__call__, True)

View File

@ -151,16 +151,16 @@ class TestTrees(TestCase):
tree = Tree("start", [Tree("a", ["test1"]), Tree("b", ["test2"])])
def test(t, s):
return s.upper()
def test(prefix, s, postfix):
return prefix + s.upper() + postfix
@v_args(inline=True)
class T(Transformer):
a = functools.partial(test)
b = functools.partial(lambda t, s: s + "!")
a = functools.partial(test, "@", postfix="!")
b = functools.partial(lambda s: s + "!")
res = T().transform(tree)
assert res.children == ["TEST1", "test2!"]
assert res.children == ["@TEST1!", "test2!"]
def test_discard(self):