Mercurial > hg
changeset 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 | 5b072d4b62f2 |
children | e2c413bde8a5 |
files | doc/gendoc.py hgext/mq.py mercurial/commands.py mercurial/extensions.py mercurial/fancyopts.py mercurial/hook.py mercurial/templater.py |
diffstat | 7 files changed, 13 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/doc/gendoc.py Mon Jul 25 14:59:55 2011 -0500 +++ b/doc/gendoc.py Mon Jul 25 16:24:37 2011 -0500 @@ -9,6 +9,7 @@ from mercurial.i18n import _ from mercurial.help import helptable from mercurial import extensions +from mercurial import util def get_desc(docstr): if not docstr: @@ -95,7 +96,7 @@ ui.write(".. _%s:\n" % name) ui.write("\n") section(ui, sec) - if hasattr(doc, '__call__'): + if util.safehasattr(doc, '__call__'): doc = doc() ui.write(doc) ui.write("\n")
--- a/hgext/mq.py Mon Jul 25 14:59:55 2011 -0500 +++ b/hgext/mq.py Mon Jul 25 16:24:37 2011 -0500 @@ -938,7 +938,7 @@ p.write("# User " + user + "\n") if date: p.write("# Date %s %s\n\n" % date) - if hasattr(msg, '__call__'): + if util.safehasattr(msg, '__call__'): msg = msg() commitmsg = msg and msg or ("[mq]: %s" % patchfn) n = repo.commit(commitmsg, user, date, match=match, force=True)
--- a/mercurial/commands.py Mon Jul 25 14:59:55 2011 -0500 +++ b/mercurial/commands.py Mon Jul 25 16:24:37 2011 -0500 @@ -2732,7 +2732,7 @@ # description if not doc: doc = _("(no help text available)") - if hasattr(doc, '__call__'): + if util.safehasattr(doc, '__call__'): doc = doc() ui.write("%s\n\n" % header)
--- a/mercurial/extensions.py Mon Jul 25 14:59:55 2011 -0500 +++ b/mercurial/extensions.py Mon Jul 25 16:24:37 2011 -0500 @@ -124,7 +124,7 @@ where orig is the original (wrapped) function, and *args, **kwargs are the arguments passed to it. ''' - assert hasattr(wrapper, '__call__') + assert util.safehasattr(wrapper, '__call__') aliases, entry = cmdutil.findcmd(command, table) for alias, e in table.iteritems(): if e is entry: @@ -177,12 +177,12 @@ your end users, you should play nicely with others by using the subclass trick. ''' - assert hasattr(wrapper, '__call__') + assert util.safehasattr(wrapper, '__call__') def wrap(*args, **kwargs): return wrapper(origfn, *args, **kwargs) origfn = getattr(container, funcname) - assert hasattr(origfn, '__call__') + assert util.safehasattr(origfn, '__call__') setattr(container, funcname, wrap) return origfn
--- a/mercurial/fancyopts.py Mon Jul 25 14:59:55 2011 -0500 +++ b/mercurial/fancyopts.py Mon Jul 25 16:24:37 2011 -0500 @@ -75,7 +75,7 @@ # copy defaults to state if isinstance(default, list): state[name] = default[:] - elif hasattr(default, '__call__'): + elif getattr(default, '__call__', False): state[name] = None else: state[name] = default
--- a/mercurial/hook.py Mon Jul 25 14:59:55 2011 -0500 +++ b/mercurial/hook.py Mon Jul 25 16:24:37 2011 -0500 @@ -21,7 +21,7 @@ ui.note(_("calling hook %s: %s\n") % (hname, funcname)) obj = funcname - if not hasattr(obj, '__call__'): + if not util.safehasattr(obj, '__call__'): d = funcname.rfind('.') if d == -1: raise util.Abort(_('%s hook is invalid ("%s" not in ' @@ -60,7 +60,7 @@ raise util.Abort(_('%s hook is invalid ' '("%s" is not defined)') % (hname, funcname)) - if not hasattr(obj, '__call__'): + if not util.safehasattr(obj, '__call__'): raise util.Abort(_('%s hook is invalid ' '("%s" is not callable)') % (hname, funcname)) @@ -99,7 +99,7 @@ env = {} for k, v in args.iteritems(): - if hasattr(v, '__call__'): + if util.safehasattr(v, '__call__'): v = v() if isinstance(v, dict): # make the dictionary element order stable across Python @@ -145,7 +145,7 @@ for hname, cmd in ui.configitems('hooks'): if hname.split('.')[0] != name or not cmd: continue - if hasattr(cmd, '__call__'): + if util.safehasattr(cmd, '__call__'): r = _pythonhook(ui, repo, name, hname, cmd, args, throw) or r elif cmd.startswith('python:'): if cmd.count(':') >= 2:
--- a/mercurial/templater.py Mon Jul 25 14:59:55 2011 -0500 +++ b/mercurial/templater.py Mon Jul 25 16:24:37 2011 -0500 @@ -135,7 +135,7 @@ v = mapping.get(key) if v is None: v = context._defaults.get(key, '') - if hasattr(v, '__call__'): + if util.safehasattr(v, '__call__'): return v(**mapping) return v