Skip to content

Commit 4ff6290

Browse files
committed
gh-000: Add missing stacklevel to warnings.warn() in subprocess.Popen
Both warnings.warn() calls in Popen.__init__ (one on POSIX for pass_fds overriding close_fds, one on Windows for handle_list overriding close_fds) were missing stacklevel=2. Without stacklevel=2, the warning points to an internal line in subprocess.py rather than the caller's Popen() invocation, making it harder for users to locate the source of the warning in their own code.
1 parent ba1e1c1 commit 4ff6290

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Lib/subprocess.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ def __init__(self, args, bufsize=-1, executable=None,
912912
else:
913913
# POSIX
914914
if pass_fds and not close_fds:
915-
warnings.warn("pass_fds overriding close_fds.", RuntimeWarning)
915+
warnings.warn("pass_fds overriding close_fds.", RuntimeWarning, stacklevel=2)
916916
close_fds = True
917917
if startupinfo is not None:
918918
raise ValueError("startupinfo is only supported on Windows "
@@ -1567,7 +1567,8 @@ def _execute_child(self, args, executable, preexec_fn, close_fds,
15671567
if handle_list:
15681568
if not close_fds:
15691569
warnings.warn("startupinfo.lpAttributeList['handle_list'] "
1570-
"overriding close_fds", RuntimeWarning)
1570+
"overriding close_fds", RuntimeWarning,
1571+
stacklevel=2)
15711572

15721573
# When using the handle_list we always request to inherit
15731574
# handles but the only handles that will be inherited are

0 commit comments

Comments
 (0)