On 9/25/06, <b class="gmail_sendername">Jim Fulton</b> <<a href="mailto:jim@zope.com">jim@zope.com</a>> wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>On Sep 22, 2006, at 5:08 PM, Christopher Armstrong wrote:</blockquote><div> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br><br>
> Now, if there is a method IFoo.__adapt__, and one calls IFoo(o),<br>> that method will not be called when using the C optimizations,<br>> because the C implementation of __call__ just directly calls the C<br>> implementation of __adapt__ without looking it up as a method on
<br>> the interface object.<br>><br>> Is this a bug?<br><br>No. PEP 246 doesn't specify a protocol __call__ method so I don't<br>feel bound by it. I never considered it a use case to be able to<br>override __adapt__ for interfaces. If you want to do that, then
<br>you'll have to override __call__ as well. Do you want to override<br>__adapt__? If so, why?</blockquote><div><br><br>That's fine, I guess. One could argue that the documentation is at least unclear or perhaps even incorrect, on this point, then:
<br><br>(from README.txt)<br>"""<br><span style="font-family: courier new,monospace;">This method is normally not called directly. It is called by the PEP</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">246 adapt framework and by the interface __call__ operator.</span><br style="font-family: courier new,monospace;">"""<br><br>Technically, __call__ doesn't call the __adapt__ method on the interface: in (the new version of) C-optimized mode, it calls some internal C function called __adapt__ which isn't a method on Interface; and this is noticeable if you try to override __adapt__, because __call__ won't call it. Anyway, I'm not that concerned with Zope PEP 246 compatibility.
<br><br>To answer your question about why we're overriding __adapt__: I didn't do this myself, but I tracked down the developer who did and he claimed that this was a more efficient way of overriding the way one particular interface adapts things. Adding an adapter_hook adds an extra function call and extends check to a ton of potential interface adaptations. I guess I will try to convert this to an overridden __call__.
<br></div></div><br clear="all"><br>-- <br>Christopher Armstrong<br>International Man of Twistery<br><a href="http://radix.twistedmatrix.com/">http://radix.twistedmatrix.com/</a><br><a href="http://twistedmatrix.com/">http://twistedmatrix.com/
</a><br><a href="http://canonical.com/">http://canonical.com/</a><br>