DEV Community

Discussion on: Alternative Constructors in Python

Collapse
 
p0intman profile image
P0intMaN

Great addition to the __init__() vs __new__() topic. My views were based on the practical understanding and I was being pretty restrictive when I said __new__() was the real constructor. I made this claim observing the fact that whenever you instantiate, in the backend, Python calls in __new__() first. Then, its the __new__() which "privately" calls __init__().

Yes, I strongly agree that both are called in while creating an object. The reason I was being defensive with __new__ is due to the strict definition of constructor I mentioned in the post and the fact that class makes an implicit call to __new__() while instantiating the object.

Again, this is purely debatable. It depends on the degree of freedom you add into the definition of constructor and purpose for which one had been using constructors for.