##// END OF EJS Templates
parser: preserve order of keyword arguments...
Yuya Nishihara -
r31922:0f41f1e3 default
parent child Browse files
Show More
@@ -154,7 +154,7 def buildargsdict(trees, funcname, argsp
154 154 "arguments")
155 155 % {'func': funcname,
156 156 'nargs': len(poskeys) + len(keys)})
157 args = {}
157 args = util.sortdict()
158 158 # consume positional arguments
159 159 for k, x in zip(poskeys, trees[:kwstart]):
160 160 args[k] = x
@@ -165,7 +165,7 def buildargsdict(trees, funcname, argsp
165 165 args[k] = x
166 166 # remainder should be keyword arguments
167 167 if optkey:
168 args[optkey] = {}
168 args[optkey] = util.sortdict()
169 169 for x in trees[kwstart:]:
170 170 if x[0] != keyvaluenode or x[1][0] != keynode:
171 171 raise error.ParseError(_("%(func)s got an invalid argument")
@@ -474,14 +474,14 def _buildfuncargs(exp, context, curmeth
474 474 ... x = _parseexpr(expr)
475 475 ... n = getsymbol(x[1])
476 476 ... return _buildfuncargs(x[2], context, exprmethods, n, argspec)
477 >>> sorted(fargs('a(l=1, k=2)', 'k l m').keys())
478 ['k', 'l']
477 >>> fargs('a(l=1, k=2)', 'k l m').keys()
478 ['l', 'k']
479 479 >>> args = fargs('a(opts=1, k=2)', '**opts')
480 >>> args.keys(), sorted(args['opts'].keys())
481 (['opts'], ['k', 'opts'])
480 >>> args.keys(), args['opts'].keys()
481 (['opts'], ['opts', 'k'])
482 482 """
483 483 def compiledict(xs):
484 return dict((k, compileexp(x, context, curmethods))
484 return util.sortdict((k, compileexp(x, context, curmethods))
485 485 for k, x in xs.iteritems())
486 486 def compilelist(xs):
487 487 return [compileexp(x, context, curmethods) for x in xs]
@@ -494,7 +494,7 def _buildfuncargs(exp, context, curmeth
494 494 _poskeys, varkey, _keys, optkey = argspec = parser.splitargspec(argspec)
495 495 treeargs = parser.buildargsdict(getlist(exp), funcname, argspec,
496 496 keyvaluenode='keyvalue', keynode='symbol')
497 compargs = {}
497 compargs = util.sortdict()
498 498 if varkey:
499 499 compargs[varkey] = compilelist(treeargs.pop(varkey))
500 500 if optkey:
General Comments 0
You need to be logged in to leave comments. Login now