Commits

Benjamin Peterson  committed 798ca16

kill _sha

  • Participants
  • Parent commits ffa255e
  • Branches py3k

Comments (0)

Files changed (10)

File pypy/config/pypyoption.py

     ["_socket", "unicodedata", "mmap", "fcntl", "_locale", "pwd",
      "rctime" , "select", "zipimport", "_lsprof",
      "crypt", "signal", "_rawffi", "termios", "zlib", "bz2",
-     "struct", "_hashlib", "_md5", "_sha", "_minimal_curses",
+     "struct", "_hashlib", "_md5", "_minimal_curses",
      "thread", "itertools", "pyexpat", "_ssl", "cpyext", "array",
      "_bisect", "binascii", "_multiprocessing", '_warnings',
      "_collections", "_multibytecodec", "micronumpy", "_ffi",
 
 # Here is the list of modules known to not work yet
 for name in ["_rawffi", "_ffi", "cpyext",
-             "_hashlib", "_md5", "_sha",
+             "_hashlib", "_md5",
              ]:
     del working_modules[name]
 
 
 working_oo_modules = default_modules.copy()
 working_oo_modules.update(dict.fromkeys(
-    ["_md5", "_sha", "itertools"]
+    ["_md5", "itertools"]
 ))
 
 # XXX this should move somewhere else, maybe to platform ("is this posixish"

File pypy/interpreter/astcompiler/ast.py

 
 class FunctionDef(stmt):
 
-    def __init__(self, name, args, body, decorator_list, lineno, col_offset):
+    def __init__(self, name, args, body, decorator_list, returns, 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 = 63
+        self.initialization_state = 127
 
     def walkabout(self, visitor):
         visitor.visit_FunctionDef(self)
             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 & ~0) ^ 63:
-            self.missing_field(space, ['lineno', 'col_offset', 'name', 'args', 'body', 'decorator_list'], 'FunctionDef')
+        if (self.initialization_state & ~64) ^ 63:
+            self.missing_field(space, ['lineno', 'col_offset', 'name', 'args', 'body', 'decorator_list', None], 'FunctionDef')
         else:
-            pass
+            if not self.initialization_state & 64:
+                self.returns = None
         self.args.sync_app_attrs(space)
         w_list = self.w_body
         if w_list is not None:
         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):
 
 class arguments(AST):
 
-    def __init__(self, args, vararg, kwonlyargs, kwarg, defaults):
+    def __init__(self, args, vararg, varargannotation, kwonlyargs, kwarg, kwargannotation, defaults, kw_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.initialization_state = 31
+        self.kw_defaults = kw_defaults
+        self.w_kw_defaults = None
+        self.initialization_state = 255
 
     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 & ~10) ^ 21:
-            self.missing_field(space, ['args', None, 'kwonlyargs', None, 'defaults'], 'arguments')
+        if (self.initialization_state & ~54) ^ 201:
+            self.missing_field(space, ['args', None, None, 'kwonlyargs', None, None, 'defaults', 'kw_defaults'], 'arguments')
         else:
             if not self.initialization_state & 2:
                 self.vararg = None
-            if not self.initialization_state & 8:
+            if not self.initialization_state & 4:
+                self.varargannotation = None
+            if not self.initialization_state & 16:
                 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(expr, w_obj) for w_obj in list_w]
+                self.args = [space.interp_w(arg, 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(expr, w_obj) for w_obj in list_w]
+                self.kwonlyargs = [space.interp_w(arg, 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)
         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):
 
         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):
         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)
 
     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)
     w_self.w_decorator_list = w_new_value
     w_self.initialization_state |= 32
 
-_FunctionDef_field_unroller = unrolling_iterable(['name', 'args', 'body', 'decorator_list'])
+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'])
 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) != 4:
-            w_err = space.wrap("FunctionDef constructor takes either 0 or 4 positional arguments")
+        if len(args_w) != 5:
+            w_err = space.wrap("FunctionDef constructor takes either 0 or 5 positional arguments")
             raise OperationError(space.w_TypeError, w_err)
         i = 0
         for field in _FunctionDef_field_unroller:
 FunctionDef.typedef = typedef.TypeDef("FunctionDef",
     stmt.typedef,
     __module__='_ast',
-    _fields=_FieldsWrapper(['name', 'args', 'body', 'decorator_list']),
+    _fields=_FieldsWrapper(['name', 'args', 'body', 'decorator_list', 'returns']),
     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),
 )
     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
