[pypy-commit] pypy default: #1180 - extend test and implement bool formatting - delegate to str
kostialopuhin
noreply at buildbot.pypy.org
Wed Jun 20 23:55:46 CEST 2012
Author: Konstantin Lopuhin <kostia.lopuhin at gmail.com>
Branch:
Changeset: r55735:e5c3ddea832e
Date: 2012-06-19 00:31 +0400
http://bitbucket.org/pypy/pypy/changeset/e5c3ddea832e/
Log: #1180 - extend test and implement bool formatting - delegate to str
diff --git a/pypy/objspace/std/boolobject.py b/pypy/objspace/std/boolobject.py
--- a/pypy/objspace/std/boolobject.py
+++ b/pypy/objspace/std/boolobject.py
@@ -1,6 +1,7 @@
from pypy.rlib.rbigint import rbigint
from pypy.rlib.rarithmetic import r_uint
from pypy.interpreter.error import OperationError
+from pypy.objspace.std import newformat
from pypy.objspace.std.model import registerimplementation, W_Object
from pypy.objspace.std.register_all import register_all
from pypy.objspace.std.intobject import W_IntObject
@@ -68,4 +69,8 @@
str__Bool = repr__Bool
+def format__Bool_ANY(space, w_bool, w_format_spec):
+ return newformat.run_formatter(
+ space, w_format_spec, "format_bool", w_bool)
+
register_all(vars())
diff --git a/pypy/objspace/std/newformat.py b/pypy/objspace/std/newformat.py
--- a/pypy/objspace/std/newformat.py
+++ b/pypy/objspace/std/newformat.py
@@ -877,6 +877,9 @@
buf[i] = "-"
assert i >= 0
return self.empty.join(buf[i:])
+
+ def format_bool(self, w_bool):
+ return self.space.str(w_bool)
def format_int_or_long(self, w_num, kind):
space = self.space
diff --git a/pypy/objspace/std/test/test_newformat.py b/pypy/objspace/std/test/test_newformat.py
--- a/pypy/objspace/std/test/test_newformat.py
+++ b/pypy/objspace/std/test/test_newformat.py
@@ -216,10 +216,8 @@
cls.w_b = cls.space.w_bool
def test_simple(self):
- # present behaviour
- # assert format(self.b(False)) == self.s("0")
- # assert format(self.b(True)) == self.s("1")
- # desired
+ assert self.s("{0}").format(self.b(True)) == self.s("True")
+ assert self.s("{0}").format(self.b(False)) == self.s("False")
assert format(self.b(False)) == self.s("False")
assert format(self.b(True)) == self.s("True")
More information about the pypy-commit
mailing list