From a2f45e7fbcf35f297a10411a6b5d2a31d228e19d Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Tue, 29 Sep 2026 22:22:22 +0200 Subject: [PATCH] Cache the release headers with functools.lru_cache Codacy (Pylint) flagged the mutable default argument that header() used as its cache. functools.lru_cache keeps the same memoization without it. The script's output is unchanged. Signed-off-by: Niels Lohmann --- docs/mkdocs/scripts/check_version_history.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/docs/mkdocs/scripts/check_version_history.py b/docs/mkdocs/scripts/check_version_history.py index 0559499d6..81d629500 100644 --- a/docs/mkdocs/scripts/check_version_history.py +++ b/docs/mkdocs/scripts/check_version_history.py @@ -10,6 +10,7 @@ they were documented for users. The check is heuristic and meant to be run by ha usage: python3 check_version_history.py (from docs/mkdocs/docs, needs the git tags) """ +import functools import glob import re # the script only runs git with fixed arguments and without a shell @@ -32,16 +33,14 @@ def release_tags(): return sorted(versions) -def header(tag, cache={}): - if tag not in cache: - cache[tag] = "" - for path in HEADER_PATHS: - # fixed git command without a shell; the tag names come from "git tag" - result = subprocess.run(["git", "show", f"{tag}:{path}"], capture_output=True, text=True) # nosec B603, B607 - if result.returncode == 0: - cache[tag] = result.stdout - break - return cache[tag] +@functools.lru_cache(maxsize=None) +def header(tag): + for path in HEADER_PATHS: + # fixed git command without a shell; the tag names come from "git tag" + result = subprocess.run(["git", "show", f"{tag}:{path}"], capture_output=True, text=True) # nosec B603, B607 + if result.returncode == 0: + return result.stdout + return "" def macros_and_versions(page):