Author: Ronan Lamy <[email protected]>
Branch: translation-cleanup
Changeset: r58222:bc346586e319
Date: 2012-10-18 15:12 +0100
http://bitbucket.org/pypy/pypy/changeset/bc346586e319/
Log: copy the tests as well
diff --git a/pypy/interpreter/argument.py b/pypy/interpreter/argument.py
--- a/pypy/interpreter/argument.py
+++ b/pypy/interpreter/argument.py
@@ -504,149 +504,6 @@
w_key = keyword_names_w[i - limit]
space.setitem(w_kwds, w_key, keywords_w[i])
-class ArgumentsForTranslation(Arguments):
- def __init__(self, space, args_w, keywords=None, keywords_w=None,
- w_stararg=None, w_starstararg=None):
- self.w_stararg = w_stararg
- self.w_starstararg = w_starstararg
- self.combine_has_happened = False
- Arguments.__init__(self, space, args_w, keywords, keywords_w)
-
- def combine_if_necessary(self):
- if self.combine_has_happened:
- return
- self._combine_wrapped(self.w_stararg, self.w_starstararg)
- self.combine_has_happened = True
-
- def prepend(self, w_firstarg): # used often
- "Return a new Arguments with a new argument inserted first."
- return ArgumentsForTranslation(self.space, [w_firstarg] +
self.arguments_w,
- self.keywords, self.keywords_w,
self.w_stararg,
- self.w_starstararg)
-
- def copy(self):
- return ArgumentsForTranslation(self.space, self.arguments_w,
- self.keywords, self.keywords_w,
self.w_stararg,
- self.w_starstararg)
-
-
-
- def _match_signature(self, w_firstarg, scope_w, signature, defaults_w=None,
- blindargs=0):
- self.combine_if_necessary()
- # _match_signature is destructive
- return Arguments._match_signature(
- self, w_firstarg, scope_w, signature,
- defaults_w, blindargs)
-
- def unpack(self):
- self.combine_if_necessary()
- return Arguments.unpack(self)
-
- def match_signature(self, signature, defaults_w):
- """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)
-
- def unmatch_signature(self, signature, data_w):
- """kind of inverse of match_signature"""
- args_w, kwds_w = self.unpack()
- need_cnt = len(args_w)
- need_kwds = kwds_w.keys()
- space = self.space
- argnames, varargname, kwargname = signature
- cnt = len(argnames)
- data_args_w = data_w[:cnt]
- if varargname:
- data_w_stararg = data_w[cnt]
- cnt += 1
- else:
- data_w_stararg = space.newtuple([])
-
- unfiltered_kwds_w = {}
- if kwargname:
- data_w_starargarg = data_w[cnt]
- 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
- 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 argname, w_arg in zip(argnames[need_cnt:],
data_args_w[need_cnt:]):
- unfiltered_kwds_w[argname] = w_arg
- assert not space.is_true(data_w_stararg)
- else:
- stararg_w = space.unpackiterable(data_w_stararg)
- datalen = len(data_args_w)
- args_w = [None] * (datalen + len(stararg_w))
- for i in range(0, datalen):
- args_w[i] = data_args_w[i]
- 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]
- p = end_keys = shape_cnt + len(shape_keys)
- if shape_star:
- w_star = data_w[p]
- p += 1
- else:
- w_star = None
- if shape_stst:
- w_starstar = data_w[p]
- p += 1
- else:
- w_starstar = None
- return ArgumentsForTranslation(space, args_w, list(shape_keys),
- data_w[shape_cnt:end_keys], w_star,
- w_starstar)
-
- def flatten(self):
- """ Argument <-> list of w_objects together with "shape" information
"""
- shape_cnt, shape_keys, shape_star, shape_stst = self._rawshape()
- data_w = self.arguments_w + [self.keywords_w[self.keywords.index(key)]
- for key in shape_keys]
- if shape_star:
- data_w.append(self.w_stararg)
- if shape_stst:
- data_w.append(self.w_starstararg)
- return (shape_cnt, shape_keys, shape_star, shape_stst), data_w
-
- def _rawshape(self, nextra=0):
- assert not self.combine_has_happened
- shape_cnt = len(self.arguments_w)+nextra # Number of
positional args
- if self.keywords:
- shape_keys = self.keywords[:] # List of keywords
(strings)
- shape_keys.sort()
- else:
- shape_keys = []
- shape_star = self.w_stararg is not None # Flag: presence of *arg
- shape_stst = self.w_starstararg is not None # Flag: presence of **kwds
- return shape_cnt, tuple(shape_keys), shape_star, shape_stst #
shape_keys are sorted
-
-def rawshape(args, nextra=0):
- return args._rawshape(nextra)
-
-
#
# ArgErr family of exceptions raised in case of argument mismatch.
# We try to give error messages following CPython's, which are very
informative.
diff --git a/pypy/interpreter/test/test_argument.py
b/pypy/objspace/flow/test/test_argument.py
copy from pypy/interpreter/test/test_argument.py
copy to pypy/objspace/flow/test/test_argument.py
--- a/pypy/interpreter/test/test_argument.py
+++ b/pypy/objspace/flow/test/test_argument.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
import py
-from pypy.interpreter.argument import (Arguments, ArgumentsForTranslation,
+from pypy.objspace.flow.argument import (Arguments, ArgumentsForTranslation,
ArgErr, ArgErrUnknownKwds, ArgErrMultipleValues, ArgErrCount, rawshape,
Signature)
from pypy.interpreter.error import OperationError
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit