Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

[Bug]: `reversed()` on a dict or dict view returns the forward iterator type instead of `dict_reverse*iterator`

Chiusa Adatta ai principianti
#1,226 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Una pull request collegata è già stata integrata.

  • #1228 di @jseop-lim — integrata

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
java, python
Ambito
backend, testing

Direzione di ricerca

Inizia in DictBuiltins.java, DictViewBuiltins.java e DictValuesBuiltins.java nei quattro punti reversed indicati nell’issue; segui come le loro factories avvolgono gli iteratori inversi dello storage. Confronta le factories di iteratori esistenti e le classi PDictReverse*Iterator, poi aggiungi test di regressione per reversed(dict), keys, values e items. Il lavoro è completato quando ciascuno restituisce il tipo di iteratore inverso corrispondente e l’ordine di iterazione rimane corretto.

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

Descrizione

bug
Describe the bug

reversed(d), reversed(d.keys()), reversed(d.values()) and reversed(d.items()) return objects of the forward iterator types (dict_keyiterator and so on). CPython returns dict_reversekeyiterator, dict_reversevalueiterator and dict_reverseitemiterator. GraalPy already defines those three types but never instantiates them.

Operating system

Linux

CPU architecture

ARM64

GraalPy version

25.0.2 (Python 3.12.8); also reproduced on 25.4.4.1.1 (Python 3.13.14)

JDK version

No response

Context configuration

No response

Steps to reproduce
d = {1: 2}
print(type(reversed(d)).__name__)
print(type(reversed(d.keys())).__name__)
print(type(reversed(d.values())).__name__)
print(type(reversed(d.items())).__name__)

GraalPy 25.0.2:

dict_keyiterator
dict_keyiterator
dict_valueiterator
dict_itemiterator
Expected behavior

CPython 3.12.13 (same on 3.13.16):

dict_reversekeyiterator
dict_reversekeyiterator
dict_reversevalueiterator
dict_reverseitemiterator
Stack trace

Additional context

Iteration order is correct; only the type differs, so type(reversed(d)) is type(iter(d)) is True on GraalPy.

For the views this looks like a regression. They returned the reverse types after 8fe0061a78 and switched to the forward factories in afc1f123e6, so 22.3 should still report the reverse names (read from the history, not run). dict.__reversed__ itself has used the forward type since 8fe0061a78.

Root Cause

The __reversed__ nodes of dict (DictBuiltins.java#L439), dict_keys and dict_items (DictViewBuiltins.java#L196, #L206) and dict_values (DictValuesBuiltins.java#L112) wrap the reverse storage iterator with the forward factories createDictKeyIterator, createDictItemIterator and createDictValueIterator. PDictReverseItemIterator, PDictReverseKeyIterator and PDictReverseValueIterator are still defined (PythonBuiltinClassType.java#L424-L430), but no code creates an instance of them. CPython's dict___reversed___impl and the three view __reversed__ functions all pass a PyDictRevIter*_Type to dictiter_new (dictobject.c#L4494, #L5129, #L5235, #L5316).

Fix Suggestion

Add createDictReverse{Key,Item,Value}Iterator factories that build the same Java iterator objects with the PDictReverse*Iterator classes, as before afc1f123e6, and call them from the four sites above. The reverse types could also take disallowInstantiation() like their forward counterparts.

Lingua principale
Python
Stelle
1.7k
Fork
163
Merge medio
14h 10m
PR unite (30g)
56

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

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 oracle/graalpython

Tutte le issue di oracle/graalpython

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.