Issue 12471: wrong TypeError message on '%i' formatting (original) (raw)
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.