https://github.com/python/cpython/commit/d82cddfe66016f2b655edc353333575ea7883634
commit: d82cddfe66016f2b655edc353333575ea7883634
branch: 3.13
author: Miss Islington (bot) <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2026-07-22T04:29:50Z
summary:

[3.13] gh-154399: Fix venv activate.csh in a non-interactive shell (GH-154400) 
(GH-154410)

activate.csh saved the prompt unconditionally, but the prompt variable
only exists in interactive shells, and csh fails on an undefined
variable.
(cherry picked from commit 4448705d879ea41ea97114ef6c8215590913811a)

Co-authored-by: Serhiy Storchaka <[email protected]>
Co-authored-by: Claude Opus 4.8 <[email protected]>

files:
A Misc/NEWS.d/next/Library/2026-07-21-21-36-59.gh-issue-154399.VSa6oH.rst
M Lib/venv/scripts/posix/activate.csh

diff --git a/Lib/venv/scripts/posix/activate.csh 
b/Lib/venv/scripts/posix/activate.csh
index 2a3fa835476ab9b..7226034df0f3941 100644
--- a/Lib/venv/scripts/posix/activate.csh
+++ b/Lib/venv/scripts/posix/activate.csh
@@ -16,10 +16,12 @@ setenv PATH "$VIRTUAL_ENV/"__VENV_BIN_NAME__":$PATH"
 setenv VIRTUAL_ENV_PROMPT __VENV_PROMPT__
 
 
-set _OLD_VIRTUAL_PROMPT="$prompt"
+if ($?prompt) then
+    set _OLD_VIRTUAL_PROMPT="$prompt"
 
-if (! "$?VIRTUAL_ENV_DISABLE_PROMPT") then
-    set prompt = "("__VENV_PROMPT__") $prompt:q"
+    if (! "$?VIRTUAL_ENV_DISABLE_PROMPT") then
+        set prompt = "("__VENV_PROMPT__") $prompt:q"
+    endif
 endif
 
 alias pydoc python -m pydoc
diff --git 
a/Misc/NEWS.d/next/Library/2026-07-21-21-36-59.gh-issue-154399.VSa6oH.rst 
b/Misc/NEWS.d/next/Library/2026-07-21-21-36-59.gh-issue-154399.VSa6oH.rst
new file mode 100644
index 000000000000000..598dd26694c73e4
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2026-07-21-21-36-59.gh-issue-154399.VSa6oH.rst
@@ -0,0 +1,3 @@
+Fix :mod:`venv` activation in a non-interactive csh:
+``activate.csh`` no longer fails
+when the ``prompt`` variable is not set.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to