Path: csiph.com!news.mixmin.net!feeder1.xsusenet.com!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'deprecated': 0.07; 'semantic': 0.07; 'backwards': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'unexpected': 0.09; 'python': 0.10; 'explicitly': 0.15; 'modification': 0.15; 'variables': 0.15; '3.0,': 0.16; 'dictionaries': 0.16; 'displays.': 0.16; 'expressions,': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'scope.': 0.16; 'subject:class': 0.16; 'url:whatsnew': 0.16; 'wrote:': 0.16; 'documented': 0.18; 'variable': 0.18; 'sets': 0.23; 'header:User- Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'equivalent': 0.27; 'separate': 0.27; '3.0': 0.27; 'moved': 0.27; 'then.': 0.27; 'behaviour': 0.29; 'dictionary': 0.29; 'pep': 0.29; 'sentence': 0.29; 'url:peps': 0.29; "i'm": 0.30; 'help,': 0.32; 'problem': 0.33; 'url:python': 0.33; 'common': 0.33; 'definition': 0.34; 'lists': 0.34; 'list': 0.34; 'could': 0.35; 'clear': 0.35; 'displays': 0.35; 'url:dev': 0.35; 'but': 0.36; 'url:org': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'thanks': 0.37; 'received:org': 0.37; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'more': 0.63; 'great': 0.63; 'between': 0.65; 'url:4': 0.70; 'answer.': 0.72; 'leak.': 0.84; 'otten': 0.84; 'leak': 0.91; 'url:reference': 0.91; 'improvement': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: Ensure unwanted names removed in class definition Date: Fri, 14 Aug 2015 08:37:30 +0200 Organization: None References: <85fv3oj2y6.fsf@benfinney.id.au> <85a8twi0j7.fsf@benfinney.id.au> <85y4hfhgh5.fsf@benfinney.id.au> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p57bd8380.dip0.t-ipconnect.de User-Agent: KNode/4.13.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 53 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1439534270 news.xs4all.nl 2959 [2001:888:2000:d::a6]:49103 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:95372 Ben Finney wrote: > Peter Otten <__peter__@web.de> writes: > >> Ben Finney wrote: >> >> > Peter Otten <__peter__@web.de> writes: >> > >> > That's an unexpected inconsistency between list comprehensions >> > versus generator expressions, then. Is that documented explicitly in >> > the Python 2 documentation? >> >> https://docs.python.org/2.4/whatsnew/node4.html > > Or > . > > Also in the PEP that introduces generator expressions, PEP 289: > > List comprehensions also "leak" their loop variable into the > surrounding scope. This will also change in Python 3.0, so that the > semantic definition of a list comprehension in Python 3.0 will be > equivalent to list(). > > > > Thanks for seeking the answer. Can you describe an improvement to > > that makes clear this unexpected, deprecated behaviour which is only in > Python 2? > A sentence like that in the PEP would help, but I think the main problem is that list comprehensions and lists are subsumed under list displays. >From a user perspective [f(x) for x in y] has more in common with {x: f(x) for x in y} than with [x, y, z]. I think it would be great if list comprehensions could be moved in a separate paragraph or into 5.2.5 Displays for [lists,] sets and dictionaries with a note For backwards compatibility list comprehensions leak their loop variables into the surrounding scope. Set and dictionary displays do not leak. I don't know if such a modification is feasible; I'm definitely no "language lawyer".