From 6eee97667dbb251d84b403bee4da8adaee9be807 Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Thu, 10 Sep 2026 20:41:44 -0400 Subject: [PATCH 1/5] gh-140971: Document pathlib.PurePath("") meaning and bool value 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. --- Co-authored-by: LiuQhahah --- Doc/library/pathlib.rst | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Doc/library/pathlib.rst b/Doc/library/pathlib.rst index ab92c142c37a4f..1f28f217b83b21 100644 --- a/Doc/library/pathlib.rst +++ b/Doc/library/pathlib.rst @@ -131,10 +131,14 @@ 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 a single empty string, + the current directory is assumed:: - >>> PurePath() - PurePosixPath('.') + >>> PurePath(), PurePath('') + (PurePosixPath('.'), PurePosixPath('.')) + + The boolean value of either expression is True. + This differs from ``os.path.exists("")``, which returns ``False``. If a segment is an absolute path, all previous segments are ignored (like :func:`os.path.join`):: From ecae948b1b186653ff74a66f09856ca37376a7b6 Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Sun, 20 Sep 2026 21:24:40 -0400 Subject: [PATCH 2/5] Address Stan's comments --- Doc/library/pathlib.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/pathlib.rst b/Doc/library/pathlib.rst index 1f28f217b83b21..56d771fd8f040e 100644 --- a/Doc/library/pathlib.rst +++ b/Doc/library/pathlib.rst @@ -131,14 +131,13 @@ we also call *flavours*: >>> PurePath(Path('foo'), Path('bar')) PurePosixPath('foo/bar') - When *pathsegments* is empty or a single empty string, + When *pathsegments* is empty or consists only of empty strings, the current directory is assumed:: >>> PurePath(), PurePath('') (PurePosixPath('.'), PurePosixPath('.')) The boolean value of either expression is True. - This differs from ``os.path.exists("")``, which returns ``False``. If a segment is an absolute path, all previous segments are ignored (like :func:`os.path.join`):: @@ -1045,6 +1044,7 @@ Querying file type and status .. method:: Path.exists(*, follow_symlinks=True) Return ``True`` if the path points to an existing file or directory. + This includes empty paths, which Path interprets as the current directory. ``False`` will be returned if the path is invalid, inaccessible or missing. Use :meth:`Path.stat` to distinguish between these cases. From c0cdb479358476cc9b3af636ade75d10c8473431 Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Mon, 21 Sep 2026 17:45:52 -0400 Subject: [PATCH 3/5] Update Doc/library/pathlib.rst --- Doc/library/pathlib.rst | 2 -- 1 file changed, 2 deletions(-) diff --git a/Doc/library/pathlib.rst b/Doc/library/pathlib.rst index 56d771fd8f040e..9cee9f40ed9fb2 100644 --- a/Doc/library/pathlib.rst +++ b/Doc/library/pathlib.rst @@ -137,8 +137,6 @@ we also call *flavours*: >>> PurePath(), PurePath('') (PurePosixPath('.'), PurePosixPath('.')) - The boolean value of either expression is True. - If a segment is an absolute path, all previous segments are ignored (like :func:`os.path.join`):: From dfa4d4ec07bda24f130fd2e26f1b74b0b6542fa7 Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Mon, 21 Sep 2026 17:46:29 -0400 Subject: [PATCH 4/5] Update Doc/library/pathlib.rst --- Doc/library/pathlib.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/Doc/library/pathlib.rst b/Doc/library/pathlib.rst index 9cee9f40ed9fb2..19770cb790952d 100644 --- a/Doc/library/pathlib.rst +++ b/Doc/library/pathlib.rst @@ -1042,7 +1042,6 @@ Querying file type and status .. method:: Path.exists(*, follow_symlinks=True) Return ``True`` if the path points to an existing file or directory. - This includes empty paths, which Path interprets as the current directory. ``False`` will be returned if the path is invalid, inaccessible or missing. Use :meth:`Path.stat` to distinguish between these cases. From 350dc49f58f27f920b78a7c01ea9b0635c8141bf Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Mon, 21 Sep 2026 18:50:23 -0400 Subject: [PATCH 5/5] more comment --- Doc/library/pathlib.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Doc/library/pathlib.rst b/Doc/library/pathlib.rst index 19770cb790952d..709e7b49632c73 100644 --- a/Doc/library/pathlib.rst +++ b/Doc/library/pathlib.rst @@ -1041,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 @@ -1050,6 +1050,8 @@ Querying file type and status :: + >>> Path('').exists() # The current directory. + True >>> Path('.').exists() True >>> Path('setup.py').exists()