From 93a5cad0033690112b4ed569073bd2071032c373 Mon Sep 17 00:00:00 2001 From: Andrew Hamilton Date: Sat, 12 Mar 2022 14:36:58 +1000 Subject: [PATCH] Coding style - Sometimes use functools.cache. --- eris/eris/__main__.py | 5 ++--- eris/eris/tools.py | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/eris/eris/__main__.py b/eris/eris/__main__.py index 6fdc68f..0f371f5 100755 --- a/eris/eris/__main__.py +++ b/eris/eris/__main__.py @@ -163,7 +163,7 @@ def fix_paths(root_path, paths): def highlight_str(line, highlight_color, transparency): - @functools.lru_cache() + @functools.lru_cache(maxsize=500) def blend_style(style): fg_color = (style.fg_color if type(style.fg_color) == tuple else termstr.XTERM_COLORS[style.fg_color]) @@ -918,13 +918,12 @@ class Screen: _STATUS_BAR = highlight_chars(" *help *quit *t*a*b:focus *turn *log *edit *next *sort" " *refresh *fullscreen *open", Log._GREEN_STYLE) - @functools.lru_cache() + @functools.cache def _get_partial_bar_chars(self, bar_transparency): bar_color = termstr.blend_color(termstr.Color.black, termstr.Color.white, bar_transparency) return [termstr.TermStr(char).fg_color(bar_color).bg_color(termstr.Color.black) for char in fill3.ScrollBar._PARTIAL_CHARS[1]] - @functools.lru_cache(maxsize=2) def _get_status_bar_appearance(self, width, progress_bar_size): bar_transparency = 0.7 bar = self._STATUS_BAR.center(width)[:width] diff --git a/eris/eris/tools.py b/eris/eris/tools.py index c1afb61..7e56a24 100755 --- a/eris/eris/tools.py +++ b/eris/eris/tools.py @@ -519,7 +519,7 @@ def dump_pickle_safe(object_, path, protocol=pickle.HIGHEST_PROTOCOL, open=open) os.rename(tmp_path, path) -@functools.lru_cache() +@functools.cache def compression_open_func(compression): return open if compression == "none" else importlib.import_module(compression).open @@ -619,7 +619,7 @@ for extensions, tool_names in tools_for_extensions: (extensions, [globals()[tool_name] for tool_name in tool_names])) -@functools.lru_cache(maxsize=1) +@functools.cache def _tools_for_extension(): result = {} for extensions, tools in TOOLS_FOR_EXTENSIONS: @@ -661,7 +661,7 @@ def splitext(path): return root, ext -@functools.lru_cache() +@functools.cache def is_tool_available(tool): if (hasattr(tool, "command") and tool.command.startswith(f"{PYTHON_EXECUTABLE} -m ")): try: