[Zope] Re: Getting a methods parent (in a product)

Tres Seaver tseaver at palladion.com
Sun Jul 24 21:54:57 EDT 2005


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jens Vagelpohl wrote:
> 
> On 23 Jul 2005, at 16:12, Peter Bengtsson wrote:
> 
>>> from Acquisition import aq_inner, aq_parent
>>>
>>> parent = aq_parent(aq_inner(self))
>>>
>>> This will return the true container the instance is set in, not just
>>> the acquisition parent.
>>>
>>>
>> What's so bad about
>> parent = self.aq_parent
> 
> 
> Two things:
> 
> - simply using aq_parent does not guarantee giving you the real 
> containment parent. Depending on the path used to access the object  it
> could be something different from the true containment parent.  That's
> the power of acquisition...

Which is why the 'aq_inner()' call is in there:  it strips away
non-contaiment wrappers.

> - direct attribute access like that makes me feel dirty. I prefer the 
> true object-oriented style where you use methods to get at stuff.

The actual issue is that attribute access will break if you have an
unwrapped object;  'aq_parent(foo)' will return 'None' in that case.

(A tiny nit, 'aq_parent()' and the related 'aq_base()' and 'aq_inner()'
are module-scope functions, rather than methods).


Tres.
- --
===================================================================
Tres Seaver          +1 202-558-7113          tseaver at palladion.com
Palladion Software   "Excellence by Design"    http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFC5EZx+gerLs4ltQ4RAk9+AKCsb9wg7edRq4HfFcHn/FwBvpSmCwCeK8Ke
zt8foauYT7v9DRf2TYbqMjE=
=eU4v
-----END PGP SIGNATURE-----



More information about the Zope mailing list