[pypy-commit] pypy less-stringly-ops: Move ._rawshape() to CallSpec
rlamy
noreply at buildbot.pypy.org
Fri Nov 22 00:02:40 CET 2013
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: less-stringly-ops
Changeset: r68275:f62d937bb4ec
Date: 2013-11-19 08:41 +0000
http://bitbucket.org/pypy/pypy/changeset/f62d937bb4ec/
Log: Move ._rawshape() to CallSpec
diff --git a/rpython/annotator/argument.py b/rpython/annotator/argument.py
--- a/rpython/annotator/argument.py
+++ b/rpython/annotator/argument.py
@@ -167,20 +167,6 @@
return cls(args_w, dict(zip(shape_keys, data_w[shape_cnt:end_keys])),
w_star)
- def flatten(self):
- """ Argument <-> list of w_objects together with "shape" information """
- shape_cnt, shape_keys, shape_star = self._rawshape()
- data_w = self.arguments_w + [self.keywords[key] for key in shape_keys]
- if shape_star:
- data_w.append(self.w_stararg)
- return (shape_cnt, shape_keys, shape_star), data_w
-
- def _rawshape(self):
- shape_cnt = len(self.arguments_w)
- shape_keys = tuple(sorted(self.keywords))
- shape_star = self.w_stararg is not None # Flag: presence of *arg
- return shape_cnt, shape_keys, shape_star
-
def rawshape(args):
return args._rawshape()
diff --git a/rpython/annotator/test/test_argument.py b/rpython/annotator/test/test_argument.py
--- a/rpython/annotator/test/test_argument.py
+++ b/rpython/annotator/test/test_argument.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
import py
from rpython.annotator.argument import ArgumentsForTranslation, rawshape
-from rpython.flowspace.argument import Signature
+from rpython.flowspace.argument import Signature, CallSpec
class MockArgs(ArgumentsForTranslation):
def newtuple(self, items):
@@ -82,28 +82,6 @@
args = MockArgs([1, 2, 3, 4, 5], {'e': 5, 'd': 7})
assert rawshape(args) == (5, ('d', 'e'), False)
- def test_flatten(self):
- args = MockArgs([1, 2, 3])
- assert args.flatten() == ((3, (), False), [1, 2, 3])
-
- args = MockArgs([1])
- assert args.flatten() == ((1, (), False), [1])
-
- args = MockArgs([1, 2, 3, 4, 5])
- assert args.flatten() == ((5, (), False), [1, 2, 3, 4, 5])
-
- args = MockArgs([1], {'c': 3, 'b': 2})
- assert args.flatten() == ((1, ('b', 'c'), False), [1, 2, 3])
-
- args = MockArgs([1], {'c': 5})
- assert args.flatten() == ((1, ('c', ), False), [1, 5])
-
- args = MockArgs([1], {'c': 5, 'd': 7})
- assert args.flatten() == ((1, ('c', 'd'), False), [1, 5, 7])
-
- args = MockArgs([1, 2, 3, 4, 5], {'e': 5, 'd': 7})
- assert args.flatten() == ((5, ('d', 'e'), False), [1, 2, 3, 4, 5, 7, 5])
-
def test_stararg_flowspace_variable(self):
var = object()
shape = ((2, ('g', ), True), [1, 2, 9, var])
diff --git a/rpython/flowspace/argument.py b/rpython/flowspace/argument.py
--- a/rpython/flowspace/argument.py
+++ b/rpython/flowspace/argument.py
@@ -93,14 +93,18 @@
def flatten(self):
""" Argument <-> list of w_objects together with "shape" information """
- shape_cnt = len(self.arguments_w) # Number of positional args
- shape_keys = tuple(sorted(self.keywords))
- shape_star = self.w_stararg is not None # Flag: presence of *arg
+ shape_cnt, shape_keys, shape_star = self._rawshape()
data_w = self.arguments_w + [self.keywords[key] for key in shape_keys]
if shape_star:
data_w.append(self.w_stararg)
return (shape_cnt, shape_keys, shape_star), data_w
+ def _rawshape(self):
+ shape_cnt = len(self.arguments_w)
+ shape_keys = tuple(sorted(self.keywords))
+ shape_star = self.w_stararg is not None # Flag: presence of *arg
+ return shape_cnt, shape_keys, shape_star
+
def as_list(self):
assert not self.keywords
if self.w_stararg is None:
diff --git a/rpython/flowspace/test/test_argument.py b/rpython/flowspace/test/test_argument.py
--- a/rpython/flowspace/test/test_argument.py
+++ b/rpython/flowspace/test/test_argument.py
@@ -1,6 +1,4 @@
-# -*- coding: utf-8 -*-
-import py
-from rpython.flowspace.argument import Signature
+from rpython.flowspace.argument import Signature, CallSpec
class TestSignature(object):
@@ -49,3 +47,27 @@
assert x == ["a", "b", "c"]
assert y == "d"
assert z == "e"
+
+
+def test_flatten_CallSpec():
+ args = CallSpec([1, 2, 3])
+ assert args.flatten() == ((3, (), False), [1, 2, 3])
+
+ args = CallSpec([1])
+ assert args.flatten() == ((1, (), False), [1])
+
+ args = CallSpec([1, 2, 3, 4, 5])
+ assert args.flatten() == ((5, (), False), [1, 2, 3, 4, 5])
+
+ args = CallSpec([1], {'c': 3, 'b': 2})
+ assert args.flatten() == ((1, ('b', 'c'), False), [1, 2, 3])
+
+ args = CallSpec([1], {'c': 5})
+ assert args.flatten() == ((1, ('c', ), False), [1, 5])
+
+ args = CallSpec([1], {'c': 5, 'd': 7})
+ assert args.flatten() == ((1, ('c', 'd'), False), [1, 5, 7])
+
+ args = CallSpec([1, 2, 3, 4, 5], {'e': 5, 'd': 7})
+ assert args.flatten() == ((5, ('d', 'e'), False), [1, 2, 3, 4, 5, 7, 5])
+
More information about the pypy-commit
mailing list