importlib.util._find_spec_from_path('__main__') fails
未关闭
还没有人认领这个 Issue。
stdlib
topic-importlib
type-bug
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 36k
- PR 合并指标
- PR 指标待抓取
描述
Bug report
Module pyclbr cannot browse a file named __main__ because it cannot get the spec.
>>> from importlib import util
>>> util._find_spec_from_path('__init__')
ModuleSpec(name='__init__', loader=<_frozen_importlib_external.SourceFileLoader object at 0x000001C6C2462DB0>, origin='C:\\Programs\\Python313\\Lib\\idlelib\\__init__.py')
>>> util._find_spec_from_path('__main__')
Traceback (most recent call last):
File "<pyshell#14>", line 1, in <module>
util._find_spec_from_path('__main__')
File "<frozen importlib.util>", line 67, in _find_spec_from_path
ValueError: __main__.__spec__ is None
This is 3.13.0a5 but same in prior versions.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
使用 importlib.util._find_spec_from_path('main') 重现失败,并跟踪 pyclbr 如何为名为 main 的文件请求 spec。检查 importlib.util 路径以及报告中描述的 pyclbr 行为。当 pyclbr 能够浏览名为 main 的文件且不出现所示的 ValueError 时,即视为完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- backend
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100