Issue 28916: Not matched behavior of modulo operator % with the description of the documentation (original) (raw)

Issue28916

Created on 2016-12-09 05:20 by woo yoo, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
py3-octal.patch martin.panter,2016-12-10 03:12 review
alt-zero.py2.patch martin.panter,2016-12-10 06:02 review
Messages (6)
msg282762 - (view) Author: woo yoo (woo yoo) Date: 2016-12-09 05:20
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."
msg282767 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-12-09 07:31
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'
msg282821 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-12-10 03:12
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.
msg282829 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-12-10 06:02
Patch for %x in Py 2.
msg282834 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-12-10 07:33
Both patches LGTM.
msg282901 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-12-11 04:10
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
History
Date User Action Args
2022-04-11 14:58:40 admin set github: 73102
2016-12-11 04:44:35 martin.panter set status: open -> closedresolution: fixedstage: commit review -> resolved
2016-12-11 04:10:48 python-dev set nosy: + python-devmessages: +
2016-12-10 07:33:35 serhiy.storchaka set nosy: + serhiy.storchakamessages: + assignee: docs@python -> martin.panterstage: patch review -> commit review
2016-12-10 06:02:49 martin.panter set files: + alt-zero.py2.patchmessages: +
2016-12-10 03:12:34 martin.panter set files: + py3-octal.patchversions: + Python 2.7messages: + keywords: + patchstage: needs patch -> patch review
2016-12-09 07:31:26 martin.panter set versions: + Python 3.6, Python 3.7nosy: + martin.pantermessages: + stage: needs patch
2016-12-09 05:20:41 woo yoo create