Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

symtable: repr() of a Symbol raises TypeError under -X lazy_imports=all

オープン 初心者向け
#160,810 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@anistark がすでに取り組んでいます。

2026年10月29日 から。

  • #160866 @anistark による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
72/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
testing

調査の方向性

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 の本文から書いたものです。

説明

stdlib topic-lazy-imports type-bug

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

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

python/cpython のほかの issue

python/cpython の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。