[issue37427] sorted() and list.sort() don't accept non-boolean objects with __bool__() as `reverse` parameter

2019-06-27 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: See issue15999. -- nosy: +serhiy.storchaka ___ Python tracker ___ ___ Python-bugs-list mailing

[issue37427] sorted() and list.sort() don't accept non-boolean objects with __bool__() as `reverse` parameter

2019-06-27 Thread Mark Dickinson
Mark Dickinson added the comment: > I'm finding it rather hard to guess what the rules are for what works and > what doesn't So now that I've looked at the source: anything with an `__int__` method works, except that `float` instances are explicitly excluded. So this explains for example:

[issue37427] sorted() and list.sort() don't accept non-boolean objects with __bool__() as `reverse` parameter

2019-06-27 Thread Mark Dickinson
Change by Mark Dickinson : -- nosy: +tim.peters ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue37427] sorted() and list.sort() don't accept non-boolean objects with __bool__() as `reverse` parameter

2019-06-27 Thread Mark Dickinson
Mark Dickinson added the comment: I haven't looked at the source yet, but from experimentation I'm finding it rather hard to guess what the rules are for what works and what doesn't: Python 3.7.3 (default, Mar 30 2019, 03:37:43) [Clang 10.0.0 (clang-1000.11.45.5)] on darwin Type "help",

[issue37427] sorted() and list.sort() don't accept non-boolean objects with __bool__() as `reverse` parameter

2019-06-27 Thread Karthikeyan Singaravelan
Change by Karthikeyan Singaravelan : -- nosy: +rhettinger ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue37427] sorted() and list.sort() don't accept non-boolean objects with __bool__() as `reverse` parameter

2019-06-27 Thread NODA, Kai
New submission from NODA, Kai : 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],