[pypy-commit] pypy py3k: merge
pjenvey
noreply at buildbot.pypy.org
Tue Mar 13 00:47:20 CET 2012
Author: Philip Jenvey <pjenvey at underboss.org>
Branch: py3k
Changeset: r53395:57571f0b103e
Date: 2012-03-12 16:46 -0700
http://bitbucket.org/pypy/pypy/changeset/57571f0b103e/
Log: merge
diff --git a/pypy/interpreter/astcompiler/ast.py b/pypy/interpreter/astcompiler/ast.py
--- a/pypy/interpreter/astcompiler/ast.py
+++ b/pypy/interpreter/astcompiler/ast.py
@@ -242,16 +242,15 @@
class FunctionDef(stmt):
- def __init__(self, name, args, body, decorator_list, returns, lineno, col_offset):
+ def __init__(self, name, args, body, decorator_list, lineno, col_offset):
self.name = name
self.args = args
self.body = body
self.w_body = None
self.decorator_list = decorator_list
self.w_decorator_list = None
- self.returns = returns
stmt.__init__(self, lineno, col_offset)
- self.initialization_state = 127
+ self.initialization_state = 63
def walkabout(self, visitor):
visitor.visit_FunctionDef(self)
@@ -262,16 +261,13 @@
visitor._mutate_sequence(self.body)
if self.decorator_list:
visitor._mutate_sequence(self.decorator_list)
- if self.returns:
- self.returns = self.returns.mutate_over(visitor)
return visitor.visit_FunctionDef(self)
def sync_app_attrs(self, space):
- if (self.initialization_state & ~64) ^ 63:
- self.missing_field(space, ['lineno', 'col_offset', 'name', 'args', 'body', 'decorator_list', None], 'FunctionDef')
+ if (self.initialization_state & ~0) ^ 63:
+ self.missing_field(space, ['lineno', 'col_offset', 'name', 'args', 'body', 'decorator_list'], 'FunctionDef')
else:
- if not self.initialization_state & 64:
- self.returns = None
+ pass
self.args.sync_app_attrs(space)
w_list = self.w_body
if w_list is not None:
@@ -293,8 +289,6 @@
if self.decorator_list is not None:
for node in self.decorator_list:
node.sync_app_attrs(space)
- if self.returns:
- self.returns.sync_app_attrs(space)
class ClassDef(stmt):
@@ -2306,75 +2300,57 @@
class arguments(AST):
- def __init__(self, args, vararg, varargannotation, kwonlyargs, kwarg, kwargannotation, defaults, kw_defaults):
+ def __init__(self, args, vararg, kwonlyargs, kwarg, defaults):
self.args = args
self.w_args = None
self.vararg = vararg
- self.varargannotation = varargannotation
self.kwonlyargs = kwonlyargs
self.w_kwonlyargs = None
self.kwarg = kwarg
- self.kwargannotation = kwargannotation
self.defaults = defaults
self.w_defaults = None
- self.kw_defaults = kw_defaults
- self.w_kw_defaults = None
- self.initialization_state = 255
+ self.initialization_state = 31
def mutate_over(self, visitor):
if self.args:
visitor._mutate_sequence(self.args)
- if self.varargannotation:
- self.varargannotation = self.varargannotation.mutate_over(visitor)
if self.kwonlyargs:
visitor._mutate_sequence(self.kwonlyargs)
- if self.kwargannotation:
- self.kwargannotation = self.kwargannotation.mutate_over(visitor)
if self.defaults:
visitor._mutate_sequence(self.defaults)
- if self.kw_defaults:
- visitor._mutate_sequence(self.kw_defaults)
return visitor.visit_arguments(self)
def walkabout(self, visitor):
visitor.visit_arguments(self)
def sync_app_attrs(self, space):
- if (self.initialization_state & ~54) ^ 201:
- self.missing_field(space, ['args', None, None, 'kwonlyargs', None, None, 'defaults', 'kw_defaults'], 'arguments')
+ if (self.initialization_state & ~10) ^ 21:
+ self.missing_field(space, ['args', None, 'kwonlyargs', None, 'defaults'], 'arguments')
else:
if not self.initialization_state & 2:
self.vararg = None
- if not self.initialization_state & 4:
- self.varargannotation = None
- if not self.initialization_state & 16:
+ if not self.initialization_state & 8:
self.kwarg = None
- if not self.initialization_state & 32:
- self.kwargannotation = None
w_list = self.w_args
if w_list is not None:
list_w = space.listview(w_list)
if list_w:
- self.args = [space.interp_w(arg, w_obj) for w_obj in list_w]
+ self.args = [space.interp_w(expr, w_obj) for w_obj in list_w]
else:
self.args = None
if self.args is not None:
for node in self.args:
node.sync_app_attrs(space)
- if self.varargannotation:
- self.varargannotation.sync_app_attrs(space)
w_list = self.w_kwonlyargs
if w_list is not None:
list_w = space.listview(w_list)
if list_w:
- self.kwonlyargs = [space.interp_w(arg, w_obj) for w_obj in list_w]
+ self.kwonlyargs = [space.interp_w(expr, w_obj) for w_obj in list_w]
else:
self.kwonlyargs = None
if self.kwonlyargs is not None:
for node in self.kwonlyargs:
node.sync_app_attrs(space)
- if self.kwargannotation:
- self.kwargannotation.sync_app_attrs(space)
w_list = self.w_defaults
if w_list is not None:
list_w = space.listview(w_list)
@@ -2385,40 +2361,6 @@
if self.defaults is not None:
for node in self.defaults:
node.sync_app_attrs(space)
- w_list = self.w_kw_defaults
- if w_list is not None:
- list_w = space.listview(w_list)
- if list_w:
- self.kw_defaults = [space.interp_w(expr, w_obj) for w_obj in list_w]
- else:
- self.kw_defaults = None
- if self.kw_defaults is not None:
- for node in self.kw_defaults:
- node.sync_app_attrs(space)
-
-class arg(AST):
-
- def __init__(self, arg, annotation):
- self.arg = arg
- self.annotation = annotation
- self.initialization_state = 3
-
- def mutate_over(self, visitor):
- if self.annotation:
- self.annotation = self.annotation.mutate_over(visitor)
- return visitor.visit_arg(self)
-
- def walkabout(self, visitor):
- visitor.visit_arg(self)
-
- def sync_app_attrs(self, space):
- if (self.initialization_state & ~2) ^ 1:
- self.missing_field(space, ['arg', None], 'arg')
- else:
- if not self.initialization_state & 2:
- self.annotation = None
- if self.annotation:
- self.annotation.sync_app_attrs(space)
class keyword(AST):
@@ -2589,8 +2531,6 @@
return self.default_visitor(node)
def visit_arguments(self, node):
return self.default_visitor(node)
- def visit_arg(self, node):
- return self.default_visitor(node)
def visit_keyword(self, node):
return self.default_visitor(node)
def visit_alias(self, node):
@@ -2614,8 +2554,6 @@
node.args.walkabout(self)
self.visit_sequence(node.body)
self.visit_sequence(node.decorator_list)
- if node.returns:
- node.returns.walkabout(self)
def visit_ClassDef(self, node):
self.visit_sequence(node.bases)
@@ -2828,17 +2766,8 @@
def visit_arguments(self, node):
self.visit_sequence(node.args)
- if node.varargannotation:
- node.varargannotation.walkabout(self)
self.visit_sequence(node.kwonlyargs)
- if node.kwargannotation:
- node.kwargannotation.walkabout(self)
self.visit_sequence(node.defaults)
- self.visit_sequence(node.kw_defaults)
-
- def visit_arg(self, node):
- if node.annotation:
- node.annotation.walkabout(self)
def visit_keyword(self, node):
node.value.walkabout(self)
@@ -3154,38 +3083,15 @@
w_self.w_decorator_list = w_new_value
w_self.initialization_state |= 32
-def FunctionDef_get_returns(space, w_self):
- if w_self.w_dict is not None:
- w_obj = w_self.getdictvalue(space, 'returns')
- if w_obj is not None:
- return w_obj
- if not w_self.initialization_state & 64:
- typename = space.type(w_self).getname(space)
- raise operationerrfmt(space.w_AttributeError, "'%s' object has no attribute '%s'", typename, 'returns')
- return space.wrap(w_self.returns)
-
-def FunctionDef_set_returns(space, w_self, w_new_value):
- try:
- w_self.returns = space.interp_w(expr, w_new_value, True)
- if type(w_self.returns) is expr:
- raise OperationError(space.w_TypeError, space.w_None)
- except OperationError, e:
- if not e.match(space, space.w_TypeError):
- raise
- w_self.setdictvalue(space, 'returns', w_new_value)
- return
- w_self.deldictvalue(space, 'returns')
- w_self.initialization_state |= 64
-
-_FunctionDef_field_unroller = unrolling_iterable(['name', 'args', 'body', 'decorator_list', 'returns'])
+_FunctionDef_field_unroller = unrolling_iterable(['name', 'args', 'body', 'decorator_list'])
def FunctionDef_init(space, w_self, __args__):
w_self = space.descr_self_interp_w(FunctionDef, w_self)
w_self.w_body = None
w_self.w_decorator_list = None
args_w, kwargs_w = __args__.unpack()
if args_w:
- if len(args_w) != 5:
- w_err = space.wrap("FunctionDef constructor takes either 0 or 5 positional arguments")
+ if len(args_w) != 4:
+ w_err = space.wrap("FunctionDef constructor takes either 0 or 4 positional arguments")
raise OperationError(space.w_TypeError, w_err)
i = 0
for field in _FunctionDef_field_unroller:
@@ -3197,12 +3103,11 @@
FunctionDef.typedef = typedef.TypeDef("FunctionDef",
stmt.typedef,
__module__='_ast',
- _fields=_FieldsWrapper(['name', 'args', 'body', 'decorator_list', 'returns']),
+ _fields=_FieldsWrapper(['name', 'args', 'body', 'decorator_list']),
name=typedef.GetSetProperty(FunctionDef_get_name, FunctionDef_set_name, cls=FunctionDef),
args=typedef.GetSetProperty(FunctionDef_get_args, FunctionDef_set_args, cls=FunctionDef),
body=typedef.GetSetProperty(FunctionDef_get_body, FunctionDef_set_body, cls=FunctionDef),
decorator_list=typedef.GetSetProperty(FunctionDef_get_decorator_list, FunctionDef_set_decorator_list, cls=FunctionDef),
- returns=typedef.GetSetProperty(FunctionDef_get_returns, FunctionDef_set_returns, cls=FunctionDef),
__new__=interp2app(get_AST_new(FunctionDef)),
__init__=interp2app(FunctionDef_init),
)
@@ -7088,32 +6993,9 @@
w_self.deldictvalue(space, 'vararg')
w_self.initialization_state |= 2
-def arguments_get_varargannotation(space, w_self):
- if w_self.w_dict is not None:
- w_obj = w_self.getdictvalue(space, 'varargannotation')
- if w_obj is not None:
- return w_obj
+def arguments_get_kwonlyargs(space, w_self):
if not w_self.initialization_state & 4:
typename = space.type(w_self).getname(space)
- raise operationerrfmt(space.w_AttributeError, "'%s' object has no attribute '%s'", typename, 'varargannotation')
- return space.wrap(w_self.varargannotation)
-
-def arguments_set_varargannotation(space, w_self, w_new_value):
- try:
- w_self.varargannotation = space.interp_w(expr, w_new_value, True)
- if type(w_self.varargannotation) is expr:
- raise OperationError(space.w_TypeError, space.w_None)
- except OperationError, e:
- if not e.match(space, space.w_TypeError):
- raise
- w_self.setdictvalue(space, 'varargannotation', w_new_value)
- return
- w_self.deldictvalue(space, 'varargannotation')
- w_self.initialization_state |= 4
-
-def arguments_get_kwonlyargs(space, w_self):
- if not w_self.initialization_state & 8:
- typename = space.type(w_self).getname(space)
raise operationerrfmt(space.w_AttributeError, "'%s' object has no attribute '%s'", typename, 'kwonlyargs')
if w_self.w_kwonlyargs is None:
if w_self.kwonlyargs is None:
@@ -7126,14 +7008,14 @@
def arguments_set_kwonlyargs(space, w_self, w_new_value):
w_self.w_kwonlyargs = w_new_value
- w_self.initialization_state |= 8
+ w_self.initialization_state |= 4
def arguments_get_kwarg(space, w_self):
if w_self.w_dict is not None:
w_obj = w_self.getdictvalue(space, 'kwarg')
if w_obj is not None:
return w_obj
- if not w_self.initialization_state & 16:
+ if not w_self.initialization_state & 8:
typename = space.type(w_self).getname(space)
raise operationerrfmt(space.w_AttributeError, "'%s' object has no attribute '%s'", typename, 'kwarg')
return space.wrap(w_self.kwarg)
@@ -7150,33 +7032,10 @@
w_self.setdictvalue(space, 'kwarg', w_new_value)
return
w_self.deldictvalue(space, 'kwarg')
- w_self.initialization_state |= 16
-
-def arguments_get_kwargannotation(space, w_self):
- if w_self.w_dict is not None:
- w_obj = w_self.getdictvalue(space, 'kwargannotation')
- if w_obj is not None:
- return w_obj
- if not w_self.initialization_state & 32:
- typename = space.type(w_self).getname(space)
- raise operationerrfmt(space.w_AttributeError, "'%s' object has no attribute '%s'", typename, 'kwargannotation')
- return space.wrap(w_self.kwargannotation)
-
-def arguments_set_kwargannotation(space, w_self, w_new_value):
- try:
- w_self.kwargannotation = space.interp_w(expr, w_new_value, True)
- if type(w_self.kwargannotation) is expr:
- raise OperationError(space.w_TypeError, space.w_None)
- except OperationError, e:
- if not e.match(space, space.w_TypeError):
- raise
- w_self.setdictvalue(space, 'kwargannotation', w_new_value)
- return
- w_self.deldictvalue(space, 'kwargannotation')
- w_self.initialization_state |= 32
+ w_self.initialization_state |= 8
def arguments_get_defaults(space, w_self):
- if not w_self.initialization_state & 64:
+ if not w_self.initialization_state & 16:
typename = space.type(w_self).getname(space)
raise operationerrfmt(space.w_AttributeError, "'%s' object has no attribute '%s'", typename, 'defaults')
if w_self.w_defaults is None:
@@ -7190,36 +7049,18 @@
def arguments_set_defaults(space, w_self, w_new_value):
w_self.w_defaults = w_new_value
- w_self.initialization_state |= 64
-
-def arguments_get_kw_defaults(space, w_self):
- if not w_self.initialization_state & 128:
- typename = space.type(w_self).getname(space)
- raise operationerrfmt(space.w_AttributeError, "'%s' object has no attribute '%s'", typename, 'kw_defaults')
- if w_self.w_kw_defaults is None:
- if w_self.kw_defaults is None:
- list_w = []
- else:
- list_w = [space.wrap(node) for node in w_self.kw_defaults]
- w_list = space.newlist(list_w)
- w_self.w_kw_defaults = w_list
- return w_self.w_kw_defaults
-
-def arguments_set_kw_defaults(space, w_self, w_new_value):
- w_self.w_kw_defaults = w_new_value
- w_self.initialization_state |= 128
-
-_arguments_field_unroller = unrolling_iterable(['args', 'vararg', 'varargannotation', 'kwonlyargs', 'kwarg', 'kwargannotation', 'defaults', 'kw_defaults'])
+ w_self.initialization_state |= 16
+
+_arguments_field_unroller = unrolling_iterable(['args', 'vararg', 'kwonlyargs', 'kwarg', 'defaults'])
def arguments_init(space, w_self, __args__):
w_self = space.descr_self_interp_w(arguments, w_self)
w_self.w_args = None
w_self.w_kwonlyargs = None
w_self.w_defaults = None
- w_self.w_kw_defaults = None
args_w, kwargs_w = __args__.unpack()
if args_w:
- if len(args_w) != 8:
- w_err = space.wrap("arguments constructor takes either 0 or 8 positional arguments")
+ if len(args_w) != 5:
+ w_err = space.wrap("arguments constructor takes either 0 or 5 positional arguments")
raise OperationError(space.w_TypeError, w_err)
i = 0
for field in _arguments_field_unroller:
@@ -7231,88 +7072,16 @@
arguments.typedef = typedef.TypeDef("arguments",
AST.typedef,
__module__='_ast',
- _fields=_FieldsWrapper(['args', 'vararg', 'varargannotation', 'kwonlyargs', 'kwarg', 'kwargannotation', 'defaults', 'kw_defaults']),
+ _fields=_FieldsWrapper(['args', 'vararg', 'kwonlyargs', 'kwarg', 'defaults']),
args=typedef.GetSetProperty(arguments_get_args, arguments_set_args, cls=arguments),
vararg=typedef.GetSetProperty(arguments_get_vararg, arguments_set_vararg, cls=arguments),
- varargannotation=typedef.GetSetProperty(arguments_get_varargannotation, arguments_set_varargannotation, cls=arguments),
kwonlyargs=typedef.GetSetProperty(arguments_get_kwonlyargs, arguments_set_kwonlyargs, cls=arguments),
kwarg=typedef.GetSetProperty(arguments_get_kwarg, arguments_set_kwarg, cls=arguments),
- kwargannotation=typedef.GetSetProperty(arguments_get_kwargannotation, arguments_set_kwargannotation, cls=arguments),
defaults=typedef.GetSetProperty(arguments_get_defaults, arguments_set_defaults, cls=arguments),
- kw_defaults=typedef.GetSetProperty(arguments_get_kw_defaults, arguments_set_kw_defaults, cls=arguments),
__new__=interp2app(get_AST_new(arguments)),
__init__=interp2app(arguments_init),
)
-def arg_get_arg(space, w_self):
- if w_self.w_dict is not None:
- w_obj = w_self.getdictvalue(space, 'arg')
- if w_obj is not None:
- return w_obj
- if not w_self.initialization_state & 1:
- typename = space.type(w_self).getname(space)
- raise operationerrfmt(space.w_AttributeError, "'%s' object has no attribute '%s'", typename, 'arg')
- return space.wrap(w_self.arg)
-
-def arg_set_arg(space, w_self, w_new_value):
- try:
- w_self.arg = space.str_w(w_new_value)
- except OperationError, e:
- if not e.match(space, space.w_TypeError):
- raise
- w_self.setdictvalue(space, 'arg', w_new_value)
- return
- w_self.deldictvalue(space, 'arg')
- w_self.initialization_state |= 1
-
-def arg_get_annotation(space, w_self):
- if w_self.w_dict is not None:
- w_obj = w_self.getdictvalue(space, 'annotation')
- if w_obj is not None:
- return w_obj
- if not w_self.initialization_state & 2:
- typename = space.type(w_self).getname(space)
- raise operationerrfmt(space.w_AttributeError, "'%s' object has no attribute '%s'", typename, 'annotation')
- return space.wrap(w_self.annotation)
-
-def arg_set_annotation(space, w_self, w_new_value):
- try:
- w_self.annotation = space.interp_w(expr, w_new_value, True)
- if type(w_self.annotation) is expr:
- raise OperationError(space.w_TypeError, space.w_None)
- except OperationError, e:
- if not e.match(space, space.w_TypeError):
- raise
- w_self.setdictvalue(space, 'annotation', w_new_value)
- return
- w_self.deldictvalue(space, 'annotation')
- w_self.initialization_state |= 2
-
-_arg_field_unroller = unrolling_iterable(['arg', 'annotation'])
-def arg_init(space, w_self, __args__):
- w_self = space.descr_self_interp_w(arg, w_self)
- args_w, kwargs_w = __args__.unpack()
- if args_w:
- if len(args_w) != 2:
- w_err = space.wrap("arg constructor takes either 0 or 2 positional arguments")
- raise OperationError(space.w_TypeError, w_err)
- i = 0
- for field in _arg_field_unroller:
- space.setattr(w_self, space.wrap(field), args_w[i])
- i += 1
- for field, w_value in kwargs_w.iteritems():
- space.setattr(w_self, space.wrap(field), w_value)
-
-arg.typedef = typedef.TypeDef("arg",
- AST.typedef,
- __module__='_ast',
- _fields=_FieldsWrapper(['arg', 'annotation']),
- arg=typedef.GetSetProperty(arg_get_arg, arg_set_arg, cls=arg),
- annotation=typedef.GetSetProperty(arg_get_annotation, arg_set_annotation, cls=arg),
- __new__=interp2app(get_AST_new(arg)),
- __init__=interp2app(arg_init),
-)
-
def keyword_get_arg(space, w_self):
if w_self.w_dict is not None:
w_obj = w_self.getdictvalue(space, 'arg')
diff --git a/pypy/interpreter/astcompiler/astbuilder.py b/pypy/interpreter/astcompiler/astbuilder.py
--- a/pypy/interpreter/astcompiler/astbuilder.py
+++ b/pypy/interpreter/astcompiler/astbuilder.py
@@ -462,13 +462,8 @@
name = name_node.value
self.check_forbidden_name(name, name_node)
args = self.handle_arguments(funcdef_node.children[2])
- suite = 4
- returns = None
- if funcdef_node.children[3].type == tokens.RARROW:
- returns = self.handle_expr(funcdef_node.children[4])
- suite += 2
- body = self.handle_suite(funcdef_node.children[suite])
- return ast.FunctionDef(name, args, body, decorators, returns,
+ body = self.handle_suite(funcdef_node.children[4])
+ return ast.FunctionDef(name, args, body, decorators,
funcdef_node.lineno, funcdef_node.column)
def handle_decorated(self, decorated_node):
@@ -513,132 +508,99 @@
# and varargslist (lambda definition).
if arguments_node.type == syms.parameters:
if len(arguments_node.children) == 2:
- return ast.arguments(None, None, None, None, None, None, None,
- None)
+ return ast.arguments(None, None, None, None, None)
arguments_node = arguments_node.children[1]
i = 0
child_count = len(arguments_node.children)
- n_pos = 0
- n_pos_def = 0
- n_kwdonly = 0
- # scan args
- while i < child_count:
- arg_type = arguments_node.children[i].type
- if arg_type == tokens.STAR:
- i += 1
- next_arg_type = arguments_node.children[i].type
- if (i < child_count and
- (next_arg_type == syms.tfpdef or
- next_arg_type == syms.vfpsdef)):
- i += 1
- break
- if arg_type == tokens.DOUBLESTAR:
- break
- if arg_type == syms.vfpdef or arg_type == syms.tfpdef:
- n_pos += 1
- if arg_type == tokens.EQUAL:
- n_pos_def += 1
- i += 1
- while i < child_count:
- arg_type = arguments_node.children[i].type
- if arg_type == tokens.DOUBLESTAR:
- break
- if arg_type == syms.vfpdef or arg_type == syms.tfpdef:
- n_kwdonly += 1
- i += 1
- pos = []
- posdefaults = []
- kwonly = []
- kwdefaults = []
- kwarg = None
- kwargann = None
- vararg = None
- varargann = None
- if n_pos + n_kwdonly > 255:
- self.error("more than 255 arguments", arguments_node)
- # process args
- i = 0
+ defaults = []
+ args = []
+ variable_arg = None
+ keywordonly_args = None
+ keywords_arg = None
have_default = False
while i < child_count:
- arg = arguments_node.children[i]
- arg_type = arg.type
+ argument = arguments_node.children[i]
+ arg_type = argument.type
if arg_type == syms.tfpdef or arg_type == syms.vfpdef:
- if i + 1 < child_count and \
- arguments_node.children[i + 1].type == tokens.EQUAL:
- default_node = arguments_node.children[i + 2]
- posdefaults.append(self.handle_expr(default_node))
+ parenthesized = False
+ complex_args = False
+ while True:
+ if i + 1 < child_count and \
+ arguments_node.children[i + 1].type == tokens.EQUAL:
+ default_node = arguments_node.children[i + 2]
+ defaults.append(self.handle_expr(default_node))
+ i += 2
+ have_default = True
+ elif have_default:
+ if parenthesized and not complex_args:
+ msg = "parenthesized arg with default"
+ else:
+ msg = ("non-default argument follows default "
+ "argument")
+ self.error(msg, arguments_node)
+ if len(argument.children) == 3:
+ sub_arg = argument.children[1]
+ if len(sub_arg.children) != 1:
+ complex_args = True
+ args.append(self.handle_arg_unpacking(sub_arg))
+ else:
+ parenthesized = True
+ argument = sub_arg.children[0]
+ continue
+ if argument.children[0].type == tokens.NAME:
+ name_node = argument.children[0]
+ arg_name = name_node.value
+ self.check_forbidden_name(arg_name, name_node)
+ name = ast.Name(arg_name, ast.Param, name_node.lineno,
+ name_node.column)
+ if keywordonly_args is None:
+ args.append(name)
+ else:
+ keywordonly_args.append(name)
i += 2
- have_default = True
- elif have_default:
- msg = "non-default argument follows default argument"
- self.error(msg, arguments_node)
- pos.append(self.handle_arg(arg))
- i += 2
+ break
elif arg_type == tokens.STAR:
- if i + 1 > child_count:
- self.error("named arguments must follow bare *")
name_node = arguments_node.children[i + 1]
keywordonly_args = []
if name_node.type == tokens.COMMA:
i += 2
- i = self.handle_keywordonly_args(arguments_node, i, kwonly,
- kwdefaults)
else:
- vararg = name_node.children[0].value
- self.check_forbidden_name(vararg, name_node)
- if len(name_node.children) > 1:
- varargann = self.handle_expr(name_node.children[2])
+ variable_arg = name_node.children[0].value
+ self.check_forbidden_name(variable_arg, name_node)
i += 3
- if i < child_count:
- next_arg_type = arguments_node.children[i].type
- if (next_arg_type == syms.tfpdef or
- next_arg_type == syms.vfpdef):
- i = self.handle_keywordonly_args(arguments_node, i,
- kwonly, kwdefaults)
elif arg_type == tokens.DOUBLESTAR:
name_node = arguments_node.children[i + 1]
- kwarg = name_node.children[0].value
- self.check_forbidden_name(kwarg, name_node)
- if len(name_node.children) > 1:
- kwargann = self.handle_expr(name_node.children[1])
+ keywords_arg = name_node.children[0].value
+ self.check_forbidden_name(keywords_arg, name_node)
i += 3
else:
raise AssertionError("unknown node in argument list")
- return ast.arguments(pos, vararg, varargann, kwonly, kwarg,
- kwargann, posdefaults, kwdefaults)
+ if not defaults:
+ defaults = None
+ if not args:
+ args = None
+ return ast.arguments(args, variable_arg, keywordonly_args, keywords_arg, defaults)
- def handle_keywordonly_args(self, arguments_node, i, kwonly, kwdefaults):
- child_count = len(arguments_node.children)
- while i < child_count:
- arg = arguments_node.children[i]
- arg_type = arg.type
- if arg_type == syms.vfpdef and arg_type == syms.tfpdef:
- if (i + 1 < child_count and
- arguments_node.children[i + 1] == tokens.EQUAL):
- expr = self.handle_expr(arguments_node.children[i + 2])
- kwdefaults.append(expr)
- i += 2
+ def handle_arg_unpacking(self, fplist_node):
+ args = []
+ for i in range((len(fplist_node.children) + 1) / 2):
+ fpdef_node = fplist_node.children[i * 2]
+ while True:
+ child = fpdef_node.children[0]
+ if child.type == tokens.NAME:
+ arg = ast.Name(child.value, ast.Store, child.lineno,
+ child.column)
+ args.append(arg)
else:
- kwdefaults.append(None)
- ann = None
- if len(arg.children) == 3:
- ann = self.handle_expr(arg.children[2])
- name_node = arg.children[0]
- argname = name_node.value
- self.check_forbidden_name(argname, name_node)
- kwonly.append(ast.arg(argname, ann))
- i += 2
- elif arg_type == tokens.DOUBLESTAR:
- return i
- return i
-
- def handle_arg(self, arg_node):
- name_node = arg_node.children[0]
- self.check_forbidden_name(name_node.value, arg_node)
- ann = None
- if len(arg_node.children) == 3:
- ann = self.handle_expr(arg_node.children[2])
- return ast.arg(name_node.value, ann)
+ child = fpdef_node.children[1]
+ if len(child.children) == 1:
+ fpdef_node = child.children[0]
+ continue
+ args.append(self.handle_arg_unpacking(child))
+ break
+ tup = ast.Tuple(args, ast.Store, fplist_node.lineno, fplist_node.column)
+ self.set_context(tup, ast.Store)
+ return tup
def handle_stmt(self, stmt):
stmt_type = stmt.type
diff --git a/pypy/interpreter/astcompiler/symtable.py b/pypy/interpreter/astcompiler/symtable.py
--- a/pypy/interpreter/astcompiler/symtable.py
+++ b/pypy/interpreter/astcompiler/symtable.py
@@ -501,8 +501,11 @@
def _handle_params(self, params, is_toplevel):
for i in range(len(params)):
- arg = params[i].arg
- self.note_symbol(arg, SYM_PARAM)
+ arg = params[i]
+ if isinstance(arg, ast.Name):
+ self.note_symbol(arg.id, SYM_PARAM)
+ else:
+ raise AssertionError("unknown parameter type")
def visit_Name(self, name):
if name.ctx == ast.Load:
diff --git a/pypy/interpreter/astcompiler/test/test_astbuilder.py b/pypy/interpreter/astcompiler/test/test_astbuilder.py
--- a/pypy/interpreter/astcompiler/test/test_astbuilder.py
+++ b/pypy/interpreter/astcompiler/test/test_astbuilder.py
@@ -478,40 +478,43 @@
assert args.defaults is None
assert args.kwarg is None
assert args.vararg is None
- assert func.returns is None
args = self.get_first_stmt("def f(a, b): pass").args
assert len(args.args) == 2
a1, a2 = args.args
- assert isinstance(a1, ast.arg)
- assert a1.arg == "a"
- assert isinstance(a2, ast.arg)
- assert a2.arg == "b"
+ assert isinstance(a1, ast.Name)
+ assert a1.id == "a"
+ assert a1.ctx == ast.Param
+ assert isinstance(a2, ast.Name)
+ assert a2.id == "b"
+ assert a2.ctx == ast.Param
assert args.vararg is None
assert args.kwarg is None
args = self.get_first_stmt("def f(a=b): pass").args
assert len(args.args) == 1
arg = args.args[0]
- assert isinstance(arg, ast.arg)
- assert arg.arg == "a"
+ assert isinstance(arg, ast.Name)
+ assert arg.id == "a"
+ assert arg.ctx == ast.Param
assert len(args.defaults) == 1
default = args.defaults[0]
assert isinstance(default, ast.Name)
assert default.id == "b"
assert default.ctx == ast.Load
args = self.get_first_stmt("def f(*a): pass").args
- assert not args.args
- assert not args.defaults
+ assert args.args is None
+ assert args.defaults is None
assert args.kwarg is None
assert args.vararg == "a"
args = self.get_first_stmt("def f(**a): pass").args
- assert not args.args
- assert not args.defaults
+ assert args.args is None
+ assert args.defaults is None
assert args.vararg is None
assert args.kwarg == "a"
args = self.get_first_stmt("def f(a, b, c=d, *e, **f): pass").args
assert len(args.args) == 3
for arg in args.args:
- assert isinstance(arg, ast.arg)
+ assert isinstance(arg, ast.Name)
+ assert arg.ctx == ast.Param
assert len(args.defaults) == 1
assert isinstance(args.defaults[0], ast.Name)
assert args.defaults[0].ctx == ast.Load
diff --git a/pypy/interpreter/astcompiler/tools/Python.asdl b/pypy/interpreter/astcompiler/tools/Python.asdl
--- a/pypy/interpreter/astcompiler/tools/Python.asdl
+++ b/pypy/interpreter/astcompiler/tools/Python.asdl
@@ -9,8 +9,8 @@
-- not really an actual node but useful in Jython's typesystem.
| Suite(stmt* body)
- stmt = FunctionDef(identifier name, arguments args,
- stmt* body, expr* decorator_list, expr? returns)
+ stmt = FunctionDef(identifier name, arguments args,
+ stmt* body, expr* decorator_list)
| ClassDef(identifier name,
expr* bases,
keyword* keywords,
@@ -106,11 +106,8 @@
excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body)
attributes (int lineno, int col_offset)
- arguments = (arg* args, identifier? vararg, expr? varargannotation,
- arg* kwonlyargs, identifier? kwarg,
- expr? kwargannotation, expr* defaults,
- expr* kw_defaults)
- arg = (identifier arg, expr? annotation)
+ arguments = (expr* args, identifier? vararg, expr* kwonlyargs,
+ identifier? kwarg, expr* defaults)
-- keyword arguments supplied to call
keyword = (identifier arg, expr value)
diff --git a/pypy/interpreter/pyparser/pytoken.py b/pypy/interpreter/pyparser/pytoken.py
--- a/pypy/interpreter/pyparser/pytoken.py
+++ b/pypy/interpreter/pyparser/pytoken.py
@@ -61,7 +61,6 @@
_add_tok('DOUBLESLASH', "//" )
_add_tok('DOUBLESLASHEQUAL',"//=" )
_add_tok('AT', "@" )
-_add_tok('RARROW', "->")
_add_tok('OP')
_add_tok('ERRORTOKEN')
More information about the pypy-commit
mailing list