Author: Alex Gaynor <[email protected]>
Branch: numpy-dtype-alt
Changeset: r46775:2efe81d81230
Date: 2011-08-25 22:39 -0400
http://bitbucket.org/pypy/pypy/changeset/2efe81d81230/
Log: give dtype a shape property and set __module__ correctly
diff --git a/pypy/module/micronumpy/interp_dtype.py
b/pypy/module/micronumpy/interp_dtype.py
--- a/pypy/module/micronumpy/interp_dtype.py
+++ b/pypy/module/micronumpy/interp_dtype.py
@@ -4,7 +4,7 @@
from pypy.interpreter.baseobjspace import Wrappable
from pypy.interpreter.error import OperationError
from pypy.interpreter.gateway import interp2app
-from pypy.interpreter.typedef import TypeDef, interp_attrproperty
+from pypy.interpreter.typedef import TypeDef, interp_attrproperty,
GetSetProperty
from pypy.module.micronumpy import signature
from pypy.objspace.std.floatobject import float2string
from pypy.rlib import rfloat
@@ -44,6 +44,9 @@
def descr_str(self, space):
return space.wrap(self.name)
+ def descr_get_shape(self, space):
+ return space.newtuple([])
+
class BaseBox(object):
pass
@@ -343,6 +346,7 @@
]))
W_Dtype.typedef = TypeDef("dtype",
+ __module__ = "numpy",
__new__ = interp2app(W_Dtype.descr__new__.im_func),
__repr__ = interp2app(W_Dtype.descr_repr),
@@ -350,4 +354,5 @@
num = interp_attrproperty("num", cls=W_Dtype),
kind = interp_attrproperty("kind", cls=W_Dtype),
+ shape = GetSetProperty(W_Dtype.descr_get_shape),
)
\ No newline at end of file
diff --git a/pypy/module/micronumpy/test/test_dtypes.py
b/pypy/module/micronumpy/test/test_dtypes.py
--- a/pypy/module/micronumpy/test/test_dtypes.py
+++ b/pypy/module/micronumpy/test/test_dtypes.py
@@ -29,6 +29,7 @@
def test_repr_str(self):
from numpy import dtype
+ assert repr(dtype) == "<type 'numpy.dtype'>"
d = dtype('?')
assert repr(d) == "dtype('bool')"
assert str(d) == "bool"
@@ -86,3 +87,8 @@
b = a + a
for i in range(5):
assert b[i] == i * 2
+
+ def test_shape(self):
+ from numpy import dtype
+
+ assert dtype(long).shape == ()
\ No newline at end of file
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit