changeset 88:36cf1d9bf40b

slightly improve type system
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 27 Apr 2012 15:18:24 -0700
parents 928654373755
children 0804a706d6bf
files configuration/configuration.py
diffstat 1 files changed, 9 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/configuration/configuration.py	Fri Apr 27 14:13:04 2012 -0700
+++ b/configuration/configuration.py	Fri Apr 27 15:18:24 2012 -0700
@@ -221,6 +221,7 @@
          float: FloatCLI(),
          list:  ListCLI(),
          dict:  DictCLI(),
+         str:   BaseCLI(),
          None:  BaseCLI()} # default
 
 __all__ += [i.__class__.__name__ for i in types.values()]
@@ -356,10 +357,17 @@
         handler = self.types[self.option_dict[option].get('type')]
         return getattr(handler, 'take_action', lambda x: 1)
 
+    def option_type(self, name):
+        value = self.option_dict[name]
+        if 'type' in value:
+            return value['type']
+        if 'default' in value:
+            return type(value['default'])
+
     def optparse_options(self, parser):
         """add optparse options to a OptionParser instance"""
         for key, value in self.items():
-            handler = self.types[value.get('type')]
+            handler = self.types[self.option_type(key)]
             args, kw = handler(key, value)
             if not args:
                 # No CLI interface