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

Benoit Boissinot bboissin at gmail.com
Sun Mar 13 06:11:19 CDT 2011


On Tue, Mar 8, 2011 at 9:36 AM, Martin Geisler <mg at aragost.com> wrote:
> 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...

It seems it could be useful? Can you respin the patch with
safe_hasattr() and the "optimized defaults"?
>
> Would it not make sense to overwrite __builtin__.hasattr with such a
> safe version or is that considered very bad style?
>

Dunno, I don't think we monkey-patch python internals already, do we?

Benoit


More information about the Mercurial-devel mailing list