diff options
author | Barney Gale <barney.gale@gmail.com> | 2024-02-10 18:12:34 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-10 18:12:34 (GMT) |
commit | 6f93b4df92b8fbf80529cb6435789f5a75664a20 (patch) | |
tree | 9847e44bb89c24c38f5217dada3fdfc83344a376 /Lib/test/test_pathlib | |
parent | 9d1a353230f555fc28239c5ca1e82b758084e02a (diff) | |
download | cpython-6f93b4df92b8fbf80529cb6435789f5a75664a20.zip cpython-6f93b4df92b8fbf80529cb6435789f5a75664a20.tar.gz cpython-6f93b4df92b8fbf80529cb6435789f5a75664a20.tar.bz2 |
GH-115060: Speed up `pathlib.Path.glob()` by removing redundant regex matching (#115061)
When expanding and filtering paths for a `**` wildcard segment, build an `re.Pattern` object from the subsequent pattern parts, rather than the entire pattern, and match against the `os.DirEntry` object prior to instantiating a path object. Also skip compiling a pattern when expanding a `*` wildcard segment.
Diffstat (limited to 'Lib/test/test_pathlib')
-rw-r--r-- | Lib/test/test_pathlib/test_pathlib.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_pathlib/test_pathlib.py b/Lib/test/test_pathlib/test_pathlib.py index 2b16645..c0dcf31 100644 --- a/Lib/test/test_pathlib/test_pathlib.py +++ b/Lib/test/test_pathlib/test_pathlib.py @@ -1250,6 +1250,19 @@ class PathTest(test_pathlib_abc.DummyPathTest, PurePathTest): self.assertEqual(expect, set(p.glob(P(pattern)))) self.assertEqual(expect, set(p.glob(FakePath(pattern)))) + @needs_symlinks + def test_glob_dot(self): + P = self.cls + with os_helper.change_cwd(P(self.base, "dirC")): + self.assertEqual( + set(P('.').glob('*')), {P("fileC"), P("novel.txt"), P("dirD")}) + self.assertEqual( + set(P('.').glob('**')), {P("fileC"), P("novel.txt"), P("dirD"), P("dirD/fileD"), P(".")}) + self.assertEqual( + set(P('.').glob('**/*')), {P("fileC"), P("novel.txt"), P("dirD"), P("dirD/fileD")}) + self.assertEqual( + set(P('.').glob('**/*/*')), {P("dirD/fileD")}) + def test_rglob_pathlike(self): P = self.cls p = P(self.base, "dirC") |