Author: mattip <[email protected]>
Branch: 
Changeset: r80245:d924723d483b
Date: 2015-10-15 20:15 +0300
http://bitbucket.org/pypy/pypy/changeset/d924723d483b/

Log:    raise a ValueError with a clear msg when attempting to create a
        ndarray from a type(ndarray)

diff --git a/pypy/module/micronumpy/compile.py 
b/pypy/module/micronumpy/compile.py
--- a/pypy/module/micronumpy/compile.py
+++ b/pypy/module/micronumpy/compile.py
@@ -80,6 +80,7 @@
     w_dict = W_TypeObject("dict")
     w_object = W_TypeObject("object")
     w_buffer = W_TypeObject("buffer")
+    w_type = W_TypeObject("type")
 
     def __init__(self, config=None):
         """NOT_RPYTHON"""
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
@@ -86,6 +86,9 @@
 
 def _array(space, w_object, w_dtype=None, copy=True, w_order=None, 
subok=False):
 
+    # numpy testing calls array(type(array([]))) and expects a ValueError
+    if space.isinstance_w(w_object, space.w_type):
+        raise oefmt(space.w_ValueError, "cannot create ndarray from type 
instance")
     # for anything that isn't already an array, try __array__ method first
     if not isinstance(w_object, W_NDimArray):
         w_array = try_array_method(space, w_object, w_dtype)
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
@@ -292,6 +292,8 @@
         a = np.array('123', dtype='intp')
         assert a == 123
         assert a.dtype == np.intp
+        # required for numpy test suite
+        raises(ValueError, np.array, type(a))
 
     def test_array_copy(self):
         from numpy import array
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to