Author PeterJCLaw
Recipients PeterJCLaw, docs@python
Date 2020-06-28.12:27:34
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1593347254.67.0.116081162021.issue41147@roundup.psfhosted.org>
In-reply-to
Content
In `contextlib`, `_RedirectStream` (the class behind `redirect_stdout` and `redirect_stderr`) returns the current stream target as its context variable, which allows code like this:

``` python
with redirect_stdout(io.StringIO()) as buffer:
    do_stuff()

use(buffer.getvalue())
```

where you capture the redirected stream without a separate line to declare the variable.

This isn't documented (See https://docs.python.org/3/library/contextlib.html#contextlib.redirect_stdout), yet is potentially useful.

Unless there's a reason that this isn't documented, I propose that the documentation be modified to include it.

Aside: After initially reporting this against the typeshed (https://github.com/python/typeshed/issues/4283) I'm also working on a PR to the typeshed to include this there.
History
Date User Action Args
2020-06-28 12:27:34PeterJCLawsetrecipients: + PeterJCLaw, docs@python
2020-06-28 12:27:34PeterJCLawsetmessageid: <1593347254.67.0.116081162021.issue41147@roundup.psfhosted.org>
2020-06-28 12:27:34PeterJCLawlinkissue41147 messages
2020-06-28 12:27:34PeterJCLawcreate