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

Jim Fulton jim at zope.com
Fri May 27 09:25:58 EDT 2005


Tim Peters wrote:
> [Tres Seaver]
> [...]
> 
>>- -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.
> 
> 
> OTOH, defining & importing a utility function-- say, safehasattr()
> --would make it all explicit.  That's what ZODB does.  I certainly
> agree that changing the behavior of a builtin function by magic is at
> best highly dubious practice.

In fact, consider this vetoed for the Zope core. :)

Jim

-- 
Jim Fulton           mailto:jim at zope.com       Python Powered!
CTO                  (540) 361-1714            http://www.python.org
Zope Corporation     http://www.zope.com       http://www.zope.org


More information about the Zope-Dev mailing list