Commits

Antonio Cuni  committed 8e98c56 Merge

merge heads

  • Participants
  • Parent commits 2784a1d, 849129c

Comments (0)

Files changed (12)

File pypy/annotation/description.py

 from pypy.interpreter.pycode import cpython_code_signature
 from pypy.interpreter.argument import rawshape
 from pypy.interpreter.argument import ArgErr
+from pypy.interpreter.function import Defaults
 from pypy.tool.sourcetools import valid_identifier
 from pypy.tool.pairtype import extendabletype
 
     overridden = False
     normalized = False
     modified   = True
-    
+
     def __init__(self, desc):
         self.descs = { desc: True }
         self.calltables = {}  # see calltable_lookup_row()
 class FunctionDesc(Desc):
     knowntype = types.FunctionType
     overridden = False
-    
+
     def __init__(self, bookkeeper, pyobj=None,
                  name=None, signature=None, defaults=None,
                  specializer=None):
                     return '_'.join(map(nameof, thing))
                 else:
                     return str(thing)[:30]
-                
+
             if key is not None and alt_name is None:
                 postfix = valid_identifier(nameof(key))
                 alt_name = "%s__%s"%(self.name, postfix)
             for x in defaults:
                 defs_s.append(self.bookkeeper.immutablevalue(x))
         try:
-            inputcells = args.match_signature(signature, defs_s)
+            inputcells = args.match_signature(signature, Defaults(defs_s))
         except ArgErr, e:
             raise TypeError, "signature mismatch: %s" % e.getmsg(self.name)
         return inputcells
 
     def bind_under(self, classdef, name):
         # XXX static methods
-        return self.bookkeeper.getmethoddesc(self, 
+        return self.bookkeeper.getmethoddesc(self,
                                              classdef,   # originclassdef,
                                              None,       # selfclassdef
                                              name)
         while name not in cdesc.classdict:
             cdesc = cdesc.basedesc
             if cdesc is None:
-                return None 
+                return None
         else:
             return cdesc
 
 class MethodDesc(Desc):
     knowntype = types.MethodType
 
-    def __init__(self, bookkeeper, funcdesc, originclassdef, 
+    def __init__(self, bookkeeper, funcdesc, originclassdef,
                  selfclassdef, name, flags={}):
         super(MethodDesc, self).__init__(bookkeeper)
         self.funcdesc = funcdesc
         # FunctionDescs, not MethodDescs.  The present method returns the
         # FunctionDesc to use as a key in that family.
         return self.funcdesc
-    
+
     def simplify_desc_set(descs):
         # Some hacking needed to make contains() happy on SomePBC: if the
         # set of MethodDescs contains some "redundant" ones, i.e. ones that
             return s_ImpossibleValue
         else:
             return self.bookkeeper.immutablevalue(value)
-    
+
     def create_new_attribute(self, name, value):
         try:
             self.read_attribute(name)
         s_self = SomePBC([self.frozendesc])
         args = args.prepend(s_self)
         return self.funcdesc.pycall(schedule, args, s_previous_result)
-    
+
     def consider_call_site(bookkeeper, family, descs, args, s_result):
         shape = rawshape(args, nextra=1)    # account for the extra 'self'
         funcdescs = [mofdesc.funcdesc for mofdesc in descs]

File pypy/interpreter/argument.py

         if i == 2:
             return self.kwargname
         raise IndexError
-        
+
 
 
 class Arguments(object):
     """
     Collects the arguments of a function call.
-    
+
     Instances should be considered immutable.
     """
 
             self._combine_starstarargs_wrapped(w_starstararg)
 
     def _combine_starargs_wrapped(self, w_stararg):
-        # unpack the * arguments 
+        # unpack the * arguments
         space = self.space
         try:
             args_w = space.fixedview(w_stararg)
         if self.arguments_w:
             return self.arguments_w[0]
         return None
-        
+
     ###  Parsing for function calls  ###
 
-    def _match_signature(self, w_firstarg, scope_w, signature, defaults_w=[],
+    def _match_signature(self, w_firstarg, scope_w, signature, defaults=None,
                          blindargs=0):
         """Parse args and kwargs according to the signature of a code object,
         or raise an ArgErr in case of failure.
         """
         if jit.we_are_jitted() and self._dont_jit:
             return self._match_signature_jit_opaque(w_firstarg, scope_w,
-                                                    signature, defaults_w,
+                                                    signature, defaults,
                                                     blindargs)
         return self._really_match_signature(w_firstarg, scope_w, signature,
-                                            defaults_w, blindargs)
+                                            defaults, blindargs)
 
     @jit.dont_look_inside
     def _match_signature_jit_opaque(self, w_firstarg, scope_w, signature,
-                                    defaults_w, blindargs):
+                                    defaults, blindargs):
         return self._really_match_signature(w_firstarg, scope_w, signature,
-                                            defaults_w, blindargs)
+                                            defaults, blindargs)
 
     @jit.unroll_safe
