extensions: add a few assertions to wrapfunction() and wrapcommand(). stable
authorDan Villiom Podlaski Christiansen <danchr@gmail.com>
Fri, 09 Jul 2010 11:04:00 +0200
branchstable
changeset 11521 3efadce5b346
parent 11520 94b3bbc886cf
child 11522 eaa7666ad53f
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().
mercurial/extensions.py
--- a/mercurial/extensions.py	Fri Jul 09 11:13:45 2010 +0200
+++ b/mercurial/extensions.py	Fri Jul 09 11:04:00 2010 +0200
@@ -116,6 +116,7 @@
     where orig is the original (wrapped) function, and *args, **kwargs
     are the arguments passed to it.
     '''
+    assert hasattr(wrapper, '__call__')
     aliases, entry = cmdutil.findcmd(command, table)
     for alias, e in table.iteritems():
         if e is entry:
@@ -168,10 +169,12 @@
     your end users, you should play nicely with others by using the
     subclass trick.
     '''
+    assert hasattr(wrapper, '__call__')
     def wrap(*args, **kwargs):
         return wrapper(origfn, *args, **kwargs)
 
     origfn = getattr(container, funcname)
+    assert hasattr(origfn, '__call__')
     setattr(container, funcname, wrap)
     return origfn