Roundup Tracker - Issues

Message7144

Author rouilj
Recipients ngaba, rouilj, schlatterbeck
Date 2021-03-28.03:39:02
Message-id <1616902742.63.0.971041307041.issue2551120@roundup.psfhosted.org>
In-reply-to
I think the way to handle this is to return tuples to
the sort routine. E.G.:

 sorted(propname, reverse=False, NoneFirst=False):

     NoneCode = (2,0)[NoneFirst] # use 2 if NoneFirst is False to sort 
to end

     def keyfunc(a):
	  if v:
	     return (1, v)
	  elif v is None
	     return (NoneCode, v)

     value.sort(key=keyfunc, reverse=reverse)

Returning a tuple from the keyfunc will allow anything that is not
None to sort first by 1 and then by the value of the item.  Items that
are None will sort before or after the items starting with 1 (0 or 2)
followed by comparing None to None which is supported.

E.G. sorting:

         id:   1  2,      3, 4,    5
   prop val:   5, 20, None, 16, None

should result in (with NoneFirst = False): 1,4,2,3,5. Sort is stable
so you should not be able to get 1,4,2,5,3. If this isn't true then I
don't see any way to add an order element last in the tuple to
preserve order.

Comments?

Also I may need to change the sort_repr methods to use the same
mechanism to sort None items as well.
History
Date User Action Args
2021-03-28 03:39:02rouiljsetmessageid: <1616902742.63.0.971041307041.issue2551120@roundup.psfhosted.org>
2021-03-28 03:39:02rouiljsetrecipients: + rouilj, schlatterbeck, ngaba
2021-03-28 03:39:02rouiljlinkissue2551120 messages
2021-03-28 03:39:02rouiljcreate