classification
Title: Avoid raising OverflowError in bool()
Type: enhancement Stage: patch review
Components: Interpreter Core Versions: Python 3.7
process
Status: open Resolution:
Dependencies: 29839 Superseder:
Assigned To: Nosy List: mark.dickinson, rhettinger, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2017-03-17 20:27 by serhiy.storchaka, last changed 2017-03-17 20:35 by serhiy.storchaka.

Files
File name Uploaded Description Edit
bool-overflow.diff serhiy.storchaka, 2017-03-17 20:35
Messages (1)
msg289781 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-03-17 20:27
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.
History
Date User Action Args
2017-03-17 20:35:34serhiy.storchakasetfiles: + bool-overflow.diff
keywords: + patch
dependencies: + Avoid raising OverflowError in len() when __len__() returns negative large value
2017-03-17 20:27:26serhiy.storchakacreate