mirror of https://github.com/lark-parser/lark.git
Fixed partials (Issue #398)
This commit is contained in:
parent
59f3a5707b
commit
def1d2931c
|
@ -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)
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue