symtable: repr() of a Symbol raises TypeError under -X lazy_imports=all
メンテナーはふだん 1 日以内に返信
評価
調査の方向性
Lib/symtable.pyを読み、特に_flagsと_scopes_value_to_nameがglobals()から構築される箇所を確認し、それらの名前を_symtableの定数と比較してください。まず、報告されたrepr()の例を-X lazy_imports=allで実行し、その後、遅延インポートの有効時と無効時に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
- 主要言語
- Python
- スター
- 77.8k
- フォーク
- 37.7k
- 平均マージ
- 12時間 27分
- マージ済み PR(30日)
- 710
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
python/cpython のほかの issue
-
3.16 build type-bug
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
python/cpython#160829 · コメント 4 件 ·
メンテナーはふだん 1 日以内に返信
-
dependencies infra topic-ensurepip
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
メンテナーはふだん 1 日以内に返信
-
tarfile: extractfile(member).read() of a sparse member is slow due to repeated bytes concatenationオープンperformance stdlib triaged type-bug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
python/cpython#160774 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
tests topic-profiling type-bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
python/cpython#160334 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
`iso2022_jp_3` encodes U+9B1D but decodes the result as U+9B1C対応中かも @kinqsradio が 3 日前に担当しました。 オープンextension-modules type-bug
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
changelog investigate
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
ramnes/notion-sdk-py#433 ·
-
docs pkg:core
難易度 1/5 1時間未満 初心者へのやさしさ 84/100
pydantic/pydantic-ai#11929 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
intake/intake-esm#789 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
MemMachine/MemMachine#1877 ·
メンテナーはふだん 3 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
openedx/openedx-authz#579 ·
メンテナーはふだん 1 日以内に返信