Skip to content

Commit c2e4d42

Browse files
miss-islingtonterryjreedyLiuQhahah
authored
[3.14] gh-140971: Document pathlib.PurePath("") meaning and bool value (GH-157293) (#157944)
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 #140993 (comment). --------- (cherry picked from commit c36aa09) Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu> Co-authored-by: LiuQhahah <liuqiang9596@gmail.com>
1 parent c77e98a commit c2e4d42

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

‎Doc/library/pathlib.rst‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,11 @@ we also call *flavours*:
131131
>>> PurePath(Path('foo'), Path('bar'))
132132
PurePosixPath('foo/bar')
133133

134-
When *pathsegments* is empty, the current directory is assumed::
134+
When *pathsegments* is empty or consists only of empty strings,
135+
the current directory is assumed::
135136

136-
>>> PurePath()
137-
PurePosixPath('.')
137+
>>> PurePath(), PurePath('')
138+
(PurePosixPath('.'), PurePosixPath('.'))
138139

139140
If a segment is an absolute path, all previous segments are ignored
140141
(like :func:`os.path.join`)::
@@ -1054,15 +1055,17 @@ Querying file type and status
10541055

10551056
.. method:: Path.exists(*, follow_symlinks=True)
10561057

1057-
Return ``True`` if the path points to an existing file or directory.
1058-
``False`` will be returned if the path is invalid, inaccessible or missing.
1058+
Return ``True`` if the path points to an existing file or directory and
1059+
``False`` if the path is invalid, inaccessible or missing.
10591060
Use :meth:`Path.stat` to distinguish between these cases.
10601061

10611062
This method normally follows symlinks; to check if a symlink exists, add
10621063
the argument ``follow_symlinks=False``.
10631064

10641065
::
10651066

1067+
>>> Path('').exists() # The current directory.
1068+
True
10661069
>>> Path('.').exists()
10671070
True
10681071
>>> Path('setup.py').exists()

0 commit comments

Comments
 (0)