[Python-Dev] PEP Idea: Syntactic sugar for StopIteration.

2007-12-08 Thread Manuel Alejandro Cerón Estrada
Hello Python developers. This is my first post on the list. I have been using Python for a while and I have been thinking about one feature I would like to see integrated into the language. I thought it could be a good topic for a PEP, so I decided to join the list and write about it. First

Re: [Python-Dev] PEP Idea: Syntactic sugar for StopIteration.

2007-12-08 Thread Raymond Hettinger
Note that 'yield break' resembles the 'break' statement used in loops, while 'StopIteration' doesn't. 'yield break' is more orthogonal to the rest of the language. I am looking forward to seeing your opinions. -1 I do not find the meaning to be transparent and the proposal adds new syntax

Re: [Python-Dev] PEP Idea: Syntactic sugar for StopIteration.

2007-12-08 Thread Terry Reedy
I would prefer plain 'yield' to 'yield break' as a synonym for 'raise StopIteration'. But the raise stands out better visually as an exit point. The point about the raise not being explicitly caught is not valid since any generator could be used in the following code g = some_gen try:

Re: [Python-Dev] PEP Idea: Syntactic sugar for StopIteration.

2007-12-08 Thread Manuel Alejandro Cerón Estrada
2007/12/8, Raymond Hettinger [EMAIL PROTECTED]: ...the proposal adds new syntax without adding functionality. That is indeed the definition of syntactic sugar [1]. Python is full of that, for example the import statement. 2007/12/8, Paul Svensson [EMAIL PROTECTED]: What is the problem that is

Re: [Python-Dev] PEP Idea: Syntactic sugar for StopIteration.

2007-12-08 Thread Raymond Hettinger
In your example, why do you raise StopIteration instead just writing return? - Original Message - From: Manuel Alejandro Cerón Estrada [EMAIL PROTECTED] Take a look at this example: def lines(): for line in my_file: if some_error(): raise StopIteration()

Re: [Python-Dev] PEP Idea: Syntactic sugar for StopIteration.

2007-12-08 Thread Steve Holden
Manuel Alejandro Cerón Estrada wrote: 2007/12/8, Raymond Hettinger [EMAIL PROTECTED]: ...the proposal adds new syntax without adding functionality. That is indeed the definition of syntactic sugar [1]. Python is full of that, for example the import statement. 2007/12/8, Paul Svensson

Re: [Python-Dev] PEP Idea: Syntactic sugar for StopIteration.

2007-12-08 Thread Manuel Alejandro Cerón Estrada
2007/12/8, Raymond Hettinger [EMAIL PROTECTED]: In your example, why do you raise StopIteration instead just writing return? In the example would be better to use 'return' rather than 'raise StopIteration'. In most cases 'return' will have the same behavior than 'raise StopIteration', but not

Re: [Python-Dev] PEP Idea: Syntactic sugar for StopIteration.

2007-12-08 Thread Greg Ewing
Terry Reedy wrote: I would prefer plain 'yield' to 'yield break' as a synonym for 'raise StopIteration'. Don't we already have a plain yield these days meaning something else? -- Greg ___ Python-Dev mailing list Python-Dev@python.org

Re: [Python-Dev] PEP Idea: Syntactic sugar for StopIteration.

2007-12-08 Thread Raymond Hettinger
2007/12/8, Raymond Hettinger [EMAIL PROTECTED]: ...the proposal adds new syntax without adding functionality. That is indeed the definition of syntactic sugar [1]. Python is full of that, for example the import statement. . . . The real problem is that raising StopIteration is not

Re: [Python-Dev] PEP Idea: Syntactic sugar for StopIteration.

2007-12-08 Thread Greg Ewing
Manuel Alejandro Cerón Estrada wrote: The real problem is that raising StopIteration is not orthogonal. This is a non-problem as far as I can see. In a generator, the way to stop the iteration is simply to return. In a non-generator iterator, you're still going to have to raise StopIteration.

Re: [Python-Dev] PEP Idea: Syntactic sugar for StopIteration.

2007-12-08 Thread Phillip J. Eby
At 12:30 PM 12/9/2007 +1300, Greg Ewing wrote: Terry Reedy wrote: I would prefer plain 'yield' to 'yield break' as a synonym for 'raise StopIteration'. Don't we already have a plain yield these days meaning something else? Yes. It's equivalent to 'yield None'.

Re: [Python-Dev] PEP Idea: Syntactic sugar for StopIteration.

2007-12-08 Thread Greg Ewing
Manuel Alejandro Cerón Estrada wrote: Acording to PEP 255: Note that return isn't always equivalent to raising StopIteration: the difference lies in how enclosing try/except constructs are treated. All that means is that def g(): try: if 0: yield

Re: [Python-Dev] PEP Idea: Syntactic sugar for StopIteration.

2007-12-08 Thread Manuel Alejandro Cerón Estrada
2007/12/8, Greg Ewing [EMAIL PROTECTED]: I would put it the other way around -- the problem that 'yield break' is meant to solve is already solved by 'return'. So there's no need for change. I have been re-thinking the problem and this is true. The only exception would be empty generators, but

Re: [Python-Dev] PEP Idea: Syntactic sugar for StopIteration.

2007-12-08 Thread Phillip J. Eby
At 07:55 PM 12/8/2007 -0500, Manuel Alejandro Cerón Estrada wrote: 2007/12/8, Greg Ewing [EMAIL PROTECTED]: I would put it the other way around -- the problem that 'yield break' is meant to solve is already solved by 'return'. So there's no need for change. I have been re-thinking the

Re: [Python-Dev] PEP Idea: Syntactic sugar for StopIteration.

2007-12-08 Thread Tristan Seligmann
* Phillip J. Eby [EMAIL PROTECTED] [2007-12-08 20:19:29 -0500]: At 07:55 PM 12/8/2007 -0500, Manuel Alejandro Cerón Estrada wrote: 2007/12/8, Greg Ewing [EMAIL PROTECTED]: I would put it the other way around -- the problem that 'yield break' is meant to solve is already solved by