From 4ff629036e853a43941dc0261b3707cede55641c Mon Sep 17 00:00:00 2001 From: zach Date: Sat, 11 Apr 2026 13:15:33 -0700 Subject: [PATCH 1/2] 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. --- Lib/subprocess.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Lib/subprocess.py b/Lib/subprocess.py index 7ac2289f535b6d..f87cc790b436cd 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -912,7 +912,7 @@ def __init__(self, args, bufsize=-1, executable=None, else: # POSIX if pass_fds and not close_fds: - warnings.warn("pass_fds overriding close_fds.", RuntimeWarning) + warnings.warn("pass_fds overriding close_fds.", RuntimeWarning, stacklevel=2) close_fds = True if startupinfo is not None: raise ValueError("startupinfo is only supported on Windows " @@ -1567,7 +1567,8 @@ def _execute_child(self, args, executable, preexec_fn, close_fds, if handle_list: if not close_fds: warnings.warn("startupinfo.lpAttributeList['handle_list'] " - "overriding close_fds", RuntimeWarning) + "overriding close_fds", RuntimeWarning, + stacklevel=2) # When using the handle_list we always request to inherit # handles but the only handles that will be inherited are From bcc7284baa2298e5a035d2663f5ef28f8051412e Mon Sep 17 00:00:00 2001 From: zach Date: Sat, 11 Apr 2026 14:29:10 -0700 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Library/2026-04-11-14-28-56.gh-issue-148402.zey6m1.rst | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2026-04-11-14-28-56.gh-issue-148402.zey6m1.rst diff --git a/Misc/NEWS.d/next/Library/2026-04-11-14-28-56.gh-issue-148402.zey6m1.rst b/Misc/NEWS.d/next/Library/2026-04-11-14-28-56.gh-issue-148402.zey6m1.rst new file mode 100644 index 00000000000000..afa8e55b8bddb4 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-04-11-14-28-56.gh-issue-148402.zey6m1.rst @@ -0,0 +1,3 @@ +Add missing ``stacklevel=2`` to two :func:`warnings.warn` calls in +:class:`subprocess.Popen` so that warnings correctly point to the caller's +code instead of ``subprocess.py`` internals.