Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
a1326c8
GH-65238: Preserve trailing slash in pathlib
barneygale Nov 24, 2023
df1e115
Fix absolute() on bare DOS drive
barneygale Nov 24, 2023
61be2e3
Simplify diff
barneygale Nov 24, 2023
445364a
Reduce diff
barneygale Nov 24, 2023
6395815
Speed up _make_child_relpath()
barneygale Nov 24, 2023
435be1b
Ignore empty initialiser arguments for backwards compat
barneygale Nov 25, 2023
e577a67
Merge branch 'main' into keep-trailing-slash-wip3
barneygale Nov 25, 2023
d766d06
Simplify implementation
barneygale Dec 1, 2023
12cfb1a
Merge branch 'main' into keep-trailing-slash-wip3
barneygale Dec 2, 2023
2593ddb
Merge branch 'main' into keep-trailing-slash-wip3
barneygale Dec 3, 2023
b275078
Add tests
barneygale Dec 3, 2023
5d87cf4
Docstrings
barneygale Dec 4, 2023
af12c24
Docs
barneygale Dec 4, 2023
cae3774
Ensure has_trailing_sep is boolean
barneygale Dec 4, 2023
d4c87c6
Add tests for new methods/properties
barneygale Dec 4, 2023
1a77c8a
Fix WindowsPath('C:').absolute()
barneygale Dec 4, 2023
120beed
Merge branch 'main' into keep-trailing-slash-wip3
barneygale Dec 4, 2023
df79c49
Don't access `.parts` from `._glob()`
barneygale Dec 7, 2023
0f75804
Fix pickle roundtripping
barneygale Dec 7, 2023
eeb35ff
Undo changes to `parts`
barneygale Dec 7, 2023
153c4af
Merge branch 'main' into keep-trailing-slash-wip3
barneygale Dec 7, 2023
b852339
Simplify `_glob()` slightly
barneygale Dec 7, 2023
2b77a61
Fix possible scoping issue in `_glob()`
barneygale Dec 7, 2023
7b6766f
Formatting
barneygale Dec 8, 2023
f5c2265
Add test cases for preserving slash in absolute() and expanduser()
barneygale Dec 8, 2023
1126117
Add notes to `match()` and `glob()` docs
barneygale Dec 8, 2023
9c9b5ea
Merge branch 'main' into keep-trailing-slash-wip3
barneygale Dec 8, 2023
9539c60
Merge branch 'main' into keep-trailing-slash-wip3
barneygale Dec 11, 2023
14a9635
Merge branch 'main' into keep-trailing-slash-wip3
barneygale Dec 17, 2023
305381b
Undo pickling change
barneygale Dec 17, 2023
dfe7aae
Undo pickling changes.
barneygale Dec 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Simplify _glob() slightly
  • Loading branch information
barneygale committed Dec 7, 2023
commit b852339e2f1ed74b5a03ce454cee5b13efed508d
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