New submission from Serhiy Storchaka: For now bool() raises OverflowError if __bool__ is not defined and __len__ returns large value.
>>> class A: ... def __len__(self): ... return 1 << 1000 ... >>> bool(A()) Traceback (most recent call last): File "<stdin>", line 1, in <module> OverflowError: cannot fit 'int' into an index-sized integer >>> bool(range(1<<1000)) Traceback (most recent call last): File "<stdin>", line 1, in <module> OverflowError: Python int too large to convert to C ssize_t Proposed patch makes bool() returning True if len() raises OverflowError. This is an alternate solution of issue28876. ---------- components: Interpreter Core messages: 289781 nosy: mark.dickinson, rhettinger, serhiy.storchaka priority: normal severity: normal stage: patch review status: open title: Avoid raising OverflowError in bool() type: enhancement versions: Python 3.7 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue29840> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com