Author: Alex Gaynor <[email protected]>
Branch:
Changeset: r50467:9b76d833f3c4
Date: 2011-12-13 14:50 -0500
http://bitbucket.org/pypy/pypy/changeset/9b76d833f3c4/
Log: Move __debug_repr__ in micronumpy into a new numpypy.pypy module
diff --git a/pypy/module/micronumpy/__init__.py
b/pypy/module/micronumpy/__init__.py
--- a/pypy/module/micronumpy/__init__.py
+++ b/pypy/module/micronumpy/__init__.py
@@ -1,9 +1,19 @@
from pypy.interpreter.mixedmodule import MixedModule
+class PyPyModule(MixedModule):
+ interpleveldefs = {
+ 'debug_repr': 'interp_extras.debug_repr',
+ }
+ appleveldefs = {}
+
class Module(MixedModule):
applevel_name = 'numpypy'
+ submodules = {
+ 'pypy': PyPyModule
+ }
+
interpleveldefs = {
'ndarray': 'interp_numarray.W_NDimArray',
'dtype': 'interp_dtype.W_Dtype',
diff --git a/pypy/module/micronumpy/interp_extras.py
b/pypy/module/micronumpy/interp_extras.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/micronumpy/interp_extras.py
@@ -0,0 +1,7 @@
+from pypy.interpreter.gateway import unwrap_spec
+from pypy.module.micronumpy.interp_numarray import BaseArray
+
+
+@unwrap_spec(array=BaseArray)
+def debug_repr(space, array):
+ return space.wrap(array.debug_repr())
diff --git a/pypy/module/micronumpy/interp_numarray.py
b/pypy/module/micronumpy/interp_numarray.py
--- a/pypy/module/micronumpy/interp_numarray.py
+++ b/pypy/module/micronumpy/interp_numarray.py
@@ -925,9 +925,6 @@
def start_iter(self, res_shape=None):
raise NotImplementedError
- def descr_debug_repr(self, space):
- return space.wrap(self.debug_repr())
-
def descr_array_iface(self, space):
concrete = self.get_concrete()
storage = concrete.get_storage(space)
@@ -1466,7 +1463,6 @@
__repr__ = interp2app(BaseArray.descr_repr),
__str__ = interp2app(BaseArray.descr_str),
- __debug_repr__ = interp2app(BaseArray.descr_debug_repr),
__array_interface__ = GetSetProperty(BaseArray.descr_array_iface),
dtype = GetSetProperty(BaseArray.descr_get_dtype),
diff --git a/pypy/module/micronumpy/test/test_numarray.py
b/pypy/module/micronumpy/test/test_numarray.py
--- a/pypy/module/micronumpy/test/test_numarray.py
+++ b/pypy/module/micronumpy/test/test_numarray.py
@@ -873,16 +873,17 @@
def test_debug_repr(self):
from numpypy import zeros, sin
+ from numpypy.pypy import debug_repr
a = zeros(1)
- assert a.__debug_repr__() == 'Array'
- assert (a + a).__debug_repr__() == 'Call2(add, Array, Array)'
- assert (a[::2]).__debug_repr__() == 'Slice(Array)'
- assert (a + 2).__debug_repr__() == 'Call2(add, Array, Scalar)'
- assert (a + a.flat).__debug_repr__() == 'Call2(add, Array,
FlatIter(Array))'
- assert sin(a).__debug_repr__() == 'Call1(sin, Array)'
+ assert debug_repr(a) == 'Array'
+ assert debug_repr(a + a) == 'Call2(add, Array, Array)'
+ assert debug_repr(a[::2]) == 'Slice(Array)'
+ assert debug_repr(a + 2) == 'Call2(add, Array, Scalar)'
+ assert debug_repr(a + a.flat) == 'Call2(add, Array, FlatIter(Array))'
+ assert debug_repr(sin(a)) == 'Call1(sin, Array)'
b = a + a
b[0] = 3
- assert b.__debug_repr__() == 'Call2(add, forced=Array)'
+ assert debug_repr(b) == 'Call2(add, forced=Array)'
def test_tolist_scalar(self):
from numpypy import int32, bool_
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit