[pypy-commit] pypy default: merge heads

arigo noreply at buildbot.pypy.org
Wed May 20 11:09:16 CEST 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r77425:81a9cd687854
Date: 2015-05-20 11:09 +0200
http://bitbucket.org/pypy/pypy/changeset/81a9cd687854/

Log:	merge heads

diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst
--- a/pypy/doc/whatsnew-head.rst
+++ b/pypy/doc/whatsnew-head.rst
@@ -114,3 +114,7 @@
 
 branch numpy-flags
 Finish implementation of ndarray.flags, including str() and repr()
+
+.. branch: cffi-1.0
+
+PyPy now includes CFFI 1.0.
diff --git a/pypy/module/_cffi_backend/test/test_file.py b/pypy/module/_cffi_backend/test/test_file.py
--- a/pypy/module/_cffi_backend/test/test_file.py
+++ b/pypy/module/_cffi_backend/test/test_file.py
@@ -20,7 +20,8 @@
     from pypy.module._cffi_backend import VERSION
     line = "Version: %s\n" % VERSION
     eggfile = py.path.local(__file__).join('..', '..', '..', '..', '..',
-                                           'lib_pypy', 'cffi.egg-info')
+                                           'lib_pypy', 'cffi.egg-info',
+                                           'PKG-INFO')
     assert line in eggfile.readlines()
 
 def test_app_version():
diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -1110,6 +1110,10 @@
     trunk_include = pypydir.dirpath() / 'include'
     copy_header_files(trunk_include)
 
+def _load_from_cffi(space, name, path, initptr):
+    from pypy.module._cffi_backend import cffi1_module
+    cffi1_module.load_cffi1_module(space, name, path, initptr)
+
 @unwrap_spec(path=str, name=str)
 def load_extension_module(space, path, name):
     # note: this is used both to load CPython-API-style C extension
@@ -1142,8 +1146,7 @@
             pass
         else:
             try:
-                from pypy.module._cffi_backend import cffi1_module
-                cffi1_module.load_cffi1_module(space, name, path, initptr)
+                _load_from_cffi(space, name, path, initptr)
             except:
                 rdynload.dlclose(dll)
                 raise
diff --git a/pypy/module/micronumpy/boxes.py b/pypy/module/micronumpy/boxes.py
--- a/pypy/module/micronumpy/boxes.py
+++ b/pypy/module/micronumpy/boxes.py
@@ -193,7 +193,7 @@
                     "'%T' object is not iterable", self)
 
     def descr_str(self, space):
-        return space.wrap(self.get_dtype(space).itemtype.str_format(self))
+        return space.wrap(self.get_dtype(space).itemtype.str_format(self, add_quotes=False))
 
     def descr_format(self, space, w_spec):
         return space.format(self.item(space), w_spec)
diff --git a/pypy/module/micronumpy/ndarray.py b/pypy/module/micronumpy/ndarray.py
--- a/pypy/module/micronumpy/ndarray.py
+++ b/pypy/module/micronumpy/ndarray.py
@@ -277,7 +277,7 @@
             if self.is_scalar() and dtype.is_str():
                 s.append(dtype.itemtype.to_str(i.getitem(state)))
             else:
-                s.append(dtype.itemtype.str_format(i.getitem(state)))
+                s.append(dtype.itemtype.str_format(i.getitem(state), add_quotes=True))
             state = i.next(state)
         if not self.is_scalar():
             s.append(']')
diff --git a/pypy/module/micronumpy/test/test_ndarray.py b/pypy/module/micronumpy/test/test_ndarray.py
--- a/pypy/module/micronumpy/test/test_ndarray.py
+++ b/pypy/module/micronumpy/test/test_ndarray.py
@@ -3468,6 +3468,9 @@
         assert str(array('abc')) == 'abc'
         assert str(array(1.5)) == '1.5'
         assert str(array(1.5).real) == '1.5'
