mirror of
https://github.com/python/cpython.git
synced 2025-07-19 17:25:54 +00:00
GH-104102: Optimize pathlib.Path.glob()
handling of ../
pattern segments (GH-104103)
These segments do not require a `stat()` call, as the selector's `_select_from()` method is called after we've established that the parent is a directory.
This commit is contained in:
parent
47770a1e91
commit
65a49c6553
3 changed files with 19 additions and 0 deletions
|
@ -74,6 +74,8 @@ def _make_selector(pattern_parts, flavour):
|
|||
return _TerminatingSelector()
|
||||
if pat == '**':
|
||||
cls = _RecursiveWildcardSelector
|
||||
elif pat == '..':
|
||||
cls = _ParentSelector
|
||||
elif '**' in pat:
|
||||
raise ValueError("Invalid pattern: '**' can only be an entire path component")
|
||||
elif _is_wildcard_pattern(pat):
|
||||
|
@ -114,6 +116,16 @@ class _TerminatingSelector:
|
|||
yield parent_path
|
||||
|
||||
|
||||
class _ParentSelector(_Selector):
|
||||
def __init__(self, name, child_parts, flavour):
|
||||
_Selector.__init__(self, child_parts, flavour)
|
||||
|
||||
def _select_from(self, parent_path, is_dir, exists, scandir):
|
||||
path = parent_path._make_child_relpath('..')
|
||||
for p in self.successor._select_from(path, is_dir, exists, scandir):
|
||||
yield p
|
||||
|
||||
|
||||
class _PreciseSelector(_Selector):
|
||||
|
||||
def __init__(self, name, child_parts, flavour):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue