[New-bugs-announce] [issue29840] Avoid raising OverflowError in bool()

Serhiy Storchaka report at bugs.python.org
Fri Mar 17 16:27:26 EDT 2017


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 <report at bugs.python.org>
<http://bugs.python.org/issue29840>
_______________________________________


More information about the New-bugs-announce mailing list