[pypy-svn] pypy default: Try to propogate the immutability of defaults through the code more, fixes the 3 failing pypy_c tests
alex_gaynor
commits-noreply at bitbucket.org
Mon Mar 21 14:06:22 CET 2011
Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch:
Changeset: r42810:ddca225a0078
Date: 2011-03-21 09:05 -0400
http://bitbucket.org/pypy/pypy/changeset/ddca225a0078/
Log: Try to propogate the immutability of defaults through the code more,
fixes the 3 failing pypy_c tests
diff --git a/pypy/objspace/std/listobject.py b/pypy/objspace/std/listobject.py
--- a/pypy/objspace/std/listobject.py
+++ b/pypy/objspace/std/listobject.py
@@ -8,6 +8,7 @@
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
@@ -32,7 +33,7 @@
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
diff --git a/pypy/interpreter/function.py b/pypy/interpreter/function.py
--- a/pypy/interpreter/function.py
+++ b/pypy/interpreter/function.py
@@ -30,6 +30,12 @@
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,
@@ -142,7 +148,7 @@
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)
@@ -175,12 +181,12 @@
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()
diff --git a/pypy/interpreter/argument.py b/pypy/interpreter/argument.py
--- a/pypy/interpreter/argument.py
+++ b/pypy/interpreter/argument.py
@@ -77,13 +77,13 @@
if i == 2:
return self.kwargname
raise IndexError
-
+
class Arguments(object):
"""
Collects the arguments of a function call.
-
+
Instances should be considered immutable.
"""
@@ -146,7 +146,7 @@
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)
@@ -236,10 +236,10 @@
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.
@@ -247,19 +247,19 @@
"""
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
@@ -283,10 +283,10 @@
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)
@@ -327,7 +327,7 @@
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
@@ -357,12 +357,12 @@
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
@@ -382,20 +382,20 @@
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.
@@ -403,32 +403,32 @@
"""
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):
@@ -473,24 +473,24 @@
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"""
@@ -513,10 +513,10 @@
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]
@@ -532,19 +532,19 @@
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]
@@ -596,23 +596,23 @@
#
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()
@@ -620,7 +620,7 @@
n = self.expected_nargs
if n == 0:
msg = "%s() takes no argument (%d given)" % (
- fnname,
+ fnname,
nargs)
else:
defcount = self.num_defaults
diff --git a/pypy/interpreter/pycode.py b/pypy/interpreter/pycode.py
--- a/pypy/interpreter/pycode.py
+++ b/pypy/interpreter/pycode.py
@@ -204,7 +204,7 @@
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()
@@ -217,7 +217,7 @@
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()
diff --git a/pypy/rpython/callparse.py b/pypy/rpython/callparse.py
--- a/pypy/rpython/callparse.py
+++ b/pypy/rpython/callparse.py
@@ -1,4 +1,5 @@
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
@@ -52,7 +53,7 @@
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)
@@ -80,7 +81,7 @@
v = self._emit(repr, hop)
cache[repr] = v
return v
-
+
class VarHolder(Holder):
@@ -95,7 +96,7 @@
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)
@@ -186,4 +187,4 @@
def type(self, item):
return type(item)
-
+
diff --git a/pypy/annotation/description.py b/pypy/annotation/description.py
--- a/pypy/annotation/description.py
+++ b/pypy/annotation/description.py
@@ -3,6 +3,7 @@
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
@@ -15,7 +16,7 @@
overridden = False
normalized = False
modified = True
-
+
def __init__(self, desc):
self.descs = { desc: True }
self.calltables = {} # see calltable_lookup_row()
@@ -172,7 +173,7 @@
class FunctionDesc(Desc):
knowntype = types.FunctionType
overridden = False
-
+
def __init__(self, bookkeeper, pyobj=None,
name=None, signature=None, defaults=None,
specializer=None):
@@ -230,7 +231,7 @@
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)
@@ -250,7 +251,7 @@
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
@@ -291,7 +292,7 @@
def bind_under(self, classdef, name):
# XXX static methods
- return self.bookkeeper.getmethoddesc(self,
+ return self.bookkeeper.getmethoddesc(self,
classdef, # originclassdef,
None, # selfclassdef
name)
@@ -574,7 +575,7 @@
while name not in cdesc.classdict:
cdesc = cdesc.basedesc
if cdesc is None:
- return None
+ return None
else:
return cdesc
@@ -750,7 +751,7 @@
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
@@ -803,7 +804,7 @@
# 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
@@ -894,7 +895,7 @@
return s_ImpossibleValue
else:
return self.bookkeeper.immutablevalue(value)
-
+
def create_new_attribute(self, name, value):
try:
self.read_attribute(name)
@@ -946,7 +947,7 @@
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]
diff --git a/pypy/objspace/std/bytearrayobject.py b/pypy/objspace/std/bytearrayobject.py
--- a/pypy/objspace/std/bytearrayobject.py
+++ b/pypy/objspace/std/bytearrayobject.py
@@ -22,6 +22,7 @@
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
@@ -42,7 +43,7 @@
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
diff --git a/pypy/interpreter/test/test_argument.py b/pypy/interpreter/test/test_argument.py
--- a/pypy/interpreter/test/test_argument.py
+++ b/pypy/interpreter/test/test_argument.py
@@ -1,8 +1,9 @@
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):
@@ -69,7 +70,7 @@
return list(it)
def listview(self, it):
- return list(it)
+ return list(it)
def unpackiterable(self, it):
return list(it)
@@ -158,18 +159,18 @@
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, [])
@@ -183,7 +184,7 @@
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]
@@ -231,7 +232,7 @@
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)
@@ -256,24 +257,24 @@
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, "**"))
@@ -354,9 +355,10 @@
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))
@@ -365,7 +367,7 @@
[], 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
@@ -374,15 +376,15 @@
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,
@@ -411,9 +413,10 @@
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]
@@ -426,17 +429,17 @@
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,
@@ -468,7 +471,7 @@
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()
@@ -508,25 +511,25 @@
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)"
@@ -600,7 +603,7 @@
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()
@@ -612,25 +615,25 @@
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()
@@ -638,7 +641,7 @@
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()
@@ -646,7 +649,7 @@
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()
@@ -684,7 +687,7 @@
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()
diff --git a/pypy/objspace/std/dictmultiobject.py b/pypy/objspace/std/dictmultiobject.py
--- a/pypy/objspace/std/dictmultiobject.py
+++ b/pypy/objspace/std/dictmultiobject.py
@@ -2,8 +2,9 @@
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
@@ -67,7 +68,7 @@
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:
@@ -188,7 +189,7 @@
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)
@@ -305,7 +306,7 @@
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):
@@ -326,7 +327,7 @@
raise KeyError
else:
self._as_rdict().impl_fallback_delitem(w_key)
-
+
def impl_length(self):
return len(self.content)
@@ -605,7 +606,7 @@
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:
@@ -670,7 +671,7 @@
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())
@@ -701,7 +702,7 @@
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
@@ -735,10 +736,10 @@
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
diff --git a/pypy/interpreter/gateway.py b/pypy/interpreter/gateway.py
--- a/pypy/interpreter/gateway.py
+++ b/pypy/interpreter/gateway.py
@@ -594,7 +594,7 @@
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:
diff --git a/pypy/interpreter/test/test_main.py b/pypy/interpreter/test/test_main.py
--- a/pypy/interpreter/test/test_main.py
+++ b/pypy/interpreter/test/test_main.py
@@ -1,6 +1,6 @@
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
@@ -25,23 +25,23 @@
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')
diff --git a/pypy/objspace/std/setobject.py b/pypy/objspace/std/setobject.py
--- a/pypy/objspace/std/setobject.py
+++ b/pypy/objspace/std/setobject.py
@@ -5,6 +5,7 @@
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
@@ -14,7 +15,7 @@
# 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
@@ -619,7 +620,7 @@
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',
@@ -641,7 +642,7 @@
del currently_in_repr[set_id]
except:
pass
-""", filename=__file__)
+""", filename=__file__)
setrepr = app.interphook("setrepr")
More information about the Pypy-commit
mailing list