[pypy-commit] pypy release-2.5.x: merge default into branch

mattip noreply at buildbot.pypy.org
Mon Feb 2 22:12:20 CET 2015


Author: mattip <matti.picus at gmail.com>
Branch: release-2.5.x
Changeset: r75663:10f1b29a2bd2
Date: 2015-02-02 23:12 +0200
http://bitbucket.org/pypy/pypy/changeset/10f1b29a2bd2/

Log:	merge default into branch

diff --git a/lib_pypy/greenlet.egg-info b/lib_pypy/greenlet.egg-info
--- a/lib_pypy/greenlet.egg-info
+++ b/lib_pypy/greenlet.egg-info
@@ -1,6 +1,6 @@
 Metadata-Version: 1.0
 Name: greenlet
-Version: 0.4.0
+Version: 0.4.5
 Summary: Lightweight in-process concurrent programming
 Home-page: https://github.com/python-greenlet/greenlet
 Author: Ralf Schmitt (for CPython), PyPy team
diff --git a/lib_pypy/greenlet.py b/lib_pypy/greenlet.py
--- a/lib_pypy/greenlet.py
+++ b/lib_pypy/greenlet.py
@@ -1,7 +1,7 @@
 import sys
 import _continuation
 
-__version__ = "0.4.0"
+__version__ = "0.4.5"
 
 # ____________________________________________________________
 # Exceptions
diff --git a/pypy/module/micronumpy/ctors.py b/pypy/module/micronumpy/ctors.py
--- a/pypy/module/micronumpy/ctors.py
+++ b/pypy/module/micronumpy/ctors.py
@@ -75,22 +75,32 @@
         if order != 'C':  # or order != 'F':
             raise oefmt(space.w_ValueError, "Unknown order: %s", order)
 
-    # arrays with correct dtype
-    if isinstance(w_object, W_NDimArray) and \
-            (space.is_none(w_dtype) or w_object.get_dtype() is dtype):
-        if copy and (subok or type(w_object) is W_NDimArray):
-            return w_object.descr_copy(space, w_order)
-        elif not copy and (subok or type(w_object) is W_NDimArray):
-            return w_object
-    if isinstance(w_object, W_NDimArray) and copy and not subok:
-        # TODO do the loop.assign without copying elems_w
-        shape = w_object.get_shape()
-        _elems_w = w_object.reshape(space, space.wrap(-1))
-        elems_w = [None] * w_object.get_size()
-        for i in range(len(elems_w)):
-            elems_w[i] = _elems_w.descr_getitem(space, space.wrap(i))
-        if space.is_none(w_dtype):
+    if isinstance(w_object, W_NDimArray):
+        if (dtype is None or w_object.get_dtype() is dtype):
+            if copy and (subok or type(w_object) is W_NDimArray):
+                return w_object.descr_copy(space, w_order)
+            elif not copy and (subok or type(w_object) is W_NDimArray):
+                return w_object
+        # we have a ndarray, but need to copy or change dtype or create W_NDimArray
+        if dtype is None:
             dtype = w_object.get_dtype()
+        if dtype != w_object.get_dtype():
+            # silently reject the copy value
+            copy = True
+        if copy:
+            shape = w_object.get_shape()
+            _elems_w = w_object.reshape(space, space.wrap(-1))
+            elems_w = [None] * w_object.get_size()
+            for i in range(len(elems_w)):
+                elems_w[i] = _elems_w.descr_getitem(space, space.wrap(i))
+        elif subok:
+            raise oefmt(space.w_NotImplementedError, 
+                "array(...copy=False, subok=True) not implemented yet")
+        else:
+            sz = support.product(w_object.get_shape()) * dtype.elsize
+            return W_NDimArray.from_shape_and_storage(space,
+                w_object.get_shape(),w_object.implementation.storage,
+                dtype, storage_bytes=sz, w_base=w_object)
     else:
         # not an array
         shape, elems_w = strides.find_shape_and_elems(space, w_object, dtype)
diff --git a/pypy/module/micronumpy/test/test_subtype.py b/pypy/module/micronumpy/test/test_subtype.py
--- a/pypy/module/micronumpy/test/test_subtype.py
+++ b/pypy/module/micronumpy/test/test_subtype.py
@@ -268,7 +268,7 @@
         c = array(a, float)
         assert c.dtype is dtype(float)
 
-    def test__getitem_modifies_shape(self):
+    def test_array_of_subtype(self):
         import numpy as N
         # numpy's matrix class caused an infinite loop
         class matrix(N.ndarray):
@@ -309,8 +309,14 @@
         a = matrix([[1., 2.], [3., 4.]])
         b = N.array([a])
         assert (b == a).all()
+
         b = N.array(a)
         assert len(b.shape) == 2
+        assert (b == a).all()
+
+        b = N.array(a, copy=False)
+        assert len(b.shape) == 2
+        assert (b == a).all()
 
     def test_setstate_no_version(self):
         # Some subclasses of ndarray, like MaskedArray, do not use
