Skip to content

gh-160732: protect venv prompts from expansion - #160734

Open
19anveshh wants to merge 2 commits into
python:mainfrom
19anveshh:fix-venv-prompt-expansion
Open

19anveshh wants to merge 2 commits into
python:mainfrom
19anveshh:fix-venv-prompt-expansion

Conversation

@19anveshh

Copy link
Copy Markdown

gh-160732: protect venv prompts from expansion

Fixes #160732.

The generated Bash activation script now keeps the prompt in
VIRTUAL_ENV_PROMPT and expands that variable when the prompt is displayed,
so prompt values containing command substitutions remain literal. The zsh path
uses a psvar entry for the same reason. Deactivation restores the prior zsh
prompt variable.

The regression test creates a venv with a $(touch ...) prompt, starts an
interactive Bash shell, and verifies that the marker is not created and the
prompt remains literal.

Checks:

  • python -m py_compile Lib/test/test_venv.py Lib/venv/__init__.py
  • bash -n on the generated activation script
  • interactive Bash smoke test of the generated activation script
  • git diff --check

The full CPython test suite was not run because this environment has no local
CPython build toolchain; the available interpreter is Python 3.13 while this
checkout uses newer CPython-main syntax.

AI tools assisted with issue discovery, code exploration, and drafting. I
reviewed the resulting patch, tests, and PR description manually.

@python-cla-bot

python-cla-bot Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app

bedevere-app Bot commented Oct 26, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@19anveshh
19anveshh force-pushed the fix-venv-prompt-expansion branch from 9379ef8 to a49bbbd Compare October 26, 2026 20:02
@bedevere-app

bedevere-app Bot commented Oct 26, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@19anveshh
19anveshh force-pushed the fix-venv-prompt-expansion branch from a49bbbd to 824f8d4 Compare October 26, 2026 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

venv: --prompt / env-dir value is not escaped for the shell's prompt-display pass in generated activate (bash/zsh)

1 participant