From 0d4a9d6b8740035346d098f5bc28ebca64f6cd4d Mon Sep 17 00:00:00 2001 From: Robert Honz Date: Tue, 19 Dec 2023 23:58:57 +0100 Subject: 🌟 Re-add all project files. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tidal_dl_ng/helper/decorator.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 tidal_dl_ng/helper/decorator.py (limited to 'tidal_dl_ng/helper/decorator.py') diff --git a/tidal_dl_ng/helper/decorator.py b/tidal_dl_ng/helper/decorator.py new file mode 100644 index 0000000..545f73b --- /dev/null +++ b/tidal_dl_ng/helper/decorator.py @@ -0,0 +1,19 @@ +class SingletonMeta(type): + """ + The Singleton class can be implemented in different ways in Python. Some + possible methods include: base class, decorator, metaclass. We will use the + metaclass because it is best suited for this purpose. + """ + + _instances = {} + + def __call__(cls, *args, **kwargs): + """ + Possible changes to the value of the `__init__` argument do not affect + the returned instance. + """ + if cls not in cls._instances: + instance = super().__call__(*args, **kwargs) + cls._instances[cls] = instance + + return cls._instances[cls] -- cgit v1.3.1