[Python-ideas] `OrderedDict.sort`

Ram Rachum ram at rachum.com
Tue Sep 24 18:19:56 CEST 2013


On Tue, Sep 24, 2013 at 7:02 PM, Stephen J. Turnbull <stephen at xemacs.org>wrote:

> Ram Rachum writes:
>
>  > I disagree with defining the entire class as an insertion ordering
>  > class and refusing
>
> There's no refusal.  It's just not in the battery pack.
>
>  > to allow users to reorder it as they wish after it's created.
>
> You can put your inefficient but useful implementation on PyPI.
> You can write a PEP in which
> you define the API.
> You can provide an efficient implementation suitable for the stdlib, or
> you can convince the gatekeepers that it doesn't need to be efficient.
> You can promise to maintain it for 5 years.[1]
>

I can do an inefficient implementation and put it on PyPI. I don't see the
need for writing a PEP for a simple method. ("Define the API"? Anything I'm
missing beyond a call signature `def sort(self, key=None)`?)

If people here are opposed to allowing an implementation of
`OrderedDict.sort` in the stdlib, I don't see a reason to waste my time
putting an implementation on PyPI. What's that implementation going to help
if you won't allow it anyway?

Here's a simple inefficient implementation you can use:

    def sort(self, key=None):
        '''
        Sort the items according to their keys, changing the order in-place.

        The optional `key` argument, (not to be confused with the dictionary
        keys,) will be passed to the `sorted` function as a key function.
        '''
        sorted_keys = sorted(self.keys(), key=key)
        for key_ in sorted_keys[1:]:
            self.move_to_end(key_)

Regarding committing to maintain it for N years: Sorry, that's beyond what
I'm willing to do. If that's a requirement for contributing a minor feature
to Python, I'll have to withdraw my suggestion.


>
> Why don't you?  Four or five hackers do it every cycle (although
> sometimes it takes more than a cycle to actually get approval).
> Recent successes include Ethan and Steven, who are giving you the
> benefit of their experience.
>
> OTOH, the barrier for mere suggestions (even backed up by proof of
> concept implementations) these days is quite high.  You need to
> convince somebody to do all of the above, which usually requires an
> argument that it's at least tricky to do right, and perhaps hard to do
> at all.
>
> Footnotes:
> [1]  Or whatever the going rate is these days.
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
>
> --
>
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "python-ideas" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/python-ideas/-RFTqV8_aS0/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> python-ideas+unsubscribe at googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130924/7fdabf1b/attachment-0001.html>


More information about the Python-ideas mailing list