10000 GH-73435: Add `pathlib.PurePath.full_match()` by barneygale · Pull Request #114350 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

GH-73435: Add pathlib.PurePath.full_match() #114350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 26, 2024
Merged
Changes from 1 commit
Commits
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
Improve variable names
  • Loading branch information
barneygale committed Jan 20, 2024
commit ed203e80d8c628e402628155e2362057fcb69062
16 changes: 8 additions & 8 deletions Lib/pathlib/_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,17 +450,17 @@ def match(self, path_pattern, *, case_sensitive=None):
if case_sensitive is None:
case_sensitive = _is_case_sensitive(self.pathmod)
sep = path_pattern.pathmod.sep
our_parts = self.parts[::-1]
pat_parts = path_pattern.parts[::-1]
if not pat_parts:
path_parts = self.parts[::-1]
pattern_parts = path_pattern.parts[::-1]
if not pattern_parts:
raise ValueError("empty pattern")
if len(our_parts) < len(pat_parts):
if len(path_parts) < len(pattern_parts):
return False
if len(our_parts) > len(pat_parts) and path_pattern.anchor:
if len(path_parts) > len(pattern_parts) and path_pattern.anchor:
return False
for our_part, pat_part in zip(our_parts, pat_parts):
match = _compile_pattern(pat_part, sep, case_sensitive, recursive=False)
if match(our_part) is None:
for path_part, pattern_part in zip(path_parts, pattern_parts):
match = _compile_pattern(pattern_part, sep, case_sensitive, recursive=False)
if match(path_part) is None:
return False
return True

Expand Down
0