list.sort, was Re: [Python-Dev] decorate-sort-undecorate

Tim Peters at
Wed Oct 15 20:33:39 EDT 2003

[Kevin J. Butler]
>> -1000.  This is non-negotiable.
> [Barry's blissful demo code snipped]
> +1
> Just 998 votes to go - nice to have a precise value on BDFL
> pronouncements.  No voting twice with bigger numbers! ;-)

-1.  Back to 999.

> I think just about everyone gets tripped up by the "sort returns None"
> behavior, and though one (e.g., BDFL) can declare that it is a less
> significant stumble than not realizing the list is sorted in place, it
> is a _continuing_ inconvenience, with virtually every call to [].sort,
> even for Python experts (like Barry, not me).

People would get in worse (subtler) trouble if it did return self.  The
trouble they get from it returning None is all of shallow, immediate, easily
fixed, and 100% consistent with other builtin container mutating methods
(dict.update, dict.clear, list.remove, list.append, list.extend,
list.insert, list.reverse).

That said, since we're having a fire sale on optional sort arguments in 2.4,
I wouldn't oppose an optional Boolean argument you could explicit set to
have x.sort() return x.  For example,

>>> [1, 2, 3].sort(happy_guido=False)
[1, 2, 3]

More information about the Python-Dev mailing list