[Zope-dev] Re: hasattr implementation for Zope?

Tres Seaver tseaver at palladion.com
Fri May 27 08:22:44 EDT 2005


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

Chris Withers wrote:
> Dieter Maurer wrote:
> 
>>>> I strongly argue against it. Fix "hasattr" in the Zope context,
>>>> instead!
>>>
>>>
>>       _marker = []
>>       def hasattr(obj, attr, marker):
>>       a = getattr(obj, attr, _marker)
>>       return a is not _marker
>>
>>       import __builtin__
>>       __builtin__.hasattr = hasattr
>>
>> Easy enough, isn't it?
>>
>> Way easier than to change "hasattr" anywhere it is now used.
> 
> 
> Anyone think putting this in Zope core is a good idea?

- -1.  Python's 'hasattr' semantics are *broken by definition*, and will
never be fixed (because of backward compatibility).  Non-Zope Python
programmers will *not* expect or want exceptions raised from 'hasattr'.

As a local patch, this isn't too bad (one could even package it as a
do-nothing-after-initialization product).  However, no redistributed
product code should rely on the presence of a patched 'hasattr', but
should use the 3 argument getattr instead.


Tres.
- --
===================================================================
Tres Seaver                                   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

iD8DBQFClxEU+gerLs4ltQ4RAto2AKDNc44GLkHYn9s2CMvEJrBZnUxaEwCfYK0J
PtE2/G2CkGBec869OOQWmjo=
=1IHS
-----END PGP SIGNATURE-----



More information about the Zope-Dev mailing list