From f29115a9545cd08467cd9a68b7ba1a9263084899 Mon Sep 17 00:00:00 2001 From: andrei kulakov Date: Sat, 10 Jul 2021 19:47:23 -0400 Subject: [PATCH 1/3] bump lru cache to 32768 in fnmatch; update docs --- Doc/library/fnmatch.rst | 3 +++ Lib/fnmatch.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Doc/library/fnmatch.rst b/Doc/library/fnmatch.rst index 925f08e914685e..06ff7d458b5487 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 size of 32768 will be 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 7c52c23067d40f..239c7490d49eec 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) -@functools.lru_cache(maxsize=256, typed=True) +@functools.lru_cache(maxsize=32768, typed=True) def _compile_pattern(pat): if isinstance(pat, bytes): pat_str = str(pat, 'ISO-8859-1') From ca7ec5eafdc48bf4b4a24541ebf7f03852baccb0 Mon Sep 17 00:00:00 2001 From: andrei kulakov Date: Sat, 10 Jul 2021 19:55:47 -0400 Subject: [PATCH 2/3] add news entry --- .../next/Library/2021-07-10-19-55-13.bpo-42799.ad4tq8.rst | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2021-07-10-19-55-13.bpo-42799.ad4tq8.rst 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 00000000000000..8a25800611a5a6 --- /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`. From a4e2e9d6dcf3b43f00cc53008ab0cac064ea87d9 Mon Sep 17 00:00:00 2001 From: andrei kulakov Date: Sat, 10 Jul 2021 19:59:01 -0400 Subject: [PATCH 3/3] doc update for clarity --- Doc/library/fnmatch.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/fnmatch.rst b/Doc/library/fnmatch.rst index 06ff7d458b5487..9163da57c7b999 100644 --- a/Doc/library/fnmatch.rst +++ b/Doc/library/fnmatch.rst @@ -46,7 +46,7 @@ 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 size of 32768 will be used to +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`.