# HG changeset patch # User Jeff Hammel # Date 1335565104 25200 # Node ID 36cf1d9bf40b112cbe4eaaf1f449e6adb755f289 # Parent 9286543737559d5ceeaf543746bb484af113e1bd slightly improve type system diff -r 928654373755 -r 36cf1d9bf40b configuration/configuration.py --- 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