Do not let the GC close a borrowed stdout#3533
Conversation
|
I realized there's already |
|
There also seems to be way too many context managers and levels of indirection for the pager machinery at this point. I'm not sure how we got here, but I'd sure love to refactor and simplify it somehow. |
TIL. Let me play a bit with |
stdout
Seems to do the trick! Thanks for the hint! :) |
This part of Click is insane. The only thing that gives me confidence is the amount of collected cases from users that we transformed into unittests. |
Complete the "I/O operation on closed file" fix from pallets#3482, and definitely addresses pallets#3449.
72c07e8 to
8b6441f
Compare
|
I squashed the commits, this is ready to be reviewed. I'll go down the pager rabbit hole in other PRs. |
Complete the partial fix proposed in #3482 for #3449.
This PR reproduce the case highlighted in #3449 where a stream that is not managed by the pager machinery is closed by it unconditionally.
As extra bonuses:
_SkipClosewithutils.KeepOpenFileKeepOpenFileelif isinstance(stream, t.BinaryIO)branch as non-buffered text streams can be yielded as-isThis is a follow up of #3482 which is a follow up of #3405 which is a follow up of #1572.
CC @ChrisPappalardo @AndreasBackx @craigds