changeset 11521:3efadce5b346 stable

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().
author Dan Villiom Podlaski Christiansen <danchr@gmail.com>
date Fri, 09 Jul 2010 11:04:00 +0200
parents 94b3bbc886cf
children eaa7666ad53f
files mercurial/extensions.py
diffstat 1 files changed, 3 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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