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.

Title: Refer to actual format string when creating “zero padding” error message
Type: Stage: resolved
Components: Interpreter Core Versions: Python 3.10
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: bignose, eric.smith, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2016-08-16 04:35 by bignose, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 11270 merged serhiy.storchaka, 2018-12-20 22:03
Messages (3)
msg272827 - (view) Author: Ben Finney (bignose) Date: 2016-08-16 04:35
When using a format specifier with leading zero, the format spec mini-language (as documented at>) says:

> '=' […] becomes the default when ‘0’ immediately precedes the field width.

When the ‘=’ option is only implied, the error message “ValueError: '=' alignment not allowed in string format specifier” becomes surprising and incomprehensible to someone who does not know that implied behaviour.

In issue 15560, Terry Reedy says:

> If the spec string is still available, it could be searched and the message adjusted if '=' is not present.  That proposal should be a new issue if someone wants to push it.

This issue raises that proposal.

The error message should be changed so that:

* It makes sense whether or not the ‘=’ option is explicit in the format specifier.


* Different messages are produced when the ‘=’ option is explicit versus when it is implicit.

I think the former option is better, but either will satisfy this request.
msg332271 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-12-20 22:10
PR 11270 fixes this issue by making such format valid. Preceding the width field by '0' no longer affects the default alignment for strings, i.e. no longer sets the alignment to invalid '=' if it is not specified explicitly.

>>> format('abc', '<8')
'abc     '
>>> format('abc', '8')
'abc     '
>>> format('abc', '<08')
>>> format('abc', '08')

This does not contradict the documentation, which specifies this case for numeric types, but not for strings.
msg385611 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-01-25 09:56
New changeset cf19cc3b920ca5995e1c202d2c3dd7a59ac8eac8 by Serhiy Storchaka in branch 'master':
bpo-27772: Make preceding width with 0 valid in string format. (GH-11270)
Date User Action Args
2022-04-11 14:58:34adminsetgithub: 71959
2021-01-25 09:58:07serhiy.storchakasetstatus: open -> closed
stage: patch review -> resolved
resolution: fixed
versions: + Python 3.10, - Python 3.8
2021-01-25 09:56:54serhiy.storchakasetmessages: + msg385611
2018-12-20 22:10:31serhiy.storchakasetcomponents: + Interpreter Core
versions: + Python 3.8, - Python 2.7, Python 3.5, Python 3.6
2018-12-20 22:10:12serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg332271
2018-12-20 22:03:36serhiy.storchakasetkeywords: + patch
stage: patch review
pull_requests: + pull_request10506
2016-08-16 04:39:57ned.deilysetnosy: + eric.smith

versions: + Python 3.6, - Python 3.2, Python 3.3, Python 3.4
2016-08-16 04:35:18bignosecreate