[pypy-commit] pypy default: make numpy boxes work with str.format
alex_gaynor
noreply at buildbot.pypy.org
Wed Feb 22 02:49:47 CET 2012
Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch:
Changeset: r52754:dde74845c41f
Date: 2012-02-21 20:48 -0500
http://bitbucket.org/pypy/pypy/changeset/dde74845c41f/
Log: make numpy boxes work with str.format
diff --git a/pypy/module/micronumpy/interp_boxes.py b/pypy/module/micronumpy/interp_boxes.py
--- a/pypy/module/micronumpy/interp_boxes.py
+++ b/pypy/module/micronumpy/interp_boxes.py
@@ -39,10 +39,10 @@
)
def descr_str(self, space):
- return self.descr_repr(space)
+ return space.wrap(self.get_dtype(space).itemtype.str_format(self))
- def descr_repr(self, space):
- return space.wrap(self.get_dtype(space).itemtype.str_format(self))
+ def descr_format(self, space, w_spec):
+ return space.format(self.item(space), w_spec)
def descr_int(self, space):
box = self.convert_to(W_LongBox.get_dtype(space))
@@ -194,7 +194,8 @@
__new__ = interp2app(W_GenericBox.descr__new__.im_func),
__str__ = interp2app(W_GenericBox.descr_str),
- __repr__ = interp2app(W_GenericBox.descr_repr),
+ __repr__ = interp2app(W_GenericBox.descr_str),
+ __format__ = interp2app(W_GenericBox.descr_format),
__int__ = interp2app(W_GenericBox.descr_int),
__float__ = interp2app(W_GenericBox.descr_float),
__nonzero__ = interp2app(W_GenericBox.descr_nonzero),
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
@@ -371,7 +371,7 @@
assert type(a[1]) is numpy.float64
assert numpy.dtype(float).type is numpy.float64
- assert "{}".format(numpy.float64(3)) == "3.0"
+ assert "{:3f}".format(numpy.float64(3)) == "3.000000"
assert numpy.float64(2.0) == 2.0
assert numpy.float64('23.4') == numpy.float64(23.4)
More information about the pypy-commit
mailing list