Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Apply suggestions from code review
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
  • Loading branch information
vstinner and picnixz authored Aug 30, 2024
commit 67210db6f79bdba98dcceb69694525276a795aa9
14 changes: 7 additions & 7 deletions Python/initconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -3812,30 +3812,30 @@ PyConfig_Set(const char *name, PyObject *value)

case PyConfig_MEMBER_WSTR:
if (!PyUnicode_CheckExact(value)) {
PyErr_Format(PyExc_TypeError, "expect str, got %T", value);
PyErr_Format(PyExc_TypeError, "expected str, got %T", value);
return -1;
}
break;

case PyConfig_MEMBER_WSTR_OPT:
if (value != Py_None && !PyUnicode_CheckExact(value)) {
PyErr_Format(PyExc_TypeError, "expect str or None, got %T", value);
PyErr_Format(PyExc_TypeError, "expected str or None, got %T", value);
return -1;
}
break;

case PyConfig_MEMBER_WSTR_LIST:
if (strcmp(spec->name, "xoptions") != 0) {
if (!PyList_Check(value)) {
PyErr_Format(PyExc_TypeError, "expect list[str], got %T",
PyErr_Format(PyExc_TypeError, "expected list[str], got %T",
value);
return -1;
}
for (Py_ssize_t i=0; i < PyList_GET_SIZE(value); i++) {
PyObject *item = PyList_GET_ITEM(value, i);
if (!PyUnicode_Check(item)) {
PyErr_Format(PyExc_TypeError,
"expect list[str], list item %zd has type %T",
"expected str, list item %zd has type %T",
i, item);
return -1;
}
Expand All @@ -3845,7 +3845,7 @@ PyConfig_Set(const char *name, PyObject *value)
// xoptions type is dict[str, str]
if (!PyDict_Check(value)) {
PyErr_Format(PyExc_TypeError,
"expect dict[str, str | bool], got %T",
"expected dict[str, str | bool], got %T",
value);
return -1;
}
Expand All @@ -3855,13 +3855,13 @@ PyConfig_Set(const char *name, PyObject *value)
while (PyDict_Next(value, &pos, &key, &item)) {
if (!PyUnicode_Check(key)) {
PyErr_Format(PyExc_TypeError,
"expect dict[str, str | bool], "
"expected str, "
"got dict key type %T", key);
return -1;
}
if (!PyUnicode_Check(item) && !PyBool_Check(item)) {
PyErr_Format(PyExc_TypeError,
"expect dict[str, str | bool], "
"expected str or bool, "
"got dict value type %T", key);
return -1;
}
Expand Down