-
-
Notifications
You must be signed in to change notification settings - Fork 424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Alternative to @v_args() #1468
Comments
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
For
For
|
Thanks for the write-up, it sounds like you gave it some thought. The idea of v_args is as a primitive to allow creating a decorator that suites you. For example, you could write: You could also create a decorator with So, I think that the fact that it can apply in different contexts is actually an advantage. Sorry to say, but I didn't find your proposal convincing. You mention easier support, but we'll still have to support Also, the following change:
Would be backwards incompatible, and might break someone's code in a very confusing way. Keep in mind inline children usually don't use *args, but actually name the children, since the arguments are known from the grammar. Maybe the API you propose would have been an improvement, if done this way from the start. But I think transitioning to it now would create a lot of confusion, and with very little benefit. |
@erezsh appreciate your explanation! Well, I think this syntactic sugar is not SO important even if safe to implement, and this feature request can be closed :) |
Thanks for the suggestion anyway! |
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.
The text was updated successfully, but these errors were encountered: