New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
itertools.count() falls back to fast (integer) mode when step rounds to 1 #72206
Comments
If the Python 3.6.0a4+ (default:ddc95a9bc2e0+, Sep 8 2016, 14:46:19)
>>> import itertools
>>> for i in itertools.count(1, step=1.5):
... print(i)
... if i > 10:
... break
1
2
3
4
5
6
7
8
9
10
11 |
Here's a first approach on fixing this bug. I'm not sure how to handle the case where step=1.0. |
I think the fix nails it; all the problem was that the "fast" mode was wrongly detected, and all the problems (counting badly, or a bad repr, etc) is a problem after setting cnt into PY_SSIZE_T_MAX. IIUC there is nothing special to do when step=1.0, as later on the original objects are used (they don't suffer a wrong cast to integer anymore). |
New patch following comments from SilentGhost. |
PyLong_AsLong() not just converts Python integer to C long, but it also converts Python float to Python integer (with the lost of the fractional part). We need to check that the value is Python integer. Here is a patch that fixes this issue and few other bugs. |
New changeset b23f963a7b45 by Serhiy Storchaka in branch '3.5': New changeset 74667320778e by Serhiy Storchaka in branch '2.7': New changeset 51dfab4f28e7 by Serhiy Storchaka in branch 'default': |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: