This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Built-in types format incorrectly with 0 padding.
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.1, Python 3.2, Python 2.7
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: eric.smith Nosy List: eric.smith, ezio.melotti, falsetru, mark.dickinson, ncoghlan, skrah
Priority: low Keywords:

Created on 2009-09-13 23:36 by eric.smith, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (5)
msg92586 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2009-09-13 23:36
Originally discussed in issue 6871. Even if an alignment of "<" is
specified, "=" is used if the padding character is "0".

>>> format(2, '0<20')
'00000000000000000002'
>>> format(2, '1<20')
'21111111111111111111'

This is a problem for at least float and integers.

This should probably be backported to 2.6 and 3.1, but I'll have to wait
and see how invasive the patch is.
msg92607 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2009-09-14 11:59
complex will also need to be addressed. The second error message is
misleading, for the same reason the formatting on float and int is
incorrect:

>> format(3-2j, "0<30")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Zero padding is not allowed in complex format specifier
>>> format(3-2j, "0=30")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Zero padding is not allowed in complex format specifier

But this is correct:
>>> format(3-2j, "=30")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: '=' alignment flag is not allowed in complex format specifier

It's not 0 padding that's not allowed, it's the implied sign alignment
when using 0 (without a specified alignment).
msg93742 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2009-10-08 12:31
Note that the 2.6 branch didn't seem to suffer this problem when I
checked it earlier tonight.
msg99849 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2010-02-22 22:05
The root of this problem is an interaction with ',' formatting that was introduced in 2.7 and 3.1. I'm still trying to figure out how to implement it.

I'm changing the priority to low because I can't imagine this is a problem in practice. If anyone thinks otherwise, please comment and give a use case.
msg99889 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2010-02-23 00:40
Fixed:

trunk: r78349
py3k: r78350
release31-maint: r78352
History
Date User Action Args
2022-04-11 14:56:52adminsetgithub: 51151
2010-02-23 00:40:21eric.smithsetstatus: open -> closed
resolution: accepted
messages: + msg99889

stage: resolved
2010-02-22 22:05:48eric.smithsetpriority: normal -> low

messages: + msg99849
2010-02-22 15:15:41eric.smithsetversions: - Python 2.6
2009-12-14 05:16:05ezio.melottisetnosy: + ezio.melotti
type: behavior
2009-12-14 04:05:24falsetrusetnosy: + falsetru
2009-10-08 12:31:08ncoghlansetnosy: + ncoghlan
messages: + msg93742
2009-10-08 12:26:32ncoghlanlinkissue7081 superseder
2009-09-14 11:59:08eric.smithsetmessages: + msg92607
2009-09-13 23:36:43eric.smithcreate