Browse Source

Fixed partials (Issue #398)

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.7.4
Erez Shinan 5 years ago
committed by Erez Sh
parent
commit
def1d2931c
2 changed files with 6 additions and 6 deletions
  1. +1
    -1
      lark/utils.py
  2. +5
    -5
      tests/test_trees.py

+ 1
- 1
lark/utils.py 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)


+ 5
- 5
tests/test_trees.py 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):


Loading…
Cancel
Save