]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #28916: Correct description of %o and %x alternative forms
authorMartin Panter <vadmium+py@gmail.com>
Sun, 11 Dec 2016 01:07:29 +0000 (01:07 +0000)
committerMartin Panter <vadmium+py@gmail.com>
Sun, 11 Dec 2016 01:07:29 +0000 (01:07 +0000)
* In Python 3, the specifier is 0o
* There is no special case for leading zeros
* Remove duplicate tests
* Clarify other existing tests and comments

Doc/library/stdtypes.rst
Lib/test/test_format.py

index 5936c6845912bd07f286cd35abd3ad0ce4bef767..5690611bb73dfb3f89f1e879445820730758eb24 100644 (file)
@@ -2193,15 +2193,12 @@ The conversion types are:
 Notes:
 
 (1)
-   The alternate form causes a leading zero (``'0'``) to be inserted between
-   left-hand padding and the formatting of the number if the leading character
-   of the result is not already a zero.
+   The alternate form causes a leading octal specifier (``'0o'``) to be
+   inserted before the first digit.
 
 (2)
    The alternate form causes a leading ``'0x'`` or ``'0X'`` (depending on whether
-   the ``'x'`` or ``'X'`` format was used) to be inserted between left-hand padding
-   and the formatting of the number if the leading character of the result is not
-   already a zero.
+   the ``'x'`` or ``'X'`` format was used) to be inserted before the first digit.
 
 (3)
    The alternate form causes the result to always contain a decimal point, even if
@@ -3294,15 +3291,12 @@ The conversion types are:
 Notes:
 
 (1)
-   The alternate form causes a leading zero (``'0'``) to be inserted between
-   left-hand padding and the formatting of the number if the leading character
-   of the result is not already a zero.
+   The alternate form causes a leading octal specifier (``'0o'``) to be
+   inserted before the first digit.
 
 (2)
    The alternate form causes a leading ``'0x'`` or ``'0X'`` (depending on whether
-   the ``'x'`` or ``'X'`` format was used) to be inserted between left-hand padding
-   and the formatting of the number if the leading character of the result is not
-   already a zero.
+   the ``'x'`` or ``'X'`` format was used) to be inserted before the first digit.
 
 (3)
    The alternate form causes the result to always contain a decimal point, even if
index 9b13632591a3ad0cf15763a2f0c186cbeac0a08c..699b717dac02b5c3d02b5aa11ac8260b73885219 100644 (file)
@@ -200,42 +200,28 @@ class FormatTest(unittest.TestCase):
         testcommon("%#+37.34o", big, "+0o0012345670123456701234567012345670")
         # next one gets one leading zero from precision
         testcommon("%.33o", big, "012345670123456701234567012345670")
-        # base marker shouldn't change that, since "0" is redundant
+        # base marker added in spite of leading zero (different to Python 2)
         testcommon("%#.33o", big, "0o012345670123456701234567012345670")
-        # but reduce precision, and base marker should add a zero
+        # reduce precision, and base marker is always added
         testcommon("%#.32o", big, "0o12345670123456701234567012345670")
-        # one leading zero from precision, and another from "0" flag & width
-        testcommon("%034.33o", big, "0012345670123456701234567012345670")
-        # base marker shouldn't change that
-        testcommon("%0#34.33o", big, "0o012345670123456701234567012345670")
+        # one leading zero from precision, plus two from "0" flag & width
+        testcommon("%035.33o", big, "00012345670123456701234567012345670")
+        # base marker shouldn't change the size
+        testcommon("%0#35.33o", big, "0o012345670123456701234567012345670")
         # Some small ints, in both Python int and flavors).
         testcommon("%d", 42, "42")
         testcommon("%d", -42, "-42")
-        testcommon("%d", 42, "42")
-        testcommon("%d", -42, "-42")
         testcommon("%d", 42.0, "42")
         testcommon("%#x", 1, "0x1")
-        testcommon("%#x", 1, "0x1")
-        testcommon("%#X", 1, "0X1")
         testcommon("%#X", 1, "0X1")
         testcommon("%#o", 1, "0o1")
-        testcommon("%#o", 1, "0o1")
-        testcommon("%#o", 0, "0o0")
         testcommon("%#o", 0, "0o0")
         testcommon("%o", 0, "0")
-        testcommon("%o", 0, "0")
         testcommon("%d", 0, "0")
-        testcommon("%d", 0, "0")
-        testcommon("%#x", 0, "0x0")
         testcommon("%#x", 0, "0x0")
         testcommon("%#X", 0, "0X0")
-        testcommon("%#X", 0, "0X0")
         testcommon("%x", 0x42, "42")
         testcommon("%x", -0x42, "-42")
-        testcommon("%x", 0x42, "42")
-        testcommon("%x", -0x42, "-42")
-        testcommon("%o", 0o42, "42")
-        testcommon("%o", -0o42, "-42")
         testcommon("%o", 0o42, "42")
         testcommon("%o", -0o42, "-42")
         # alternate float formatting