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/2] 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/2] 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.