[issue29840] Avoid raising OverflowError in bool()

Serhiy Storchaka report at bugs.python.org
Sat Apr 22 11:18:18 EDT 2017


Serhiy Storchaka added the comment:

I had similar doubts about this patch and needed opinions of other core developers.

> Maybe, if __len__() raises an OverflowError: call again the len(), but using the "__len__" method instead of the slot?

Following patch implements this idea. I don't like it because it is too complicated.

I think that we should either document that raising an OverflowError by __len__() is normal and interpreted as true in Boolean context, or document that __len__() should return a value not larger than sys.maxsize, otherwise len() and bool() can raise an OverflowError (see issue15718).

----------
Added file: http://bugs.python.org/file46826/bool-no-overflow-double-call.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29840>
_______________________________________


More information about the Python-bugs-list mailing list