[PATCH 3 of 8] py3: handle sysstr conversion around get/set attr in contrib/perf

Matt Harbison mharbison72 at gmail.com
Sun Sep 23 09:48:38 EDT 2018


> On Sep 23, 2018, at 2:42 AM, Yuya Nishihara <yuya at tcha.org> wrote:
> 
>> On Sat, 22 Sep 2018 11:28:39 -0400, Matt Harbison wrote:
>> # HG changeset patch
>> # User Matt Harbison <matt_harbison at yahoo.com>
>> # Date 1537575036 14400
>> #      Fri Sep 21 20:10:36 2018 -0400
>> # Node ID c0c842de276702455060c3d5fd3a6aa80185cdc6
>> # Parent  0d1b3d5a92e159506c823be481cf9f57e45ec03d
>> py3: handle sysstr conversion around get/set attr in contrib/perf
>> 
>> diff --git a/contrib/perf.py b/contrib/perf.py
>> --- a/contrib/perf.py
>> +++ b/contrib/perf.py
>> @@ -95,7 +95,7 @@ except (AttributeError, ImportError):
>> # available since 1.9.3 (or 94b200a11cf7)
>> _undefined = object()
>> def safehasattr(thing, attr):
>> -    return getattr(thing, attr, _undefined) is not _undefined
>> +    return getattr(thing, pycompat.sysstr(attr), _undefined) is not _undefined
>> setattr(util, 'safehasattr', safehasattr)
>> 
>> # for "historical portability":
>> @@ -340,12 +340,12 @@ def safeattrsetter(obj, name, ignoremiss
>>         raise error.Abort((b"missing attribute %s of %s might break assumption"
>>                            b" of performance measurement") % (name, obj))
>> 
>> -    origvalue = getattr(obj, name)
>> +    origvalue = getattr(obj, pycompat.sysstr(name))
>>     class attrutil(object):
>>         def set(self, newvalue):
>> -            setattr(obj, name, newvalue)
>> +            setattr(obj, pycompat.sysstr(name), newvalue)
>>         def restore(self):
>> -            setattr(obj, name, origvalue)
>> +            setattr(obj, pycompat.sysstr(name), origvalue)
> 
> Perhaps another hasattr() would be needed since perf.py has to support
> old Mercurial codebase where pycompat doesn't exist. The same thing applies
> to the other patches.

Oops.  I see what you mean about missing pycompat, but don’t understand the hasattr() part.  Wouldn’t you just, say at the top of the module, import pycompat and define local aliases for these things, and then in the ImportError handler, define legacy aliases?


More information about the Mercurial-devel mailing list