Skip to content
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

OMetaBase.apply should take kwargs, and _GrammarWrapper should pass them along #11

Open
Julian opened this issue Apr 23, 2013 · 10 comments

Comments

@Julian
Copy link
Member

Julian commented Apr 23, 2013

Maybe if I create some tickets it will persuade me to actually send you pull requests.

Right now _GrammarWrapper eats kwargs, so you can't actually get anything to the rules without icky positional args.

@washort
Copy link
Contributor

washort commented Apr 23, 2013

what would the syntax for rules that take keyword args look like?

@Julian
Copy link
Member Author

Julian commented Apr 23, 2013

I don't know! Good question. Maybe this is not such a great idea, and also probably since I don't need it anymore I probably won't think too hard about it, so maybe it should go away. Keyword args are so much cooler than positional args though so maybe this would be a nice thing if it were possible.

@Julian
Copy link
Member Author

Julian commented Apr 23, 2013

ruleName(arg1=foo arg3=bar arg2=baz) is probably the obvious thing

@Julian
Copy link
Member Author

Julian commented Apr 23, 2013

Or I guess ruleName(foo:arg1 bar:arg3) would be somewhat consistenty in a cutesy way.

@washort
Copy link
Contributor

washort commented Apr 23, 2013

if you can figure out how to make it work I would love to see a patch.
(P.S. First see if you can figure out how positional arguments currently work! :)

@versae
Copy link

versae commented Apr 24, 2013

I don't know if related, but I had a rule in which some parameters could be or could not, by using ?

rule = <("this" | "that"):r>? "one":o "two":t
      -> rule_func(**locals())

So rule_func is defined like

def rule_func(r=None, o=None, t=None, **kwargs):
    return {}  # real code goes here

Is this the proper way to go?

@washort
Copy link
Contributor

washort commented Apr 24, 2013

No. locals() will not do what you want here, and should never be used in Python code.

@versae
Copy link

versae commented Apr 24, 2013

I know, but actually it does work. So, what is the right way to manage optional variables?

@washort
Copy link
Contributor

washort commented Apr 24, 2013

well first, the <> brackets are not doing anything in your case since you ignore the value they return and it would be the same as the literal anyway.

I would rewrite the first expression as ("this" | "that")?:r. r will be None if the expression is not matched.

@versae
Copy link

versae commented Apr 24, 2013

I see, thanks for the explanation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants