From 435be1b5823a50b3c1627e7238cb92164cbddd99 Mon Sep 17 00:00:00 2001 From: barneygale Date: Sat, 25 Nov 2023 11:59:57 +0000 Subject: [PATCH] Ignore empty initialiser arguments for backwards compat --- Lib/pathlib.py | 3 ++- Lib/test/test_pathlib.py | 11 +++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Lib/pathlib.py b/Lib/pathlib.py index b0e6739d3715ce..7e2a8b30e4eb10 100644 --- a/Lib/pathlib.py +++ b/Lib/pathlib.py @@ -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 diff --git a/Lib/test/test_pathlib.py b/Lib/test/test_pathlib.py index af10b35d9711ea..06604cdbc5773a 100644 --- a/Lib/test/test_pathlib.py +++ b/Lib/test/test_pathlib.py @@ -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'), @@ -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", @@ -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") @@ -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",