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 wolma
Recipients bkabrda, ethan.furman, georg.brandl, ncoghlan, paul.moore, python-dev, sYnfo, serhiy.storchaka, vstinner, wolma
Date 2015-03-20.14:38:15
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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:16wolmasetrecipients: + wolma, georg.brandl, paul.moore, ncoghlan, vstinner, ethan.furman, python-dev, serhiy.storchaka, bkabrda, sYnfo
2015-03-20 14:38:16wolmasetmessageid: <>
2015-03-20 14:38:16wolmalinkissue23700 messages
2015-03-20 14:38:15wolmacreate