[pypy-commit] pypy default: Merged in kostialopuhin/pypy-fix1180 (pull request #70). Thanks!

amauryfa noreply at buildbot.pypy.org
Wed Jun 20 23:55:54 CEST 2012


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: 
Changeset: r55742:7be473583322
Date: 2012-06-20 23:55 +0200
http://bitbucket.org/pypy/pypy/changeset/7be473583322/

Log:	Merged in kostialopuhin/pypy-fix1180 (pull request #70). Thanks!

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,9 @@
 
 str__Bool = repr__Bool
 
+def format__Bool_ANY(space, w_bool, w_format_spec):
+    return newformat.run_formatter(
+            space, w_format_spec, "format_int_or_long", w_bool,
+            newformat.INT_KIND)
+
 register_all(vars())
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
@@ -209,6 +209,23 @@
         assert self.s("{!r}").format(x()) == self.s("32")
 
 
+class AppTestBoolFormat:
+
+    def test_str_format(self):
+        assert format(False) == "False"
+        assert format(True) == "True"
+        assert "{0}".format(True) == "True"
+        assert "{0}".format(False) == "False"
+        assert "{0} or {1}".format(True, False) == "True or False"
+        assert "{} or {}".format(True, False) == "True or False"
+
+    def test_int_delegation_format(self):
+        assert "{:f}".format(True) == "1.000000"
+        assert "{:05d}".format(False) == "00000"
+        assert "{:g}".format(True) == "1"
+
+
+
 class BaseIntegralFormattingTest:
 
     def test_simple(self):


More information about the pypy-commit mailing list