[issue29000] Not matched behavior within printf style bytes formatting
New submission from woo yoo: Per the documentation,"The alternate form causes a leading octal specifier ('0o') to be inserted before the first digit", However the actual behavior didn't conform to the principle. Code:
b'%#07o' % 34
Output: b'0000o42' ---------- assignee: docs@python components: Documentation messages: 283485 nosy: docs@python, woo yoo priority: normal severity: normal status: open title: Not matched behavior within printf style bytes formatting versions: Python 3.5 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue29000> _______________________________________
woo yoo added the comment: The link is https://docs.python.org/3.5/library/stdtypes.html#printf-style-bytes-formatt... ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue29000> _______________________________________
R. David Murray added the comment: The documentation matches the behavior. In this context "the first digit" is the 4. The leading zeros are the pad fill. Now, whether this is *useful* behavior or not is a separate question :) And yes, the docs could be clarified on this point either way. ---------- nosy: +r.david.murray _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue29000> _______________________________________
woo yoo added the comment: Make a slight change to my code, which becomes `b'%#07x' % 34`, the weird situation appears. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue29000> _______________________________________
Serhiy Storchaka added the comment: This is not documentation issue, but a bug in formatting octals in bytes.
'%#07x' % 123 '0x0007b' b'%#07x' % 123 b'0x0007b' '%#07o' % 123 '0o00173' b'%#07o' % 123 b'000o173' ^
---------- components: +Interpreter Core -Documentation nosy: +ethan.furman, serhiy.storchaka stage: -> needs patch type: -> behavior versions: +Python 3.6, Python 3.7 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue29000> _______________________________________
Serhiy Storchaka added the comment: Proposed patch fixes this inconsistency. ---------- keywords: +patch stage: needs patch -> patch review Added file: http://bugs.python.org/file45943/bytes-format-oct-alt-zero.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue29000> _______________________________________
R. David Murray added the comment: OK, that makes sense. Patch looks good to me. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue29000> _______________________________________
Roundup Robot added the comment: New changeset 96d728c14267 by Serhiy Storchaka in branch '3.5': Issue #29000: Fixed bytes formatting of octals with zero padding in alternate https://hg.python.org/cpython/rev/96d728c14267 New changeset 29c9c414c310 by Serhiy Storchaka in branch '3.6': Issue #29000: Fixed bytes formatting of octals with zero padding in alternate https://hg.python.org/cpython/rev/29c9c414c310 New changeset 4e55e011dd80 by Serhiy Storchaka in branch 'default': Issue #29000: Fixed bytes formatting of octals with zero padding in alternate https://hg.python.org/cpython/rev/4e55e011dd80 ---------- nosy: +python-dev _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue29000> _______________________________________
Serhiy Storchaka added the comment: Thanks David. ---------- assignee: docs@python -> serhiy.storchaka resolution: -> fixed stage: patch review -> resolved status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue29000> _______________________________________
Changes by Donald Stufft <donald@stufft.io>: ---------- pull_requests: +1017 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue29000> _______________________________________
participants (5)
-
Donald Stufft -
R. David Murray -
Roundup Robot -
Serhiy Storchaka -
woo yoo