Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee='https://github.com/rhettinger'closed_at=<Date2017-03-20.07:39:08.069>created_at=<Date2016-12-05.09:37:42.421>labels= ['interpreter-core', 'type-bug', '3.7']
title='bool of large range raises OverflowError'updated_at=<Date2017-03-24.20:18:43.324>user='https://github.com/mdickinson'
>>> bool(range(2**63))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OverflowError: Python int too large to convert to C ssize_t
This is a side-effect of len raising OverflowError, which is a general problem that's nontrivial to fix (the sq_length slot is constrained to return a ssize_t). In theory, though, it would be possible to implement nb_bool for range objects to do the right thing.
In practice, this may well not be worth fixing, though I think it's at least worth reporting.
In bpo-29840 proposed an alternate and more general solution. But I think that nb_bool should be implemented for range objects since bpo-29840 is 3.7 only and nb_bool is faster.
Activity
mdickinson commented on Dec 5, 2016
The bool of a large range raises OverflowError:
>>> bool(range(2**63)) Traceback (most recent call last): File "<stdin>", line 1, in <module> OverflowError: Python int too large to convert to C ssize_tThis is a side-effect of len raising OverflowError, which is a general problem that's nontrivial to fix (the sq_length slot is constrained to return a ssize_t). In theory, though, it would be possible to implement nb_bool for range objects to do the right thing.
In practice, this may well not be worth fixing, though I think it's at least worth reporting.
rhettinger commented on Dec 5, 2016
+1 for implementing nb_bool for range objects.
4kir4 commented on Dec 5, 2016
Here's a patch with range_bool() implementation, tests and the docs update.
I'm not sure how it should be documented. I've specified it as
versionchanged:: 3.6
mdickinson commented on Dec 5, 2016
I think a change at this level probably isn't worth documenting in the official docs; it's enough that there's a Misc/NEWS entry for it.
4kir4 commented on Dec 6, 2016
I've removed the documentation changes from the patch.
mdickinson commented on Dec 13, 2016
Patch LGTM. You could safely drop the initialisers beyond nb_bool in the range_as_number struct (per C99 6.7.8p21), but it's fine as it is.
4kir4 commented on Jan 22, 2017
Following the python-dev discussion [1] I've added a variant of the patch that uses c99 designated initializers [2]
[1] https://mail.python.org/pipermail/python-dev/2017-January/147175.html
[2] https://gcc.gnu.org/onlinedocs/gcc/Designated-Inits.html
rhettinger commented on Jan 23, 2017
This patch looks ready to go. I'll wait a bit to see it there are any other comments. If not, I'll apply it shortly.
methane commented on Jan 23, 2017
LGTM, except 2-space indent.
4kir4 commented on Jan 23, 2017
I've updated the patch to use 4-space indent (pep-7).
I've added space around "=" (pep-7); unlike the usual
"dict(designator=value)" -- no space around "=" for keyword argument
(pep-8).
mdickinson commented on Jan 23, 2017
Latest patch LGTM too.
serhiy-storchaka commented on Mar 17, 2017
Akira, could you open a pull request on GitHub?
4kir4 commented on Mar 17, 2017
Done. PR 699
serhiy-storchaka commented on Mar 17, 2017
In bpo-29840 proposed an alternate and more general solution. But I think that nb_bool should be implemented for range objects since bpo-29840 is 3.7 only and nb_bool is faster.
serhiy-storchaka commented on Mar 20, 2017
Thank you Akira for your patch.
serhiy-storchaka commented on Mar 24, 2017
New changeset 4276068 by Serhiy Storchaka in branch '3.5':
bpo-28876: bool of large range raises OverflowError (#699) (#735)
4276068
serhiy-storchaka commented on Mar 24, 2017
New changeset 6fad409 by Serhiy Storchaka in branch '3.6':
bpo-28876: bool of large range raises OverflowError (#699) (#734)
6fad409
serhiy-storchaka commented on Mar 24, 2017
New changeset e46fb86 by Serhiy Storchaka (4kir4) in branch 'master':
bpo-28876: bool of large range raises OverflowError (#699)
e46fb86