Daniel Nouri wrote:
> Ross Patterson wrote:
>> Daniel Nouri <[EMAIL PROTECTED]>
>> writes:
>>
>>> Martin Aspeli wrote:
>>>
>>>> Unfortunately, acquisition doesn't work properly inside Python property
>>>> __get__ accessors. I've seen this pattern before, but I've seen people have
>>>> various problems with it (that I can't remember the details of right now).
>>> Hmm, I've been using @property now for quite a long time for handling
>>> context without any problems.  It would be good to have a minimal failing
>>> example.
>>>
>>> I know that formlib actions, which are applied via a decorator, have
>>> problems with acquisition.  But then, they do much more than @property.
>> Here's a doctest showing what I think Martin was talking about:
>>
>> <snip>
>>
>>     >>> foo.aq_parent
>>     <Application at >
>>     >>> foo.has_aq
>>     True
>>     >>> foo.has_aq_descr
>>     True
>>
>> Those last two "True"s come out "False" if you actually run this test.
>>
>> It's a problem in all descriptors as far as I can tell.  I'd be very
>> interested in any work arounds for this as I run into it all the time.
>>
>> Also, is there someplace this test might be included?  Or is this
>> considered not to be a bug?
> 
> Thanks for providing this clear example.  I agree that it's a bug.
> 
> I added a bit to the doctest, just to make sure that the acquisition
> wrapping of an attribute that's accessed in a descriptor (or property) is
> preserved:
> 
>     >>> foo.bar = SimpleItem('bar').__of__(foo)
>     >>> foo.bar_property.aq_parent
>     <Foo at />
>     >>> foo.bar_descr.aq_parent
>     <Foo at />
> 
> For a view, this means that when returning context in a property 'context',
> the wrapping would be okay.  This base class would thus do the "right thing"
> and also work if Acquisition would be fixed to also work in descriptors:

Some further experiments showed that this is not true.  The call to
'self.context' will aq wrap the value returned by the context descriptor in
self.  Thus making a context descriptor proves to be totally pointless. :)



-- 
http://danielnouri.org


_______________________________________________
Product-Developers mailing list
[email protected]
http://lists.plone.org/mailman/listinfo/product-developers

Reply via email to