From 011a7064ad233eaf17a27584d8cf484bd1692197 Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Tue, 22 Sep 2026 07:37:03 -0400 Subject: [PATCH] gh-140971: Document pathlib.PurePath("") meaning and bool value (GH-157293) pathlib.PurePath() and pathlib.PurePath('') both mean the current working directory and both have boolean value True. Patch implements suggestion in https://github.com/python/cpython/pull/140993#discussion_r2490858118. --------- (cherry picked from commit c36aa097768eb78cce371d975d173bd04060db56) Co-authored-by: Terry Jan Reedy Co-authored-by: LiuQhahah --- Doc/library/pathlib.rst | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Doc/library/pathlib.rst b/Doc/library/pathlib.rst index 45b5797058f6239..04b1bd01af11879 100644 --- a/Doc/library/pathlib.rst +++ b/Doc/library/pathlib.rst @@ -131,10 +131,11 @@ we also call *flavours*: >>> PurePath(Path('foo'), Path('bar')) PurePosixPath('foo/bar') - When *pathsegments* is empty, the current directory is assumed:: + When *pathsegments* is empty or consists only of empty strings, + the current directory is assumed:: - >>> PurePath() - PurePosixPath('.') + >>> PurePath(), PurePath('') + (PurePosixPath('.'), PurePosixPath('.')) If a segment is an absolute path, all previous segments are ignored (like :func:`os.path.join`):: @@ -1040,8 +1041,8 @@ Querying file type and status .. method:: Path.exists(*, follow_symlinks=True) - Return ``True`` if the path points to an existing file or directory. - ``False`` will be returned if the path is invalid, inaccessible or missing. + Return ``True`` if the path points to an existing file or directory and + ``False`` if the path is invalid, inaccessible or missing. Use :meth:`Path.stat` to distinguish between these cases. This method normally follows symlinks; to check if a symlink exists, add @@ -1049,6 +1050,8 @@ Querying file type and status :: + >>> Path('').exists() # The current directory. + True >>> Path('.').exists() True >>> Path('setup.py').exists()