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 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.