Unhelpful error message from sorted
Hello all, It seems to me that the following error message, whilst technically correct, is unhelpful:
sorted([3, 2, 1], reverse=None) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: an integer is required
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 Mon, May 14, 2012 at 4:28 PM, Michael Foord <fuzzyman@gmail.com> wrote:
Hello all,
It seems to me that the following error message, whilst technically correct, is unhelpful:
sorted([3, 2, 1], reverse=None) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: an integer is required
Worth creating an issue for?
IMO, yes. Surely a *bool[ean]* value ought to be required. (And mentioning the `reverse` parameter by name would of course also be nice.) Cheers, Chris
On 5/14/2012 8:04 PM, Chris Rebert wrote:
On Mon, May 14, 2012 at 4:28 PM, Michael Foord<fuzzyman@gmail.com> wrote:
Hello all,
It seems to me that the following error message, whilst technically correct, is unhelpful:
sorted([3, 2, 1], reverse=None) Traceback (most recent call last): File "<stdin>", line 1, in<module> TypeError: an integer is required
Worth creating an issue for?
IMO, yes. Surely a *bool[ean]* value ought to be required. (And mentioning the `reverse` parameter by name would of course also be nice.)
There are still overly cryptic errors messages. I would like to see something more like TypeError: 'reverse' argument must be bool, not Nonetype -- Terry Jan Reedy
On 15.05.12 09:52, Terry Reedy wrote:
There are still overly cryptic errors messages. I would like to see something more like TypeError: 'reverse' argument must be bool, not Nonetype
With using issue14705 [1] sort can accepts reverse=None. [1] http://bugs.python.org/issue14705
Serhiy Storchaka, 15.05.2012 09:16:
On 15.05.12 09:52, Terry Reedy wrote:
There are still overly cryptic errors messages. I would like to see something more like TypeError: 'reverse' argument must be bool, not Nonetype
With using issue14705 [1] sort can accepts reverse=None.
Looks like a side effect, though. It doesn't make any sense to me to pass None for the "reversed" argument. Stefan
On Tue, May 15, 2012 at 12:28:02AM +0100, Michael Foord wrote:
Hello all,
It seems to me that the following error message, whilst technically correct, is unhelpful:
sorted([3, 2, 1], reverse=None) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: an integer is required
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:
On Tue, May 15, 2012 at 12:28:02AM +0100, Michael Foord wrote:
Hello all,
It seems to me that the following error message, whilst technically correct, is unhelpful:
sorted([3, 2, 1], reverse=None) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: an integer is required
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).
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
+0 to allowing only True or False. -1 to half-heartedly allowing ints but no other values.
-- Steven _______________________________________________ Python-ideas mailing list Python-ideas@python.org http://mail.python.org/mailman/listinfo/python-ideas
-- 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