gh-106046: Improve error message from os.fspath if __fspath__ is set to None (#106082)

This commit is contained in:
Alex Waygood 2023-06-26 00:06:12 +01:00 committed by GitHub
parent 8c24a83737
commit 93a970ffbc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 52 additions and 4 deletions

View file

@ -1197,7 +1197,7 @@ path_converter(PyObject *o, void *p)
PyObject *func, *res;
func = _PyObject_LookupSpecial(o, &_Py_ID(__fspath__));
if (NULL == func) {
if ((NULL == func) || (func == Py_None)) {
goto error_format;
}
res = _PyObject_CallNoArgs(func);
@ -15430,7 +15430,7 @@ PyOS_FSPath(PyObject *path)
}
func = _PyObject_LookupSpecial(path, &_Py_ID(__fspath__));
if (NULL == func) {
if ((NULL == func) || (func == Py_None)) {
return PyErr_Format(PyExc_TypeError,
"expected str, bytes or os.PathLike object, "
"not %.200s",