[PATCH 4 of 9 V2] py3: handle sysstr conversion around get/set attr in contrib/perf

Matt Harbison mharbison72 at gmail.com
Mon Sep 24 22:25:37 EDT 2018


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1537575036 14400
#      Fri Sep 21 20:10:36 2018 -0400
# Node ID f0849e47b29986ba6bc765226cba3bfb50c9c3ee
# Parent  788eb3e31f3a6f5edca3125cc08dc74e75cb936e
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
@@ -67,9 +67,11 @@ except ImportError:
 try:
     from mercurial import pycompat
     getargspec = pycompat.getargspec  # added to module after 4.5
+    _sysstr = pycompat.sysstr         # since 4.0 (or 2219f4f82ede)
 except (ImportError, AttributeError):
     import inspect
     getargspec = inspect.getargspec
+    _sysstr = lambda x: x             # no py3 support
 
 try:
     # 4.7+
@@ -95,7 +97,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, _sysstr(attr), _undefined) is not _undefined
 setattr(util, 'safehasattr', safehasattr)
 
 # for "historical portability":
@@ -340,12 +342,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, _sysstr(name))
     class attrutil(object):
         def set(self, newvalue):
-            setattr(obj, name, newvalue)
+            setattr(obj, _sysstr(name), newvalue)
         def restore(self):
-            setattr(obj, name, origvalue)
+            setattr(obj, _sysstr(name), origvalue)
 
     return attrutil()
 


More information about the Mercurial-devel mailing list