summaryrefslogtreecommitdiffstats
path: root/Lib/os.py
diff options
context:
space:
mode:
authorAlex Waygood <Alex.Waygood@Gmail.com>2023-06-25 23:06:12 (GMT)
committerGitHub <noreply@github.com>2023-06-25 23:06:12 (GMT)
commit93a970ffbce58657cc99305be69e460a11371730 (patch)
tree599086f9f8f32527b67951ed6fbf3fe9a1e7457f /Lib/os.py
parent8c24a837371439b8e922ff47275085b581f510c5 (diff)
downloadcpython-93a970ffbce58657cc99305be69e460a11371730.zip
cpython-93a970ffbce58657cc99305be69e460a11371730.tar.gz
cpython-93a970ffbce58657cc99305be69e460a11371730.tar.bz2
gh-106046: Improve error message from `os.fspath` if `__fspath__` is set to `None` (#106082)
Diffstat (limited to 'Lib/os.py')
-rw-r--r--Lib/os.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/Lib/os.py b/Lib/os.py
index 31b957f..d8c9ba4 100644
--- a/Lib/os.py
+++ b/Lib/os.py
@@ -1061,6 +1061,12 @@ def _fspath(path):
else:
raise TypeError("expected str, bytes or os.PathLike object, "
"not " + path_type.__name__)
+ except TypeError:
+ if path_type.__fspath__ is None:
+ raise TypeError("expected str, bytes or os.PathLike object, "
+ "not " + path_type.__name__) from None
+ else:
+ raise
if isinstance(path_repr, (str, bytes)):
return path_repr
else: