[Python-Dev] multidict API (original) (raw)
Ian Bicking ianb at colorstudy.com
Fri Mar 10 18:25:26 CET 2006
- Previous message: [Python-Dev] Developing/patching ctypes (was: Re: integrating ctypes into python)
- Next message: [Python-Dev] multidict API
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
I'm not really making any actionable proposal here, so maybe this is off-topic; if so, sorry.
Back during the defaultdict discussion I proposed a multidict object (http://mail.python.org/pipermail/python-dev/2006-February/061264.html) -- right now I need to implement one to represent web form submissions. It would also be ordered in that case.
The question then is what the API should look like for such an object -- an ordered, multi-value dictionary. I would really like if this object was in the collections module, but I'm too lazy to try to pursue that now. But if it did show up, I'd like the class I write to look the same. There's some open questions I see:
Does getitem return a list of all matching keys (never a KeyError, though possibly returning []), or does it return the first matching key?
Either way, I assume there will be another method, like getfirst or getall, that will present the other choice. What would it be named? Should it have a default?
Should there be a method to get a single value, that implicitly asserts that there is only one matching key?
Should the default for .get() be None, or something else?
Does setitem overwrite any or all values with matching keys?
If so, there should be another method like .add(key, value) which does not overwrite. Or, if setitem does not overwrite, then there should be a method that does.
Does delitem raise a KeyError if the key is not found?
Does .keys() return all unique keys, or all keys in order (meaning a key may show up more than once in the list)?
I really could go either way on all of these questions, though I think there's constraints -- answer one of the questions and another becomes obvious. But you can answer them in whatever order you want.
-- Ian Bicking / ianb at colorstudy.com / http://blog.ianbicking.org
- Previous message: [Python-Dev] Developing/patching ctypes (was: Re: integrating ctypes into python)
- Next message: [Python-Dev] multidict API
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]