mirror of
https://github.com/python/cpython.git
synced 2025-07-23 19:25:40 +00:00
Issue #27186: Update os.fspath()/PyOS_FSPath() to check the return
type of __fspath__(). As part of this change, also make sure that the pure Python implementation of os.fspath() is tested.
This commit is contained in:
parent
19b2a53a82
commit
c78ca1e044
7 changed files with 101 additions and 71 deletions
|
@ -12317,12 +12317,21 @@ PyOS_FSPath(PyObject *path)
|
|||
if (NULL == func) {
|
||||
return PyErr_Format(PyExc_TypeError,
|
||||
"expected str, bytes or os.PathLike object, "
|
||||
"not %S",
|
||||
path->ob_type);
|
||||
"not %.200s",
|
||||
Py_TYPE(path)->tp_name);
|
||||
}
|
||||
|
||||
path_repr = PyObject_CallFunctionObjArgs(func, NULL);
|
||||
Py_DECREF(func);
|
||||
if (!(PyUnicode_Check(path_repr) || PyBytes_Check(path_repr))) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"expected %.200s.__fspath__() to return str or bytes, "
|
||||
"not %.200s", Py_TYPE(path)->tp_name,
|
||||
Py_TYPE(path_repr)->tp_name);
|
||||
Py_DECREF(path_repr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return path_repr;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue