In next super-primitive code when __new__
method is defined __init__
method for created objects is not called.
class NaiveSingleton:
def __new__(cls):
pass
def __init__(self):
print("NaiveSingleton init called")
so, call
nsA1 = NaiveSingletonA()
nsA2 = NaiveSingletonA()
brings no __init__
printout. Why?
Second question:
Why definition of empty __new__
method make this class work as singleton?