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: wrong TypeError message on '%i' formatting
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: python-dev, rndblnch
Priority: normal Keywords: patch

Created on 2011-07-01 21:05 by rndblnch, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
PyUnicode_Format_TypeError_message.patch rndblnch, 2011-07-01 21:05 patch fixing the bug
PyUnicode_Format_TypeError_message.2.7.patch rndblnch, 2011-07-04 09:30 patch backported to 2.7 review
Messages (3)
msg139607 - (view) Author: Renaud Blanch (rndblnch) Date: 2011-07-01 21:05
The TypeError message is erroneous when attempting to format a non number object with a '%i' string (notice the '%d' in the error message):

    >>> '%i' % 's'
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: %d format: a number is required, not str

This is because PyUnicode_Format aliases i to d for the formatting handling, but this has the side effect of performing the substitution in the error message too.

The attached patch (against 3.3, but this behaviour has been there since 2.6) suppress the side effect and corrects the error message.
msg139734 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-07-04 04:05
New changeset 97707459bb5a by Senthil Kumaran in branch '3.2':
Fix closes issue12471 - wrong TypeError message when '%i' format spec was used.
http://hg.python.org/cpython/rev/97707459bb5a
msg139744 - (view) Author: Renaud Blanch (rndblnch) Date: 2011-07-04 09:30
that was quick!
just a question: is it worth backporting the fix to 2.7?
if this helps, here is a backport for the patch commited to 3.2 <http://hg.python.org/cpython/rev/97707459bb5a>
History
Date User Action Args
2022-04-11 14:57:19adminsetgithub: 56680
2011-07-04 09:30:49rndblnchsetfiles: + PyUnicode_Format_TypeError_message.2.7.patch

messages: + msg139744
2011-07-04 04:05:37python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg139734

resolution: fixed
stage: resolved
2011-07-01 21:05:18rndblnchcreate