[PATCH V2] fancyopts: allow all callable as default parameter value

shiyao.ma i at introo.me
Thu Jun 11 15:43:53 UTC 2015


# HG changeset patch
# User introom <i at introo.me>
# Date 1434027264 14400
#      Thu Jun 11 08:54:24 2015 -0400
# Node ID 6f7a864921721a28fe55622aa5246608b7f58051
# Parent  ad14fb602e5e54e5432fbc776dd5d1bad63f1f68
fancyopts: allow all callable as default parameter value

The current fancyopts allows function as default parameter value
but not other callables.
By supporting other callables, we can have the benefits of e.g.,
custom __str__ method, which will be printed by 'hg help' as
the default value.

diff --git a/mercurial/fancyopts.py b/mercurial/fancyopts.py
--- a/mercurial/fancyopts.py
+++ b/mercurial/fancyopts.py
@@ -103,8 +103,9 @@
     # transfer result to state
     for opt, val in opts:
         name = argmap[opt]
-        t = type(defmap[name])
-        if t is type(fancyopts):
+        obj = defmap[name]
+        t = type(obj)
+        if callable(obj):
             state[name] = defmap[name](val)
         elif t is type(1):
             try:


More information about the Mercurial-devel mailing list