Message238683
so let's look at this step-by-step (and I hope I fully understood this myself):
- calling fileobj.__iter__ creates a generator because the method uses yield from
- that generator does not get assigned to any reference so it will be garbage-collected
- when the generator is garbage-collected, the subgenerator specified to the rigth of the yield from is finalized (that is PEP380-mandated behavior) and, in this case, that is iter(self.file)
- for an io module-based fileobject, iter(f) is f and finalizing it means that its close method will be called
So this is not about the file object getting garbage-collected, it is about it getting closed.
Since PEP380 explicitly mentions that problem with yield from and a shared subiterator, I don't think you can call it a bug, but I think it is very problematic behavior as illustrated by this issue because client code is supposed to know whether a particular generator uses yield from or not. |
|
Date |
User |
Action |
Args |
2015-03-20 14:38:16 | wolma | set | recipients:
+ wolma, georg.brandl, paul.moore, ncoghlan, vstinner, ethan.furman, python-dev, serhiy.storchaka, bkabrda, sYnfo |
2015-03-20 14:38:16 | wolma | set | messageid: <1426862296.08.0.221969878889.issue23700@psf.upfronthosting.co.za> |
2015-03-20 14:38:16 | wolma | link | issue23700 messages |
2015-03-20 14:38:15 | wolma | create | |
|