Author: martin.v.loewis
Date: Tue Aug 14 23:57:32 2007
New Revision: 57042

Modified:
   python/branches/py3k/Lib/test/test_bool.py
   python/branches/py3k/Objects/stringobject.c
Log:
Format bools properly in %d.


Modified: python/branches/py3k/Lib/test/test_bool.py
==============================================================================
--- python/branches/py3k/Lib/test/test_bool.py  (original)
+++ python/branches/py3k/Lib/test/test_bool.py  Tue Aug 14 23:57:32 2007
@@ -163,6 +163,12 @@
         self.assertIs(bool(""), False)
         self.assertIs(bool(), False)
 
+    def test_format(self):
+        self.assertEqual("%d" % False, "0")
+        self.assertEqual("%d" % True, "1")
+        self.assertEqual("%x" % False, "0")
+        self.assertEqual("%x" % True, "1")
+
     def test_hasattr(self):
         self.assertIs(hasattr([], "append"), True)
         self.assertIs(hasattr([], "wobble"), False)

Modified: python/branches/py3k/Objects/stringobject.c
==============================================================================
--- python/branches/py3k/Objects/stringobject.c (original)
+++ python/branches/py3k/Objects/stringobject.c Tue Aug 14 23:57:32 2007
@@ -4144,11 +4144,14 @@
                return NULL;
        }
 
-
        switch (type) {
        case 'd':
        case 'u':
-               result = Py_Type(val)->tp_str(val);
+               /* Special-case boolean: we want 0/1 */
+               if (PyBool_Check(val))
+                       result = PyNumber_ToBase(val, 10);
+               else
+                       result = Py_Type(val)->tp_str(val);
                break;
        case 'o':
                numnondigits = 2;
_______________________________________________
Python-3000-checkins mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000-checkins

Reply via email to