safehasattr: pass attribute name as string instead of bytes
authorPierre-Yves David <pierre-yves.david@octobus.net>
Thu, 02 Feb 2023 17:23:03 +0100
changeset 50564 1ea84989c389
parent 50563 8020be6a9d28
child 50565 2b1cd454793a
safehasattr: pass attribute name as string instead of bytes This is a step toward replacing `util.safehasattr` usage with plain `hasattr`. The builtin function behave poorly in Python2 but this was fixed in Python3. These change are done one by one as they tend to have a small odd to trigger puzzling breackage.
mercurial/debugcommands.py
--- a/mercurial/debugcommands.py	Thu Feb 02 17:22:55 2023 +0100
+++ b/mercurial/debugcommands.py	Thu Feb 02 17:23:03 2023 +0100
@@ -1943,7 +1943,7 @@
     """show stats related to the changelog index"""
     repo.changelog.shortest(repo.nullid, 1)
     index = repo.changelog.index
-    if not util.safehasattr(index, b'stats'):
+    if not util.safehasattr(index, 'stats'):
         raise error.Abort(_(b'debugindexstats only works with native code'))
     for k, v in sorted(index.stats().items()):
         ui.write(b'%s: %d\n' % (k, v))