Skip to content

Commit

Permalink
Add comment explaining regex that consumes "empty" paths.
Browse files Browse the repository at this point in the history
  • Loading branch information
barneygale committed Sep 30, 2023
1 parent 78292eb commit 5d4062c
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Lib/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ def _compile_pattern(pat, sep, case_sensitive):
sensitivity)."""
flags = re.NOFLAG if case_sensitive else re.IGNORECASE
regex = glob.translate(pat, recursive=True, include_hidden=True, seps=sep)
return re.compile(r'(\.\Z)?+' + regex, flags).match
# The string representation of an empty path is a single dot ('.'). Empty
# paths shouldn't match wildcards, so we consume it with an atomic group.
regex = r'(\.\Z)?+' + regex
return re.compile(regex, flags).match


def _select_children(parent_paths, dir_only, follow_symlinks, match):
Expand Down

0 comments on commit 5d4062c

Please sign in to comment.