[Zope-dev] Why use apply(foo.__call__, ..)?

Ross Boylan RossBoylan@stanfordalumni.org
Thu, 31 Aug 2000 23:55:50 -0700


In looking over the code for ZWiki/ZC, I see a lot of places with the 
following construct:
apply(foo.__call__, some, arguments)
Why not just say
foo(some, arguments)?

Examples of the construct from ZWikiPage.py:
            apply(self.aq_parent.standard_wiki_page.__call__,
                       (None, REQUEST, REQUEST.RESPONSE))
or
            apply(DTMLDocument.__call__,(self, self.aq_parent,
                                              REQUEST, REQUEST.RESPONSE))

[OK, in this case the question technically is why use apply(foo.__call__, 
(a, b, c)) instead of foo(a,b,c)? Hmmm...
x.foo(a, b, c) -> foo.__call__(x, a, b, c).]

These requests are mostly, if not entirely, directed at 
WikiPages/Headers/etc, whose definition is, in part,
class ZWikiPage(DTMLDocument): #, CatalogAware):
     def __call__(self, client=None, REQUEST={}, RESPONSE=None, **kw):
         """Render a zwiki page, with standard header & footer
         """

I thought the use of keyword argument dictionaries in apply might explain 
this, but, as the two opening examples show, not all cases have 
keywords.  Second, even if they do one could say
aDocument(self, REQUEST, REQUEST.RESPONSE, kw).

I understand from Johan that this is "inherited" code (in the non OO 
sense), so I thought I'd throw this out as a general question.  Is there 
some subtlety of the interaction of Zope (acquisition, perhaps, or 
extension classes in general) and python that makes foo(x) and 
foo.__call__(x) have different meanings?
Is it something about standard_zwiki_page, which I notice is not a regular 
python variable?

I don't need the answer to this to do something; I'm just trying to 
understand how things work.

Thanks.