|
From: David H. <neg...@gm...> - 2010-03-04 15:18:11
|
On Tue, Mar 2, 2010 at 10:23, Michael Foord <fuz...@vo...>wrote: > > * BUGFIX: Members that were lists were being returned as copies due to > interpolation introduced in 4.7. Lists are now only copies if > interpolation > changes a list member. (See below.) > > For general information on string interpolation in ConfigObj see: > http://www.voidspace.org.uk/python/configobj.html#string-interpolation > > Since version 4.7 string interpolation is done on string members of list > values. If interpolation changes any members of the list then what you get > back is a *copy* of the list rather than the original list. > > This makes fetching list values slightly slower when interpolation is on, > it also means that if you mutate the list changes won't be reflected in the > original list: > > >>> c = ConfigObj()>>> c['foo'] = 'boo'>>> c['bar'] = ['%(foo)s']>>> c['bar']['boo']>>> c['bar'].append('fish')>>> c['bar']['boo'] > > Instead of mutating the list you must create a new list and reassign it. > Hey Michael, I have some concern over this behavior. Namely, the inconsistency bothers me. I don't like that the programmer now needs to know the nature of a string value for a given list option in order to be able to interact with it correctly. Because the string's value *changes* the behavior. It feels sort of like if I were to need to know the value of an integer in order to know how to use it in a mathematical expression. a+b would work for certain integer values of b, but would need to become a+int(str(b)[:]) for other integer values of b. Yuk. One of the most powerful things about ConfigObj is that it insulates program logic from needing a priori knowledge of input data. I feel like this new list interpolation behavior violates that. As programmer, I shouldn't ever care, know, or need to know, whether or not the person who is providing input data elected to have one piece of data substituted via reference with the value of another, before it's ever given to me. Interpolation of input data is something that is done outside of the purview of the program consuming the input data. Value substitution provided by interpolation is a convenience mechanism for the data provider, and using it or not using it shouldn't alter the consumer's interface for ConfigObj. As it stands, the choice to use or not use list interpolation ripples over into the other side. I think any program consuming list data provided by ConfigObj will have to (or should) treat it as always immutable. In other words -- I'll pretend that all lists are of the interpolated variety (copies) since I can't be sure when they are and when they aren't, and it's much safer to make this assumption than it is to assume the opposite. Thoughts? As always - thanks for your hard work! regards, -David |