From e237c4a7e25a8a9c4581f29e2066c765b64d376b Mon Sep 17 00:00:00 2001 From: Manuel Barkhau Date: Thu, 24 Sep 2020 19:22:32 +0000 Subject: [PATCH] add missing module --- src/pycalver/utils.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/pycalver/utils.py diff --git a/src/pycalver/utils.py b/src/pycalver/utils.py new file mode 100644 index 0000000..5f7c5bc --- /dev/null +++ b/src/pycalver/utils.py @@ -0,0 +1,24 @@ +# This file is part of the pycalver project +# https://github.com/mbarkhau/pycalver +# +# Copyright (c) 2018-2020 Manuel Barkhau (mbarkhau@gmail.com) - MIT License +# SPDX-License-Identifier: MIT +import typing as typ +import functools + +# NOTE (mb 2020-09-24): The main use of the memo function is +# not as a performance optimization, but to reduce logging +# spam. + + +def memo(func: typ.Callable) -> typ.Callable: + cache = {} + + @functools.wraps(func) + def wrapper(*args): + key = str(args) + if key not in cache: + cache[key] = func(*args) + return cache[key] + + return wrapper