On Wed, Jul 21, 2010 at 7:20 AM, Nick Coghlan <ncoghlan@gmail.com> wrote:
On Wed, Jul 21, 2010 at 12:56 PM, Chris Rebert <pyideas@rebertia.com> wrote:
On Tue, Jul 20, 2010 at 3:13 PM, Nick Coghlan <ncoghlan@gmail.com> wrote:
On Wed, Jul 21, 2010 at 6:13 AM, Alex Light <scialexlight@gmail.com> wrote:
i would use as because this whole where clause acts very similarly to a context manager in that it sets a variable to a value for a small block
No, the idea is for the indented suite to be a perfectly normal suite of Python code. We want to be able to define functions, classes, etc in there. Inventing a new mini-language specifically for these clauses would be a bad idea (and make them unnecessarily hard to understand) <snip> Did you not read Nick's reply yet when you wrote this, or...?
Alex actually has a reasonable point here: break, continue, yield and return actually don't make sense in the top-level of the given clause (since it is conceptually all one statement).
For break and continue, they will naturally give a SyntaxError with the proposed implementation (for "'break' outside loop" or "'continue' not properly in loop", just to be randomly inconsistent).
yield and return (at the level of the given clause itself) will need to be disallowed explicitly by the compiler (similar to the "'return' outside function" and "'yield' outside function" errors you get if you attempt to use these keywords in a class or module scope).
I'm -sys.maxint on the PEP for a many reasons. 1) I don't want to have to explain this to people. "It's just like regular python but you can't read it top-to-bottom and you can't include control flow statements." 2a) No control flow statements in the block means if you need to augment the code to do a return/break/continue/yield you then have to refactor so everything in the "given:" block gets moved to the top and a 1-line change becomes a 10 line diff. 2b) Allowing control flow statements in the block would be even more confusing. 2c) Is this legal? x = b given: b = 0 for item in range(100): b += item if b > 10: break 3) I really don't want to have to explain to people why that is, or isn't valid. 4) decorators and "with" blocks read top-to-bottom even if they change the emphasis. This doesn't. 5) There are no compelling use cases. The two examples in the PEP are toys. -Jack