diff options
author | Raymond Hettinger <python@rcn.com> | 2009-01-08 05:20:19 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2009-01-08 05:20:19 (GMT) |
commit | 825758c50b3c8006db16c1b8627e417db32a1d23 (patch) | |
tree | 119e0903dc54f33806e5eae267ee52328b6d027c /Modules | |
parent | cd610ae7f21db5782b76d562002b27959d7e87b7 (diff) | |
download | cpython-825758c50b3c8006db16c1b8627e417db32a1d23.zip cpython-825758c50b3c8006db16c1b8627e417db32a1d23.tar.gz cpython-825758c50b3c8006db16c1b8627e417db32a1d23.tar.bz2 |
- Issue 4816: itertools.combinations() and itertools.product were raising
a ValueError for values of *r* larger than the input iterable. They now
correctly return an empty iterator.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/itertoolsmodule.c | 12 |
1 files changed, 2 insertions, 10 deletions
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c index 18a1229..5875d10 100644 --- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -2059,10 +2059,6 @@ combinations_new(PyTypeObject *type, PyObject *args, PyObject *kwds) PyErr_SetString(PyExc_ValueError, "r must be non-negative"); goto error; } - if (r > n) { - PyErr_SetString(PyExc_ValueError, "r cannot be bigger than the iterable"); - goto error; - } indices = PyMem_Malloc(r * sizeof(Py_ssize_t)); if (indices == NULL) { @@ -2082,7 +2078,7 @@ combinations_new(PyTypeObject *type, PyObject *args, PyObject *kwds) co->indices = indices; co->result = NULL; co->r = r; - co->stopped = 0; + co->stopped = r > n ? 1 : 0; return (PyObject *)co; @@ -2318,10 +2314,6 @@ permutations_new(PyTypeObject *type, PyObject *args, PyObject *kwds) PyErr_SetString(PyExc_ValueError, "r must be non-negative"); goto error; } - if (r > n) { - PyErr_SetString(PyExc_ValueError, "r cannot be bigger than the iterable"); - goto error; - } indices = PyMem_Malloc(n * sizeof(Py_ssize_t)); cycles = PyMem_Malloc(r * sizeof(Py_ssize_t)); @@ -2345,7 +2337,7 @@ permutations_new(PyTypeObject *type, PyObject *args, PyObject *kwds) po->cycles = cycles; po->result = NULL; po->r = r; - po->stopped = 0; + po->stopped = r > n ? 1 : 0; return (PyObject *)po; |