Hi all,

I’m putting together a minor DSL whereby it’d be preferable to pass args
*after* kwargs, like so.

my_function(name="Marcus", True)

This is normally a syntax error in Python..

SyntaxError: non-keyword arg after keyword arg

But I’m not looking to actually *run* this, but rather get a dictionary out
of it. Like an “argument signature definition” if you will.

def my_function(*args, **kwargs):
  kwargs["children"] = args
  return kwargs

Cosmetically, it’d looks something like this.

Rig(
  Chain(name="Arm"),
  Chain(name="Leg"),

  name="MyCharacter",
  symmetry=True,
)

But would make somewhat more sense to look at like this.

Rig(
  name="MyCharacter",
  symmetry=True,

  Chain(name="Arm"),
  Chain(name="Leg"),
)

I’ve tried passing it through ast, in the hopes that it’d look past this
superficial syntax error, but alas it does not.

import ast
tree = ast.parse("""\
Rig(
  name="MyCharacter",
  symmetry=True,

  Chain(name="Arm"),
  Chain(name="Leg"),
)
""")
ast.dump(tree)# SyntaxError: non-keyword arg after keyword arg

What I’d rather not do is get into manipulating text “by hand”, such
writing it as the above, and then moving any line that looks like a keyword
argument to the end of what looks like a closure; but if there’s nothing
else that’s where I’m headed.

I’d also not like to assume the exact look of any line, such as asserting
that arguments are on a single line, as I can’t assume what the value of an
argument might be. It may be another object with arguments of its own.

Any ideas?
​

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOD4B-Mu4D%2By97e7RgK8Zfiod3-ZqzTk5QXwnL2q4FHVpg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to