Issue 17705: Fill Character cannot be \0 (original) (raw)

Created on 2013-04-12 16:54 by Julian, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
cpython-3.3-17705.patch Jason.Michalski,2013-04-13 20:57 review
Messages (6)
msg186653 - (view) Author: Julian Berman (Julian) * Date: 2013-04-12 16:54
The docs say: "The fill character can be any character other than ‘{‘ or ‘}’." http://docs.python.org/dev/library/string.html#format-specification-mini-language But: >>> "{0:\x01>8.2f}".format(12) '\x01\x01\x0112.00' whereas: >>> "{0:\x00>8.2f}".format(12) ' 12.00'
msg186724 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2013-04-13 14:47
Unsurprisingly (libmpdec is a C library) this also does not work in _decimal. I could add a special case in _decimal.c at the cost of two additional if statements for all regular use cases. Is padding with NUL a legitimate use case? IOW, is the slowdown justified?
msg186726 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2013-04-13 14:51
> Is padding with NUL a legitimate use case? I don't see a good reason to disallow it, and it seems like a fairly plausible need. Numpy, for example, pads strings will NUL bytes when placing a short string in long fixed-width field.
msg186731 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2013-04-13 15:13
Mark Dickinson <report@bugs.python.org> wrote: > Numpy, for example, pads strings will NUL bytes when placing a short > string in long fixed-width field. I was hoping to escape the work, but that's quite convincing. ;) Changing libmpdec doesn't look very appealing, so probably I'll use "{" as a placeholder for NUL and then rewrite the result.
msg186842 - (view) Author: Jason Michalski (Jason.Michalski) * Date: 2013-04-13 20:57
I worked on a patch that allows NUL padding for longs, floats and complex numbers. It seems NUL was being used as a sentinel in the format string parsing when no padding character is given. It was then replaced with a space in each call to fill_padding if it was NUL.
msg215456 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2014-04-03 16:14
This looks like a duplicate of #12546.
History
Date User Action Args
2022-04-11 14:57:44 admin set github: 61905
2014-04-03 16:15:23 skrah set superseder: builtin __format__ methods cannot fill with \x00 char
2014-04-03 16:14:29 skrah set status: open -> closedversions: + Python 3.5, - Python 2.7, Python 3.3messages: + resolution: duplicatestage: patch review -> resolved
2013-05-04 20:31:38 pitrou set stage: patch review
2013-04-19 18:57:24 terry.reedy set versions: - Python 3.2
2013-04-13 23:24:10 eric.smith set assignee: eric.smith
2013-04-13 20:57:04 Jason.Michalski set files: + cpython-3.3-17705.patchnosy: + Jason.Michalskimessages: + keywords: + patch
2013-04-13 15:13:26 skrah set messages: +
2013-04-13 14:51:55 mark.dickinson set nosy: + mark.dickinsonmessages: +
2013-04-13 14:47:32 skrah set nosy: + skrahmessages: +
2013-04-12 22:34:57 eric.smith set nosy: + eric.smith
2013-04-12 16:54:55 Julian create