From 493eb8f711319d350ca9678d10ff5c88bf5346cb Mon Sep 17 00:00:00 2001 From: John Merkel Date: Mon, 11 May 2026 17:37:06 -0700 Subject: [PATCH 1/4] Fully silence potential `hash -r` error --- Lib/venv/scripts/common/activate | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/venv/scripts/common/activate b/Lib/venv/scripts/common/activate index 70673a265d41f8..dbd3ffe6388ffb 100644 --- a/Lib/venv/scripts/common/activate +++ b/Lib/venv/scripts/common/activate @@ -73,4 +73,4 @@ fi # Call hash to forget past commands. Without forgetting # past commands the $PATH changes we made may not be respected -hash -r 2> /dev/null +hash -r 2> /dev/null || true From 0edef6d3d7fbd5827b5ac127543bde09ae52d9f2 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Tue, 12 May 2026 06:24:56 +0000 Subject: [PATCH 2/4] =?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 --- .../next/Library/2026-05-12-06-24-54.gh-issue-149701.8v9RTm.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2026-05-12-06-24-54.gh-issue-149701.8v9RTm.rst diff --git a/Misc/NEWS.d/next/Library/2026-05-12-06-24-54.gh-issue-149701.8v9RTm.rst b/Misc/NEWS.d/next/Library/2026-05-12-06-24-54.gh-issue-149701.8v9RTm.rst new file mode 100644 index 00000000000000..676d788cbce62a --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-05-12-06-24-54.gh-issue-149701.8v9RTm.rst @@ -0,0 +1 @@ +Fix bad return code from Lib/venv/bin/activate if hashing is disabled From 91f660b879ba7689586c81499e6275042640db68 Mon Sep 17 00:00:00 2001 From: John Merkel Date: Tue, 12 May 2026 12:34:53 -0700 Subject: [PATCH 3/4] Added regression test --- Lib/test/test_venv.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py index 78461abcd69f33..a42787f261bfe8 100644 --- a/Lib/test/test_venv.py +++ b/Lib/test/test_venv.py @@ -656,6 +656,26 @@ def test_deactivate_with_strict_bash_opts(self): self.assertEqual(out, "".encode()) self.assertEqual(err, "".encode()) + # gh-149701: Test exit code is zero even when hashing is disabled + @unittest.skipIf(os.name == 'nt', 'not relevant on Windows') + def test_deactivate_with_strict_bash_opts_and_hashing_disabled(self): + bash = shutil.which("bash") + if bash is None: + self.skipTest("bash required for this test") + rmtree(self.env_dir) + builder = venv.EnvBuilder(clear=True) + builder.create(self.env_dir) + activate = os.path.join(self.env_dir, self.bindir, "activate") + test_script = os.path.join(self.env_dir, "test_hash_disabled.sh") + with open(test_script, "w") as f: + f.write("set -euo pipefail\n" + "set +h\n" # disable hashing + f"source {activate}\n" + "deactivate") + out, err = check_output([bash, test_script]) + self.assertEqual(out, "".encode()) + self.assertEqual(err, "".encode()) + @unittest.skipUnless(sys.platform == 'darwin', 'only relevant on macOS') def test_macos_env(self): From 9230ae5c55ce27171b01a9ec5714d3cbcd73207f Mon Sep 17 00:00:00 2001 From: John Merkel Date: Tue, 12 May 2026 12:42:27 -0700 Subject: [PATCH 4/4] Silence potential `hash -r` error in `deactivate` --- Lib/venv/scripts/common/activate | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/venv/scripts/common/activate b/Lib/venv/scripts/common/activate index dbd3ffe6388ffb..241a8650bda33a 100644 --- a/Lib/venv/scripts/common/activate +++ b/Lib/venv/scripts/common/activate @@ -17,7 +17,7 @@ deactivate () { # Call hash to forget past locations. Without forgetting # past locations the $PATH changes we made may not be respected. # See "man bash" for more details. hash is usually a builtin of your shell - hash -r 2> /dev/null + hash -r 2> /dev/null || true if [ -n "${_OLD_VIRTUAL_PS1:-}" ] ; then PS1="${_OLD_VIRTUAL_PS1:-}"