I guess the Python folks just decided that there is no reason to enforce __new__(cls, ...) to return instances of cls. __new__ is a fairly advanced method, so the user probably knows what he's doing, and there could be some reasons to exploit this behavior.
They still have to do the check, though. During instance creation, __init__ should be called. This is only reasonable if the instance (returned from __new__) really is a cls. If __new__ returns something different, chances are that the object cannot handle the arguments that would be passed to __init__.
In the end, the addition of __new__ to the language left the developers with three choices:
- Enforce
__new__(cls, ...) to return an instance of cls
- Always call
__init__ on the instance returned by __new__, leaving it up to the user to ensure that the object can handle the arguments.
- Only call
__init__ if the instance really is an instance of cls.
I guess that option 3 seemed most practical.
answered 2012-04-18T10:02:19.283