Skip to content

Commit b39eea0

Browse files
authored
bpo-42799: fnmatch module: bump up size of lru_cache for patterns (GH-27084)
1 parent 3527569 commit b39eea0

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

Doc/library/fnmatch.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ module. See module :mod:`glob` for pathname expansion (:mod:`glob` uses
4646
a period are not special for this module, and are matched by the ``*`` and ``?``
4747
patterns.
4848

49+
Also note that :func:`functools.lru_cache` with the *maxsize* of 32768 is used to
50+
cache the compiled regex patterns in the following functions: :func:`fnmatch`,
51+
:func:`fnmatchcase`, :func:`filter`.
4952

5053
.. function:: fnmatch(filename, pattern)
5154

Lib/fnmatch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def fnmatch(name, pat):
4141
pat = os.path.normcase(pat)
4242
return fnmatchcase(name, pat)
4343

44-
@functools.lru_cache(maxsize=256, typed=True)
44+
@functools.lru_cache(maxsize=32768, typed=True)
4545
def _compile_pattern(pat):
4646
if isinstance(pat, bytes):
4747
pat_str = str(pat, 'ISO-8859-1')
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
In :mod:`fnmatch`, the cache size for compiled regex patterns
2+
(:func:`functools.lru_cache`) was bumped up from 256 to 32768, affecting
3+
functions: :func:`fnmatch.fnmatch`, :func:`fnmatch.fnmatchcase`,
4+
:func:`fnmatch.filter`.

0 commit comments

Comments
 (0)