lambda generator - curious behavior in 2.5

Raymond Hettinger python at rcn.com
Sat Apr 21 16:32:48 EDT 2007


[Gabriel Genellina]
> This time, the ((tuple) and None) is like saying "discard the tuple and  
> return None instead", and that fires the usual StopIteration.

It looks like the offending code is in the gen_send_ex() function in
Objects/genobject.c:

	if (result == Py_None && f->f_stacktop == NULL) {
		Py_DECREF(result);
		result = NULL;
		/* Set exception if not called by gen_iternext() */
		if (arg)
			PyErr_SetNone(PyExc_StopIteration);
	}

The conditional should probably be:

	if (result 1= NULL && f->f_stacktop == NULL)

Please open a bug report on SF and assign to me.


Raymond Hettinger




More information about the Python-list mailing list