[Interface-dev] overriding InterfaceClass.__call__ and 3.4.2dev
Jim Fulton
jim at zope.com
Mon Jan 7 07:12:59 EST 2008
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.
> 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.
...
> 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.
Jim
--
Jim Fulton
Zope Corporation
More information about the Interface-dev
mailing list