+    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 & 4:
+    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:
 
 def arguments_set_kwonlyargs(space, w_self, w_new_value):
     w_self.w_kwonlyargs = w_new_value
-    w_self.initialization_state |= 4
+    w_self.initialization_state |= 8
 
 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 & 8:
+    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, 'kwarg')
     return space.wrap(w_self.kwarg)
         w_self.setdictvalue(space, 'kwarg', w_new_value)
         return
     w_self.deldictvalue(space, 'kwarg')
-    w_self.initialization_state |= 8
+    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
 
 def arguments_get_defaults(space, w_self):
-    if not w_self.initialization_state & 16:
+    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, 'defaults')
     if w_self.w_defaults is None:
 
 def arguments_set_defaults(space, w_self, w_new_value):
     w_self.w_defaults = w_new_value
-    w_self.initialization_state |= 16
-
-_arguments_field_unroller = unrolling_iterable(['args', 'vararg', 'kwonlyargs', 'kwarg', 'defaults'])
+    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'])
 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) != 5:
-            w_err = space.wrap("arguments constructor takes either 0 or 5 positional arguments")
+        if len(args_w) != 8:
+            w_err = space.wrap("arguments constructor takes either 0 or 8 positional arguments")
             raise OperationError(space.w_TypeError, w_err)
         i = 0
         for field in _arguments_field_unroller:
 arguments.typedef = typedef.TypeDef("arguments",
     AST.typedef,
     __module__='_ast',
-    _fields=_FieldsWrapper(['args', 'vararg', 'kwonlyargs', 'kwarg', 'defaults']),
+    _fields=_FieldsWrapper(['args', 'vararg', 'varargannotation', 'kwonlyargs', 'kwarg', 'kwargannotation', 'defaults', 'kw_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')

File pypy/interpreter/astcompiler/astbuilder.py

         name = name_node.value
         self.check_forbidden_name(name, name_node)
         args = self.handle_arguments(funcdef_node.children[2])
-        body = self.handle_suite(funcdef_node.children[4])
-        return ast.FunctionDef(name, args, body, decorators,
+        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,
                                funcdef_node.lineno, funcdef_node.column)
 
     def handle_decorated(self, decorated_node):
         # and varargslist (lambda definition).
         if arguments_node.type == syms.parameters:
             if len(arguments_node.children) == 2:
-                return ast.arguments(None, None, None, None, None)
+                return ast.arguments(None, None, None, None, None, None, None,
+                                     None)
             arguments_node = arguments_node.children[1]
         i = 0
         child_count = len(arguments_node.children)
-        defaults = []
-        args = []
-        variable_arg = None
-        keywordonly_args = None
-        keywords_arg = None
+        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
         have_default = False
         while i < child_count:
-            argument = arguments_node.children[i]
-            arg_type = argument.type
+            arg = arguments_node.children[i]
+            arg_type = arg.type
             if arg_type == syms.tfpdef or arg_type == syms.vfpdef:
-                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)
+                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))
                     i += 2
-                    break
+                    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
             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:
-                    variable_arg = name_node.children[0].value
-                    self.check_forbidden_name(variable_arg, name_node)
+                    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])
                     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]
-                keywords_arg = name_node.children[0].value
-                self.check_forbidden_name(keywords_arg, name_node)
+                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])
                 i += 3
             else:
                 raise AssertionError("unknown node in argument list")
-        if not defaults:
-            defaults = None
-        if not args:
-            args = None
-        return ast.arguments(args, variable_arg, keywordonly_args, keywords_arg, defaults)
+        return ast.arguments(pos, vararg, varargann, kwonly, kwarg,
+                             kwargann, posdefaults, kwdefaults)
 
-    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)
+    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
                 else:
-                    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
+                    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)
 
     def handle_stmt(self, stmt):
         stmt_type = stmt.type

File pypy/interpreter/astcompiler/symtable.py

 
     def _handle_params(self, params, is_toplevel):
         for i in range(len(params)):
-            arg = params[i]
-            if isinstance(arg, ast.Name):
-                self.note_symbol(arg.id, SYM_PARAM)
-            else:
-                raise AssertionError("unknown parameter type")
+            arg = params[i].arg
+            self.note_symbol(arg, SYM_PARAM)
 
     def visit_Name(self, name):
         if name.ctx == ast.Load:

