[New-bugs-announce] [issue12471] wrong TypeError message on '%i' formatting

Renaud Blanch report at bugs.python.org
Fri Jul 1 23:05:18 CEST 2011


New submission from Renaud Blanch <rndblnch at gmail.com>:

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.

----------
components: Interpreter Core
files: PyUnicode_Format_TypeError_message.patch
keywords: patch
messages: 139607
nosy: rndblnch
priority: normal
severity: normal
status: open
title: wrong TypeError message on '%i' formatting
type: behavior
versions: Python 3.3
Added file: http://bugs.python.org/file22542/PyUnicode_Format_TypeError_message.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12471>
_______________________________________


More information about the New-bugs-announce mailing list