From c63ed02153869aeefb35502df8e60c29dba68b2f Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Wed, 16 Oct 2019 17:53:37 +0300 Subject: [PATCH] Minimal changes to document Singleton and class definitions it wraps --- src/bmconfigparser.py | 6 ++++-- src/singleton.py | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/bmconfigparser.py b/src/bmconfigparser.py index 726d32eb..7f28d1b8 100644 --- a/src/bmconfigparser.py +++ b/src/bmconfigparser.py @@ -43,8 +43,10 @@ BMConfigDefaults = { @Singleton class BMConfigParser(ConfigParser.SafeConfigParser): - """Singleton class inherited from ConfigParser.SafeConfigParser - with additional methods specific to bitmessage config.""" + """ + Singleton class inherited from :class:`ConfigParser.SafeConfigParser` + with additional methods specific to bitmessage config. + """ _temp = {} diff --git a/src/singleton.py b/src/singleton.py index 1eef08e1..5c6c43be 100644 --- a/src/singleton.py +++ b/src/singleton.py @@ -1,6 +1,21 @@ +""" +Singleton decorator definition +""" + +from functools import wraps + + def Singleton(cls): + """ + Decorator implementing the singleton pattern: + it restricts the instantiation of a class to one "single" instance. + """ instances = {} + + # https://github.com/sphinx-doc/sphinx/issues/3783 + @wraps(cls) def getinstance(): + """Find an instance or save newly created one""" if cls not in instances: instances[cls] = cls() return instances[cls]