symtable: repr() of a Symbol raises TypeError under -X lazy_imports=all
维护者通常 1 天内回复
评估
调研方向
阅读 Lib/symtable.py,尤其是从 globals() 构建 _flags 和 _scopes_value_to_name 的位置,并将这些名称与 _symtable 中的常量进行比较。先使用 -X lazy_imports=all 运行报告中的 repr() 示例;然后分别在启用和禁用延迟导入时运行 test_symtable。完成标准是:两种模式下符号都显示预期的标志和作用域名称,并且不再需要将该测试从 Lib/test/lazy_imports_all_exclude.txt 中排除。
由索引模型根据 Issue 内容生成。
描述
Bug report
Bug description:
With -X lazy_imports=all, repr() of a symtable.Symbol raises TypeError:
import symtable
top = symtable.symtable('x = 1', '<string>', 'exec')
print(top.get_symbols())
$ ./python -X lazy_imports=all repro.py
Traceback (most recent call last):
File "repro.py", line 3, in <module>
print(top.get_symbols())
~~~~~^^^^^^^^^^^^^^^^^^^
File "Lib/symtable.py", line 264, in __repr__
flags_str = '|'.join(self._flags_str())
File "Lib/symtable.py", line 272, in _flags_str
if self.__flags & flagvalue == flagvalue:
~~~~~~~~~~~~~^~~~~~~~~~~
TypeError: unsupported operand type(s) for &: 'int' and 'lazy_import'
Without the option it prints [<symbol 'x': LOCAL, DEF_LOCAL>].
Lib/symtable.py builds its _flags and _scopes_value_to_name tables from globals(): https://github.com/python/cpython/blob/c79146a9eb05dea735a6a22dc004379cdec3ed0e/Lib/symtable.py#L388-L391
With lazy_imports=all, the from _symtable import ... at the top of the module is lazy, so globals() holds lazy_import objects instead of the integer constants. _flags breaks repr() as above, and once that is fixed, _scopes_value_to_name still makes the scope print as 1 instead of LOCAL.
This is the test_symtable failure mentioned in gh-149640, and why test_symtable is in Lib/test/lazy_imports_all_exclude.txt. The 3.15 branch has the same code.
Possible fix: take the values from the _symtable module (for example getattr(_symtable, name)) instead of from globals(). With that, test_symtable passes with and without -X lazy_imports=all and can come off the exclusion list. I can open a PR if this sounds right.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
- gh-160866
- 主要语言
- Python
- 星标
- 77.8k
- 派生
- 37.7k
- 平均合并
- 17 小时 24 分钟
- 30 天内合并 PR
- 716
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
python/cpython 的其他 Issue
-
build OS-unsupported OS-windows type-bug
难度 2/5 1-3 小时 新手友好度 60/100
维护者通常 1 天内回复
-
What's New in 3.12 credits the unstable C API tier to PEP 697 instead of PEP 689可能已有人在做 @TheLouisMahdi 于 1 天前认领。 未关闭docs
难度 1/5 1 小时以内 新手友好度 82/100
python/cpython#161078 · 3 条评论 ·
维护者通常 1 天内回复
-
OS-windows type-bug
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
docs
难度 2/5 1-3 小时 新手友好度 72/100
python/cpython#161007 · 4 条评论 ·
维护者通常 1 天内回复
-
Null dereferencing of a pointer in initconfig.c可能已有人在做 @lazerg 于 4 天前认领。 未关闭interpreter-core topic-C-API type-bug
难度 2/5 1-3 小时 新手友好度 72/100
python/cpython#160962 · 4 条评论 ·
维护者通常 1 天内回复
相似的 Issue
-
ci-rerun: collect.py fails a whole pr-babysit cycle on one transient GitHub 5xx and never retries未关闭follow-up
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
-
Built-in QUBO fallback applies bitwise xor to floating binary states可能已有人在做 @iloveeyjafjalla 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
qboson/kaiwu-pytorch-plugin#1702 ·
维护者通常 3 天内回复
-
bug v2
难度 2/5 1-3 小时 新手友好度 76/100
modelcontextprotocol/python-sdk#3811 ·
维护者通常 1 天内回复
-
cost:cheap practicality:seen-in-the-wild severity:medium
难度 2/5 1-3 小时 新手友好度 72/100
fairagro/m4.2_advanced_middleware_api#620 ·
维护者通常 1 天内回复