[pypy-commit] pypy numpy-dtype: Add num and kind attributes to dtype
justinpeel
noreply at buildbot.pypy.org
Tue Aug 2 21:28:47 CEST 2011
Author: Justin Peel <notmuchtotell at gmail.com>
Branch: numpy-dtype
Changeset: r46218:83b6f9331702
Date: 2011-08-02 13:29 -0600
http://bitbucket.org/pypy/pypy/changeset/83b6f9331702/
Log: Add num and kind attributes to dtype
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
@@ -1,7 +1,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
+from pypy.interpreter.typedef import TypeDef, GetSetProperty
from pypy.rlib.rarithmetic import r_int, r_uint, LONG_BIT, LONGLONG_BIT
_letters_to_nums = [-1]*128
@@ -58,6 +58,12 @@
self.num = num
self.kind = kind
+ def descr_num(self, space):
+ return space.wrap(self.num)
+
+ def descr_kind(self, space):
+ return space.wrap(self.kind)
+
def conv_float(space, val):
return space.float(val)
@@ -120,4 +126,7 @@
Dtype.typedef = TypeDef(
'numpy.dtype',
__new__ = interp2app(descr_new_dtype),
+
+ num = GetSetProperty(Dtype.descr_num),
+ kind = GetSetProperty(Dtype.descr_kind),
)
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
@@ -6,3 +6,5 @@
def test_dtype(self):
from numpy import dtype
d = dtype('l')
+ assert d.num == 7
+ assert d.kind == 'i'
More information about the pypy-commit
mailing list