python / python/cpython

`LOAD_SMALL_INT` has empty `argrepr` via `Bytecode`

Abierto
#140,256 8 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

stdlib type-bug
Lenguaje dominante
Python
Estrellas
77.2k
Forks
35.9k
Métricas de merge de PR
Métricas de PR pendientes

Descripción

Bug report

Bug description:

When using Bytecode to disassemble some Python code I've noticed that the argrepr attribute of the Instruction holding a LOAD_SMALL_INT isn't populated. For example:

Python 3.14.0 (main, Oct 16 2025, 09:17:39) [Clang 17.0.0 (clang-1700.3.19.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from dis import Bytecode
>>> list(Bytecode("1"))
[
    Instruction(
        opname='RESUME',
        opcode=128,
        arg=0,
        argval=0,
        argrepr='',
        offset=0,
        start_offset=0,
        starts_line=True,
        line_number=0,
        label=None,
        positions=Positions(lineno=0, end_lineno=1, col_offset=0, end_col_offset=0),
        cache_info=None
    ),
    Instruction(
        opname='LOAD_SMALL_INT',
        opcode=94,
        arg=1,
        argval=1,
        argrepr='',     # <--- Empty string
        offset=2,
        start_offset=2,
        starts_line=True,
        line_number=1,
        label=None,
        positions=Positions(lineno=1, end_lineno=1, col_offset=0, end_col_offset=1),
        cache_info=None
    ),
    Instruction(
        opname='RETURN_VALUE',
        opcode=35,
        arg=None,
        argval=None,
        argrepr='',
        offset=4,
        start_offset=4,
        starts_line=False,
        line_number=1,
        label=None,
        positions=Positions(lineno=1, end_lineno=1, col_offset=0, end_col_offset=1),
        cache_info=None
    )
]

I would have expected this to have the repr of the argument in there.

A quick and ignorant reading of dis.py suggests to me that there should be a change akin to this:

--- ../cpython/Lib/dis.py       2025-10-17 14:31:35.495151419 +0100
+++ my/dis.py   2025-10-17 14:43:26.650409153 +0100
@@ -586,7 +586,7 @@
             #    _disassemble_bytes needs the string repr of the
             #    raw name index for LOAD_GLOBAL, LOAD_CONST, etc.
             argval = arg
-            if deop in hasconst:
+            if deop in hasconst or deop == LOAD_SMALL_INT:
                 argval, argrepr = _get_const_info(deop, arg, self.co_consts)
             elif deop in hasname:
                 if deop == LOAD_GLOBAL:
CPython versions tested on:

3.14

Operating systems tested on:

macOS

Linked PRs
  • gh-140258

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Empieza en Lib/dis.py, en la lógica de manejo de argumentos de Bytecode, y reproduce el ejemplo con list(Bytecode("1")). Comprueba la ruta LOAD_SMALL_INT y el comportamiento de _get_const_info; se considera terminado cuando su Instruction tiene el argrepr no vacío esperado, con el comportamiento comprobado frente al trabajo enlazado gh-140258.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
devtools
Tipo de issue
Error
Dificultad
2/5
Tiempo estimado
1-3 horas
Estado de actividad
Estancado
Claridad
Bien especificado
Aptitud para principiantes
25/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.