+        arr = array(['abc', 'abc'])
+        for a in arr.flat:
+             assert str(a) == 'abc'
 
     def test_ndarray_buffer_strides(self):
         from numpy import ndarray, array
diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py
--- a/pypy/module/micronumpy/types.py
+++ b/pypy/module/micronumpy/types.py
@@ -388,7 +388,7 @@
     def to_builtin_type(self, space, w_item):
         return space.wrap(self.unbox(w_item))
 
-    def str_format(self, box):
+    def str_format(self, box, add_quotes=True):
         return "True" if self.unbox(box) else "False"
 
     @staticmethod
@@ -454,7 +454,7 @@
     def _coerce(self, space, w_item):
         return self._base_coerce(space, w_item)
 
-    def str_format(self, box):
+    def str_format(self, box, add_quotes=True):
         return str(self.for_computation(self.unbox(box)))
 
     @staticmethod
@@ -727,7 +727,7 @@
             return self.box(rfloat.NAN)
         return self.box(space.float_w(space.call_function(space.w_float, w_item)))
 
-    def str_format(self, box):
+    def str_format(self, box, add_quotes=True):
         return float2string(self.for_computation(self.unbox(box)), "g",
                             rfloat.DTSF_STR_PRECISION)
 
@@ -1132,7 +1132,7 @@
         w_obj.__init__(w_tmpobj.real, w_tmpobj.imag)
         return w_obj
 
-    def str_format(self, box):
+    def str_format(self, box, add_quotes=True):
         real, imag = self.for_computation(self.unbox(box))
         imag_str = str_format(imag)
         if not rfloat.isfinite(imag):
@@ -1862,7 +1862,7 @@
         w_obj = self.space.newcomplex(real, imag)
         return self.BoxType(w_obj)
 
-    def str_format(self, box):
+    def str_format(self, box, add_quotes=True):
         return self.space.str_w(self.space.repr(self.unbox(box)))
 
     def runpack_str(self, space, s):
@@ -2122,11 +2122,13 @@
             dtype = arr.dtype
         return boxes.W_StringBox(arr, i + offset, dtype)
 
-    def str_format(self, item):
+    def str_format(self, item, add_quotes=True):
         builder = StringBuilder()
-        builder.append("'")
+        if add_quotes:
+            builder.append("'")
         builder.append(self.to_str(item))
-        builder.append("'")
+        if add_quotes:
+            builder.append("'")
         return builder.build()
 
     # XXX move the rest of this to base class when UnicodeType is supported
@@ -2209,7 +2211,7 @@
     def read(self, arr, i, offset, dtype=None):
         raise oefmt(self.space.w_NotImplementedError, "unicode type not completed")
 
-    def str_format(self, item):
+    def str_format(self, item, add_quotes=True):
         raise oefmt(self.space.w_NotImplementedError, "unicode type not completed")
 
     def to_builtin_type(self, space, box):
@@ -2314,7 +2316,7 @@
         return boxes.W_VoidBox(arr, i + offset, dtype)
 
     @jit.unroll_safe
-    def str_format(self, box):
+    def str_format(self, box, add_quotes=True):
         assert isinstance(box, boxes.W_VoidBox)
         arr = self.readarray(box.arr, box.ofs, 0, box.dtype)
         return arr.dump_data(prefix='', suffix='')
@@ -2425,7 +2427,7 @@
         return space.newtuple(items)
 
     @jit.unroll_safe
-    def str_format(self, box):
+    def str_format(self, box, add_quotes=True):
         assert isinstance(box, boxes.W_VoidBox)
         pieces = ["("]
         first = True
@@ -2437,7 +2439,7 @@
             else:
                 pieces.append(", ")
             val = tp.read(box.arr, box.ofs, ofs, subdtype)
-            pieces.append(tp.str_format(val))
+            pieces.append(tp.str_format(val, add_quotes=add_quotes))
         pieces.append(")")
         return "".join(pieces)
 


More information about the pypy-commit mailing list