-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
gh-106046: Improve error message from os.fspath
if __fspath__
is set to None
#106082
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
Changes from 1 commit
3ec02c8
1e9ebd4
dbfb232
982d663
1dcf5e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Improve the error message from :func:`os.fspath` if called on an object | ||
where ``__fspath__`` is set to ``None``. Patch by Alex Waygood. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A few thoughts, no change requested:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Thanks for explaining this! I wondered what the rationale was here for writing it like this!
Huh. I checked the API docs for |
||
goto error_format; | ||
} | ||
res = _PyObject_CallNoArgs(func); | ||
|
@@ -1271,11 +1271,11 @@ path_converter(PyObject *o, void *p) | |
path->function_name ? path->function_name : "", | ||
path->function_name ? ": " : "", | ||
path->argument_name ? path->argument_name : "path", | ||
path->allow_fd && path->nullable ? "string, bytes, os.PathLike, " | ||
"integer or None" : | ||
path->allow_fd ? "string, bytes, os.PathLike or integer" : | ||
path->nullable ? "string, bytes, os.PathLike or None" : | ||
"string, bytes or os.PathLike", | ||
path->allow_fd && path->nullable ? "str, bytes, os.PathLike, " | ||
"int or None" : | ||
path->allow_fd ? "str, bytes, os.PathLike or int" : | ||
path->nullable ? "str, bytes, os.PathLike or None" : | ||
"str, bytes or os.PathLike", | ||
_PyType_Name(Py_TYPE(o))); | ||
goto error_exit; | ||
} | ||
|
@@ -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", | ||
|
Uh oh!
There was an error while loading. Please reload this page.