Enforce keyword order.

pull/15/head
Jussi Pakkanen 12 years ago
parent ed53c4f5ac
commit ab85e72410
  1. 2
      bparser.py
  2. 2
      interpreter.py
  3. 3
      nodes.py

@ -174,7 +174,7 @@ def p_args_multiple(t):
def p_kwargs_multiple(t): def p_kwargs_multiple(t):
'args : expression COLON statement COMMA args' 'args : expression COLON statement COMMA args'
args = t[5] args = t[5]
args.add_kwarg(t[1], t[3]) args.set_kwarg(t[1], t[3])
t[0] = args t[0] = args
def p_args_single_pos(t): def p_args_single_pos(t):

@ -616,6 +616,8 @@ class Interpreter():
def reduce_arguments(self, args): def reduce_arguments(self, args):
assert(isinstance(args, nodes.Arguments)) assert(isinstance(args, nodes.Arguments))
if args.incorrect_order():
raise InvalidArguments('Line %d: all keyword arguments must be after positional arguments.' % args.lineno())
reduced_pos = [self.reduce_single(arg) for arg in args.arguments] reduced_pos = [self.reduce_single(arg) for arg in args.arguments]
reduced_kw = {} reduced_kw = {}
for key in args.kwargs.keys(): for key in args.kwargs.keys():

@ -187,6 +187,9 @@ class Arguments(Statement):
def num_kwargs(self): def num_kwargs(self):
return len(self.kwargs) return len(self.kwargs)
def incorrect_order(self):
return self.order_error
def __len__(self): def __len__(self):
return self.num_args() # Fixme return self.num_args() # Fixme

Loading…
Cancel
Save