New submission from Yan Mitrofanov :
Sorting documentation claims that sorting algorithm is only using < comparisons
https://docs.python.org/3/howto/sorting.html#odd-and-ends
https://docs.python.org/3/library/stdtypes.html#list.sort
When __lt__ implementation is missing, you get an exception
class Foo:
pass
sorted([Foo(), Foo(), Foo()])
TypeError: '<' not supported between instances of 'Foo' and 'Foo'
However, if implement __gt__ method, you doesn't get an exception
class Foo:
def __gt__(self, other):
return False
sorted([Foo(), Foo(), Foo()]) # ok
Is it supposed to work like this? Or is it lack of documentation?
--
assignee: docs@python
components: Documentation
messages: 359293
nosy: docs@python, yanmitrofanov
priority: normal
severity: normal
status: open
title: Sorting falls back to use __gt__ when __lt__ is not present
versions: Python 3.8
___
Python tracker
<https://bugs.python.org/issue39210>
___
___
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com