[Python-3000] How much should non-dict mappings behave like dict?
skip at pobox.com
skip at pobox.com
Fri Sep 12 20:02:44 CEST 2008
Guido> What's the purpose of the "order by key" clauses here? Doesn't
Guido> that force the return order? Perhaps you meant to leave those
>>> It's simply to guarantee that the order of the elements of values()
>>> is the same as the order of the elements of keys(). Again, I was
>>> thinking that this property: zip(d.keys(), d.values()) == d.items()
>>> was a desirable property of mappings, not just of the CPython dict
>> But in SQL this would force alphabetical ordering so of course it
>> would both return them in corresponding order. Maybe we should just
>> drop this, it seems hardly relevant.
Josiah> If the desire is to behave like a bsddb.btree instance,
Josiah> alphabetical is ok. Replacing the 'order by key' with 'order by
Josiah> rowid' is reasonably sane, if alphabetical is explicitly
Josiah> undesired. Really there are 3 options: alphabetical ordering,
Josiah> rowid ordering, no guaranteed ordering (which seems to be
Josiah> on-disk or rowid ordering, my brief tests tell me nothing).
Folks, this is my last comment on this particular issue. I think everybody
misunderstands what I was getting at here. All I wanted to do was guarantee
that keys and values were returned in the same order if called with no
intervening updates. Ordering both statements by the keys seemed to be the
easiest way to accomplish that. I could have cared less if the result was
sorted, just that it was predictable. Gerhard suggested that if predictable
ordering was desired that "order by rowid" would be better.
>> That's a C API definition that hasn't been updated. If anything
>> documents the concept of a mapping it would be the Mapping ABC in the
>> collections module.
Josiah> According to PEP 3119 on the mapping ABC: "i.e. iterating over
Josiah> the items, keys and values should return results in the same
Josiah> So... key ordered, or rowid ordered?
I could care less, just so it's predictable. Ordering by rowid is probably
More information about the Python-3000