<br><br><div class="gmail_quote">On 15 May 2012 09:02, Steven D'Aprano <span dir="ltr"><<a href="mailto:steve@pearwood.info" target="_blank">steve@pearwood.info</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On Tue, May 15, 2012 at 12:28:02AM +0100, Michael Foord wrote:<br>
> Hello all,<br>
><br>
> It seems to me that the following error message, whilst technically<br>
> correct, is unhelpful:<br>
><br>
> >>> sorted([3, 2, 1], reverse=None)<br>
> Traceback (most recent call last):<br>
> File "<stdin>", line 1, in <module><br>
> TypeError: an integer is required<br>
<br>
</div>I don't know what you mean by "technically correct". Surely the Pythonic<br>
idiom is to allow any value in a boolean context.<br>
<br>
sorted() here is neither one thing nor the other, neither duck-typing,<br>
since it won't accept flags that quack like a bool, nor does it strictly<br>
insist on a bool, since it accepts ints:<br>
<br>
>>> sorted([1,2,3], reverse=42)<br>
[3, 2, 1]<br>
<br>
I can't see any sense to this almost-but-not-quite type restriction.<br>
<br>
+1 to allow any object that is truthy or falsey (i.e. anything).<br></blockquote><div><br>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).<br>
<br>Michael<br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+0 to allowing only True or False.<br>
-1 to half-heartedly allowing ints but no other values.<br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
--<br>
Steven<br>
</font></span><div class="HOEnZb"><div class="h5">_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/python-ideas" target="_blank">http://mail.python.org/mailman/listinfo/python-ideas</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br><pre cols="72"><a href="http://www.voidspace.org.uk/" target="_blank">http://www.voidspace.org.uk/</a><br><br>May you do good and not evil<br>May you find forgiveness for yourself and forgive others<br>
May you share freely, never taking more than you give.<br>-- the sqlite blessing <a href="http://www.sqlite.org/different.html" target="_blank">http://www.sqlite.org/different.html</a></pre>
<br>