I switched to python some years ago because:- it is used by mainstream open source ai research and many hobbyists
- it has language support to reference, mutate, and recompile its own bytecode while executing it, and has some syntax mutability
- it's concise
There are downsides to python. Notably it is hard to debug interpreter problems from chip or kernel misbehavior. C is much better in my opinion.
Anyway, I've been using python for some time without understanding __new__, which is an important construct.
Here's how the manual says __new__ works. It's not complicated.
1. python calls Class.__new__(cls, ...) when Class(...) is called.
2. Unlike all other methods, __new__ is never passed a self object, and always passed a class object, no matter how it is decorated.
3. The return value of __new__ is passed on to __init__, after __new__ returns, if and only if it is an object of the class. Then it is returned to the user.
4. New objects can be constructed via super().__new__(cls), to return.
This lets one write constructors that for example instantiate a child class selected from arguments and perform other tricks.