[Python-bugs-list] [Bug #116174] using %% in cstrings sometimes fails with unicode params

noreply@sourceforge.net noreply@sourceforge.net
Thu, 5 Oct 2000 13:37:47 -0700


Bug #116174, was updated on 2000-Oct-05 12:50
Here is a current snapshot of the bug.

Project: Python
Category: Core
Status: Open
Resolution: None
Bug Group: None
Priority: 9
Summary: using %% in cstrings sometimes fails with unicode params

Details: There are various ways to show this but here's an example:

>>> "%s %%" % u"test"
u'test %'
>>> "%% %s %%" % u"test"
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: not all arguments converted

This is still present in a recent CVS version of Python2.0

Follow-Ups:

Date: 2000-Oct-05 12:57
By: gvanrossum

Comment:
Marc-Andre, this is clearly a bug in the unicode specific % formatting code... Can you fix it before Sunday?
-------------------------------------------------------

Date: 2000-Oct-05 13:37
By: lemburg

Comment:
Ok, here's what I think is going wrong:

When the string %-formatting code sees a Unicode object as
argument, it tries to pass the already formatted part of the string
together with the not yet formatted part to the Unicode %-formatting
code which then takes care of formatting the remaining arguments.

The reason for this was to avoid duplicate evaluations of %-arguments.

Now if there happens to be a "%%" *before* the first Unicode
argument, the Unicode %-formatting function will see this
as "%" (it was already formatted by the string %-formatting
code) and this produces the error message you see.

I will look into this, but can't promise anything w/r to the deadline.
The patch will surely be a little complicated due to the way
the string/Unicode interaction works here.

-------------------------------------------------------

For detailed info, follow this link:
http://sourceforge.net/bugs/?func=detailbug&bug_id=116174&group_id=5470