New submission from NODA, Kai <[email protected]>:
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 <[email protected]>
<https://bugs.python.org/issue37427>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com