python / python/cpython

3.14 is missing a bytecode line number for one-line conditionals

Aperta
#136,190 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

3.13 3.14 3.15 interpreter-core type-bug
Lingua principale
Python
Stelle
77.2k
Fork
35.9k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

Bug report

Bug description:

(from https://github.com/nedbat/coveragepy/issues/1991)

Here is b1991.py:

% cat b1991.py
def func(x, y):
    for size in (x or ()) if y else ():
        print(size)

func([3], True)

The disassembly looks like this:

% python3.14 -m dis -O b1991.py
  0          0       RESUME                   0

  1          2       LOAD_CONST               0 (<code object func at 0x1045ef0e0, file "b1991.py", line 1>)
             4       MAKE_FUNCTION
             6       STORE_NAME               0 (func)

  5          8       LOAD_NAME                0 (func)
            10       PUSH_NULL
            12       LOAD_SMALL_INT           3
            14       BUILD_LIST               1
            16       LOAD_CONST               1 (True)
            18       CALL                     2
            26       POP_TOP
            28       LOAD_CONST               2 (None)
            30       RETURN_VALUE

Disassembly of <code object func at 0x1045ef0e0, file "b1991.py", line 1>:
   1          0       RESUME                   0

   2          2       LOAD_FAST_BORROW         1 (y)
              4       TO_BOOL
             12       POP_JUMP_IF_FALSE       13 (to L2)
             16       NOT_TAKEN
             18       LOAD_FAST                0 (x)
             20       COPY                     1
             22       TO_BOOL
             30       POP_JUMP_IF_TRUE         3 (to L1)
             34       NOT_TAKEN
             36       POP_TOP
             38       LOAD_CONST               1 (())

  --   L1:   40       JUMP_FORWARD             1 (to L3)               <----------###

   2   L2:   42       LOAD_CONST               1 (())
       L3:   44       GET_ITER
       L4:   46       FOR_ITER                14 (to L5)
             50       STORE_FAST               2 (size)

   3         52       LOAD_GLOBAL              1 (print + NULL)
             62       LOAD_FAST_BORROW         2 (size)
             64       CALL                     1
             72       POP_TOP
             74       JUMP_BACKWARD           16 (to L4)

   2   L5:   78       END_FOR
             80       POP_ITER
             82       LOAD_CONST               0 (None)
             84       RETURN_VALUE

Offset 40 has no line number, but shouldn't it be attributed to line 2? The same problem happens on 3.13 and on the tip of main.

CPython versions tested on:

3.14, 3.15, CPython main branch, 3.13

Operating systems tested on:

macOS

Linked PRs
  • gh-136923

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Riproduci il report di b1991.py con python3.14 -m dis -O b1991.py, quindi esamina come vengono assegnate le informazioni sulle righe alla condizionale su una sola riga nel disassemblato generato. La modifica è completata quando l’offset 40 viene attribuito alla riga 2 senza introdurre regressioni nelle altre associazioni di righe visualizzate; gh-136923 indica che potrebbe esserci già del lavoro correlato in corso.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
compilers
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.