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.

Author Carl.Friedrich.Bolz
Recipients Carl.Friedrich.Bolz
Date 2020-01-29.14:49:08
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1580309349.27.0.404972763443.issue39486@roundup.psfhosted.org>
In-reply-to
Content
The following behaviour of %-formatting changed between Python3.6 and Python3.7, and is in my opinion a bug that was introduced.

So far, it has been possible to add conversion flags to a conversion specifier in %-formatting, even if the conversion is '%' (meaning a literal % is emitted and no argument consumed).

Eg this works in Python3.6:

>>>> "%+%abc% %" % ()
'%abc%'

The conversion flags '+' and ' ' are ignored.

Was it discussed and documented anywhere that this is now an error? Because Python3.7 has the following strange behaviour instead:

>>> "%+%abc% %" % ()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: not enough arguments for format string

That error message is just confusing, because the amount of arguments is not the problem here. If I pass a dict (thus making the number of arguments irrelevant) I get instead:

>>> "%+%abc% %" % {}
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: unsupported format character '%' (0x25) at index 2

(also a confusing message, because '%' is a perfectly fine format character)

In my opinion this behaviour should either be reverted to how Python3.6 worked, or the new restrictions should be documented and the error messages improved.
History
Date User Action Args
2020-01-29 14:49:09Carl.Friedrich.Bolzsetrecipients: + Carl.Friedrich.Bolz
2020-01-29 14:49:09Carl.Friedrich.Bolzsetmessageid: <1580309349.27.0.404972763443.issue39486@roundup.psfhosted.org>
2020-01-29 14:49:09Carl.Friedrich.Bolzlinkissue39486 messages
2020-01-29 14:49:08Carl.Friedrich.Bolzcreate