Whole file

vidartf/globmatch

The author described this change as Fix matching dotfiles. It counts as a record because the check below fails on the code as it stood at 61d2d26d7 and passes on 254852544, with nothing else changed between the two runs.

Fix saved2021-01-06
Sharing licenceBSD-3-Clause · LICENSE.md
Change size+5 4

What the code was meant to do, written into the code itself as a save note

Fix matching dotfiles

The change

2020
2121 # TODO: In the future use f-strings for formatting
2222
23+double_start_re = r'.*((?<=(/))|(?<=(\A)))'
2324
25+
2426 @lru_cache(maxsize=256, typed=True)
2527 def compile_pattern(pat, subentries_match=None):
2628 """Translate and compile a glob pattern to a regular expression matcher.
4042 res = translate_glob(os.path.normcase(pat), subentries_match=subentries_match)
4143 return re.compile(res).match
4244
43-
4445 def translate_glob(pat, subentries_match=None):
4546 """Translate a glob PATTERN to a regular expression."""
4647 translated_parts = []
6061 """
6162 res = ''
6263 for part in translated_parts[:-1]:
63- if part == '.*':
64+ if part == double_start_re:
6465 # drop separator, since it is optional
6566 # (** matches ZERO or more dirs)
6667 res += part
6768 else:
6869 res += part + os_sep_class
6970
70- if translated_parts[-1] == '.*':
71+ if translated_parts[-1] == double_start_re:
7172 # Final part is **
7273 # Should not match directory:
7374 res += '.+'
9192 """Translate a glob PATTERN PART to a regular expression."""
9293 # Code modified from Python 3 standard lib fnmatch:
9394 if pat == '**':
94- return '.*'
95+ return double_start_re
9596 i, n = 0, len(pat)
9697 res = []
9798 while i < n:

The check that tells the two apart

failpass·tests/test_match.py::test_match_dot_files

Check file tests/test_match.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before it61d2d26d7845127b06ec5857a32d82dfde545136
Broken version dated2021-01-06
Moduleglobmatch.translation
Units changedjoin_translated, translate_glob_part
Fingerprintdc81c00e5c1b8694
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.