Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vague description of generator close() method #44343

Closed
kermode mannequin opened this issue Dec 15, 2006 · 2 comments
Closed

Vague description of generator close() method #44343

kermode mannequin opened this issue Dec 15, 2006 · 2 comments
Assignees
Labels
docs Documentation in the Doc dir

Comments

@kermode
Copy link
Mannequin

kermode mannequin commented Dec 15, 2006

BPO 1616726
Nosy @akuchling

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/akuchling'
closed_at = <Date 2006-12-18.17:30:29.000>
created_at = <Date 2006-12-15.21:09:29.000>
labels = ['docs']
title = 'Vague description of generator close() method'
updated_at = <Date 2006-12-18.17:30:29.000>
user = 'https://bugs.python.org/kermode'

bugs.python.org fields:

activity = <Date 2006-12-18.17:30:29.000>
actor = 'akuchling'
assignee = 'akuchling'
closed = True
closed_date = None
closer = None
components = ['Documentation']
creation = <Date 2006-12-15.21:09:29.000>
creator = 'kermode'
dependencies = []
files = []
hgrepos = []
issue_num = 1616726
keywords = []
message_count = 2.0
messages = ['30820', '30821']
nosy_count = 2.0
nosy_names = ['akuchling', 'kermode']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue1616726'
versions = ['Python 2.5']

@kermode
Copy link
Mannequin Author

kermode mannequin commented Dec 15, 2006

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?

@kermode kermode mannequin closed this as completed Dec 15, 2006
@kermode kermode mannequin assigned akuchling Dec 15, 2006
@kermode kermode mannequin added the docs Documentation in the Doc dir label Dec 15, 2006
@kermode kermode mannequin closed this as completed Dec 15, 2006
@kermode kermode mannequin assigned akuchling Dec 15, 2006
@akuchling
Copy link
Member

You're right; thanks for pointing out the error. Corrected in rev. 53051.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir
Projects
None yet
Development

No branches or pull requests

1 participant