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

login
register
mail settings
Submitter shiyao.ma
Date June 11, 2015, 3:43 p.m.
Message ID <6f7a864921721a28fe55.1434037433@datanode>
Download mbox | patch
Permalink /patch/9606/
State Accepted
Commit 69e8384a436ce703dba436fd8d6e49a63efe517b
Headers show

Comments

shiyao.ma - June 11, 2015, 3:43 p.m.
# HG changeset patch
# User introom <i@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.
Matt Mackall - June 15, 2015, 5:28 p.m.
On Thu, 2015-06-11 at 11:43 -0400, shiyao.ma wrote:
> # HG changeset patch
> # User introom <i@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

This is queued for default, thanks. Congratulations on your first
Mercurial patch.

Patch

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: