no return values for __init__ ??

Helge Hess helge.hess at mdlink.de
Sun Jan 9 19:37:03 EST 2000


Gordon McMillan wrote:
> Is inheritance a matter of taste?

Strange questions ?!

> You claim to have patched your interpreter. Try this:
> 
> class A:
>   def __init__(self):
>     pass
> 
> class B:
>   def __init__(self):
>     return A()
> 
> class C(B):
>   def __init__(self):
>     self = B.__init__(self)
>   def method(self):
>     print "C.method called"
> 
> c = C()
> c.method()
> 
> Produces an AttributeError, doesn't it?

(First, *no*, it doesn't, since C.__init__ doesn't return a new object,
but only reassigns 'self').

Why should I do the above ? It's a completly constructed example. It's
similiar to this:

class A:     def __init__(self):  pass
class B(A):  def __init__(self):  return self.method()

Produces an AttributeError as well ...

The problem in your example is that you are misusing return values, eg

  class C(B):
    def __init__(self):
      s = B.__init__(self)
      if (s is not None) & (s is not self): return s

will work perfectly.

Helge
-- 
SKYRIX-OS  Web Application Environment - http://www.skyrix.com
SKYRIX-IAS Groupware Application Suite - http://www.skyrix.com




More information about the Python-list mailing list