Skip to content

Commit

Permalink
Ignore empty initialiser arguments for backwards compat
Browse files Browse the repository at this point in the history
  • Loading branch information
barneygale committed Nov 25, 2023
1 parent 6395815 commit 435be1b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
3 changes: 2 additions & 1 deletion Lib/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,8 @@ 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
self._resolving = False

Expand Down
11 changes: 5 additions & 6 deletions Lib/test/test_pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,10 @@ class PurePathTest(unittest.TestCase):
'a/b': [
('a', 'b'), ('a/', 'b'), ('a//b',),
# Empty components get removed.
('', 'a', 'b'), ('a', '', 'b'),
('', 'a', 'b'), ('a', '', 'b'), ('a', 'b', ''),
],
'a/b/': [
('a', 'b/'), ('a/', 'b/'),
('a/b/',), ('a//b//',), ('a', 'b', ''),
('a', 'b/'), ('a/', 'b/'), ('a/b/',), ('a//b//',),
],
'/b/c/d': [
('a', '/b/c', 'd'), ('/a', '/b/c', 'd'),
Expand Down Expand Up @@ -2069,7 +2068,7 @@ def _check(glob, expected):
"dirA/", "dirA/linkC/", "dirB/", "dirB/linkD/", "dirC/",
"dirC/dirD/", "dirE/", "linkB/",
])
_check(p.rglob(""), ["", "dirA/", "dirB/", "dirC/", "dirE/", "dirC/dirD/"])
_check(p.rglob(""), ["./", "dirA/", "dirB/", "dirC/", "dirE/", "dirC/dirD/"])

p = P(BASE, "dirC")
_check(p.rglob("*"), ["dirC/fileC", "dirC/novel.txt",
Expand Down Expand Up @@ -2101,7 +2100,7 @@ def _check(path, glob, expected):
"dirC/fileC", "dirC/dirD/fileD", "linkB/fileB"])
_check(p, "*/", ["dirA/", "dirA/linkC/", "dirA/linkC/linkD/", "dirB/", "dirB/linkD/",
"dirC/", "dirC/dirD/", "dirE/", "linkB/", "linkB/linkD/"])
_check(p, "", ["", "dirA/", "dirA/linkC/", "dirA/linkC/linkD/", "dirB/", "dirB/linkD/",
_check(p, "", ["./", "dirA/", "dirA/linkC/", "dirA/linkC/linkD/", "dirB/", "dirB/linkD/",
"dirC/", "dirE/", "dirC/dirD/", "linkB/", "linkB/linkD/"])

p = P(BASE, "dirC")
Expand All @@ -2128,7 +2127,7 @@ def _check(path, glob, expected):
_check(p, "*/fileB", ["dirB/fileB"])
_check(p, "file*", ["fileA", "dirB/fileB", "dirC/fileC", "dirC/dirD/fileD", ])
_check(p, "*/", ["dirA/", "dirB/", "dirC/", "dirC/dirD/", "dirE/"])
_check(p, "", ["", "dirA/", "dirB/", "dirC/", "dirE/", "dirC/dirD/"])
_check(p, "", ["./", "dirA/", "dirB/", "dirC/", "dirE/", "dirC/dirD/"])

p = P(BASE, "dirC")
_check(p, "*", ["dirC/fileC", "dirC/novel.txt",
Expand Down

0 comments on commit 435be1b

Please sign in to comment.