[Patches] [ python-Patches-661092 ] list.sort cmpfunc default

noreply@sourceforge.net noreply@sourceforge.net
Thu, 02 Jan 2003 08:40:20 -0800


Patches item #661092, was opened at 2003-01-02 09:28
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=661092&group_id=5470

Category: Core (C code)
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Skip Montanaro (montanaro)
Assigned to: Tim Peters (tim_one)
Summary: list.sort cmpfunc default

Initial Comment:
It surprised me today when I saw a functional sort written like this:

def sort(sequence, cmpfunc=None):
    sorted = list(sequence)
    if cmpfunc is None:
        sorted.sort()
    else:
        sorted.sort(cmpfunc)
    return sorted

If [].sort() was written in Python its function signature would be declared as above (obviously the body would be different), and the above functional sort could be written as:

def sort(sequence, cmpfunc=None):
    sorted = list(sequence)
    sorted.sort(cmpfunc)
    return sorted

The attached patch supports calling [].sort() with an explicit argument of None.  (No doc change yet. If you approve, I will make that mod.)


----------------------------------------------------------------------

>Comment By: Neal Norwitz (nnorwitz)
Date: 2003-01-02 11:40

Message:
Logged In: YES 
user_id=33168

The patch looks correct.  You should also add a test if Tim
accepts this.

----------------------------------------------------------------------

Comment By: Skip Montanaro (montanaro)
Date: 2003-01-02 11:30

Message:
Logged In: YES 
user_id=44345

Thanks, Neal...  

*sigh*  I guess I didn't get the memo.  When I submitted the patch, I saw that the return screen was blank.  I checked a bit later to see if a patch had been created, but didn't think to check if the file was uploaded.  I'll check this time.


----------------------------------------------------------------------

Comment By: Neal Norwitz (nnorwitz)
Date: 2003-01-02 11:19

Message:
Logged In: YES 
user_id=33168

Skip, there's no file attached.  Unfortunately, SF doesn't
upload the file any more when submitting a new patch.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=661092&group_id=5470