[PATCH 1 of 3] fancyopts: Fix argument parsing type logic to be same as default creation

Eric Hopper hopper at omnifarious.org
Fri Jul 24 13:29:21 CDT 2009


 mercurial/fancyopts.py |  20 +++++++++++---------
 1 files changed, 11 insertions(+), 9 deletions(-)


# HG changeset patch
# User Eric Hopper <hopper at omnifarious.org>
# Date 1248458745 25200
# Node ID bf45c5ce3d0dafb7b9006ece189a578e8bf79947
# Parent  d98cef25b5afed5d8aa325ef87f98789367d8b6e
fancyopts: Fix argument parsing type logic to be same as default creation.

diff --git a/mercurial/fancyopts.py b/mercurial/fancyopts.py
--- a/mercurial/fancyopts.py
+++ b/mercurial/fancyopts.py
@@ -94,17 +94,19 @@
     # transfer result to state
     for opt, val in opts:
         name = argmap[opt]
-        t = type(defmap[name])
-        if t is type(fancyopts):
+        default = defmap[name]
+        if isinstance(default, list):
+            state[name].append(val)
+        elif hasattr(default, '__call__'):
             state[name] = defmap[name](val)
-        elif t is type(1):
+        elif isinstance(default, basestring):
+            state[name] = val
+        elif isinstance(default, (type(None), bool)):
+            # bool is a subtype of int, so this test must be before int test.
+            state[name] = True
+        elif isinstance(default, (int,long)):
+            # bool is a subtype of int, so this test must be after bool test.
             state[name] = int(val)
-        elif t is type(''):
-            state[name] = val
-        elif t is type([]):
-            state[name].append(val)
-        elif t is type(None) or t is type(False):
-            state[name] = True
 
     # return unparsed args
     return args

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 652 bytes
Desc: not available
Url : http://selenic.com/pipermail/mercurial-devel/attachments/20090724/de8eba6c/attachment.pgp 


More information about the Mercurial-devel mailing list