[PATCH 2 of 3 RFC] Remove all uses of hasattr(a, b) in favor of getattr(a, b, None)
Augie Fackler
durin42 at gmail.com
Mon Mar 14 14:19:05 CDT 2011
On Mar 14, 2011, at 12:48 PM, Matt Mackall wrote:
> On Sun, 2011-03-13 at 12:11 +0100, Benoit Boissinot wrote:
>> 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"?
Will do, hopefully later this week.
>>> 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?
>
> We do, but sparingly (see demandimport). In WSGI environments and
> elsewhere, messing with globals can be problematic.
This feels evil to me.
I'll try and re-roll this work later this week, once I'm caught up from pycon.
More information about the Mercurial-devel
mailing list