I understand what __new__
does (and how it's different from __init__
) so I'm not interested in definitions, I'm interested in when and how to use __new__
.
The documentation says:
In general, you shouldn't need to override
__new__
unless you're subclassing an immutable type likestr
,int
,unicode
ortuple
But I can't think of other cases to use __new__
or how to use it correctly (for example when subclassing an immutable type or why it's needed in this case).
So, when, why and how do you need to use __new__
?
I'm interested in the use cases, not what it does (I know what it does).