Open makukha opened 2 months ago
Use explicitly named decorators: @wrap_every (class level only), @inline_children (method level only)
Can you explain your rationale?
Use explicitly named decorators: @wrap_every (class level only), @inline_children (method level only)
Can you explain your rationale?
First of all, let me say that Lark is an awesome project and already saved me days of life. I appreciate hard work, dedication and talent of Lark's maintainers. I don't understand much in parsers and lexers, but want to dedicate some of my time to the field where I touch Lark the most as a developer: its API.
The main reasons for change proposed are
For v_args(meta=, tree=)
:
For v_args(wrapper=)
:
For v_args(inline)
:
inline_children
seems better to me. Also this will be more readable when used as a standalone decorator on methods.@inline_children
is more readable that @wraps_every(inline_children)
, if your question was about this case.
Suggestion
@wrap_every
(class level only),@inline_children
(method level only)Transformer
decide which arguments to pass based on method signature:children
regardless of its name (this will preserve backwards compatibility)meta
,tree
,children
} — pass respective values.v_args
is left unchanged for backwards compatibility.This may make API more explicit and sound. The second approach is used in e.g. Pydantic (see validators in v.1).
I'm not aware of all possible use cases for
v_args
, but at least some of them are covered.Describe alternatives you've considered
@v_args
is the only alternative.Additional context Usage examples:
Class level only
@wrap_every
Method level only
@inline_children
Method signature auto detection
If this change sounds reasonable, I'm ready to work on PR.