[Python-Dev] How to suppress instance __dict__?

David Abrahams dave at boost-consulting.com
Mon Mar 24 04:01:14 CET 2003

"Delaney, Timothy C (Timothy)" <tdelaney at avaya.com> writes:

>> From: David Abrahams [mailto:dave at boost-consulting.com]
>> Guido van Rossum <guido at python.org> writes:
>> > So I don't think __new__ is preferred over __init__, unless
>> you need a
>> > feature that only __new__ offers (like initializing an
>> immutable base
>> > class or returning an existing object or an object of a different
>> > class).
>>  In other words, TIMTOWTDI? <0.3 wink>
> [Moved to python-list as I think it's gone well beyond python-dev].
> I wouldn't say that. Use __init__ unless you *must* use __new__. And
> when you use __new__, still use __init__ for initialisation.
> And if you are going to use __new__, you are expected to be able to
> explain *why*.
> Pretty straightforward to me.

Why should that be the rule? Why not the opposite?

FWIW, if everyone used the opposite policy (__new__ unless you must
use __init__), the problem of __del__ operating on uninitialized
objects could be substantially relieved.

However, tradition has us working the other way.

Dave Abrahams
Boost Consulting

More information about the Python-list mailing list