hi @monorail would you like to see a really fucking stupid joke
@wallhackio @monorail yes
@monorail I don't get it
⚠️ i've been writing python for most of my time on earth ⚠️
@wallhackio @The_T extremely loud incorrect buzzer
most languages don't have anything exactly equivalent to __init__
, but they have something equivalent to python's __new__
. in python we just prefer to create bare objects and initialize them rather than do it in the constructor for some reason
re: ⚠️ i've been writing python for most of my time on earth ⚠️
@vaporeon_ @monorail @The_T normally in OOP, object instantiation logic is contained within a constructor, but Python decided to split the process into two steps:
1) __new__
is a function which returns the instantiated object,
2) __init__
is a function that receives the instantiated object and and initializes its state
It is very rare that a Python programmer ever use __new__
. In 99% of cases, what you would put in a constructor in some other language is put in the __init__
method when you use Python.
You can override __new__
, however, so that it returns anything you want. You typically do this when you subclass immutable types. Because, if you try to manipulate a subclassed immutable object in the __init__
function, well you can't. Because its immutable. So you have to override the creation of the object itself, typically by calling the superclass's constructor, in the __new__
method.