[Cython] Recent bugs in generators

Vitja Makarov vitja.makarov at gmail.com
Sun Apr 17 17:57:28 CEST 2011


Hi!

1. Lambda-generator:

Previous implementation was inspired by Python2.6:
>>> list((lambda:((yield 1), (yield 2)))())
[1, 2, (None, None)]

things changed in python2.7:
>>> list((lambda:((yield 1), (yield 2)))())
[1, 2]

2. GeneratorExit is initialized to StopIteration when running
generators_py doctests

This is strange behaviour of doctest module, try this:
x = __builtins__
def foo():
    """
    >>> type(x)
    <type 'module'>
    """

3. check_yield_in_exception()

Cython calls __Pyx_ExceptionReset when except block is done, so when
yield is there no exception reset is called.

I'm not sure how to fix this.

import sys

def foo():
    """
    >>> list(foo())
    [<type 'exceptions.ValueError'>, None]
    """
    try:
        raise ValueError
    except ValueError:
        yield sys.exc_info()[0]
        yield sys.exc_info()[0] # exc_info is lost here


Here is quick fix for 1 and 2 https://github.com/cython/cython/pull/25

-- 
vitja.


More information about the cython-devel mailing list