File pypy/interpreter/astcompiler/test/test_astbuilder.py

         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.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 isinstance(a1, ast.arg)
+        assert a1.arg == "a"
+        assert isinstance(a2, ast.arg)
+        assert a2.arg == "b"
         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.Name)
-        assert arg.id == "a"
-        assert arg.ctx == ast.Param
+        assert isinstance(arg, ast.arg)
+        assert arg.arg == "a"
         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 args.args is None
-        assert args.defaults is None
+        assert not args.args
+        assert not args.defaults
         assert args.kwarg is None
         assert args.vararg == "a"
         args = self.get_first_stmt("def f(**a): pass").args
-        assert args.args is None
-        assert args.defaults is None
+        assert not args.args
+        assert not args.defaults
         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.Name)
-            assert arg.ctx == ast.Param
+            assert isinstance(arg, ast.arg)
         assert len(args.defaults) == 1
         assert isinstance(args.defaults[0], ast.Name)
         assert args.defaults[0].ctx == ast.Load

File pypy/interpreter/astcompiler/tools/Python.asdl

 	    -- 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)
+	stmt = FunctionDef(identifier name, arguments args,
+                            stmt* body, expr* decorator_list, expr? returns)
 	      | ClassDef(identifier name, 
 			 expr* bases,
 			 keyword* keywords,
 	excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body)
 	                attributes (int lineno, int col_offset)
 
-	arguments = (expr* args, identifier? vararg, expr* kwonlyargs, 
-		     identifier? kwarg, expr* defaults)
+        arguments = (arg* args, identifier? vararg, expr? varargannotation,
+                     arg* kwonlyargs, identifier? kwarg,
+                     expr? kwargannotation, expr* defaults,
+                     expr* kw_defaults)
+        arg = (identifier arg, expr? annotation)
 
         -- keyword arguments supplied to call
         keyword = (identifier arg, expr value)

File pypy/interpreter/pyparser/pytoken.py

 _add_tok('DOUBLESLASH', "//" )
 _add_tok('DOUBLESLASHEQUAL',"//=" )
 _add_tok('AT', "@" )
+_add_tok('RARROW', "->")
 _add_tok('OP')
 _add_tok('ERRORTOKEN')
 

File pypy/module/_sha/__init__.py

-
-"""
-Mixed-module definition for the sha module.
-Note that there is also a pure Python implementation in pypy/lib/sha.py;
-the present mixed-module version of sha takes precedence if it is enabled.
-"""
-
-from pypy.interpreter.mixedmodule import MixedModule
-
-
-class Module(MixedModule):
-    """\
-This module implements the interface to NIST's secure hash algorithm,
-known as SHA-1. SHA-1 is an improved version of the original SHA hash
-algorithm. It is used in the same way as the md5 module: use new() to
-create an sha object, then feed this object with arbitrary strings using
-the update() method, and at any point you can ask it for the digest of
-the concatenation of the strings fed to it so far. SHA-1 digests are 160
-bits instead of MD5's 128 bits."""
-
-    applevel_name = '_sha1'
-
-    interpleveldefs = {
-        'sha1': 'interp_sha.W_SHA',
-        }
-
-    appleveldefs = {
-        }

File pypy/module/_sha/interp_sha.py

-from pypy.rlib import rsha
-from pypy.interpreter.baseobjspace import Wrappable
-from pypy.interpreter.typedef import TypeDef
-from pypy.interpreter.gateway import interp2app, unwrap_spec
-
-
-class W_SHA(Wrappable, rsha.RSHA):
-    """
-    A subclass of RSHA that can be exposed to app-level.
-    """
-
-    def __init__(self, space):
-        self.space = space
-        self._init()
-
-    @unwrap_spec(string='bufferstr')
-    def update_w(self, string):
-        self.update(string)
-
-    def digest_w(self):
-        return self.space.wrap(self.digest())
-
-    def hexdigest_w(self):
-        return self.space.wrap(self.hexdigest())
-
-    def copy_w(self):
-        clone = W_SHA(self.space)
-        clone._copyfrom(self)
-        return self.space.wrap(clone)
-
-
-@unwrap_spec(initialdata='bufferstr')
-def W_SHA___new__(space, w_subtype, initialdata=''):
-    """
-    Create a new sha object and call its initializer.
-    """
-    w_sha = space.allocate_instance(W_SHA, w_subtype)
-    sha = space.interp_w(W_SHA, w_sha)
-    W_SHA.__init__(sha, space)
-    sha.update(initialdata)
-    return w_sha
-
-
-W_SHA.typedef = TypeDef(
-    'SHAType',
-    __new__   = interp2app(W_SHA___new__),
-    update    = interp2app(W_SHA.update_w),
-    digest    = interp2app(W_SHA.digest_w),
-    hexdigest = interp2app(W_SHA.hexdigest_w),
-    copy      = interp2app(W_SHA.copy_w),
-    digest_size = 20,
-    digestsize = 20,
-    block_size = 64,
-    __doc__   = """sha(arg) -> return new sha object.
-
-If arg is present, the method call update(arg) is made.""")

