Browse Source

Merge pull request #557 from MegaIng/staticmethod-inline

Added fix for v_args
tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.8.6
Erez Shinan 4 years ago
committed by GitHub
parent
commit
445c8d43ef
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions
  1. +2
    -2
      lark/visitors.py
  2. +9
    -0
      tests/test_trees.py

+ 2
- 2
lark/visitors.py View File

@@ -24,11 +24,11 @@ class _Decoratable:
# Make sure the function isn't inherited (unless it's overwritten)
if name.startswith('_') or (name in libmembers and name not in cls.__dict__):
continue
if not callable(cls.__dict__[name]):
if not callable(value):
continue

# Skip if v_args already applied (at the function level)
if hasattr(cls.__dict__[name], 'vargs_applied'):
if hasattr(cls.__dict__[name], 'vargs_applied') or hasattr(value, 'vargs_applied'):
continue

static = isinstance(cls.__dict__[name], (staticmethod, classmethod))


+ 9
- 0
tests/test_trees.py View File

@@ -166,6 +166,15 @@ class TestTrees(TestCase):
x = MyTransformer().transform( Tree('hello', [2]))
self.assertEqual(x, 'hello')

def test_inline_static(self):
@v_args(inline=True)
class T(Transformer):
@staticmethod
def test(a, b):
return a + b
x = T().transform(Tree('test', ['a', 'b']))
self.assertEqual(x, 'ab')

def test_vargs_override(self):
t = Tree('add', [Tree('sub', [Tree('i', ['3']), Tree('f', ['1.1'])]), Tree('i', ['1'])])



Loading…
Cancel
Save