[PATCH 3 of 3] extensions: add a few assertions to wrapfunction() and wrapcommand()

Dan Villiom Podlaski Christiansen danchr at gmail.com
Fri Jul 9 04:24:42 CDT 2010


# HG changeset patch
# User Dan Villiom Podlaski Christiansen <danchr at gmail.com>
# Date 1278666240 -7200
# Node ID 526534a6236692420d3bacf97cffb3519d3faa0a
# Parent  a62edd2d93a439a55893038fcde793b95ca2bfec
extensions: add a few assertions to wrapfunction() and wrapcommand().

Specifically, assert that the given wrapper is callable in both
functions, and assert that the original was also callable in
wrapfunction().

diff --git a/mercurial/extensions.py b/mercurial/extensions.py
--- a/mercurial/extensions.py
+++ b/mercurial/extensions.py
@@ -116,6 +116,7 @@ def wrapcommand(table, command, wrapper)
     where orig is the original (wrapped) function, and *args, **kwargs
     are the arguments passed to it.
     '''
+    assert callable(wrapper)
     aliases, entry = cmdutil.findcmd(command, table)
     for alias, e in table.iteritems():
         if e is entry:
@@ -168,10 +169,12 @@ def wrapfunction(container, funcname, wr
     your end users, you should play nicely with others by using the
     subclass trick.
     '''
+    assert callable(wrapper)
     def wrap(*args, **kwargs):
         return wrapper(origfn, *args, **kwargs)
 
     origfn = getattr(container, funcname)
+    assert callable(origfn)
     setattr(container, funcname, wrap)
     return origfn
 


More information about the Mercurial-devel mailing list