Robert Bradshaw, 24.05.2010 20:44:
> On May 24, 2010, at 11:13 AM, Stefan Behnel wrote:
>> My main concern isn't even breaking code by ripping out the loop
>> variable(s), which most code won't rely upon anyway. It's the fact
>> that the
>> behaviour will change with the -3 switch because type declarations
>> will
>> disappear from the genexpr scope. That will break code in a much more
>> subtle way, and may lead to hard to find/understand changes in
>> behaviour.
>> We can warn about it, but I always find it better to prevent non-
>> future
>> proof code from getting written as early as possible.
>
> Leaking vs. non-leaking loop variables, though I'd hope it isn't
> counted on much, can be a subtle difference too.

I've reverted the change for comprehensions, they behave as before.

BTW, there's also a related bug: the loop variable shows up in locals(), 
which it does not in CPython.


>> 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.

Stefan
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to