classification
Title: Not matched behavior of modulo operator % with the description of the documentation
Type: behavior Stage: resolved
Components: Documentation Versions: Python 3.7, Python 3.6, Python 3.5, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: martin.panter Nosy List: docs@python, martin.panter, python-dev, serhiy.storchaka, woo yoo
Priority: normal Keywords: patch

Created on 2016-12-09 05:20 by woo yoo, last changed 2016-12-11 04:44 by martin.panter. 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
2016-12-11 04:44:35martin.pantersetstatus: open -> closed
resolution: fixed
stage: commit review -> resolved
2016-12-11 04:10:48python-devsetnosy: + python-dev
messages: + msg282901
2016-12-10 07:33:35serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg282834

assignee: docs@python -> martin.panter
stage: patch review -> commit review
2016-12-10 06:02:49martin.pantersetfiles: + alt-zero.py2.patch

messages: + msg282829
2016-12-10 03:12:34martin.pantersetfiles: + py3-octal.patch
versions: + Python 2.7
messages: + msg282821

keywords: + patch
stage: needs patch -> patch review
2016-12-09 07:31:26martin.pantersetversions: + Python 3.6, Python 3.7
nosy: + martin.panter

messages: + msg282767

stage: needs patch
2016-12-09 05:20:41woo yoocreate