python / python/cpython

pyrepl should provide full traceback if possible to help debug possible buggy failures.

未关闭
#127,442 0 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

topic-repl type-feature
主要语言
Python
星标
77.2k
派生
35.9k
PR 合并指标
PR 指标待抓取

描述

Bug report

Bug description:

Currently pyrepl has the following bug that is hard to debug:

config.site_import is value: '0'
config.user_site_directory is value: '0'
config.site_import is value: '0'
config.user_site_directory is value: '0'
Python 3.14.0a2+ (heads/main-dirty:49f15d8667e, Nov 29 2024, 21:28:03) [MSC v.1943 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
C:\Users\user\AppData\Roaming\Python\Python314\site-packages\easy-install.pth
warning: can't use pyrepl: 'NoneType' object does not support the context manager protocol (missed __exit__ method)
>>> 

This bug then results in site.py getting imported anyways despite my setting config.site_import AND config.user_site_directory in my own version of Py_Initialize in my C program that embeds the interpreter on Windows (exe). This results in the incorrect appending of the user site-packages folder at the end of sys.path that I did NOT OPT into at all. I did NOT want the interpreter to go about trying to open any pth file for which my own OpenCodeHook successfully captured and printed to my console to let me know that site.py was imported when it should not have been imported at all.

As such if tracebacks were printed whenever it would print the warning that pyrepl cannot be used it would help all possible situations where pyrepl cannot be used and give the user more information into fixing the root problem itself (even if it means pull requesting this repository with a fix for pyrepl itself).

Long story short EXTRA information is better than NOT ENOUGH information to debug and fix problems with pyrepl on embedded interpreters. Likewise site.py and the user site packages folder should be optional and not a hard requirement to using pyrepl either. Basically any and all places in this repository that imports site.py without checking if both config.site_import and config.user_site_directory should be made to check them first before attempting to import it, even if pyrepl cannot be used.

CPython versions tested on:

3.14, CPython main branch

Operating systems tested on:

Windows

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先追踪 pyrepl 在哪里发出无法使用的警告,以及解释器初始化期间在哪里导入 site.py。检查 config.site_import 和 config.user_site_directory 的处理方式,然后找出涵盖嵌入式解释器或 pyrepl 失败的测试。当警告包含完整的 traceback,并且在导入 site.py 之前遵循所报告的配置时,即视为完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
cli
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
需要澄清
新手友好度
30/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。