Issue 28019: itertools.count() falls back to fast (integer) mode when step rounds to 1 (original) (raw)

Created on 2016-09-08 12:48 by StyXman, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
fix_28019.diff StyXman,2016-09-08 14:22 review
fix_28019.diff StyXman,2016-09-08 15:08 review
itertools_count_truncated_step.patch serhiy.storchaka,2016-09-08 17:57 review
Messages (6)
msg275007 - (view) Author: Marcos Dione (StyXman) * Date: 2016-09-08 12:48
If the `step` parameter for `itertools.count()` rounds to 1 (f.i., 1.1, 1.437643, 1.99999), then it fallsback to fast (integer) mode and increases the counter by 1. Here's an example: 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
msg275016 - (view) Author: Marcos Dione (StyXman) * Date: 2016-09-08 14:22
Here's a first approach on fixing this bug. I'm not sure how to handle the case where step=1.0.
msg275025 - (view) Author: Facundo Batista (facundobatista) * (Python committer) Date: 2016-09-08 14:43
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).
msg275038 - (view) Author: Marcos Dione (StyXman) * Date: 2016-09-08 15:08
New patch following comments from SilentGhost.
msg275082 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-09-08 17:57
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.
msg275583 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-09-10 06:54
New changeset b23f963a7b45 by Serhiy Storchaka in branch '3.5': Issue #28019: itertools.count() no longer rounds non-integer step in range https://hg.python.org/cpython/rev/b23f963a7b45 New changeset 74667320778e by Serhiy Storchaka in branch '2.7': Issue #28019: Backported additional tests for itertools.count(). https://hg.python.org/cpython/rev/74667320778e New changeset 51dfab4f28e7 by Serhiy Storchaka in branch 'default': Issue #28019: itertools.count() no longer rounds non-integer step in range https://hg.python.org/cpython/rev/51dfab4f28e7
History
Date User Action Args
2022-04-11 14:58:36 admin set github: 72206
2016-09-10 07:11:34 serhiy.storchaka set status: open -> closedresolution: fixedstage: patch review -> resolved
2016-09-10 06:54:45 python-dev set nosy: + python-devmessages: +
2016-09-08 20:51:43 rhettinger set assignee: rhettinger -> serhiy.storchaka
2016-09-08 17:57:08 serhiy.storchaka set files: + itertools_count_truncated_step.patchversions: - Python 3.3, Python 3.4nosy: + serhiy.storchakamessages: + stage: commit review -> patch review
2016-09-08 16:08:23 StyXman set versions: + Python 3.3, Python 3.4
2016-09-08 15:43:00 SilentGhost set stage: patch review -> commit review
2016-09-08 15:08:25 StyXman set files: + fix_28019.diffmessages: +
2016-09-08 14:59:26 rhettinger set assignee: rhettinger
2016-09-08 14:43:21 facundobatista set nosy: + facundobatistamessages: +
2016-09-08 14:34:26 SilentGhost set stage: patch reviewversions: - Python 3.3, Python 3.4
2016-09-08 14:25:15 StyXman set versions: + Python 3.3, Python 3.4
2016-09-08 14:22:46 StyXman set files: + fix_28019.diffkeywords: + patchmessages: +
2016-09-08 12:56:03 facundobatista set versions: + Python 3.5
2016-09-08 12:51:07 serhiy.storchaka set nosy: + rhettinger
2016-09-08 12:48:32 StyXman create