[ python-Bugs-1616726 ] Vague description of generator close() method

SourceForge.net noreply at sourceforge.net
Fri Dec 15 22:09:29 CET 2006


Bugs item #1616726, was opened at 2006-12-15 13:09
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1616726&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Documentation
Group: Python 2.5
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Lenard Lindstrom (kermode)
Assigned to: Nobody/Anonymous (nobody)
Summary: Vague description of generator close() method

Initial Comment:
In section 7 of "What's New in Python 2.5" the
subsection on the close() generator method states:

    close() raises a new GeneratorExit exception 
    inside the generator to terminate the iteration.
    On receiving this exception, the generator's code
    must either raise GeneratorExit or StopIteration;
    catching the exception and doing anything else is
    illegal and will trigger a RuntimeError. 

This suggests that if a generator raises a new exception that is neither a GeneratorExit nor 
StopIteration a RuntimeError is raised. But this
is not the case according to Part 4 of PEP 342's
"Specification Summary":

    If the generator raises any other exception,
    it is propagated to the caller.

The Python 2.5 interpreter is consistent with PEP 342:


Python 2.5 (r25:51908, Sep 19 2006, 09:52:17)
 [MSC v.1310 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for
 more information.
>>> def raise_wrong_exception():
...     try:
...         yield 1
...         yield 2
...     except GeneratorExit:
...         raise TypeError("Where is the RuntimeError?")
...
>>> i=raise_wrong_exception()
>>> i.next()
1
>>> i.close()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 6, in raise_wrong_exception
TypeError: Where is the RuntimeError?


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1616726&group_id=5470


More information about the Python-bugs-list mailing list