Re: return None in constructor call?

Tim Peters (tim@ksr.com)
Sun, 21 Nov 93 13:50:42 EST

> > > [matt]
> > > Is there some reason the Some_Class __init__ routine isn't allowed
> > > to return 'self' in some form?
> > [tim]
> > Maybe because __init__ is a magical method, and Python "just knows" to
> > return the self it passed to __init__ to begin with. Agreed it's not
> > obvious ...
> [guido]
> Why isn't it obvious? I have a feeling that all this confusion stems
> from the old convention to have an "init()" method which *did* have to
> return self to be useful.

Yes, I'm sure that's most of it. For old-timers, it's natural to
mentally translate
thing = Class_Name(arglist)
into
thing = Class_Name().__init__(arglist)

in analogy with the old convention. It's not obvious at first that this
is inappropriate.

The rest of it is that the special semantics of __init__ aren't quite
fully spelled out in section 3.3.1 of the reference manual: when the
manual doesn't _say_ what an __init__ method should return, "not obvious"
seems a fair characterization of the reader's position.

BTW, none of this is to say I have a complaint about __init__. It's
fine!

just-not-obvious<grin>-ly y'rs - tim

Tim Peters tim@ksr.com
not speaking for Kendall Square Research Corp