Skip to content

Commit

Permalink
Simplify _glob() slightly
Browse files Browse the repository at this point in the history
  • Loading branch information
barneygale committed Dec 7, 2023
1 parent 153c4af commit b852339
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Lib/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1065,21 +1065,21 @@ def _glob(self, pattern, case_sensitive, follow_symlinks):
elif not path_pattern._tail:
raise ValueError("Unacceptable pattern: {!r}".format(pattern))

sep = self.pathmod.sep
pattern = str(path_pattern)
pattern_parts = pattern.split(sep)
if pattern_parts[-1] == '**':
if path_pattern.name == '**' and not path_pattern.has_trailing_sep:
# GH-70303: '**' only matches directories. Add trailing slash.
warnings.warn(
"Pattern ending '**' will match files and directories in a "
"future Python release. Add a trailing slash to match only "
"directories and remove this warning.",
FutureWarning, 3)
pattern_parts.append('')
path_pattern = path_pattern.with_trailing_sep()

if case_sensitive is None:
# TODO: evaluate case-sensitivity of each directory in _select_children().
case_sensitive = _is_case_sensitive(self.pathmod)
sep = self.pathmod.sep
pattern_str = str(path_pattern)
pattern_parts = pattern_str.split(sep)

# If symlinks are handled consistently, and the pattern does not
# contain '..' components, then we can use a 'walk-and-match' strategy
Expand Down Expand Up @@ -1117,7 +1117,7 @@ def _glob(self, pattern, case_sensitive, follow_symlinks):

# Filter out paths that don't match pattern.
prefix_len = len(str(self._make_child_relpath('_'))) - 1
match = _compile_pattern(pattern, sep, case_sensitive)
match = _compile_pattern(pattern_str, sep, case_sensitive)
paths = (path for path in paths if match(str(path), prefix_len))
return paths

Expand Down

0 comments on commit b852339

Please sign in to comment.