Skip to content

Commit c36aa09

Browse files
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 #140993 (comment). --------- Co-authored-by: LiuQhahah <liuqiang9596@gmail.com>
1 parent 6eedb1a commit c36aa09

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`)::
@@ -1040,15 +1041,17 @@ Querying file type and status
10401041

10411042
.. method:: Path.exists(*, follow_symlinks=True)
10421043

1043-
Return ``True`` if the path points to an existing file or directory.
1044-
``False`` will be returned if the path is invalid, inaccessible or missing.
1044+
Return ``True`` if the path points to an existing file or directory and
1045+
``False`` if the path is invalid, inaccessible or missing.
10451046
Use :meth:`Path.stat` to distinguish between these cases.
10461047

10471048
This method normally follows symlinks; to check if a symlink exists, add
10481049
the argument ``follow_symlinks=False``.
10491050

10501051
::
10511052

1053+
>>> Path('').exists() # The current directory.
1054+
True
10521055
>>> Path('.').exists()
10531056
True
10541057
>>> Path('setup.py').exists()

0 commit comments

Comments
 (0)