Per the description, this patch correctly implements Singleton as a metaclass.
This works by re-implementing the object's metaclass __call__ method such that its class __new__ (and __init__) is called only once. Subsequent object creation returns the prior constructed instance:
class Example(metaclass=Singleton):
pass
a = Example()
b = Example()
assert a is b
Per the description, this patch correctly implements
Singleton
as a metaclass.This works by re-implementing the object's metaclass
__call__
method such that its class__new__
(and__init__
) is called only once. Subsequent object creation returns the prior constructed instance: