Patchwork [7,of,8] hook: restore use of callable() since it was readded in Python 3.2

login
register
mail settings
Submitter Augie Fackler
Date June 24, 2014, 6:37 p.m.
Message ID <57b09c58165f42eb8ecc.1403635063@augie-macbookair>
Download mbox | patch
Permalink /patch/5061/
State Accepted
Commit b009dd135aa0601155e196de892215832e0a1baa
Headers show

Comments

Augie Fackler - June 24, 2014, 6:37 p.m.
# HG changeset patch
# User Augie Fackler <raf@durin42.com>
# Date 1403529878 14400
#      Mon Jun 23 09:24:38 2014 -0400
# Node ID 57b09c58165f42eb8eccc7be8ebd89101fb95914
# Parent  2bc882dca6c612558554cd777c9e972b21f6e9c8
hook: restore use of callable() since it was readded in Python 3.2

Patch

diff --git a/mercurial/hook.py b/mercurial/hook.py
--- a/mercurial/hook.py
+++ b/mercurial/hook.py
@@ -19,7 +19,7 @@ 
     unmodified commands (e.g. mercurial.commands.update) can
     be run as hooks without wrappers to convert return values.'''
 
-    if util.safehasattr(funcname, '__call__'):
+    if callable(funcname):
         obj = funcname
         funcname = obj.__module__ + "." + obj.__name__
     else:
@@ -70,7 +70,7 @@ 
             raise util.Abort(_('%s hook is invalid '
                                '("%s" is not defined)') %
                              (hname, funcname))
-        if not util.safehasattr(obj, '__call__'):
+        if not callable(obj):
             raise util.Abort(_('%s hook is invalid '
                                '("%s" is not callable)') %
                              (hname, funcname))
@@ -117,7 +117,7 @@ 
     starttime = time.time()
     env = {}
     for k, v in args.iteritems():
-        if util.safehasattr(v, '__call__'):
+        if callable(v):
             v = v()
         if isinstance(v, dict):
             # make the dictionary element order stable across Python
@@ -184,7 +184,7 @@ 
                     # files seem to be bogus, give up on redirecting (WSGI, etc)
                     pass
 
-            if util.safehasattr(cmd, '__call__'):
+            if callable(cmd):
                 r = _pythonhook(ui, repo, name, hname, cmd, args, throw) or r
             elif cmd.startswith('python:'):
                 if cmd.count(':') >= 2: