Sort documentation inaccurate?

David Bolen db3l at fitlinxx.com
Thu Sep 27 20:15:25 CEST 2001


Bruce Dawson <comments at cygnus-software.com> writes:

> According to the documentation strcmp() would not be appropriate.
> strcmp() does not return -1, 0, 1 it returns negative, zero, positive
> and sort() expects -1, 0, 1.
> 
> I suspect that the documentation should either say:
> 
>     sort expects negative, zero, positive
> 
> or:
> 
>     sort expects negative or zero
> 
> but I don't know for sure.

Internally when not given any arguments, sort is calling the same
function used by the built-in cmp() function, which itself returns <0,
0 or >0.

Thus, although the doc string for the sort function itself does
specifically say -1, 0 and 1, it must work today with <0, 0 or >0.

So I guess the big question is whether sort() is documented too
strictly (than implementation) by accident or to permit later changes
that only work under the stricter returns, or if cmp() is documented
too liberally and actually returns a more restrictive set.

--
-- David
-- 
/-----------------------------------------------------------------------\
 \               David Bolen            \   E-mail: db3l at fitlinxx.com  /
  |             FitLinxx, Inc.            \  Phone: (203) 708-5192    |
 /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \
\-----------------------------------------------------------------------/



More information about the Python-list mailing list