gh-148402: add missing stacklevel to warnings.warn() in subprocess.Popen#148668
Open
stef41 wants to merge 1 commit intopython:mainfrom
Open
gh-148402: add missing stacklevel to warnings.warn() in subprocess.Popen#148668stef41 wants to merge 1 commit intopython:mainfrom
stef41 wants to merge 1 commit intopython:mainfrom
Conversation
…ess.Popen Add stacklevel to two warnings.warn() calls in subprocess.Popen so that warnings point to the caller's code instead of subprocess internals: - POSIX: 'pass_fds overriding close_fds' in __init__: stacklevel=2 - Windows: 'handle_list overriding close_fds' in _execute_child: stacklevel=3 (_execute_child is called from __init__, adding one extra frame)
| close_fds=False, pass_fds=(fd, ))) | ||
| self.assertIn('overriding close_fds', str(context.warning)) | ||
|
|
||
| def test_pass_fds_overriding_close_fds_warning_location(self): |
Member
There was a problem hiding this comment.
2. The warning message was already tested in
test_pass_fds(line 3174:assertIn('overriding close_fds', str(context.warning))).
If the warning message was already tested, why not simply add an assertion for filename there?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add
stacklevelto twowarnings.warn()calls insubprocess.Popensothat warnings point to the caller's code instead of
subprocessinternals.Changes
__init__(POSIX)pass_fds overriding close_fdscaller → __init__ → warn_execute_child(Windows)handle_list overriding close_fdscaller → __init__ → _execute_child → warnTests
test_pass_fds_overriding_close_fds_warning_locationinPOSIXProcessTestCase: callsPopen()directly and assertscm.filename == __file__.test_close_fds_with_stdioinWin32ProcessTestCase: switched fromcheck_warningstoassertWarns, addedcm.filename == __file__assertion.Supersedes #148400 which was accidentally closed during a force push.