Re: [Python-ideas] a sorting protocol dunder method?

2017-12-03 Thread Carl Meyer
I think this is an interesting idea, and I don't believe that either performance or "sortable vs comparable" are very relevant. I doubt there is much performance to gain here, and I think the default sort order for a class must continue to match its comparison behavior. I think the case in favor

Re: [Python-ideas] a sorting protocol dunder method?

2017-12-03 Thread Serhiy Storchaka
04.12.17 01:06, Chris Barker пише: So: has this already been brought up and rejected? https://bugs.python.org/issue20632 Am I imagining the performance benefits? This will add an additional overhead. This will be even slower than passing the key function, since you will need to look up

Re: [Python-ideas] a sorting protocol dunder method?

2017-12-03 Thread David Mertz
And if this is a method on a custom *collection*, it can do whatever it wants in MyCollection.sort() already. On Dec 3, 2017 7:14 PM, "David Mertz" wrote: > I'm not sure I understand the motivation to make elements *sortable* but > not comparable. If an arbitrary order is still

Re: [Python-ideas] a sorting protocol dunder method?

2017-12-03 Thread Bruce Leban
On Sun, Dec 3, 2017 at 3:06 PM, Chris Barker wrote: > > However, if you are writing a custom class ... > > But what if there was a sort key magic method: > > __key__ or __sort_key__ (or whatever) > > that would be called by the sorting functions > > It seems this would

Re: [Python-ideas] a sorting protocol dunder method?

2017-12-03 Thread Steven D'Aprano
On Sun, Dec 03, 2017 at 06:46:45PM -0500, Nathan Schneider wrote: > On Sun, Dec 3, 2017 at 6:06 PM, Chris Barker wrote: > > > In fact, it's striking me that there may well be classes that are defining > > the comparison magic methods not because they want the objects to

Re: [Python-ideas] a sorting protocol dunder method?

2017-12-03 Thread Steven D'Aprano
On Sun, Dec 03, 2017 at 03:06:02PM -0800, Chris Barker wrote: > Recent python has moved toward a "key" function for customized sorting: > > list.sort(key=key_fun) > > key is also used (according to > https://docs.python.org/3.6/library/functools.html#functools.cmp_to_key) in: > > min(), max(),

Re: [Python-ideas] a sorting protocol dunder method?

2017-12-03 Thread Nathan Schneider
On Sun, Dec 3, 2017 at 6:06 PM, Chris Barker wrote: > In fact, it's striking me that there may well be classes that are defining > the comparison magic methods not because they want the objects to "work" > with the comparison operators, but because that want them to work

[Python-ideas] a sorting protocol dunder method?

2017-12-03 Thread Chris Barker
I can't believe this hasn't been brought up before, but searching the web, and python-ideas, and all the PEPs has found nothing (could be my lame google-fu), so here goes: Recent python has moved toward a "key" function for customized sorting: list.sort(key=key_fun) key is also used (according

Re: [Python-ideas] PEP 447: Adding type.__getdescriptor__

2017-12-03 Thread Nick Coghlan
On 3 December 2017 at 21:36, Ronald Oussoren wrote: > > >> On 3 Dec 2017, at 03:58, Nick Coghlan wrote: >> >> On 2 December 2017 at 01:12, Ronald Oussoren wrote: >>> On 1 Dec 2017, at 12:29, Nick Coghlan

Re: [Python-ideas] PEP 447: Adding type.__getdescriptor__

2017-12-03 Thread Ronald Oussoren
> On 3 Dec 2017, at 03:58, Nick Coghlan wrote: > > On 2 December 2017 at 01:12, Ronald Oussoren wrote: >> On 1 Dec 2017, at 12:29, Nick Coghlan wrote: >>> 2. Define it as a class method, but have the convention be for the >>>