[issue28916] Not matched behavior of modulo operator % with the description of the documentation
New submission from woo yoo: Mismatch occurs within the "Notes" section,row 1.Here is the link:https://docs.python.org/3/library/stdtypes.html#old-string-formatting The course of coding shows below:
'%#07o' % 1223 Result value is '0o02307',which is not in line with the description.
Description is "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." ---------- assignee: docs@python components: Documentation messages: 282762 nosy: docs@python, woo yoo priority: normal severity: normal status: open title: Not matched behavior of modulo operator % with the description of the documentation type: behavior versions: Python 3.5 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue28916> _______________________________________
Martin Panter added the comment: Looks like a leftover relic from Python 2. In Python 3, the prefix is “0o”, not just “0”. This matches to change in Python 2 to 3 octal literal syntax. And there is no special handling of zero in 3:
"%#o" % 0 '0o0'
---------- nosy: +martin.panter stage: -> needs patch versions: +Python 3.6, Python 3.7 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue28916> _______________________________________
Martin Panter added the comment: The documentation for %x etc also had the same problem, and it applies to Python 2 for %x. Here is a patch for Python 3. The behaviour is already tested, but there were some quirks due to porting from Py 2 tests, and duplicate tests which I removed. ---------- keywords: +patch stage: needs patch -> patch review versions: +Python 2.7 Added file: http://bugs.python.org/file45826/py3-octal.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue28916> _______________________________________
Martin Panter added the comment: Patch for %x in Py 2. ---------- Added file: http://bugs.python.org/file45828/alt-zero.py2.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue28916> _______________________________________
Serhiy Storchaka added the comment: Both patches LGTM. ---------- assignee: docs@python -> martin.panter nosy: +serhiy.storchaka stage: patch review -> commit review _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue28916> _______________________________________
Roundup Robot added the comment: New changeset 35e66eb101da by Martin Panter in branch '3.5': Issue #28916: Correct description of %o and %x alternative forms https://hg.python.org/cpython/rev/35e66eb101da New changeset bc7fc85beed1 by Martin Panter in branch '3.6': Issues #28916, #26483: Merge stdtypes.rst from 3.5 https://hg.python.org/cpython/rev/bc7fc85beed1 New changeset b11850871300 by Martin Panter in branch 'default': Issues #28916, #26483: Merge stdtypes.rst from 3.6 https://hg.python.org/cpython/rev/b11850871300 New changeset 8359ee62dde3 by Martin Panter in branch '2.7': Issue #28916: No special case for leading zeros with %x alternative form https://hg.python.org/cpython/rev/8359ee62dde3 ---------- nosy: +python-dev _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue28916> _______________________________________
Changes by Martin Panter <vadmium+py@gmail.com>: ---------- resolution: -> fixed stage: commit review -> resolved status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue28916> _______________________________________
participants (4)
-
Martin Panter -
Roundup Robot -
Serhiy Storchaka -
woo yoo