mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
gh-126618: fix repr(itertools.count(sys.maxsize)) (#127048)
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
This commit is contained in:
parent
c112de1da2
commit
930ba0ce60
3 changed files with 28 additions and 6 deletions
|
@ -3235,7 +3235,7 @@ typedef struct {
|
|||
|
||||
fast_mode: when cnt an integer < PY_SSIZE_T_MAX and no step is specified.
|
||||
|
||||
assert(cnt != PY_SSIZE_T_MAX && long_cnt == NULL && long_step==PyLong(1));
|
||||
assert(long_cnt == NULL && long_step==PyLong(1));
|
||||
Advances with: cnt += 1
|
||||
When count hits PY_SSIZE_T_MAX, switch to slow_mode.
|
||||
|
||||
|
@ -3291,9 +3291,6 @@ itertools_count_impl(PyTypeObject *type, PyObject *long_cnt,
|
|||
PyErr_Clear();
|
||||
fast_mode = 0;
|
||||
}
|
||||
else if (cnt == PY_SSIZE_T_MAX) {
|
||||
fast_mode = 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
cnt = 0;
|
||||
|
@ -3325,7 +3322,7 @@ itertools_count_impl(PyTypeObject *type, PyObject *long_cnt,
|
|||
else
|
||||
cnt = PY_SSIZE_T_MAX;
|
||||
|
||||
assert((cnt != PY_SSIZE_T_MAX && long_cnt == NULL && fast_mode) ||
|
||||
assert((long_cnt == NULL && fast_mode) ||
|
||||
(cnt == PY_SSIZE_T_MAX && long_cnt != NULL && !fast_mode));
|
||||
assert(!fast_mode ||
|
||||
(PyLong_Check(long_step) && PyLong_AS_LONG(long_step) == 1));
|
||||
|
@ -3418,7 +3415,7 @@ count_next(countobject *lz)
|
|||
static PyObject *
|
||||
count_repr(countobject *lz)
|
||||
{
|
||||
if (lz->cnt != PY_SSIZE_T_MAX)
|
||||
if (lz->long_cnt == NULL)
|
||||
return PyUnicode_FromFormat("%s(%zd)",
|
||||
_PyType_Name(Py_TYPE(lz)), lz->cnt);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue