On May 25, 2010, at 1:15 AM, Stefan Behnel wrote: > Stefan Behnel, 25.05.2010 09:07: >> Robert Bradshaw, 24.05.2010 20:44: >>> On May 24, 2010, at 11:13 AM, Stefan Behnel wrote: >>>> Can we at least emit a warning that there is a better way to do it, >>>> when we find that a comprehension is based on a cdef-ed variable? >>> >>> Yes, we should probably omit a warning. Another idea to throw out >>> there is that we could borrow the type from the containing scope, if >>> any, just not alter its value. Thinking of it, I've actually used >>> this >>> a lot: >>> >>> cdef int i >>> L = [foo[i] for i in range(...)] >>> >>> or other more complicated expressions. -1 to changing it and making >>> all such loops slow Python loops. >> >> I agree that that's a major concern. Taking the declaration from the >> surrounding scope may actually be the simplest way to fix it, >> especially >> since this will also work in pure mode. > > The behaviour I now implemented in cython-closures is this: > > 1) all comprehensions continue to leak loop variables > 2) genexps have their own scope and do not leak variables > 3) if the outer scope of a genexp has a type declaration for a > variable > defined in the inner scope, the type is inherited by the inner scope > > This keeps backwards compatibility with existing code like above, > and makes > it easy to declare the type of a loop variable for generator > expressions in > both Cython code and pure Python code.
Sounds good. - Robert _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
