no return values for __init__ ??
Gordon McMillan
gmcm at hypernet.com
Thu Jan 6 19:17:35 EST 2000
Helge Hess wrote:
> Gordon McMillan wrote:
> > > def __init__(self...
> > > s = super.__init__(self...
> >
> > OK, but it introduces a "gotcha". As in, what happened to the
> > stuff I set up before calling super.__init__, (which is not
> > only valid, but often useful).
>
> I don't know what you mean with that. It is deallocated if
> another value is returned and available to super.__init__ as
> usual. super.__init__ can base it's decision about the value to
> return on state already set up in self as well. I cannot see a
> problem here.
Hmmm...
class Base:
def __init__(self, arg):
if type(arg) is type(''):
s = String(arg)
elif type(arg) is UnicodeType:
s = Unicode(arg)
# preserve any mods to the instance
s.__dict__.update(self.__dict__)
if self.__class__ is Base:
return s
# oops, there are other classes involved
# now rebuild the class hierarchy
klass = self.__class__
while klass:
# assuming no MI, so we don't
# have to get recursive
parent = klass.__base__
if parent and parent is Base:
klass.__base__ = #oops,
# what do I do now?
Guess what? I need to derive a new class on the fly!
- Gordon
More information about the Python-list
mailing list