App: Replace @lru_cache() with @cache

Replace the @functools.lru_cache(maxsize=None) decorator with @functools.cache throughout App. functools.cache is a shorthand for functools.lru_cache(maxsize=None) introduced in Python 3.9 and is more concise and readable with identical behaviour.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-06-09 12:51:25 +02:00
commit bb228f1929
Signed by: Jan Lindemann
GPG key ID: 3750640C9E25DD61

View file

@ -10,7 +10,7 @@ import re
import sys import sys
from enum import Enum, auto from enum import Enum, auto
from functools import lru_cache from functools import cache
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from .lib.App import App as Base from .lib.App import App as Base
@ -512,7 +512,7 @@ class App(Base):
def strip_module_from_spec(self, mod): def strip_module_from_spec(self, mod):
return re.sub(r'-dev$|-devel$|-run$', '', re.split('([=><]+)', mod)[0].strip()) return re.sub(r'-dev$|-devel$|-run$', '', re.split('([=><]+)', mod)[0].strip())
@lru_cache(maxsize = None) @cache
def get_section(self, path: str, section: str) -> str: def get_section(self, path: str, section: str) -> str:
ret = '' ret = ''
pat = '[' + section + ']' pat = '[' + section + ']'
@ -529,7 +529,7 @@ class App(Base):
file.close() file.close()
return ret.rstrip() return ret.rstrip()
@lru_cache(maxsize = None) @cache
def read_value(self, path: str, section: str, key: str) -> str | None: def read_value(self, path: str, section: str, key: str) -> str | None:
def scan_section(f, key: str) -> str | None: def scan_section(f, key: str) -> str | None:
@ -582,7 +582,7 @@ class App(Base):
return 'none' return 'none'
return None return None
@lru_cache(maxsize = None) @cache
def get_value(self, project: str, section: str, key: str) -> str | None: def get_value(self, project: str, section: str, key: str) -> str | None:
ret: str | None ret: str | None
proj_dir = self.__proj_dir(project, pretty = False) proj_dir = self.__proj_dir(project, pretty = False)
@ -612,7 +612,7 @@ class App(Base):
) )
return ret return ret
@lru_cache(maxsize = None) @cache
def get_version(self, project) -> str: def get_version(self, project) -> str:
ret = self.get_value(project, 'version', '') ret = self.get_value(project, 'version', '')
if ret is None: if ret is None: