Re: Adapter for class with slots

Wolfgang Schnerring <[email protected]>
Newsgroups gmane.comp.web.zope.devel
Message-ID <[email protected]>
* Shane Hathaway <[email protected]> [2009-12-03 11:44]:
> Wolfgang Schnerring wrote:
>> The minimal reproduction recipe to see the error is this:
>> 
>>     class Slotted(object):
>>         __slots__ = ('__provides__')
>> 
>>     zope.component.provideAdapter(
>>         lambda x: True, (Slotted,), zope.interface.Interface)
>> 
>> Which will raise
>>   File "/home/wosc/.python-eggs/zope.component-3.7.1-py2.6.egg/zope/component/registry.py",
>>   line 419, in _getAdapterRequired
>>       elif not ISpecification.providedBy(r):
>>   TypeError: 'member_descriptor' object is not callable
>
> It looks to me like a possible bug in zope.interface.  Try deleting 
> _zope_interface_coptimizations.so to hopefully expand that traceback.

Thanks for the hint! This enabled me to step through all of it with pdb,
which turns up zope/interface/declarations.py:1249

  def getObjectSpecification(ob):
      provides = getattr(ob, '__provides__', None)
      if provides is not None:
          return provides
      [...]

So it seems that __provides__ is part of the zope.interface mechanics,
and if unset that attribute should not exist -- but when using __slots__
it always exists, namely as a 'member_descriptor' object.

I'll try and see whether I can come up with a way for zope.interface to
do the Right Thing(tm) in this situation.

Wolfgang

_______________________________________________
Zope-Dev maillist  -  [email protected]
https://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 https://mail.zope.org/mailman/listinfo/zope-announce
 https://mail.zope.org/mailman/listinfo/zope )
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.