Commits

Ronan Lamy committed f62d937

Move ._rawshape() to CallSpec

Comments (0)

Files changed (4)

rpython/annotator/argument.py

         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()

rpython/annotator/test/test_argument.py

 # -*- 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):
         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])

rpython/flowspace/argument.py

 
     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:

rpython/flowspace/test/test_argument.py

-# -*- coding: utf-8 -*-
-import py
-from rpython.flowspace.argument import Signature
+from rpython.flowspace.argument import Signature, CallSpec
 
 
 class TestSignature(object):
         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])
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.