]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.11] gh-112431: Unconditionally call `hash -r` (GH-112432) (GH-112492)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 28 Nov 2023 09:43:38 +0000 (10:43 +0100)
committerGitHub <noreply@github.com>
Tue, 28 Nov 2023 09:43:38 +0000 (15:13 +0530)
gh-112431: Unconditionally call `hash -r` (GH-112432)

The `activate` script calls `hash -r` in two places to make sure the shell picks
up the environment changes the script makes. Before that, it checks to
see if the shell running the script is bash or zsh.

`hash -r` is specified by POSIX and is not exclusive to bash and zsh.
This guard prevents the script from calling `hash -r` in other
`GH-!/bin/sh`-compatible shells like dash.
(cherry picked from commit a194938f33a71e727e53490815bae874eece1460)

Co-authored-by: James Morris <6653392+J-M0@users.noreply.github.com>
Lib/venv/scripts/common/activate

index 6fbc2b8801da0498b4d526bbac11ab5b0d2a4de7..982da08163b12d53acd701b706ab057fec572b6f 100644 (file)
@@ -14,12 +14,9 @@ deactivate () {
         unset _OLD_VIRTUAL_PYTHONHOME
     fi
 
-    # This should detect bash and zsh, which have a hash command that must
-    # be called to get it to forget past commands.  Without forgetting
+    # Call hash to forget past commands. Without forgetting
     # past commands the $PATH changes we made may not be respected
-    if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
-        hash -r 2> /dev/null
-    fi
+    hash -r 2> /dev/null
 
     if [ -n "${_OLD_VIRTUAL_PS1:-}" ] ; then
         PS1="${_OLD_VIRTUAL_PS1:-}"
@@ -61,9 +58,6 @@ if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT:-}" ] ; then
     export VIRTUAL_ENV_PROMPT
 fi
 
-# This should detect bash and zsh, which have a hash command that must
-# be called to get it to forget past commands.  Without forgetting
+# Call hash to forget past commands. Without forgetting
 # past commands the $PATH changes we made may not be respected
-if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
-    hash -r 2> /dev/null
-fi
+hash -r 2> /dev/null