On Tue, Feb 19, 2013 at 03:52:31PM +0100, Michael Hanselmann wrote: > 2013/2/19 Iustin Pop <[email protected]>: > > Looking at the patch, I don't understand why we need to call fn for > > every key. Just make the dictionary with the tuples: > > > > my_dict = { > > ("/2/node", node_name): …, > > … > > } > > > > return dict((translate_fn(key), value) for key, value in my_dict.items()) > > Not all keys use fn()—some are static strings as they are easier to > look up (see L{utils.FindMatch}) as opposed to compiled regular > expressions. Your idea means building the dictionary now needs special > treatment for those.
Yes, of course. There are 15 static patterns, and they can be made into a trivial regexp pattern. That way, all the keys in the dict would be homogenous, instead of having a mashup of both strings and regexpes, and requiring that callers (quoting from the docstring of FindMatch) “… have to ensure the data names aren't contradictory (e.g. a regexp that matches a string)”. Who came up with the non-homogenous dict in the first place? Bad, bad. regards, iustin
