##// END OF EJS Templates
py3: handle sysstr conversion around get/set attr in contrib/perf
Matt Harbison -
r39846:6787dc1b default
parent child Browse files
Show More
@@ -67,9 +67,11 b' except ImportError:'
67 67 try:
68 68 from mercurial import pycompat
69 69 getargspec = pycompat.getargspec # added to module after 4.5
70 _sysstr = pycompat.sysstr # since 4.0 (or 2219f4f82ede)
70 71 except (ImportError, AttributeError):
71 72 import inspect
72 73 getargspec = inspect.getargspec
74 _sysstr = lambda x: x # no py3 support
73 75
74 76 try:
75 77 # 4.7+
@@ -95,7 +97,7 b' except (AttributeError, ImportError):'
95 97 # available since 1.9.3 (or 94b200a11cf7)
96 98 _undefined = object()
97 99 def safehasattr(thing, attr):
98 return getattr(thing, attr, _undefined) is not _undefined
100 return getattr(thing, _sysstr(attr), _undefined) is not _undefined
99 101 setattr(util, 'safehasattr', safehasattr)
100 102
101 103 # for "historical portability":
@@ -340,12 +342,12 b' def safeattrsetter(obj, name, ignoremiss'
340 342 raise error.Abort((b"missing attribute %s of %s might break assumption"
341 343 b" of performance measurement") % (name, obj))
342 344
343 origvalue = getattr(obj, name)
345 origvalue = getattr(obj, _sysstr(name))
344 346 class attrutil(object):
345 347 def set(self, newvalue):
346 setattr(obj, name, newvalue)
348 setattr(obj, _sysstr(name), newvalue)
347 349 def restore(self):
348 setattr(obj, name, origvalue)
350 setattr(obj, _sysstr(name), origvalue)
349 351
350 352 return attrutil()
351 353
General Comments 0
You need to be logged in to leave comments. Login now