python / python/cpython

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

Ouverte
#140,256 8 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

stdlib type-bug
Langage dominant
Python
Étoiles
77.2k
Forks
35.9k
Métriques de merge des PR
Métriques de PR en attente

Description

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

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez dans Lib/dis.py, au niveau de la logique de gestion des arguments de Bytecode, et reproduisez l’exemple avec list(Bytecode("1")). Vérifiez le chemin LOAD_SMALL_INT et le comportement de _get_const_info ; c’est terminé lorsque son Instruction possède le argrepr non vide attendu, avec un comportement vérifié par rapport au travail lié gh-140258.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
python
Domaine
devtools
Type d'issue
Bug
Difficulté
2/5
Temps estimé
1-3 heures
Activité
À l'abandon
Clarté
Clairement spécifiée
Accessibilité débutants
25/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.