[PATCH STABLE] mq: replace hasattr() with util.safehasattr(), update check-code.py

Patrick Mezard patrick at mezard.eu
Fri Apr 13 08:11:35 CDT 2012


# HG changeset patch
# User Patrick Mezard <patrick at mezard.eu>
# Date 1334322433 -7200
# Branch stable
# Node ID c3aedd526d530506891caf690ff9688404bb5ea8
# Parent  03e408a122c40ce974d648f5c05177676adfbc72
mq: replace hasattr() with util.safehasattr(), update check-code.py

diff --git a/contrib/check-code.py b/contrib/check-code.py
--- a/contrib/check-code.py
+++ b/contrib/check-code.py
@@ -177,7 +177,7 @@
      "comparison with singleton, use 'is' or 'is not' instead"),
     (r'^\s*(while|if) [01]:',
      "use True/False for constant Boolean expression"),
-    (r'(?<!def)\s+hasattr',
+    (r'(?:(?<!def)\s+|\()hasattr',
      'hasattr(foo, bar) is broken, use util.safehasattr(foo, bar) instead'),
     (r'opener\([^)]*\).read\(',
      "use opener.read() instead"),
diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -3308,7 +3308,7 @@
         repo._phasedefaults.append(mqphasedefaults)
 
 def mqimport(orig, ui, repo, *args, **kwargs):
-    if (hasattr(repo, 'abortifwdirpatched')
+    if (util.safehasattr(repo, 'abortifwdirpatched')
         and not kwargs.get('no_commit', False)):
         repo.abortifwdirpatched(_('cannot import over an applied patch'),
                                    kwargs.get('force'))


More information about the Mercurial-devel mailing list