Skip to content

gh-131484: Document that directory and zipfile script targets stay on sys.path - #154853

Open
yhay81 wants to merge 1 commit into
python:mainfrom
yhay81:gh-131484-doc-safe-path
Open

gh-131484: Document that directory and zipfile script targets stay on sys.path#154853
yhay81 wants to merge 1 commit into
python:mainfrom
yhay81:gh-131484-doc-safe-path

Conversation

@yhay81

@yhay81 yhay81 commented Jul 29, 2026

Copy link
Copy Markdown

The -P documentation covers only the -m / script / -c / REPL cases. A directory
or zipfile passed as the script argument stays at the start of sys.path, in
safe-path and isolated modes alike: that entry is used to locate __main__ and makes
other modules stored in the target importable.

This documents existing behavior; there is no code change. It assumes keeping the
named target is intended — if it should change instead, please close this; the
analysis is in #131484.

Verified with 3.14.6 and main at 8b048eb.

AI-assisted; I reviewed the changes and verified the behavior and cited source myself.

… sys.path

-P, -I and PYTHONSAFEPATH drop the implicit sys.path[0] entries (current
directory, script directory, empty string), but a directory or zipfile named
as the script argument is still prepended: that entry is used to locate
__main__.py and makes other modules stored in the target importable. The -P
section currently enumerates only the -m, script and -c/REPL cases.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #33809389 | 📁 Comparing 28b1ba2 against main (8b048eb)

  🔍 Preview build  

2 files changed
± using/cmdline.html
± whatsnew/changelog.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review docs Documentation in the Doc dir

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

1 participant