Unhelpful error message from sorted

Hello all, It seems to me that the following error message, whilst technically correct, is unhelpful:
Worth creating an issue for? Michael -- http://www.voidspace.org.uk/ May you do good and not evil May you find forgiveness for yourself and forgive others May you share freely, never taking more than you give. -- the sqlite blessing http://www.sqlite.org/different.html

On 15.05.12 09:52, Terry Reedy wrote:
With using issue14705 [1] sort can accepts reverse=None. [1] http://bugs.python.org/issue14705

On Tue, May 15, 2012 at 12:28:02AM +0100, Michael Foord wrote:
I don't know what you mean by "technically correct". Surely the Pythonic idiom is to allow any value in a boolean context. sorted() here is neither one thing nor the other, neither duck-typing, since it won't accept flags that quack like a bool, nor does it strictly insist on a bool, since it accepts ints:
sorted([1,2,3], reverse=42) [3, 2, 1]
I can't see any sense to this almost-but-not-quite type restriction. +1 to allow any object that is truthy or falsey (i.e. anything). +0 to allowing only True or False. -1 to half-heartedly allowing ints but no other values. -- Steven

On 15 May 2012 09:02, Steven D'Aprano <steve@pearwood.info> wrote:
I would rather have "sorted(some_list, reverse=[1, 2, 3])" raise an error (and preferably a helpful error message that tells you which argument is faulty and why). Michael
-- http://www.voidspace.org.uk/ May you do good and not evil May you find forgiveness for yourself and forgive others May you share freely, never taking more than you give. -- the sqlite blessing http://www.sqlite.org/different.html

On 15.05.12 09:52, Terry Reedy wrote:
With using issue14705 [1] sort can accepts reverse=None. [1] http://bugs.python.org/issue14705

On Tue, May 15, 2012 at 12:28:02AM +0100, Michael Foord wrote:
I don't know what you mean by "technically correct". Surely the Pythonic idiom is to allow any value in a boolean context. sorted() here is neither one thing nor the other, neither duck-typing, since it won't accept flags that quack like a bool, nor does it strictly insist on a bool, since it accepts ints:
sorted([1,2,3], reverse=42) [3, 2, 1]
I can't see any sense to this almost-but-not-quite type restriction. +1 to allow any object that is truthy or falsey (i.e. anything). +0 to allowing only True or False. -1 to half-heartedly allowing ints but no other values. -- Steven

On 15 May 2012 09:02, Steven D'Aprano <steve@pearwood.info> wrote:
I would rather have "sorted(some_list, reverse=[1, 2, 3])" raise an error (and preferably a helpful error message that tells you which argument is faulty and why). Michael
-- http://www.voidspace.org.uk/ May you do good and not evil May you find forgiveness for yourself and forgive others May you share freely, never taking more than you give. -- the sqlite blessing http://www.sqlite.org/different.html
participants (6)
-
Chris Rebert
-
Michael Foord
-
Serhiy Storchaka
-
Stefan Behnel
-
Steven D'Aprano
-
Terry Reedy