[Twisted-Python] Disturbing aspect of zope.interface
ellisonbg.net at gmail.com
Fri Oct 9 01:53:48 EDT 2009
> On Thu, Oct 8, 2009 at 7:23 PM, Brian Granger <ellisonbg.net at gmail.com>wrote:
>> I know this is not the zope list
> You're right, it's not. Perhaps you could send a message to the interface
> package development list?
Yes, I will do that. I wanted to get an opinion here first from the "users
of zope.interface" first though
to see if anyone else had run into these things in the wild.
> The disturbing thing is that now A (which is just an object) has been
>> hacked on
>> by zope.interface. It has additional methods (__provides__, etc.) that
>> are specific to
> Why does this disturb you? Would you feel better if it were called
Maybe a little bit, but name collisions are a minor concern in my case...
> Summary: If a class A is later subclassed by something B that calls
>> zi.implements, the original class A
>> becomes infected with all the zope.interface stuff.
> A gets an additional attribute. Its behavior doesn't change in any other
> way. I don't really see what's wrong with that, unless you have a differing
> definition of the __provides__ attribute in your code.
...but __provides__ is not exactly a "plain old attribute":
* The __provides__ attribute is a descriptor that sometimes raises
AttributeError even though it exists.
This is how I found all of this. I called dir on my class and __provides__
was listed. But
hasattr(cls, '__provides') returned False. I consider this to be a separate
bug, but because __provides__
started to appear on all of my classes, I was seeing it *everywhere*.
* The internal implementation of __provides__ is handled by a custom
zope.interface tries to be pretty careful in not actually *using* a custom
metaclass, but it
does set and then later remove the __metaclass__ hook.
In my mind, both of these things are in the "unwanted side effect" category.
> Is there a way to avoid this?
> Depending on what your definition of "this" is, there almost certainly is.
> In the simplest case, you could submit a patch to zope interface.
That is definitely a likely outcome of this discussion. For now though, I
was just wondering
if other's had run into this issue. For now, it sounds like not.
> Doesn't this seem like a bad idea?
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Twisted-Python