[Interface-dev] overriding InterfaceClass.__call__ and 3.4.2dev

Jean-Paul Calderone exarkun at divmod.com
Mon Jan 7 07:27:55 EST 2008


On Mon, 7 Jan 2008 07:12:59 -0500, Jim Fulton <jim at zope.com> wrote:
>
>On Jan 6, 2008, at 12:46 PM, Jean-Paul Calderone wrote:
>>Hey,
>>
>>I just noticed a change between 3.4.1 and 3.4.2dev
>
>3.4.2dev? Wazzat? Do you mean the trunk? I hope there isn't a 3.4.2dev 
>release somewhere.

Yea, I should have said trunk.

>>relating to the __call__
>>method of InterfaceClass.  If you override it in 3.4.1, it will be  used. 
>>If
>>you override it in 3.4.2dev, it won't be.
>
>On the trunk, I get:
>
>   >>> import zope.interface.interface
>   >>> class InterfaceClass(zope.interface.interface.InterfaceClass):
>   ...     def __call__(self, *args):
>   ...         print 'called', self, args
>   ...
>   >>> IFoo = InterfaceClass('IFoo', (zope.interface.Interface,))
>   >>> IFoo(1)
>   called <InterfaceClass __main__.IFoo> (1,)
>   >>> class IBar(IFoo): pass
>   ...
>   >>> IBar()
>   called <InterfaceClass __main__.IBar> ()
>   >>> class ISpam(zope.interface.Interface): pass
>   ...
>   >>> ISpam()
>   Traceback (most recent call last):
>     File "<console>", line 1, in ?
>   TypeError: function takes at least 1 argument (0 given)
>   >>> ISpam.__class__ = InterfaceClass
>   >>> ISpam()
>   Traceback (most recent call last):
>     File "<console>", line 1, in ?
>   TypeError: function takes at least 1 argument (0 given)
>
>So overriding through subclassing works just fine.  Overriding through 
>assigning the __class__ seems to be broken, although this seems to me  to be 
>a kind of odd way to override.
>

I agree it's somewhat odd.  I guess the code is written that way so that it
doesn't have to call InterfaceClass directly (but I dunno, I didn't write
it).

>...
>>Is this an intentional change?
>
>There was a recent change intended to speed application startup that  broke 
>this. I'm a bit suspicious of this change because it uses  __setattr__.
>>  It breaks a feature of Twisted (in web2).
>
>...
>>
>>Was this accidental?
>
>
>I'm sure it was.
>
>We'll fix this.

Cool, thanks.

Jean-Paul


More information about the Interface-dev mailing list