-    def _really_match_signature(self, w_firstarg, scope_w, signature, defaults_w=[],
+    def _really_match_signature(self, w_firstarg, scope_w, signature, defaults=None,
                                 blindargs=0):
         #
         #   args_w = list of the normal actual parameters, wrapped
                 scope_w[0] = w_firstarg
                 input_argcount = 1
             else:
-                extravarargs = [ w_firstarg ]
+                extravarargs = [w_firstarg]
         else:
             upfront = 0
-        
+
         args_w = self.arguments_w
         num_args = len(args_w)
 
         elif avail > co_argcount:
             raise ArgErrCount(avail, num_kwds,
                               co_argcount, has_vararg, has_kwarg,
-                              defaults_w, 0)
+                              defaults, 0)
 
         # the code assumes that keywords can potentially be large, but that
         # argnames is typically not too large
                     num_remainingkwds -= 1
         missing = 0
         if input_argcount < co_argcount:
-            def_first = co_argcount - len(defaults_w)
+            def_first = co_argcount - (0 if defaults is None else defaults.getlen())
             for i in range(input_argcount, co_argcount):
                 if scope_w[i] is not None:
                     pass
                 elif i >= def_first:
-                    scope_w[i] = defaults_w[i-def_first]
+                    scope_w[i] = defaults.getitem(i - def_first)
                 else:
                     # error: not enough arguments.  Don't signal it immediately
                     # because it might be related to a problem with */** or
             if co_argcount == 0:
                 raise ArgErrCount(avail, num_kwds,
                               co_argcount, has_vararg, has_kwarg,
-                              defaults_w, missing)
+                              defaults, missing)
             raise ArgErrUnknownKwds(num_remainingkwds, keywords, used_keywords)
 
         if missing:
             raise ArgErrCount(avail, num_kwds,
                               co_argcount, has_vararg, has_kwarg,
-                              defaults_w, missing)
+                              defaults, missing)
 
         return co_argcount + has_vararg + has_kwarg
-    
+
 
 
     def parse_into_scope(self, w_firstarg,
-                         scope_w, fnname, signature, defaults_w=[]):
+                         scope_w, fnname, signature, defaults=None):
         """Parse args and kwargs to initialize a frame
         according to the signature of code object.
         Store the argumentvalues into scope_w.
         """
         try:
             return self._match_signature(w_firstarg,
-                                         scope_w, signature, defaults_w, 0)
+                                         scope_w, signature, defaults, 0)
         except ArgErr, e:
             raise OperationError(self.space.w_TypeError,
                                  self.space.wrap(e.getmsg(fnname)))
 
-    def _parse(self, w_firstarg, signature, defaults_w, blindargs=0):
+    def _parse(self, w_firstarg, signature, defaults, blindargs=0):
         """Parse args and kwargs according to the signature of a code object,
         or raise an ArgErr in case of failure.
         """
         scopelen = signature.scope_length()
         scope_w = [None] * scopelen
-        self._match_signature(w_firstarg, scope_w, signature, defaults_w,
+        self._match_signature(w_firstarg, scope_w, signature, defaults,
                               blindargs)
-        return scope_w    
+        return scope_w
 
 
     def parse_obj(self, w_firstarg,
-                  fnname, signature, defaults_w=[], blindargs=0):
+                  fnname, signature, defaults=None, blindargs=0):
         """Parse args and kwargs to initialize a frame
         according to the signature of code object.
         """
         try:
-            return self._parse(w_firstarg, signature, defaults_w, blindargs)
+            return self._parse(w_firstarg, signature, defaults, blindargs)
         except ArgErr, e:
             raise OperationError(self.space.w_TypeError,
-                                 self.space.wrap(e.getmsg(fnname)))        
+                                 self.space.wrap(e.getmsg(fnname)))
 
     @staticmethod
     def frompacked(space, w_args=None, w_kwds=None):
                                        self.w_starstararg)
 
 
