[Zope3-Users] __init__ method never called?

John Smith jsmith030416 at yahoo.co.uk
Tue Sep 19 08:23:02 EDT 2006


Hi,
both Resource and BrowserView have a common parent
class, viz Location, whose parent class is object.

           object
             |
             |
         Location
           /   \
          /     \
         /       \
   BrowserView   Resource
         \        /
          \      /
           \    /
        FileResource


As there are no calls to super() in any of the
definitions of BrowserView, Reource, FileResource or
Location, only the __init__ method of BrowserView
would appear to be called because attribute lookup
proceeds through the parent classes in the order they
are provided in the definition.

This can be practically tested by inserting a
NotImplementedError into to the definition of
Resource.__init__.

I'm pretty certain that that method is never called,
unless perhaps somewhere else in zope there is another
class that inherits from it first.

Cheers,

John.


--- Stephan Richter <srichter at cosmos.phy.tufts.edu>
wrote:

> On Tuesday 19 September 2006 03:47, FB wrote:
> > (Please correct me if I'm wrong, I'm not a Python
> guru :-) )
> >
> > Whenever you inherit from two classes, only the
> first class'
> > __init__ method is called implicitely on create of
> a new instance.
> 
> >>> class First(object):
> ...     def __init__(self):
> ...         print 'init 1-before'
> ...         super(First, self).__init__()
> ...         print 'init 1-after'
> ...
> >>> class Second(object):
> ...     def __init__(self):
> ...         print 'init 2-before'
> ...         super(Second, self).__init__()
> ...         print 'init 2-after'
> ...
> >>> class Join(First, Second):
> ...     def __init__(self):
> ...         print 'init 3-before'
> ...         super(Join, self).__init__()
> ...         print 'init 3-after'
> ...
> >>> Join()
> init 3-before
> init 1-before
> init 2-before
> init 2-after
> init 1-after
> init 3-after
> <__main__.Join object at 0xb7b5fb6c>
> >>>
> 
> Regards,
> Stephan
> -- 
> Stephan Richter
> CBU Physics & Chemistry (B.S.) / Tufts Physics
> (Ph.D. student)
> Web2k - Web Software Design, Development and
> Training
> _______________________________________________
> Zope3-users mailing list
> Zope3-users at zope.org
> http://mail.zope.org/mailman/listinfo/zope3-users
> 



		
___________________________________________________________ 
Yahoo! Photos – NEW, now offering a quality print service from just 8p a photo http://uk.photos.yahoo.com


More information about the Zope3-users mailing list