[Zope-dev] zope.interface: verifyObject vs properties

Tres Seaver tseaver at palladion.com
Wed Oct 15 12:20:57 EDT 2008


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

Thomas Lotze wrote:
> Jim Fulton <jim at zope.com> wrote:
> 
>> I would change it to just use getattr rather than hasattr.
>>
>> try:
>>     getattr(ob, name)
>> except AttributeError:
>>     return False
>> ...
> 
> This doesn't handle the case that the attribute exists as a property
> but raises an AttributeError when trying to produce its value.

What is the difference?  Any property which raises an attribute error is
broken, and does not satisfy the contract of the interface:  it might as
well not be there at all.

On a de gustibus note, I would have spelled it without the try:

 return getattr(ob, name, ob) is not ob



Tres.
- --
===================================================================
Tres Seaver          +1 540-429-0999          tseaver at palladion.com
Palladion Software   "Excellence by Design"    http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFI9hhp+gerLs4ltQ4RAvYYAJkBpvcecqFmmSf9c9KMtPITnocOgQCghD71
irczDNf47QMt2qXB6LuBPKw=
=Atrg
-----END PGP SIGNATURE-----



More information about the Zope-Dev mailing list