-            
-    def _match_signature(self, w_firstarg, scope_w, signature, defaults_w=[],
+
+    def _match_signature(self, w_firstarg, scope_w, signature, defaults=None,
                          blindargs=0):
         self.combine_if_necessary()
         # _match_signature is destructive
         return Arguments._match_signature(
                self, w_firstarg, scope_w, signature,
-               defaults_w, blindargs)
+               defaults, blindargs)
 
     def unpack(self):
         self.combine_if_necessary()
         return Arguments.unpack(self)
 
-    def match_signature(self, signature, defaults_w):
+    def match_signature(self, signature, defaults):
         """Parse args and kwargs according to the signature of a code object,
         or raise an ArgErr in case of failure.
         """
-        return self._parse(None, signature, defaults_w)
+        return self._parse(None, signature, defaults)
 
     def unmatch_signature(self, signature, data_w):
         """kind of inverse of match_signature"""
             for w_key in space.unpackiterable(data_w_starargarg):
                 key = space.str_w(w_key)
                 w_value = space.getitem(data_w_starargarg, w_key)
-                unfiltered_kwds_w[key] = w_value            
+                unfiltered_kwds_w[key] = w_value
             cnt += 1
         assert len(data_w) == cnt
-        
+
         ndata_args_w = len(data_args_w)
         if ndata_args_w >= need_cnt:
             args_w = data_args_w[:need_cnt]
             for i in range(0, len(stararg_w)):
                 args_w[i + datalen] = stararg_w[i]
             assert len(args_w) == need_cnt
-            
+
         keywords = []
         keywords_w = []
         for key in need_kwds:
             keywords.append(key)
             keywords_w.append(unfiltered_kwds_w[key])
-                    
+
         return ArgumentsForTranslation(self.space, args_w, keywords, keywords_w)
 
     @staticmethod
     def frompacked(space, w_args=None, w_kwds=None):
         raise NotImplementedError("go away")
-    
+
     @staticmethod
     def fromshape(space, (shape_cnt,shape_keys,shape_star,shape_stst), data_w):
         args_w = data_w[:shape_cnt]
 #
 
 class ArgErr(Exception):
-    
+
     def getmsg(self, fnname):
         raise NotImplementedError
 
 class ArgErrCount(ArgErr):
 
     def __init__(self, got_nargs, nkwds, expected_nargs, has_vararg, has_kwarg,
-                 defaults_w, missing_args):
+                 defaults, missing_args):
         self.expected_nargs = expected_nargs
         self.has_vararg = has_vararg
         self.has_kwarg = has_kwarg
-        
-        self.num_defaults = len(defaults_w)
+
+        self.num_defaults = 0 if defaults is None else defaults.getlen()
         self.missing_args = missing_args
         self.num_args = got_nargs
         self.num_kwds = nkwds
-        
+
     def getmsg(self, fnname):
         args = None
         #args_w, kwds_w = args.unpack()
         n = self.expected_nargs
         if n == 0:
             msg = "%s() takes no argument (%d given)" % (
-                fnname, 
+                fnname,
                 nargs)
         else:
             defcount = self.num_defaults

File pypy/interpreter/function.py

     def getitems(self):
         return jit.hint(self, promote=True).items
 
