Minimal changes to document Singleton and class definitions it wraps

This commit is contained in:
Dmitri Bogomolov 2019-10-16 17:53:37 +03:00
parent 86f0860cb2
commit c63ed02153
Signed by untrusted user: g1itch
GPG Key ID: 720A756F18DEED13
2 changed files with 19 additions and 2 deletions

View File

@ -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 = {}

View File

@ -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]