[PATCH 2 of 3 RFC] Remove all uses of hasattr(a, b) in favor of getattr(a, b, None)

Martin Geisler mg at aragost.com
Tue Mar 8 02:36:28 CST 2011


Augie Fackler <durin42 at gmail.com> writes:

> On Mar 3, 2011, at 8:03 AM, Michael Haggerty wrote:
>
>> For the other cases, maybe it would make sense to define a
>> 
>> def safe_hasattr(o, name):
>>    try:
>>        getattr(o, name)
>>    except AttributeError:
>>        return False
>>    else:
>>        return True
>
> Does anyone in the wider mercurial-devel have a feeling on this one?
> It seems reasonable as a hedge against the day in about 2050 that we
> can be Python3 only...

Would it not make sense to overwrite __builtin__.hasattr with such a
safe version or is that considered very bad style?

Or is the problem that we then need to make sure that such an overwrite
it loaded early enough?

-- 
Martin Geisler

aragost Trifork
Professional Mercurial support
http://aragost.com/en/services/mercurial/blog/


More information about the Mercurial-devel mailing list