Repository navigation
bool of large range raises OverflowError #73062
Copy link
Copy link
Closed
Labels
3.7 (EOL)end of lifeend of lifeinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
| BPO | 28876 |
|---|---|
| Nosy | @rhettinger, @mdickinson, @methane, @4kir4, @serhiy-storchaka |
| PRs | |
| Files |
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 = <Date 2017-03-20.07:39:08.069>
created_at = <Date 2016-12-05.09:37:42.421>
labels = ['interpreter-core', 'type-bug', '3.7']
title = 'bool of large range raises OverflowError'
updated_at = <Date 2017-03-24.20:18:43.324>
user = 'https://github.com/mdickinson'bugs.python.org fields:
activity = <Date 2017-03-24.20:18:43.324>
actor = 'serhiy.storchaka'
assignee = 'rhettinger'
closed = True
closed_date = <Date 2017-03-20.07:39:08.069>
closer = 'serhiy.storchaka'
components = ['Interpreter Core']
creation = <Date 2016-12-05.09:37:42.421>
creator = 'mark.dickinson'
dependencies = []
files = ['45765', '45773', '46378', '46391']
hgrepos = []
issue_num = 28876
keywords = ['patch']
message_count = 18.0
messages = ['282402', '282405', '282414', '282418', '282506', '283137', '286008', '286048', '286055', '286089', '286092', '289772', '289778', '289786', '289876', '290129', '290130', '290132']
nosy_count = 5.0
nosy_names = ['rhettinger', 'mark.dickinson', 'methane', 'akira', 'serhiy.storchaka']
pr_nums = ['699', '734', '735']
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue28876'
versions = ['Python 3.5', 'Python 3.6', 'Python 3.7']Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
3.7 (EOL)end of lifeend of lifeinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Activity
mdickinson commentedon 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 commentedon Dec 5, 2016
+1 for implementing nb_bool for range objects.
4kir4 commentedon 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 commentedon 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 commentedon Dec 6, 2016
I've removed the documentation changes from the patch.
mdickinson commentedon Dec 13, 2016
Patch LGTM. You could safely drop the initialisers beyond
nb_boolin therange_as_numberstruct (per C99 6.7.8p21), but it's fine as it is.4kir4 commentedon 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 commentedon 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 commentedon Jan 23, 2017
LGTM, except 2-space indent.
4kir4 commentedon 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 commentedon Jan 23, 2017
Latest patch LGTM too.
serhiy-storchaka commentedon Mar 17, 2017
Akira, could you open a pull request on GitHub?
4kir4 commentedon Mar 17, 2017
Done. PR 699
serhiy-storchaka commentedon 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 commentedon Mar 20, 2017
Thank you Akira for your patch.
serhiy-storchaka commentedon 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 commentedon 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 commentedon Mar 24, 2017
New changeset e46fb86 by Serhiy Storchaka (4kir4) in branch 'master':
bpo-28876: bool of large range raises OverflowError (#699)
e46fb86