8000 Check "sep" and "end" for stringness in Print(). · python/cpython@16f3e03 · GitHub
[go: up one dir, main page]

Skip to content

Commit 16f3e03

Browse files
committed
Check "sep" and "end" for stringness in Print().
1 parent 3434351 commit 16f3e0
10000
3

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

Python/bltinmodule.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1429,7 +1429,20 @@ builtin_print(PyObject *self, PyObject *args, PyObject *kwds)
14291429
if (file == NULL || file == Py_None)
14301430
file = PySys_GetObject("stdout");
14311431

1432-
/* XXX Verify that sep and end are None, NULL or strings. */
1432+
if (sep && sep != Py_None && !PyString_Check(sep) &&
1433+
!PyUnicode_Check(sep)) {
1434+
PyErr_Format(PyExc_TypeError,
1435+
"sep must be None, str or unicode, not %.200s",
1436+
sep->ob_type->tp_name);
1437+
return NULL;
1438+
}
1439+
if (end && end != Py_None && !PyString_Check(end) &&
1440+
!PyUnicode_Check(end)) {
1441+
PyErr_Format(PyExc_TypeError,
1442+
"end must be None, str or unicode, not %.200s",
1443+
end->ob_type->tp_name);
1444+
return NULL;
1445+
}
14331446

14341447
for (i = 0; i < PyTuple_Size(args); i++) {
14351448
if (i > 0) {

0 commit comments

Comments
 (0)
0