Skip to content

Commit 3f2291f

Browse files
committed
Change fnmatch.py to use separate caches for str and bytes keys.
This is necessary to pass the tests with -bb.
1 parent 7ed5196 commit 3f2291f

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

Lib/fnmatch.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414

1515
__all__ = ["filter", "fnmatch","fnmatchcase","translate"]
1616

17-
_cache = {}
17+
_cache = {} # Maps text patterns to compiled regexen.
18+
_cacheb = {} # Ditto for bytes patterns.
1819

1920
def fnmatch(name, pat):
2021
"""Test whether FILENAME matches PATTERN.
@@ -38,15 +39,16 @@ def fnmatch(name, pat):
3839
return fnmatchcase(name, pat)
3940

4041
def _compile_pattern(pat):
41-
regex = _cache.get(pat)
42+
cache = _cacheb if isinstance(pat, bytes) else _cache
43+
regex = cache.get(pat)
4244
if regex is None:
4345
if isinstance(pat, bytes):
4446
pat_str = str(pat, 'ISO-8859-1')
4547
res_str = translate(pat_str)
4648
res = bytes(res_str, 'ISO-8859-1')
4749
else:
4850
res = translate(pat)
49-
_cache[pat] = regex = re.compile(res)
51+
cache[pat] = regex = re.compile(res)
5052
return regex.match
5153

5254
def filter(names, pat):

0 commit comments

Comments
 (0)