+    def getitem(self, idx):
+        return self.getitems()[idx]
+
+    def getlen(self):
+        return len(self.getitems())
+
 class Function(Wrappable):
     """A function is a code object captured with some environment:
     an object space, a dictionary of globals, default arguments,
             return self._flat_pycall(code, nargs, frame)
         elif fast_natural_arity & Code.FLATPYCALL:
             natural_arity = fast_natural_arity & 0xff
-            if natural_arity > nargs >= natural_arity - len(self.defs.getitems()):
+            if natural_arity > nargs >= natural_arity - self.defs.getlen():
                 assert isinstance(code, PyCode)
                 return self._flat_pycall_defaults(code, nargs, frame,
                                                   natural_arity - nargs)
             w_arg = frame.peekvalue(nargs-1-i)
             new_frame.fastlocals_w[i] = w_arg
 
-        defs_w = self.defs.getitems()
-        ndefs = len(defs_w)
+        defs = self.defs
+        ndefs = defs.getlen()
         start = ndefs - defs_to_load
         i = nargs
         for j in xrange(start, ndefs):
-            new_frame.fastlocals_w[i] = defs_w[j]
+            new_frame.fastlocals_w[i] = defs.getitem(j)
             i += 1
         return new_frame.run()
 

File pypy/interpreter/gateway.py

         space = func.space
         activation = self.activation
         scope_w = args.parse_obj(w_obj, func.name, self.sig,
-                                 func.defs.getitems(), self.minargs)
+                                 func.defs, self.minargs)
         try:
             w_result = activation._run(space, scope_w)
         except DescrMismatch:

File pypy/interpreter/pycode.py

                                       fresh_virtualizable=True)
         args_matched = args.parse_into_scope(None, fresh_frame.fastlocals_w,
                                              func.name,
-                                             sig, func.defs.getitems())
+                                             sig, func.defs)
         fresh_frame.init_cells()
         return frame.run()
 
                                       fresh_virtualizable=True)
         args_matched = args.parse_into_scope(w_obj, fresh_frame.fastlocals_w,
                                              func.name,
-                                             sig, func.defs.getitems())
+                                             sig, func.defs)
         fresh_frame.init_cells()
         return frame.run()
 

File pypy/interpreter/test/test_argument.py

 import py
-from pypy.interpreter.argument import Arguments, ArgumentsForTranslation, ArgErr
-from pypy.interpreter.argument import ArgErrUnknownKwds, ArgErrMultipleValues
-from pypy.interpreter.argument import ArgErrCount, rawshape, Signature
+from pypy.interpreter.argument import (Arguments, ArgumentsForTranslation,
+    ArgErr, ArgErrUnknownKwds, ArgErrMultipleValues, ArgErrCount, rawshape,
+    Signature)
 from pypy.interpreter.error import OperationError
+from pypy.interpreter.function import Defaults
 
 
 class TestSignature(object):
         return list(it)
 
     def listview(self, it):
-        return list(it)        
+        return list(it)
 
     def unpackiterable(self, it):
         return list(it)
 
     def test_fixedunpacked(self):
         space = DummySpace()
-        
+
         args = Arguments(space, [], ["k"], [1])
         py.test.raises(ValueError, args.fixedunpack, 1)
 
         args = Arguments(space, ["a", "b"])
         py.test.raises(ValueError, args.fixedunpack, 0)
-        py.test.raises(ValueError, args.fixedunpack, 1)        
+        py.test.raises(ValueError, args.fixedunpack, 1)
         py.test.raises(ValueError, args.fixedunpack, 3)
         py.test.raises(ValueError, args.fixedunpack, 4)
 
         assert args.fixedunpack(2) == ['a', 'b']
-    
+
     def test_match0(self):
         space = DummySpace()
         args = Arguments(space, [])
         py.test.raises(ArgErr, args._match_signature, None, l, Signature(["a"], "*"))
         args = Arguments(space, [])
         l = [None]
-        args._match_signature(None, l, Signature(["a"]), defaults_w=[1])
+        args._match_signature(None, l, Signature(["a"]), defaults=Defaults([1]))
         assert l == [1]
         args = Arguments(space, [])
         l = [None]
                 py.test.raises(ArgErr, args._match_signature, firstarg, l, Signature(["a", "b", "c", "d", "e"], "*"))
                 l = [None, None, None, None, None]
                 args = Arguments(space, arglist, w_stararg=starargs)
-                args._match_signature(firstarg, l, Signature(["a", "b", "c", "d", "e"]), defaults_w=[1])
+                args._match_signature(firstarg, l, Signature(["a", "b", "c", "d", "e"]), defaults=Defaults([1]))
                 assert l == [4, 5, 6, 7, 1]
                 for j in range(len(values)):
                     l = [None] * (j + 1)
             assert len(keywords) == len(keywords_w)
             args = Arguments(space, [1, 2], keywords[:], keywords_w[:], w_starstararg=w_kwds)
             l = [None, None, None]
-            args._match_signature(None, l, Signature(["a", "b", "c"]), defaults_w=[4])
+            args._match_signature(None, l, Signature(["a", "b", "c"]), defaults=Defaults([4]))
             assert l == [1, 2, 3]
             args = Arguments(space, [1, 2], keywords[:], keywords_w[:], w_starstararg=w_kwds)
             l = [None, None, None, None]
-            args._match_signature(None, l, Signature(["a", "b", "b1", "c"]), defaults_w=[4, 5])
+            args._match_signature(None, l, Signature(["a", "b", "b1", "c"]), defaults=Defaults([4, 5]))
             assert l == [1, 2, 4, 3]
             args = Arguments(space, [1, 2], keywords[:], keywords_w[:], w_starstararg=w_kwds)
             l = [None, None, None, None]
-            args._match_signature(None, l, Signature(["a", "b", "c", "d"]), defaults_w=[4, 5])
+            args._match_signature(None, l, Signature(["a", "b", "c", "d"]), defaults=Defaults([4, 5]))
             assert l == [1, 2, 3, 5]
             args = Arguments(space, [1, 2], keywords[:], keywords_w[:], w_starstararg=w_kwds)
             l = [None, None, None, None]
             py.test.raises(ArgErr, args._match_signature, None, l,
-                           Signature(["c", "b", "a", "d"]), defaults_w=[4, 5])
+                           Signature(["c", "b", "a", "d"]), defaults=Defaults([4, 5]))
             args = Arguments(space, [1, 2], keywords[:], keywords_w[:], w_starstararg=w_kwds)
             l = [None, None, None, None]
             py.test.raises(ArgErr, args._match_signature, None, l,
-                           Signature(["a", "b", "c1", "d"]), defaults_w=[4, 5])
+                           Signature(["a", "b", "c1", "d"]), defaults=Defaults([4, 5]))
             args = Arguments(space, [1, 2], keywords[:], keywords_w[:], w_starstararg=w_kwds)
             l = [None, None, None]
             args._match_signature(None, l, Signature(["a", "b"], None, "**"))
         calls = []
 
         def _match_signature(w_firstarg, scope_w, signature,
-                             defaults_w=[], blindargs=0):
+                             defaults=None, blindargs=0):
+            defaults = [] if defaults is None else defaults.getitems()
             calls.append((w_firstarg, scope_w, signature.argnames, signature.has_vararg(),
-                          signature.has_kwarg(), defaults_w, blindargs))
+                          signature.has_kwarg(), defaults, blindargs))
         args._match_signature = _match_signature
 
         scope_w = args.parse_obj(None, "foo", Signature(["a", "b"], None, None))
                             [], 0)
         assert calls[0][1] is scope_w
         calls = []
-            
+
         scope_w = args.parse_obj(None, "foo", Signature(["a", "b"], "args", None),
                                  blindargs=1)
         assert len(calls) == 1
         calls = []
 
         scope_w = args.parse_obj(None, "foo", Signature(["a", "b"], "args", "kw"),
-                             defaults_w=['x', 'y'])
+                             defaults=Defaults(['x', 'y']))
         assert len(calls) == 1
         assert calls[0] == (None, [None, None, None, None], ["a", "b"],
                             True, True,
                             ["x", "y"], 0)
         calls = []
-        
+
         scope_w = args.parse_obj("obj", "foo", Signature(["a", "b"], "args", "kw"),
-                             defaults_w=['x', 'y'], blindargs=1)
+                             defaults=Defaults(['x', 'y']), blindargs=1)
         assert len(calls) == 1
         assert calls[0] == ("obj", [None, None, None, None], ["a", "b"],
                             True, True,
         calls = []
 
         def _match_signature(w_firstarg, scope_w, signature,
-                             defaults_w=[], blindargs=0):
+                             defaults=None, blindargs=0):
+            defaults = [] if defaults is None else defaults.getitems()
             calls.append((w_firstarg, scope_w, signature.argnames, signature.has_vararg(),
-                          signature.has_kwarg(), defaults_w, blindargs))
+                          signature.has_kwarg(), defaults, blindargs))
         args._match_signature = _match_signature
 
         scope_w = [None, None]
 
         scope_w = [None, None, None, None]
         args.parse_into_scope(None, scope_w, "foo", Signature(["a", "b"], "args", "kw"),
-                              defaults_w=['x', 'y'])
+                              defaults=Defaults(['x', 'y']))
         assert len(calls) == 1
         assert calls[0] == (None, scope_w, ["a", "b"],
                             True, True,
                             ["x", "y"], 0)
         calls = []
 
-        scope_w = [None, None, None, None]        
+        scope_w = [None, None, None, None]
         args.parse_into_scope("obj", scope_w, "foo", Signature(["a", "b"],
                                                       "args", "kw"),
-                              defaults_w=['x', 'y'])
+                              defaults=Defaults(['x', 'y']))
         assert len(calls) == 1
         assert calls[0] == ("obj", scope_w, ["a", "b"],
                             True, True,
         assert args.arguments_w == [1]
         assert set(args.keywords) == set(['a', 'b'])
         assert args.keywords_w[args.keywords.index('a')] == 2
-        assert args.keywords_w[args.keywords.index('b')] == 3        
+        assert args.keywords_w[args.keywords.index('b')] == 3
 
         args = Arguments(space, [1])
         w_args, w_kwds = args.topacked()
     def test_missing_args(self):
         # got_nargs, nkwds, expected_nargs, has_vararg, has_kwarg,
         # defaults_w, missing_args
-        err = ArgErrCount(1, 0, 0, False, False, [], 0)
+        err = ArgErrCount(1, 0, 0, False, False, Defaults([]), 0)
         s = err.getmsg('foo')
         assert s == "foo() takes no argument (1 given)"
-        err = ArgErrCount(0, 0, 1, False, False, [], 1)
+        err = ArgErrCount(0, 0, 1, False, False, Defaults([]), 1)
         s = err.getmsg('foo')
         assert s == "foo() takes exactly 1 argument (0 given)"
-        err = ArgErrCount(3, 0, 2, False, False, [], 0)
+        err = ArgErrCount(3, 0, 2, False, False, Defaults([]), 0)
         s = err.getmsg('foo')
         assert s == "foo() takes exactly 2 arguments (3 given)"
-        err = ArgErrCount(1, 0, 2, True, False, [], 1)
+        err = ArgErrCount(1, 0, 2, True, False, Defaults([]), 1)
         s = err.getmsg('foo')
         assert s == "foo() takes at least 2 arguments (1 given)"
-        err = ArgErrCount(3, 0, 2, True, False, ['a'], 0)
+        err = ArgErrCount(3, 0, 2, True, False, Defaults(['a']), 0)
         s = err.getmsg('foo')
         assert s == "foo() takes at most 2 arguments (3 given)"
-        err = ArgErrCount(0, 1, 2, True, False, ['a'], 1)
+        err = ArgErrCount(0, 1, 2, True, False, Defaults(['a']), 1)
         s = err.getmsg('foo')
         assert s == "foo() takes at least 1 argument (1 given)"
-        err = ArgErrCount(2, 1, 1, False, True, [], 0)
+        err = ArgErrCount(2, 1, 1, False, True, Defaults([]), 0)
         s = err.getmsg('foo')
         assert s == "foo() takes exactly 1 argument (3 given)"
 
 
         args = make_arguments_for_translation(space, [1])
         sig = Signature(['a', 'b', 'c'], None, None)
-        data = args.match_signature(sig, [2, 3])
+        data = args.match_signature(sig, Defaults([2, 3]))
         new_args = args.unmatch_signature(sig, data)
         assert args.unpack() == new_args.unpack()
 
 
         args = make_arguments_for_translation(space, [1], {'c': 3, 'b': 2})
         sig = Signature(['a', 'b', 'c'], None, None)
-        data = args.match_signature(sig, [])
+        data = args.match_signature(sig, Defaults([]))
         new_args = args.unmatch_signature(sig, data)
         assert args.unpack() == new_args.unpack()
 
         args = make_arguments_for_translation(space, [1], {'c': 5})
         sig = Signature(['a', 'b', 'c'], None, None)
-        data = args.match_signature(sig, [2, 3])
+        data = args.match_signature(sig, Defaults([2, 3]))
         new_args = args.unmatch_signature(sig, data)
         assert args.unpack() == new_args.unpack()
 
         args = make_arguments_for_translation(space, [1], {'c': 5, 'd': 7})
         sig = Signature(['a', 'b', 'c'], None, 'kw')
-        data = args.match_signature(sig, [2, 3])
+        data = args.match_signature(sig, Defaults([2, 3]))
         new_args = args.unmatch_signature(sig, data)
         assert args.unpack() == new_args.unpack()
 
         args = make_arguments_for_translation(space, [1,2,3,4,5], {'e': 5, 'd': 7})
         sig = Signature(['a', 'b', 'c'], 'r', 'kw')
-        data = args.match_signature(sig, [2, 3])
+        data = args.match_signature(sig, Defaults([2, 3]))
         new_args = args.unmatch_signature(sig, data)
         assert args.unpack() == new_args.unpack()
 
                                        w_stararg=[1],
                                        w_starstararg={'c': 5, 'd': 7})
         sig = Signature(['a', 'b', 'c'], None, 'kw')
-        data = args.match_signature(sig, [2, 3])
+        data = args.match_signature(sig, Defaults([2, 3]))
         new_args = args.unmatch_signature(sig, data)
         assert args.unpack() == new_args.unpack()
 
                                        w_stararg=[3,4,5],
                                        w_starstararg={'e': 5, 'd': 7})
         sig = Signature(['a', 'b', 'c'], 'r', 'kw')
-        data = args.match_signature(sig, [2, 3])
+        data = args.match_signature(sig, Defaults([2, 3]))
         new_args = args.unmatch_signature(sig, data)
         assert args.unpack() == new_args.unpack()
 
         assert rawshape(args) == (2, ('g', ), True, True)
 
     def test_copy_and_shape(self):
-        space = DummySpace()        
+        space = DummySpace()
         args = ArgumentsForTranslation(space, ['a'], ['x'], [1],
                                        ['w1'], {'y': 'w2'})
         args1 = args.copy()

File pypy/interpreter/test/test_main.py

 from cStringIO import StringIO
 
-import py 
+import py
 from pypy.tool.udir import udir
 from pypy.interpreter.baseobjspace import OperationError
 from pypy.interpreter import main
 testresultoutput = '11\n'
 
 def checkoutput(space, expected_output,f,*args):
-    w_oldout = space.sys.get('stdout') 
+    w_oldout = space.sys.get('stdout')
     capturefn = udir.join('capturefile')
-    capturefile = capturefn.open('w') 
+    capturefile = capturefn.open('w')
     w_sys = space.sys.getmodule('sys')
     space.setattr(w_sys, space.wrap("stdout"), space.wrap(capturefile))
     try:
         f(*(args + (space,)))
     finally:
         space.setattr(w_sys, space.wrap("stdout"), w_oldout)
-    capturefile.close() 
+    capturefile.close()
     assert capturefn.read(mode='rU') == expected_output
 
 testfn = udir.join('tmp_hello_world.py')
 testmodule = 'tmp_hello_module'
 testpackage = 'tmp_package'
 
-class TestMain: 
+class TestMain:
     def setup_class(cls):
         testfn.write(testcode, 'w')
         udir.join(testmodule + '.py').write(testmodulecode, 'w')

File pypy/objspace/std/bytearrayobject.py

 from pypy.interpreter import gateway
 from pypy.interpreter.argument import Signature
 from pypy.interpreter.buffer import RWBuffer
+from pypy.interpreter.function import Defaults
 from pypy.objspace.std.bytearraytype import (
     makebytearraydata_w, getbytevalue,
     new_bytearray
 registerimplementation(W_BytearrayObject)
 
 init_signature = Signature(['source', 'encoding', 'errors'], None, None)
-init_defaults = [None, None, None]
+init_defaults = Defaults([None, None, None])
 
 def init__Bytearray(space, w_bytearray, __args__):
     # this is on the silly side

File pypy/objspace/std/dictmultiobject.py

 from pypy.objspace.std.model import registerimplementation, W_Object
 from pypy.objspace.std.register_all import register_all
 from pypy.interpreter import gateway
+from pypy.interpreter.argument import Signature
 from pypy.interpreter.error import OperationError, operationerrfmt
-from pypy.interpreter.argument import Signature
+from pypy.interpreter.function import Defaults
 from pypy.module.__builtin__.__init__ import BUILTIN_TO_INDEX, OPTIMIZED_BUILTINS
 
 from pypy.rlib.objectmodel import r_dict, we_are_translated
         assert self.r_dict_content is None
         self.r_dict_content = r_dict(self.space.eq_w, self.space.hash_w)
         return self.r_dict_content
-        
+
 
     def initialize_content(w_self, list_pairs_w):
         for w_k, w_v in list_pairs_w:
 
     def impl_fallback_delitem(self, w_key):
         del self.r_dict_content[w_key]
-        
+
     def impl_fallback_length(self):
         return len(self.r_dict_content)
 
     def __init__(self, space):
         self.space = space
         self.content = {}
-        
+
     def impl_setitem(self, w_key, w_value):
         space = self.space
         if space.is_w(space.type(w_key), space.w_str):
             raise KeyError
         else:
             self._as_rdict().impl_fallback_delitem(w_key)
-        
+
     def impl_length(self):
         return len(self.content)
 
 
 
 init_signature = Signature(['seq_or_map'], None, 'kwargs')
-init_defaults = [None]
+init_defaults = Defaults([None])
 
 def update1(space, w_dict, w_data):
     if space.findattr(w_data, space.wrap("keys")) is None:
         w_dict.delitem(w_key)
     except KeyError:
         space.raise_key_error(w_key)
-    
+
 def len__DictMulti(space, w_dict):
     return space.wrap(w_dict.length())
 
     return space.w_True
 
 def characterize(space, w_a, w_b):
-    """ (similar to CPython) 
+    """ (similar to CPython)
     returns the smallest key in acontent for which b's value is different or absent and this value """
     w_smallest_diff_a_key = None
     w_its_value = None
     w_rightdiff, w_rightval = characterize(space, w_right, w_left)
     if w_rightdiff is None:
         # w_leftdiff is not None, w_rightdiff is None
