code goes first:
def singleton(cls):
instances = {}
def get_instance():
if cls not in instances:
instances[cls] = cls()
return instances[cls]
return get_instance
@singleton
class A:
#...
Ok, the code above is an implementation of Singleton, I saw this implementation in another post.
I don't understand why the singleton function returns a function but A is a class. How does it worK?