Re: [Rest2web-develop] None and Defaults
Brought to you by:
mjfoord
From: Nicola L. <ni...@te...> - 2005-08-16 15:09:49
|
> I have a question about your changes to validate regarding None : > > Specifically this code : > if missing: > try: > value = fun_kwargs['default'] > except KeyError: > raise ValidateMissingValue > # None is an admissible value for all types > if isinstance(value, StringTypes) and (value.lower() == 'none'): > return None > > This means that the string 'none' in a value will *always* be converted > to ``None``. I think this should only happen if 'none' is the default > value and the value itself is missing. Maybe somebody would like to explicitly put a None value in the config value, instead of just omitting it and having to say "default = None" in the configspec. Maybe the default is something else, and there's a need to unset a value in the config. I'm cool with the "None" string, by itself, always meaning the None value, like True or False, but not restricted to one check type. Maybe we should take out that "lower" method, though. > Also - in case validate is called later ``None`` ought to always go > through (e.g. to verify user changes to the config file made via a GUI). That's right, I didn't think about that, good catch. > These two changes make the code (I think) : > > if missing: > try: > value = fun_kwargs['default'] > except KeyError: > raise ValidateMissingValue > # None is an admissible value for all types > if isinstance(value, StringTypes) and (value.lower() == 'none'): > value = None > if value is None: > return None Then it would become something like: if missing: try: value = fun_kwargs['default'] except KeyError: raise ValidateMissingValue # None is an admissible value for all types if (value is None) or (value == 'None'): return None -- Nicola Larosa - ni...@te... Python is the best thing I've seen in 30 years of computing for pedogogical and productive purposes. Only when I want speed do I see a need for something else. -- Chuck Allison, June 2005 |