On 05/07/2010 14:12, Tim Golden wrote:
On 05/07/2010 14:06, Stefan Behnel wrote:
Hi,

I only noticed now that set/dict comprehensions were backported to 2.7
without letting the loop Variables leak into the surrounding scope. So
they now behave different from list comprehensions. Is this intentional
or just a backporting oversight?

I'm asking because we had a discussion about the 'right' semantics
several times on the Cython list, and the current behaviour is that all
comprehensions leak when compiling Py2 code and the do not leak when
compiling Py3 code. I would hate to fix that up to match 2.7 and then
see that the behaviour in Py2.7 is to be considered an accident.

Depends on your definition of "comprehension", but generator expressions
have always not leaked, so these are already different in Py2.x:

[i for i in range (10)]

list (i for i in range (10))

I had understood (without being able to put my finger on a relevant thread)
that all comprehensions were going not leak their loop variables in the
future.

Similarly my understanding was that list comprehensions leaking was an unfortunate implementation detail and that to depend on it was therefore "a bug". I don't see it as an issue that set and dict comprehensions don't leak in 2.7 (and in fact it is a good thing as it makes it harder to write code that works in 2.7 but fails in 3.x).

Michael


TJG
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/fuzzyman%40voidspace.org.uk


--
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog

READ CAREFULLY. By accepting and reading this email you agree, on behalf of 
your employer, to release me from all obligations and waivers arising from any 
and all NON-NEGOTIATED agreements, licenses, terms-of-service, shrinkwrap, 
clickwrap, browsewrap, confidentiality, non-disclosure, non-compete and 
acceptable use policies (”BOGUS AGREEMENTS”) that I have entered into with your 
employer, its partners, licensors, agents and assigns, in perpetuity, without 
prejudice to my ongoing rights and privileges. You further represent that you 
have the authority to release me from any BOGUS AGREEMENTS on behalf of your 
employer.


_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to