classification
Title: PyUnicode_FromFormatV handles %R and %S incorrectly.
Type: behavior Stage: resolved
Components: Interpreter Core, Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: PyUnicode_FromFormat broken and not documented for 2.x
View: 7574
Assigned To: Nosy List: alexandre.vassalotti
Priority: normal Keywords:

Created on 2009-12-30 23:16 by alexandre.vassalotti, last changed 2009-12-30 23:20 by alexandre.vassalotti. This issue is now closed.

Messages (1)
msg97067 - (view) Author: Alexandre Vassalotti (alexandre.vassalotti) * (Python committer) Date: 2009-12-30 23:16
It seems PyUnicode_FromFormatV wrongly assumes that the return value of
PyObject_Str and PyObject_Repr is a unicode object. It looks like  the
%S and %R feature was backported from 3.x without updating the code for 2.x.


PyObject *
PyUnicode_FromFormatV(const char *format, va_list vargs)
{
...
            case 'S':
            {
                PyObject *obj = va_arg(count, PyObject *);
                PyObject *str;
                assert(obj);
                str = PyObject_Str(obj);
                if (!str)
                    goto fail;
                n += PyUnicode_GET_SIZE(str);
                /* Remember the str and switch to the next slot */
                *callresult++ = str;
                break;
            }
            case 'R':
            {
                PyObject *obj = va_arg(count, PyObject *);
                PyObject *repr;
                assert(obj);
                repr = PyObject_Repr(obj);
                if (!repr)
                    goto fail;
                n += PyUnicode_GET_SIZE(repr);
                /* Remember the repr and switch to the next slot */
                *callresult++ = repr;
                break;
            }
...
}
History
Date User Action Args
2009-12-30 23:20:38alexandre.vassalottisetstage: test needed -> resolved
2009-12-30 23:20:18alexandre.vassalottisetstatus: open -> closed
resolution: duplicate
superseder: PyUnicode_FromFormat broken and not documented for 2.x
2009-12-30 23:16:53alexandre.vassalotticreate