aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib_pypy/greenlet.egg-info2
-rw-r--r--lib_pypy/greenlet.py2
-rw-r--r--pypy/module/micronumpy/ctors.py40
-rw-r--r--pypy/module/micronumpy/test/test_subtype.py8
-rw-r--r--pypy/module/micronumpy/test/test_ufuncs.py3
-rw-r--r--pypy/module/micronumpy/ufuncs.py9
-rw-r--r--rpython/rlib/rfile.py6
-rw-r--r--rpython/rlib/test/test_rfile.py31
8 files changed, 81 insertions, 20 deletions
diff --git a/lib_pypy/greenlet.egg-info b/lib_pypy/greenlet.egg-info
index e28ff25b91..085bc5cc6e 100644
--- 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
index 038b224ff4..b1d8918e7c 100644
--- 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
index b0497166d4..2cdef6f2af 100644
--- a/pypy/module/micronumpy/ctors.py
+++ b/pypy/module/micronumpy/ctors.py
@@ -75,22 +75,32 @@ def _array(space, w_object, w_dtype=None, copy=True, w_order=None, subok=False):
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
index 97aa18864a..268a9d6729 100644
--- a/pypy/module/micronumpy/test/test_subtype.py
+++ b/pypy/module/micronumpy/test/test_subtype.py
@@ -268,7 +268,7 @@ class AppTestSupport(BaseNumpyAppTest):
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 @@ class AppTestSupport(BaseNumpyAppTest):
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
index 5654441abe..88c66cefcd 100644
--- a/pypy/module/micronumpy/test/test_ufuncs.py
+++ b/pypy/module/micronumpy/test/test_ufuncs.py
@@ -220,6 +220,9 @@ class AppTestUfuncs(BaseNumpyAppTest):
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
index d8e0fcbbd2..85c73fd1ab 100644
--- a/pypy/module/micronumpy/ufuncs.py
+++ b/pypy/module/micronumpy/ufuncs.py
@@ -774,8 +774,13 @@ class W_UfuncGeneric(W_Ufunc):
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
index bc13cc467d..23fb199fbd 100644
--- a/rpython/rlib/rfile.py
+++ b/rpython/rlib/rfile.py
@@ -535,3 +535,9 @@ class RFile(object):
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
index b29cfbf216..ff816495f1 100644
--- a/rpython/rlib/test/test_rfile.py
+++ b/rpython/rlib/test/test_rfile.py
@@ -26,6 +26,7 @@ class TestFile(BaseRtypingTest):
f()
assert open(fname, "r").read() == "dupa"
+ os.unlink(fname)
self.interpret(f, [])
assert open(fname, "r").read() == "dupa"
@@ -102,6 +103,7 @@ class TestFile(BaseRtypingTest):
f2.close()
f()
+ os.unlink(fname)
self.interpret(f, [])
@py.test.mark.skipif("sys.platform == 'win32'")
@@ -121,6 +123,7 @@ class TestFile(BaseRtypingTest):
f2.close()
f()
+ os.unlink(fname)
self.interpret(f, [])
def test_open_buffering_full(self):
@@ -138,6 +141,7 @@ class TestFile(BaseRtypingTest):
f2.close()
f()
+ os.unlink(fname)
self.interpret(f, [])
def test_fdopen_buffering_full(self):
@@ -157,6 +161,7 @@ class TestFile(BaseRtypingTest):
f2.close()
f()
+ os.unlink(fname)
self.interpret(f, [])
def test_read_write(self):
@@ -203,6 +208,7 @@ class TestFile(BaseRtypingTest):
f2.close()
f()
+ os.unlink(fname)
self.interpret(f, [])
def test_read_sequentially(self):
@@ -277,6 +283,7 @@ class TestFile(BaseRtypingTest):
f.close()
f()
+ os.unlink(fname)
self.interpret(f, [])
def test_tempfile(self):
@@ -309,6 +316,7 @@ class TestFile(BaseRtypingTest):
f()
assert open(fname).read() == "xxx"
+ os.unlink(fname)
self.interpret(f, [])
assert open(fname).read() == "xxx"
@@ -325,6 +333,7 @@ class TestFile(BaseRtypingTest):
res = f()
assert res > 2
+ os.unlink(fname)
res = self.interpret(f, [])
assert res > 2
@@ -341,6 +350,7 @@ class TestFile(BaseRtypingTest):
res = f()
assert res == 3
+ os.unlink(fname)
res = self.interpret(f, [])
assert res == 3
@@ -357,6 +367,7 @@ class TestFile(BaseRtypingTest):
f.close()
f()
+ os.unlink(fname)
self.interpret(f, [])
def test_truncate(self):
@@ -381,8 +392,28 @@ class TestFile(BaseRtypingTest):
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):