Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Ignore empty segments.
  • Loading branch information
barneygale committed Dec 4, 2023
commit 0f4122a2a410d36be5fed3d7721723f9f5b1e989
7 changes: 3 additions & 4 deletions Lib/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,6 @@ def with_segments(self, *pathsegments):

@classmethod
def _parse_path(cls, path):
if not path:
return '', '', []
sep = cls.pathmod.sep
altsep = cls.pathmod.altsep
if altsep:
Expand Down Expand Up @@ -605,12 +603,13 @@ def __init__(self, *args):
"argument should be a str or an os.PathLike "
"object where __fspath__ returns a str, "
f"not {type(path).__name__!r}")
paths.append(path)
if path:
paths.append(path)
self._raw_paths = paths
if len(paths) == 1:
self._raw_path_cached = paths[0]
elif len(paths) == 0:
self._raw_path_cached = ''
self._raw_path_cached = '.'
self._resolving = False

def __reduce__(self):
Expand Down
7 changes: 7 additions & 0 deletions Lib/test/test_pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,13 @@ def test_fspath_common(self):
p = P('a/b')
self._check_str(p.__fspath__(), ('a/b',))
self._check_str(os.fspath(p), ('a/b',))
self.assertEqual('.', P().__fspath__())
self.assertEqual('.', P('').__fspath__())
self.assertEqual('.', P('.').__fspath__())
self.assertEqual('.', P('', '').__fspath__())
self.assertEqual('.', P('.', '').__fspath__())
self.assertEqual('.', P('', '.').__fspath__())
self.assertEqual(f'.{self.sep}.', P('.', '.').__fspath__())

def test_bytes(self):
P = self.cls
Expand Down