Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

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

Aberta Para iniciantes
#160,810 3 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

@anistark já está trabalhando nisso.

Desde 29/10/2026.

Avaliação

Dificuldade
2/5
Tempo estimado
1-3 horas
Facilidade para iniciantes
72/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
python
Domínio
testing

Direção de pesquisa

Leia Lib/symtable.py, especialmente onde _flags e _scopes_value_to_name são construídos a partir de globals(), e compare esses nomes com as constantes em _symtable. Comece executando o exemplo repr() relatado com -X lazy_imports=all; depois execute test_symtable com e sem importações lazy. O trabalho estará concluído quando os símbolos exibirem os flags e nomes de escopo esperados nos dois modos, e o teste não precisar mais ser excluído de Lib/test/lazy_imports_all_exclude.txt.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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

Linguagem predominante
Python
Estrelas
77.8k
Forks
37.7k
Merge médio
12h 27min
PRs com merge (30d)
710

Preparar o ambiente

Abrir no Codespaces

Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de python/cpython

Todas as issues de python/cpython

Issues semelhantes

Mais issues de Python

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.