diff --git a/pypy/module/micronumpy/test/test_ufuncs.py b/pypy/module/micronumpy/test/test_ufuncs.py
--- a/pypy/module/micronumpy/test/test_ufuncs.py
+++ b/pypy/module/micronumpy/test/test_ufuncs.py
@@ -220,6 +220,9 @@
         af = arange(10, dtype=float)
         af2 = ufunc(af)
         assert all(af2 == af * 2)
+        ac = arange(10, dtype=complex)
+        skip('casting not implemented yet')
+        ac1 = ufunc(ac)
 
     def test_frompyfunc_2d_sig(self):
         def times_2(in_array, out_array):
diff --git a/pypy/module/micronumpy/ufuncs.py b/pypy/module/micronumpy/ufuncs.py
--- a/pypy/module/micronumpy/ufuncs.py
+++ b/pypy/module/micronumpy/ufuncs.py
@@ -774,8 +774,13 @@
                 break
         else:
             if len(self.funcs) > 1:
-                dtypesstr = ','.join(['%s%s%s' % (d.byteorder, d.kind, d.elsize) \
-                                 for d in dtypes])
+                
+                dtypesstr = ''
+                for d in dtypes:
+                    if d is None:
+                        dtypesstr += 'None,'
+                    else:
+                        dtypesstr += '%s%s%s,' % (d.byteorder, d.kind, d.elsize)
                 _dtypesstr = ','.join(['%s%s%s' % (d.byteorder, d.kind, d.elsize) \
                                 for d in _dtypes])
                 raise oefmt(space.w_TypeError,
diff --git a/rpython/rlib/rfile.py b/rpython/rlib/rfile.py
--- a/rpython/rlib/rfile.py
+++ b/rpython/rlib/rfile.py
@@ -535,3 +535,9 @@
     def isatty(self):
         self._check_closed()
         return os.isatty(c_fileno(self._ll_file))
+
+    def __enter__(self):
+        return self
+
+    def __exit__(self, *args):
+        self.close()
diff --git a/rpython/rlib/test/test_rfile.py b/rpython/rlib/test/test_rfile.py
--- a/rpython/rlib/test/test_rfile.py
+++ b/rpython/rlib/test/test_rfile.py
@@ -26,6 +26,7 @@
 
         f()
         assert open(fname, "r").read() == "dupa"
+        os.unlink(fname)
         self.interpret(f, [])
         assert open(fname, "r").read() == "dupa"
 
@@ -102,6 +103,7 @@
             f2.close()
 
         f()
+        os.unlink(fname)
         self.interpret(f, [])
 
     @py.test.mark.skipif("sys.platform == 'win32'")
@@ -121,6 +123,7 @@
             f2.close()
 
         f()
+        os.unlink(fname)
         self.interpret(f, [])
 
     def test_open_buffering_full(self):
@@ -138,6 +141,7 @@
             f2.close()
 
         f()
+        os.unlink(fname)
         self.interpret(f, [])
 
     def test_fdopen_buffering_full(self):
@@ -157,6 +161,7 @@
             f2.close()
 
         f()
+        os.unlink(fname)
         self.interpret(f, [])
 
     def test_read_write(self):
@@ -203,6 +208,7 @@
                 f2.close()
 
         f()
+        os.unlink(fname)
         self.interpret(f, [])
 
     def test_read_sequentially(self):
@@ -277,6 +283,7 @@
             f.close()
 
         f()
+        os.unlink(fname)
         self.interpret(f, [])
 
     def test_tempfile(self):
@@ -309,6 +316,7 @@
 
         f()
         assert open(fname).read() == "xxx"
+        os.unlink(fname)
         self.interpret(f, [])
         assert open(fname).read() == "xxx"
 
@@ -325,6 +333,7 @@
 
         res = f()
         assert res > 2
+        os.unlink(fname)
         res = self.interpret(f, [])
         assert res > 2
 
@@ -341,6 +350,7 @@
 
         res = f()
         assert res == 3
+        os.unlink(fname)
         res = self.interpret(f, [])
         assert res == 3
 
@@ -357,6 +367,7 @@
             f.close()
 
         f()
+        os.unlink(fname)
         self.interpret(f, [])
 
     def test_truncate(self):
@@ -381,8 +392,28 @@
             f.close()
 
         f()
+        os.unlink(fname)
         self.interpret(f, [])
 
+    def test_with_statement(self):
+        fname = str(self.tmpdir.join('file_6'))
+
+        def f():
+            with open(fname, "w") as f:
+                f.write("dupa")
+            try:
+                f.write("dupb")
+            except ValueError:
+                pass
+            else:
+                assert False
+
+        f()
+        assert open(fname, "r").read() == "dupa"
+        os.unlink(fname)
+        self.interpret(f, [])
+        assert open(fname, "r").read() == "dupa"
+
 
 class TestDirect:
     def setup_class(cls):


More information about the pypy-commit mailing list