[PEAK] ObjectWrapper subclasses always callable

PJ Eby pje at telecommunity.com
Wed May 23 14:01:11 EDT 2012


On Wed, May 23, 2012 at 11:25 AM, Marcin Tustin <marcin.tustin at gmail.com>wrote:

> Python 2.7.2
>
>
> On Wed, May 23, 2012 at 4:23 PM, PJ Eby <pje at telecommunity.com> wrote:
>
>>
>> On May 23, 2012 10:39 AM, "Marcin Tustin" <marcin.tustin at gmail.com>
>> wrote:
>> >
>> > I've found that instances of ObjectWrapper (and any subclasses) are
>> always callable (the callable function returns True), notwithstanding that
>> the __subject__ is not callable. Is there a way to remedy this?
>> >
>> > I've tried deleting the __call__ method, creating empty slots, creating
>> my own call method, then trying to delete, using del or delattr on the
>> subclass object, and creating a custom __getattribute__, all to no avail.
>>
>> Which Python version are you using?
>>
>
> Okay, I've verified that this happens all the way back to 2.3, so that's
not it.  (I think that maybe Python 3 uses hasattr(__call__) as its
callable() implementation, but I'm not sure.)

It looks like the only way for me to fix this is with a major revision:
change the base classes to not have a __call__ slot, and dynamically change
type at runtime to a subclass with a __call__ slot, if and only if their
subject is callable...  and to somehow change if the subject changes.  (Not
really sure how that's going to work.)

What's the use case for this?  What code is using callable(), and can you
convince its author to use hasattr instead?  ;-)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.eby-sarna.com/pipermail/peak/attachments/20120523/3db32446/attachment.html


More information about the PEAK mailing list