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:
from Products.Five import BrowserView
class BaseView(BrowserView):
def _set_context(self, context):
self._context = [context]
def _get_context(self):
return self._context[0]
context = property(_get_context, _set_context)
--
http://danielnouri.org
_______________________________________________
Product-Developers mailing list
[email protected]
http://lists.plone.org/mailman/listinfo/product-developers