Stephen Drake added the comment:
Ok, I can accept that. I think my mistake was to assume that because a
generator has a close() method, I could treat it as a lightweight wrapper for
another closeable object.
But it's better to regard a generator function that wraps an iterable as
some
New submission from Stephen Drake:
If a generator has its close() method called before any items are requested
from it, a finally block in the generator function will not be executed.
I encountered this when wrapping an open file to alter the result of iterating
over it. Using a generator