[Python-checkins] bpo-42799: fnmatch module: bump up size of lru_cache for patterns (GH-27084)
ambv
webhook-mailer at python.org
Thu Jul 15 06:53:30 EDT 2021
https://github.com/python/cpython/commit/b39eea06d148887dd91a3612febafbddda760593
commit: b39eea06d148887dd91a3612febafbddda760593
branch: main
author: andrei kulakov <andrei.avk at gmail.com>
committer: ambv <lukasz at langa.pl>
date: 2021-07-15T12:53:26+02:00
summary:
bpo-42799: fnmatch module: bump up size of lru_cache for patterns (GH-27084)
files:
A Misc/NEWS.d/next/Library/2021-07-10-19-55-13.bpo-42799.ad4tq8.rst
M Doc/library/fnmatch.rst
M Lib/fnmatch.py
diff --git a/Doc/library/fnmatch.rst b/Doc/library/fnmatch.rst
index 925f08e914685..9163da57c7b99 100644
--- a/Doc/library/fnmatch.rst
+++ b/Doc/library/fnmatch.rst
@@ -46,6 +46,9 @@ module. See module :mod:`glob` for pathname expansion (:mod:`glob` uses
a period are not special for this module, and are matched by the ``*`` and ``?``
patterns.
+Also note that :func:`functools.lru_cache` with the *maxsize* of 32768 is used to
+cache the compiled regex patterns in the following functions: :func:`fnmatch`,
+:func:`fnmatchcase`, :func:`filter`.
.. function:: fnmatch(filename, pattern)
diff --git a/Lib/fnmatch.py b/Lib/fnmatch.py
index 7c52c23067d40..239c7490d49ee 100644
--- a/Lib/fnmatch.py
+++ b/Lib/fnmatch.py
@@ -41,7 +41,7 @@ def fnmatch(name, pat):
pat = os.path.normcase(pat)
return fnmatchcase(name, pat)
- at functools.lru_cache(maxsize=256, typed=True)
+ at functools.lru_cache(maxsize=32768, typed=True)
def _compile_pattern(pat):
if isinstance(pat, bytes):
pat_str = str(pat, 'ISO-8859-1')
diff --git a/Misc/NEWS.d/next/Library/2021-07-10-19-55-13.bpo-42799.ad4tq8.rst b/Misc/NEWS.d/next/Library/2021-07-10-19-55-13.bpo-42799.ad4tq8.rst
new file mode 100644
index 0000000000000..8a25800611a5a
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2021-07-10-19-55-13.bpo-42799.ad4tq8.rst
@@ -0,0 +1,4 @@
+In :mod:`fnmatch`, the cache size for compiled regex patterns
+(:func:`functools.lru_cache`) was bumped up from 256 to 32768, affecting
+functions: :func:`fnmatch.fnmatch`, :func:`fnmatch.fnmatchcase`,
+:func:`fnmatch.filter`.
More information about the Python-checkins
mailing list