Commit 1edfca8d authored by Vitja Makarov's avatar Vitja Makarov

Backport generators to python < 2.5, use StopIteration instead of GeneratorExit.

parent c0643507
...@@ -8360,7 +8360,11 @@ static PyObject *__Pyx_Generator_Close(PyObject *self) ...@@ -8360,7 +8360,11 @@ static PyObject *__Pyx_Generator_Close(PyObject *self)
{ {
struct __pyx_Generator_object *generator = (struct __pyx_Generator_object *) self; struct __pyx_Generator_object *generator = (struct __pyx_Generator_object *) self;
PyObject *retval; PyObject *retval;
#if PY_VERSION_HEX < 0x02050000
PyErr_SetNone(PyExc_StopIteration);
#else
PyErr_SetNone(PyExc_GeneratorExit); PyErr_SetNone(PyExc_GeneratorExit);
#endif
retval = __Pyx_Generator_SendEx(generator, NULL); retval = __Pyx_Generator_SendEx(generator, NULL);
if (retval) { if (retval) {
Py_DECREF(retval); Py_DECREF(retval);
...@@ -8368,8 +8372,12 @@ static PyObject *__Pyx_Generator_Close(PyObject *self) ...@@ -8368,8 +8372,12 @@ static PyObject *__Pyx_Generator_Close(PyObject *self)
"generator ignored GeneratorExit"); "generator ignored GeneratorExit");
return NULL; return NULL;
} }
#if PY_VERSION_HEX < 0x02050000
if (PyErr_ExceptionMatches(PyExc_StopIteration))
#else
if (PyErr_ExceptionMatches(PyExc_StopIteration) if (PyErr_ExceptionMatches(PyExc_StopIteration)
|| PyErr_ExceptionMatches(PyExc_GeneratorExit)) || PyErr_ExceptionMatches(PyExc_GeneratorExit))
#endif
{ {
PyErr_Clear(); /* ignore these errors */ PyErr_Clear(); /* ignore these errors */
Py_INCREF(Py_None); Py_INCREF(Py_None);
......
...@@ -62,7 +62,6 @@ VER_DEP_MODULES = { ...@@ -62,7 +62,6 @@ VER_DEP_MODULES = {
]), ]),
(2,5) : (operator.lt, lambda x: x in ['run.any', (2,5) : (operator.lt, lambda x: x in ['run.any',
'run.all', 'run.all',
'run.generators',
]), ]),
(2,6) : (operator.lt, lambda x: x in ['run.print_function', (2,6) : (operator.lt, lambda x: x in ['run.print_function',
'run.cython3', 'run.cython3',
......
...@@ -5,6 +5,11 @@ except ImportError: ...@@ -5,6 +5,11 @@ except ImportError:
def next(it): def next(it):
return it.next() return it.next()
if hasattr(__builtins__, 'GeneratorExit'):
GeneratorExit = __builtins__.GeneratorExit
else: # < 2.5
GeneratorExit = StopIteration
def very_simple(): def very_simple():
""" """
>>> x = very_simple() >>> x = very_simple()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment