comparison mercurial/extensions.py @ 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 891ddf76b73e
comparison
equal deleted inserted replaced
11520:94b3bbc886cf 11521:3efadce5b346
114 wrapper(orig, *args, **kwargs) 114 wrapper(orig, *args, **kwargs)
115 115
116 where orig is the original (wrapped) function, and *args, **kwargs 116 where orig is the original (wrapped) function, and *args, **kwargs
117 are the arguments passed to it. 117 are the arguments passed to it.
118 ''' 118 '''
119 assert hasattr(wrapper, '__call__')
119 aliases, entry = cmdutil.findcmd(command, table) 120 aliases, entry = cmdutil.findcmd(command, table)
120 for alias, e in table.iteritems(): 121 for alias, e in table.iteritems():
121 if e is entry: 122 if e is entry:
122 key = alias 123 key = alias
123 break 124 break
166 In general, combining wrapfunction() with subclassing does not 167 In general, combining wrapfunction() with subclassing does not
167 work. Since you cannot control what other extensions are loaded by 168 work. Since you cannot control what other extensions are loaded by
168 your end users, you should play nicely with others by using the 169 your end users, you should play nicely with others by using the
169 subclass trick. 170 subclass trick.
170 ''' 171 '''
172 assert hasattr(wrapper, '__call__')
171 def wrap(*args, **kwargs): 173 def wrap(*args, **kwargs):
172 return wrapper(origfn, *args, **kwargs) 174 return wrapper(origfn, *args, **kwargs)
173 175
174 origfn = getattr(container, funcname) 176 origfn = getattr(container, funcname)
177 assert hasattr(origfn, '__call__')
175 setattr(container, funcname, wrap) 178 setattr(container, funcname, wrap)
176 return origfn 179 return origfn
177 180
178 def _disabledpaths(strip_init=False): 181 def _disabledpaths(strip_init=False):
179 '''find paths of disabled extensions. returns a dict of {name: path} 182 '''find paths of disabled extensions. returns a dict of {name: path}