Matt McEwen <mmce...@google.com> added the comment:

My interpretation of issue 24018 was that the Generator ABC was trying to 
follow the PEP as much as possible, so that users were able to produce a custom 
generator object and have it behave just like a builtin generator object.

I know that subclassing Generator is unusual; In my case that is a custom 
object that needs to be an iterator and also enter context managers internally. 
This seemed to me a very similar problem that the `close` machinery for 
generators was aimed to address, and subclassing generator worked really 
nicely, with one exception.

It took me some time to understand why the context managers weren't being 
exited correctly when the generator was interrupted, and it was because my 
`close` wasn't being called when the object fell out of scope, as it would have 
been if my object was a builtin generator object. Manually implementing __del__ 
fixed this.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue38911>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to