Message357467
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() |
|
Date |
User |
Action |
Args |
2019-11-26 00:29:58 | mmcewen-g | set | recipients:
+ mmcewen-g |
2019-11-26 00:29:58 | mmcewen-g | set | messageid: <1574728198.51.0.732377638731.issue38911@roundup.psfhosted.org> |
2019-11-26 00:29:58 | mmcewen-g | link | issue38911 messages |
2019-11-26 00:29:57 | mmcewen-g | create | |
|