File pypy/module/_sha/test/test_sha.py

-"""
-Tests for the sha module implemented at interp-level in pypy/module/sha.
-"""
-
-import py
-from pypy.conftest import gettestobjspace
-
-
-class AppTestSHA(object):
-
-    def setup_class(cls):
-        """
-        Create a space with the sha module and import it for use by the
-        tests.
-        """
-        cls.space = gettestobjspace(usemodules=['_sha'])
-        cls.w_sha = cls.space.appexec([], """():
-            import sha
-            return sha
-        """)
-
-
-    def test_digest_size(self):
-        """
-        Check some numeric values from the sha module.
-        """
-        assert self.sha.blocksize == 1
-        assert self.sha.digest_size == 20
-        assert self.sha.digestsize == 20
-        d = self.sha.sha()
-        assert d.digest_size == 20
-        assert d.digestsize == 20
-
-
-    def test_SHAType(self):
-        """
-        Test the two ways to construct an sha object.
-        """
-        sha = self.sha
-        d = sha.sha()
-        if not hasattr(sha, 'SHAType'):
-            skip("no sha.SHAType on CPython")
-        assert isinstance(d, sha.SHAType)
-        d = sha.new()
-        assert isinstance(d, sha.SHAType)
-
-
-    def test_shaobject(self):
-        """
-        Feed example strings into a sha object and check the digest and
-        hexdigest.
-        """
-        sha = self.sha
-        cases = (
-          ("",
-           "da39a3ee5e6b4b0d3255bfef95601890afd80709"),
-          ("a",
-           "86f7e437faa5a7fce15d1ddcb9eaeaea377667b8"),
-          ("abc",
-           "a9993e364706816aba3e25717850c26c9cd0d89d"),
-          ("message digest",
-           "c12252ceda8be8994d5fa0290a47231c1d16aae3"),
-          ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
-           "761c457bf73b14d27e9e9265c46f4b4dda11f940"),
-          ("1234567890"*8,
-           "50abf5706a150990a08b2c5ea40fa0e585554732"),
-          ("1234567890"*999,
-           "eaaca5490568fde98d8dc553d9566bdc602fde4a"),
-        )
-        for input, expected in cases:
-            d = sha.new(input)
-            assert d.hexdigest() == expected
-            assert d.digest() == expected.decode('hex')
-
-
-    def test_copy(self):
-        """
-        Test the copy() method.
-        """
-        sha = self.sha
-        d1 = sha.sha()
-        d1.update("abcde")
-        d2 = d1.copy()
-        d2.update("fgh")
-        d1.update("jkl")
-        assert d1.hexdigest() == 'f5d13cf6341db9b0e299d7b9d562de9572b58e5d'
-        assert d2.hexdigest() == '425af12a0743502b322e93a015bcf868e324d56a'
-
-
-    def test_buffer(self):
-        """
-        Test passing a buffer object.
-        """
-        sha = self.sha
-        d1 = sha.sha(buffer("abcde"))
-        d1.update(buffer("jkl"))
-        assert d1.hexdigest() == 'f5d13cf6341db9b0e299d7b9d562de9572b58e5d'
-
-
-    def test_unicode(self):
-        """
-        Test passing unicode strings.
-        """
-        sha = self.sha
-        d1 = sha.sha(u"abcde")
-        d1.update(u"jkl")
-        assert d1.hexdigest() == 'f5d13cf6341db9b0e299d7b9d562de9572b58e5d'
-        raises(UnicodeEncodeError, d1.update, u'\xe9')