comparison mercurial/extensions.py @ 14943:d3bb825ddae3

globally: use safehasattr(x, '__call__') instead of hasattr(x, '__call__')
author Augie Fackler <durin42@gmail.com>
date Mon, 25 Jul 2011 16:24:37 -0500
parents 558ec14ba6be
children 56da00994067
comparison
equal deleted inserted replaced
14942:5b072d4b62f2 14943:d3bb825ddae3
122 wrapper(orig, *args, **kwargs) 122 wrapper(orig, *args, **kwargs)
123 123
124 where orig is the original (wrapped) function, and *args, **kwargs 124 where orig is the original (wrapped) function, and *args, **kwargs
125 are the arguments passed to it. 125 are the arguments passed to it.
126 ''' 126 '''
127 assert hasattr(wrapper, '__call__') 127 assert util.safehasattr(wrapper, '__call__')
128 aliases, entry = cmdutil.findcmd(command, table) 128 aliases, entry = cmdutil.findcmd(command, table)
129 for alias, e in table.iteritems(): 129 for alias, e in table.iteritems():
130 if e is entry: 130 if e is entry:
131 key = alias 131 key = alias
132 break 132 break
175 In general, combining wrapfunction() with subclassing does not 175 In general, combining wrapfunction() with subclassing does not
176 work. Since you cannot control what other extensions are loaded by 176 work. Since you cannot control what other extensions are loaded by
177 your end users, you should play nicely with others by using the 177 your end users, you should play nicely with others by using the
178 subclass trick. 178 subclass trick.
179 ''' 179 '''
180 assert hasattr(wrapper, '__call__') 180 assert util.safehasattr(wrapper, '__call__')
181 def wrap(*args, **kwargs): 181 def wrap(*args, **kwargs):
182 return wrapper(origfn, *args, **kwargs) 182 return wrapper(origfn, *args, **kwargs)
183 183
184 origfn = getattr(container, funcname) 184 origfn = getattr(container, funcname)
185 assert hasattr(origfn, '__call__') 185 assert util.safehasattr(origfn, '__call__')
186 setattr(container, funcname, wrap) 186 setattr(container, funcname, wrap)
187 return origfn 187 return origfn
188 188
189 def _disabledpaths(strip_init=False): 189 def _disabledpaths(strip_init=False):
190 '''find paths of disabled extensions. returns a dict of {name: path} 190 '''find paths of disabled extensions. returns a dict of {name: path}