-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bpo-41147 Document that redirect_stdout provides the new stream as context var #21199
bpo-41147 Document that redirect_stdout provides the new stream as context var #21199
Conversation
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA). CLA MissingOur records indicate the following people have not signed the CLA: For legal reasons we need all the people listed to sign the CLA before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. If you have recently signed the CLA, please wait at least one business day You can check yourself to see if the CLA has been received. Thanks again for the contribution, we look forward to reviewing it! |
"context variable" is not a clear term in light of the `contextvars` module.
@JelleZijlstra would you have time to have another look at this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good apart from this typo. I don't have the permissions to merge this PR though.
@PeterJCLaw, please sign the CLA. Thank you! |
Most odd. I signed it back in June when I opened this PR (I have a confirmation email to that effect), though the CLA now shows that I've not signed one. Anyway, I've signed another. The only difference I can see is that the first one I did used the email address I have on bugs.python.org; this time I've used the same email address as I commit with. |
@csabella is there anything I can do to help progress this? |
Doc/library/contextlib.rst
Outdated
@@ -236,10 +236,11 @@ Functions and classes provided: | |||
|
|||
For example, the output of :func:`help` normally is sent to *sys.stdout*. | |||
You can capture that output in a string by redirecting the output to an | |||
:class:`io.StringIO` object:: | |||
:class:`io.StringIO` object. For convenience, the new stream is returned |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not necessarily a new stream.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hrm, I was meaning new in the sense of now being the one used for stdout
. Perhaps "replacement" would be clearer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I missed your reaction earlier in the year. I've now made this change (in 14d7692).
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
@bedevere-bot I have made the requested changes; please review again. |
Thanks for making the requested changes! @iritkatriel: please review the changes made to this pull request. |
@rhettinger Are you happy for this to be a documented feature? |
This is actually covered by a unit test: test_enter_result_is_target cpython/Lib/test/test_contextlib.py Line 960 in 14d7692
|
Thanks @PeterJCLaw for the PR, and @iritkatriel for merging it 🌮🎉.. I'm working now to backport this PR to: 3.10, 3.9. |
… as context var (pythonGH-21199) (cherry picked from commit 46db39d) Co-authored-by: Peter Law <[email protected]>
GH-26379 is a backport of this pull request to the 3.10 branch. |
… as context var (pythonGH-21199) (cherry picked from commit 46db39d) Co-authored-by: Peter Law <[email protected]>
GH-26380 is a backport of this pull request to the 3.9 branch. |
… as context var (GH-21199) (GH-26379) (cherry picked from commit 46db39d) Co-authored-by: Peter Law <[email protected]>
… as context var (GH-21199) (GH-26380) (cherry picked from commit 46db39d) Co-authored-by: Peter Law <[email protected]>
In
contextlib
,_RedirectStream
(the class behindredirect_stdout
andredirect_stderr
) returns the current stream target as its context variable, which allows code like this:where you capture the redirected stream without a separate line to declare the variable.
This PR intends to document this functionality.
https://bugs.python.org/issue41147
See also python/typeshed#4283