From c36aa097768eb78cce371d975d173bd04060db56 Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Tue, 22 Sep 2026 07:37:03 -0400 Subject: [PATCH 1/2] gh-140971: Document pathlib.PurePath("") meaning and bool value (#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. --------- 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 ab92c142c37a4f6..709e7b49632c735 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() From 9777e8a67776ce225bfa594b4aedae0f18d2e3be Mon Sep 17 00:00:00 2001 From: Vasiliy Kiryanov Date: Tue, 22 Sep 2026 07:48:38 -0400 Subject: [PATCH 2/2] gh-119048: Use shutil._use_fd_functions directly in test (GH-157912) Use shutil._use_fd_functions in test_rmtree_uses_safe_fd_version_if_available --- Lib/test/test_shutil.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py index 06ebdf9b68f20fc..a7825adf923c19d 100644 --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -552,11 +552,7 @@ def raiser(fn, *args, **kwargs): os.lstat = orig_lstat def test_rmtree_uses_safe_fd_version_if_available(self): - _use_fd_functions = ({os.open, os.stat, os.unlink, os.rmdir} <= - os.supports_dir_fd and - os.listdir in os.supports_fd and - os.stat in os.supports_follow_symlinks) - if _use_fd_functions: + if shutil._use_fd_functions: self.assertTrue(shutil.rmtree.avoids_symlink_attacks) tmp_dir = self.mkdtemp() d = os.path.join(tmp_dir, 'a')