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