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:
parent
3eb2904958
commit
bb228f1929
1 changed files with 5 additions and 5 deletions
|
|
@ -10,7 +10,7 @@ import re
|
|||
import sys
|
||||
|
||||
from enum import Enum, auto
|
||||
from functools import lru_cache
|
||||
from functools import cache
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from .lib.App import App as Base
|
||||
|
|
@ -512,7 +512,7 @@ class App(Base):
|
|||
def strip_module_from_spec(self, mod):
|
||||
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:
|
||||
ret = ''
|
||||
pat = '[' + section + ']'
|
||||
|
|
@ -529,7 +529,7 @@ class App(Base):
|
|||
file.close()
|
||||
return ret.rstrip()
|
||||
|
||||
@lru_cache(maxsize = None)
|
||||
@cache
|
||||
def read_value(self, path: str, section: str, key: str) -> str | None:
|
||||
|
||||
def scan_section(f, key: str) -> str | None:
|
||||
|
|
@ -582,7 +582,7 @@ class App(Base):
|
|||
return 'none'
|
||||
return None
|
||||
|
||||
@lru_cache(maxsize = None)
|
||||
@cache
|
||||
def get_value(self, project: str, section: str, key: str) -> str | None:
|
||||
ret: str | None
|
||||
proj_dir = self.__proj_dir(project, pretty = False)
|
||||
|
|
@ -612,7 +612,7 @@ class App(Base):
|
|||
)
|
||||
return ret
|
||||
|
||||
@lru_cache(maxsize = None)
|
||||
@cache
|
||||
def get_version(self, project) -> str:
|
||||
ret = self.get_value(project, 'version', '')
|
||||
if ret is None:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue