This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Vague description of generator close() method
Type: Stage:
Components: Documentation Versions: Python 2.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: akuchling Nosy List: akuchling, kermode
Priority: normal Keywords:

Created on 2006-12-15 21:09 by kermode, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg30820 - (view) Author: Lenard Lindstrom (kermode) Date: 2006-12-15 21:09
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?
msg30821 - (view) Author: A.M. Kuchling (akuchling) * (Python committer) Date: 2006-12-18 17:30
You're right; thanks for pointing out the error.  Corrected in rev. 53051.
History
Date User Action Args
2022-04-11 14:56:21adminsetgithub: 44343
2006-12-15 21:09:29kermodecreate