`deque.index` result changed in 3.14.7 when a bound's `__index__` mutates the deque
Personne n'a encore pris cette issue.
- Langage dominant
- Python
- Étoiles
- 77.2k
- Forks
- 35.9k
- Métriques de merge des PR
- Métriques de PR en attente
Description
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
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par reproduire l’exemple de deque.index et examiner l’implémentation de deque.index, l’entrée NEWS et la PR #157784 liée. Le travail est terminé lorsqu’il est établi si le comportement de 3.14.7 doit être conservé et, si c’est le cas, que la modification est documentée et que la couverture de régression manquante est ajoutée.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- python
- Domaine
- documentation, testing
- Type d'issue
- Bug
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Activité
- À l'abandon
- Clarté
- À clarifier
- Accessibilité débutants
- 35/100