-        return space.w_True 
+        return space.w_True
     w_res = space.lt(w_leftdiff, w_rightdiff)
     if (not space.is_true(w_res) and
-        space.eq_w(w_leftdiff, w_rightdiff) and 
+        space.eq_w(w_leftdiff, w_rightdiff) and
         w_rightval is not None):
         w_res = space.lt(w_leftval, w_rightval)
     return w_res

File pypy/objspace/std/listobject.py

 
 from pypy.objspace.std import slicetype
 from pypy.interpreter import gateway, baseobjspace
+from pypy.interpreter.function import Defaults
 from pypy.rlib.listsort import TimSort
 from pypy.interpreter.argument import Signature
 
 
 
 init_signature = Signature(['sequence'], None, None)
-init_defaults = [None]
+init_defaults = Defaults([None])
 
 def init__List(space, w_list, __args__):
     # this is on the silly side

File pypy/objspace/std/setobject.py

 from pypy.interpreter.error import OperationError
 from pypy.interpreter import gateway
 from pypy.interpreter.argument import Signature
+from pypy.interpreter.function import Defaults
 from pypy.objspace.std.settype import set_typedef as settypedef
 from pypy.objspace.std.frozensettype import frozenset_typedef as frozensettypedef
 
     # make sure that Base is used for Set and Frozenset in multimethod
     # declarations
     @classmethod
