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.

Author mmcewen-g
Recipients mmcewen-g
Date 2019-11-26.00:29:57
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1574728198.51.0.732377638731.issue38911@roundup.psfhosted.org>
In-reply-to
Content
The Generator ABC in the standard library lets users define objects that follow the Generator specification given in PEP342, and which can be used in the place of builtin generator objects. 

This was originally added in issue 24018

The ABC enforces that the methods `send`, `throw` and `close` are implemented, as per the spec. It doesn't enforce that `__del__` is implemented. PEP342 specifies that `__del__` be a wrapper for `close`, such that when a generator object is garbage collected `close` is called.

For a user (like me) implementing such a generator object by inheriting the Generator ABC, the resulting objects do not have `close` called when they are garbage collected. Fixing this requires manually implementing a `__del__` that calls `close`. 

Ideally from the user perspective, inheriting from Generator should be enough to guarantee that the object behaves like a generator object, provided the abstract methods are correctly implemented. This could be easily achieved by implementing `__del__` concretely in the ABC as a wrapper for `close`:

def __del__(self):
    self.close()
History
Date User Action Args
2019-11-26 00:29:58mmcewen-gsetrecipients: + mmcewen-g
2019-11-26 00:29:58mmcewen-gsetmessageid: <1574728198.51.0.732377638731.issue38911@roundup.psfhosted.org>
2019-11-26 00:29:58mmcewen-glinkissue38911 messages
2019-11-26 00:29:57mmcewen-gcreate