mirror of
https://github.com/python/cpython.git
synced 2025-10-21 22:22:48 +00:00
Patch by Tommy Burnette to accept an arbitrary sequence when "(...)"
is used in the format string, instead of requiring a tuple. This is in line with the general trend towards accepting arbitrary sequences.
This commit is contained in:
parent
127ed0a71e
commit
66368ccc55
1 changed files with 10 additions and 7 deletions
|
@ -357,27 +357,30 @@ converttuple(arg, p_format, p_va, levels, msgbuf, toplevel)
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!PyTuple_Check(arg)) {
|
if (!PySequence_Check(arg)) {
|
||||||
levels[0] = 0;
|
levels[0] = 0;
|
||||||
sprintf(msgbuf,
|
sprintf(msgbuf,
|
||||||
toplevel ? "%d arguments, %s" : "%d-tuple, %s",
|
toplevel ? "%d arguments, %s" : "%d-sequence, %s",
|
||||||
n, arg == Py_None ? "None" : arg->ob_type->tp_name);
|
n, arg == Py_None ? "None" : arg->ob_type->tp_name);
|
||||||
return msgbuf;
|
return msgbuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((i = PyTuple_Size(arg)) != n) {
|
if ((i = PySequence_Length(arg)) != n) {
|
||||||
levels[0] = 0;
|
levels[0] = 0;
|
||||||
sprintf(msgbuf,
|
sprintf(msgbuf,
|
||||||
toplevel ? "%d arguments, %d" : "%d-tuple, %d-tuple",
|
toplevel ? "%d arguments, %d" : "%d-sequence, %d-sequence",
|
||||||
n, i);
|
n, i);
|
||||||
return msgbuf;
|
return msgbuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
format = *p_format;
|
format = *p_format;
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
char *msg;
|
char *msg;
|
||||||
msg = convertitem(PyTuple_GetItem(arg, i), &format, p_va,
|
PyObject *item;
|
||||||
levels+1, msgbuf);
|
item = PySequence_GetItem(arg, i);
|
||||||
|
msg = convertitem(item, &format, p_va, levels+1, msgbuf);
|
||||||
|
/* PySequence_GetItem calls tp->sq_item, which INCREFs */
|
||||||
|
Py_XDECREF(item);
|
||||||
if (msg != NULL) {
|
if (msg != NULL) {
|
||||||
levels[0] = i+1;
|
levels[0] = i+1;
|
||||||
return msg;
|
return msg;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue