8000 gh-106046: Improve error message from `os.fspath` if `__fspath__` is set to `None` by AlexWaygood · Pull Request #106082 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

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

Merged
merged 5 commits into from
Jun 25, 2023
Merged
Show file tree
Hide file tree
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
Revert change to make error message more consistent: it makes other t…
…ests fail elsewhere
  • Loading branch information
AlexWaygood committed Jun 25, 2023
commit dbfb232a5e13dcc77076b62d7b47afd7dad536e8
10 changes: 7 additions & 3 deletions Lib/test/test_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -4659,7 +4659,7 @@ class Baz(Bar):
__fspath__ = None

good_error_msg = (
r"((expected)|(should be)) str, bytes or os.PathLike( object)?, not {}".format
r"expected str, bytes or os.PathLike object, not {}".format
)

with self.assertRaisesRegex(TypeError, good_error_msg("Foo")):
Expand All @@ -4676,10 +4676,14 @@ class Baz(Bar):
with self.assertRaisesRegex(TypeError, good_error_msg("Baz")):
open(Baz())

with self.assertRaisesRegex(TypeError, good_error_msg("Foo")):
other_good_error_msg = (
r"should be string, bytes or os.PathLike, not {}".format
)

with self.assertRaisesRegex(TypeError, other_good_error_msg("Foo")):
os.rename(Foo(), "foooo")

with self.assertRaisesRegex(TypeError, good_error_msg("Baz")):
with self.assertRaisesRegex(TypeError, other_good_error_msg("Baz")):
os.rename(Baz(), "bazzz")

class TimesTests(unittest.TestCase):
Expand Down
10 changes: 5 additions & 5 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ? "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",
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",
_PyType_Name(Py_TYPE(o)));
goto error_exit;
}
Expand Down
0