On Sat, Dec 14, 2019 at 02:40:04PM +0200, Serhiy Storchaka wrote:
> 14.12.19 12:45, Steven D'Aprano пише:
> >The list.sort method is documented to only use less than:
> >
> >https://docs.python.org/3/library/stdtypes.html#list.sort
> >
> >but I don't think that is correct, it seems to use greater than if it
> >exists and less than doesn't. My understanding is that items need to
> >define one of l.t. or g.t. to make it sortable, not the full complement
> >of six rich comparison methods.
> 
> What evidence do you have that it is not correct?


I might be misinterpreting the evidence, but sorting works on objects 
that define `__gt__` without `__lt__`.

py> class A:
...     def __init__(self, x): self.x = x
...     def __gt__(self, other): return self.x > other.x
...
py> L = [A(9), A(1), A(8)]
py> L.sort()
py> [obj.x for obj in L]
[1, 8, 9]


But the main part of my question is whether we should make the same 
guarantee for sorted, min and max as we already make for list.sort.



-- 
Steven
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/K7BSMHSC5SWDS3222SI3M4UJ4FHCQRFX/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to