-    def is_implementation_for(cls, typedef): 
+    def is_implementation_for(cls, typedef):
         if typedef is frozensettypedef or typedef is settypedef:
             assert cls is W_BaseSetObject
             return True
 cmp__Frozenset_frozensettypedef = cmp__Set_settypedef
 
 init_signature = Signature(['some_iterable'], None, None)
-init_defaults = [None]
+init_defaults = Defaults([None])
 def init__Set(space, w_set, __args__):
     w_iterable, = __args__.parse_obj(
             None, 'set',
                 del currently_in_repr[set_id]
             except:
                 pass
-""", filename=__file__) 
+""", filename=__file__)
 
 setrepr = app.interphook("setrepr")
 

File pypy/rpython/callparse.py

 from pypy.interpreter.argument import ArgumentsForTranslation, ArgErr
+from pypy.interpreter.function import Defaults
 from pypy.annotation import model as annmodel
 from pypy.rpython import rtuple
 from pypy.rpython.error import TyperError
         for x in graph.defaults:
             defs_h.append(ConstHolder(x))
     try:
-        holders = arguments.match_signature(signature, defs_h)
+        holders = arguments.match_signature(signature, Defaults(defs_h))
     except ArgErr, e:
         raise TyperError, "signature mismatch: %s" % e.getmsg(graph.name)
 
             v = self._emit(repr, hop)
             cache[repr] = v
             return v
-    
+
 
 class VarHolder(Holder):
 
         assert self.is_tuple()
         n = len(self.s_obj.items)
         return tuple([ItemHolder(self, i) for i in range(n)])
-        
+
     def _emit(self, repr, hop):
         return hop.inputarg(repr, arg=self.num)
 
 
     def type(self, item):
         return type(item)
-    
+