[New-bugs-announce] [issue37427] sorted() and list.sort() don't accept non-boolean objects with __bool__() as `reverse` parameter
NODA, Kai
report at bugs.python.org
Thu Jun 27 05:51:45 EDT 2019
New submission from NODA, Kai <nodakai at gmail.com>:
class X:
def __bool__(self):
return True
x = [1, 2, 3]
x.sort(reverse=X())
print(x)
print(sorted([1, 2, 3], reverse=X()))
TypeError: an integer is required (got type X)
We can always still do
x.sort(reverse=bool(X()))
print(sorted([1, 2, 3], reverse=bool(X())))
but that isn't cool
----------
components: Interpreter Core
messages: 346722
nosy: nodakai
priority: normal
severity: normal
status: open
title: sorted() and list.sort() don't accept non-boolean objects with __bool__() as `reverse` parameter
type: behavior
versions: Python 3.9
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37427>
_______________________________________
More information about the New-bugs-announce
mailing list