Thread: [Rest2web-develop] None and Defaults
Brought to you by:
mjfoord
From: Michael F. <mi...@pc...> - 2005-08-16 14:49:52
|
Hello Nicola, About to commit a few minor changes to ConfigObj. 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. 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). 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 Fuzzy |
From: Michael F. <mi...@pc...> - 2005-08-16 15:02:12
|
Commit done anyway - minor changes to ConfigObj and validate. Michael Foord wrote: > Hello Nicola, > > About to commit a few minor changes to ConfigObj. > > 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. > > 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). > > 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 > > Fuzzy > > > ------------------------------------------------------- > SF.Net email is Sponsored by the Better Software Conference & EXPO > September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices > Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA > Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf > _______________________________________________ > Rest2web-develop mailing list > Res...@li... > https://lists.sourceforge.net/lists/listinfo/rest2web-develop > > > |
From: Nicola L. <ni...@te...> - 2005-08-16 15:11:29
|
> Commit done anyway - minor changes to ConfigObj and validate. You can still do another one, if needed. ;-) -- 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 |
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 |
From: Michael F. <mi...@pc...> - 2005-08-16 15:28:10
|
Nicola Larosa wrote: >>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. > I'm not - ConfigObj shouldn't change the type without the programmer specifying it. Don't forget the value is set by the *user* - not the programmer. ConfigObj should only convert type if the programmer says. None shouldn't be an acceptable value for every check - maybe it *isn't* an acceptable value (what if the programmer really does want an integer there - he expects validate to tell him). > > >>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 > This means that someone's program will break because a user enters 'None' as a string value. It ought to be possible to have 'None' as a string value in a config file without our program converting it to another type. I thought the point was to catch defaults ? My proposed (and currently committed) solution allows the programmer to specify that None is ok (by using default='None'), which makes the value explicitly (user sets value as 'None') and implicitly (user omits value altogether) optional. I'm fine with removing the 'lower'. All the best, Fuzzy |
From: Nicola L. <ni...@te...> - 2005-08-16 16:09:50
|
>> 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. > I'm not - ConfigObj shouldn't change the type without the programmer > specifying it. Good point. > Don't forget the value is set by the *user* - not the programmer. > ConfigObj should only convert type if the programmer says. None > shouldn't be an acceptable value for every check - maybe it *isn't* an > acceptable value (what if the programmer really does want an integer > there - he expects validate to tell him). Yes, actually None is a value of type NoneType. Hadn't realized that before, was thinking of it as an amorphous no-type-every-type non-value. > This means that someone's program will break because a user enters > 'None' as a string value. It ought to be possible to have 'None' as a > string value in a config file without our program converting it to > another type. Another good point. > I thought the point was to catch defaults ? Yes, it was, but then I incautiously adventured into YAGNI land. ;-) > My proposed (and currently committed) solution allows the programmer to > specify that None is ok (by using default='None'), which makes the value > explicitly (user sets value as 'None') I don't think the user may explicitly set a None value, now, but it may as well be that way. > and implicitly (user omits value altogether) optional. That's probably enough. > I'm fine with removing the 'lower'. So be it. Sorry for the confusion. -- 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 |