# -*- coding: utf-8 -*-
"""pyhades/_singleton.py

This module implements a singleton pattern design, a base class for
inheritance in other classes
"""
from weakref import WeakValueDictionary

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 = WeakValueDictionary()

    def __call__(cls, *args, **kwargs):
        if cls not in cls._instances:
            # This variable declaration is required to force a
            # strong reference on the instance.
            instance = super().__call__(*args, **kwargs)
            cls._instances[cls] = instance
        return cls._instances[cls]
    


class Singleton(metaclass=SingletonMeta):
    """
    The Singleton with simple class name.
    """