Incorrect docs for `-i` flag and `PYTHONSTARTUP`
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
Documentation
The docs for the -i flag state that "Interactive mode will start even when sys.stdin does not appear to be a terminal. The PYTHONSTARTUP flie is not read". This is incorrect, as can be shown by this test:
% echo "print('running pystartup')" > startup.py
% PYTHONSTARTUP=startup.py python3 -i < /dev/null
Python 3.13.2 (main, Feb 4 2025, 14:51:09) [Clang 16.0.0 (clang-1600.0.26.6)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
running pystartup
>>>
The behavior is the same in all versions of python I have installed (3.10, 3.11, 3.12, 3.13) on macOS, so it's not something that changed with the new REPL implementation.
Note that PYTHONSTARTUP is not used if the -c flag is also used.
% PYTHONSTARTUP=startup.py python3.10 -i -c "print('-c')" < /dev/null
-c
>>>
I think what I'm seeing here is that the -i flag has two distinct uses:
- Run a script or command and go into interactive mode. PYTHONSTARTUP is not used in this case.
- Run in interactive mode even when sys.stdin does not appear to be a terminal. This only changes the terminal check, so PYTHONSTARTUP is run as usual, contrary to the documentation.
If that's right, then I think the docs should be updated to describe these two aspects of the flag separately and point out that PYTHONSTARTUP is only disabled in the execute-and-interactive case.
(How did I discover this? I have test cases that run python -u -i to interact with an interpreter on stdin/stdout. vscode recently started injecting a PYTHONSTARTUP file that changes sys.ps1 in ways that broke my test. What I really want is to add the -I flag to these tests for isolated mode, but along the way I came across this incorrect statement in the docs)
Linked PRs
- gh-142502
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
该 issue 将 -i 和 PYTHONSTARTUP 的文档确定为切入点;首先结合演示的命令检查相关措辞。完成标准是文档区分 -i 的两种用法,并说明何时会跳过 PYTHONSTARTUP,同时示例仍然准确。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- documentation
- Issue 类型
- 文档
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 25/100