[Python-3000] How much should non-dict mappings behave like dict?

Guido van Rossum guido at python.org
Fri Sep 12 19:33:06 CEST 2008


On Fri, Sep 12, 2008 at 10:13 AM,  <skip at pobox.com> wrote:
>
>    >> select key from dict order by key
>    >> select value from dict order by key
>
>    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
>    Guido> out?
>
> 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 implementation.

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.

> So is there a definition of what it means to be a mapping?  Maybe this page
> in the C API doc?
>
>    http://docs.python.org/api/mapping.html
>
> From that I infer that a mapping must offer these methods: keys, values,
> items, __len__, __contains__, __getitem__, __setitem__ and __delitem__.  No
> guarantee about the ordering of keys, values and items is made.  Can we
> settle on something like this and spell it out explicitly somewhere in the
> 3.0 docs?

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.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list