`deque.index` result changed in 3.14.7 when a bound's `__index__` mutates the deque

Aperta
#156,743 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
python

Direzione di ricerca

Inizia riproducendo l’esempio di deque.index e rivedendo l’implementazione di deque.index, la voce NEWS e la PR #157784 collegata. Il lavoro è completato quando si determina se il comportamento della versione 3.14.7 debba rimanere e, in tal caso, si documenta la modifica e si aggiunge la copertura di regressione mancante.

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

Descrizione

3.14 3.15 3.16 docs

I'm Samuel the human, and I endorse this message.


(written by claude)

Bug description

gh-150750 (merged in 3.14.7 via #150921) changed the result of deque.index when a bound's __index__ mutates the deque.
The change is not mentioned in the NEWS entry, which only describes the free-threading race, and is not covered by a test.

from collections import deque

d = deque([1, 2, 3])

class Grow:
    def __index__(self):
        d.extend([2, 2, 2])
        return -1

print(d.index(2, Grow()))

3.14.6 and earlier raise ValueError: deque.index(x): x not in deque.
3.14.7 prints 5.

Before #150779, stop defaulted to Py_SIZE(deque) read during argument parsing, before the start converter called __index__.
In the example, stop was captured as 3, start=-1 then resolved against the live size 6 to give 5, and start > stop clamped the search to an empty window.
After #150779, deque_index_impl reads the size once, after argument conversion, so both bounds resolve against the mutated size and the search finds the element.

The new behavior is self-consistent (one size snapshot, taken after both converters run) and matches what list.index does, so this is probably fine to keep.
Reporting it because the change is user-visible in a patch release: it may deserve a changelog note and a regression test, or reverting if the old behavior was intended.

Your environment

  • CPython versions tested on: 3.14.0, 3.14.2, 3.14.4 (old behavior); 3.14.7, 3.15.0rc1 (new behavior)
  • Operating system and architecture: macOS arm64
Linked PRs
  • gh-157784
Lingua principale
Python
Stelle
77.2k
Fork
36k
Merge medio
1g 9h
PR unite (30g)
558

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.

Altre issue di python/cpython

Tutte le issue di python/cpython

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.