A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/2005-October/057113.html below:

start(), __call__() and unwind_call() methods

[Python-Dev] PEP 342 suggestion: start(), __call__() and unwind_call() methodsJames Y Knight foom at fuhm.net
Sun Oct 9 04:54:10 CEST 2005
On Oct 8, 2005, at 9:10 PM, Nick Coghlan wrote:
> So, instead of having "return" automatically map to "raise  
> StopIteration"
> inside generators, I'd like to suggest we keep it illegal to use  
> "return"
> inside a generator

Only one issue with that: it's _not currently illegal_ to use return  
inside a generator. From the view of the outsider, it currently  
effectively does currently map to "raise StopIteration". But not on  
the inside, just like you'd expect to happen. The only proposed  
change to the semantics is to also allow a value to be provided with  
the return.

>    def generator():
>       yield
>       try:
>          return
>       except StopIteration:
>          print "But we would get here!"

 >>> def generator():
...  yield 5
...  try:
...   return
...  except StopIteration:
...   print "But we would get here!"
...
 >>> x=generator()
 >>> x.next()
5
 >>> x.next()
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
StopIteration
 >>>


James

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4