Skip to content

gh-112234: Remove the toplevel parameter in converttuple() #112235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 6 additions & 16 deletions Python/getargs.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static void seterror(Py_ssize_t, const char *, int *, const char *, const char *
static const char *convertitem(PyObject *, const char **, va_list *, int, int *,
char *, size_t, freelist_t *);
static const char *converttuple(PyObject *, const char **, va_list *, int,
int *, char *, size_t, int, freelist_t *);
int *, char *, size_t, freelist_t *);
static const char *convertsimple(PyObject *, const char **, va_list *, int,
char *, size_t, freelist_t *);
static Py_ssize_t convertbuffer(PyObject *, const void **p, const char **);
Expand Down Expand Up @@ -454,7 +454,7 @@ seterror(Py_ssize_t iarg, const char *msg, int *levels, const char *fname,

static const char *
converttuple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
int *levels, char *msgbuf, size_t bufsize, int toplevel,
int *levels, char *msgbuf, size_t bufsize,
freelist_t *freelist)
{
int level = 0;
Expand Down Expand Up @@ -484,7 +484,6 @@ converttuple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
if (!PySequence_Check(arg) || PyBytes_Check(arg)) {
levels[0] = 0;
PyOS_snprintf(msgbuf, bufsize,
toplevel ? "expected %d arguments, not %.50s" :
"must be %d-item sequence, not %.50s",
n,
arg == Py_None ? "None" : Py_TYPE(arg)->tp_name);
Expand All @@ -494,18 +493,9 @@ converttuple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
len = PySequence_Size(arg);
if (len != n) {
levels[0] = 0;
if (toplevel) {
PyOS_snprintf(msgbuf, bufsize,
"expected %d argument%s, not %zd",
n,
n == 1 ? "" : "s",
len);
}
else {
PyOS_snprintf(msgbuf, bufsize,
"must be sequence of length %d, not %zd",
n, len);
}
PyOS_snprintf(msgbuf, bufsize,
"must be sequence of length %d, not %zd",
n, len);
return msgbuf;
}

Expand Down Expand Up @@ -548,7 +538,7 @@ convertitem(PyObject *arg, const char **p_format, va_list *p_va, int flags,
if (*format == '(' /* ')' */) {
format++;
msg = converttuple(arg, &format, p_va, flags, levels, msgbuf,
bufsize, 0, freelist);
bufsize, freelist);
if (msg == NULL)
format++;
}
Expand Down