@@ -5,11 +5,12 @@ use std::ops::{Deref, DerefMut};
55
66use crate :: function:: { KwArgs , OptionalArg } ;
77use crate :: pyobject:: {
8- DictProtocol , PyAttributes , PyContext , PyIteratorValue , PyObjectRef , PyRef , PyResult , PyValue ,
8+ DictProtocol , PyAttributes , PyContext , PyObjectRef , PyRef , PyResult , PyValue ,
99} ;
1010use crate :: vm:: { ReprGuard , VirtualMachine } ;
1111
1212use super :: objiter;
13+ use super :: objlist:: PyListIterator ;
1314use super :: objstr:: { self , PyStringRef } ;
1415use super :: objtype;
1516use crate :: obj:: objtype:: PyClassRef ;
@@ -210,7 +211,8 @@ impl PyDictRef {
210211 }
211212
212213 /// When iterating over a dictionary, we iterate over the keys of it.
213- fn iter ( self , vm : & VirtualMachine ) -> PyIteratorValue {
214+ fn iter ( self , vm : & VirtualMachine ) -> PyListIterator {
215+ // TODO: separate type, not a list iterator
214216 let keys = self
215217 . entries
216218 . borrow ( )
@@ -219,13 +221,14 @@ impl PyDictRef {
219221 . collect ( ) ;
220222 let key_list = vm. ctx . new_list ( keys) ;
221223
222- PyIteratorValue {
224+ PyListIterator {
223225 position : Cell :: new ( 0 ) ,
224- iterated_obj : key_list,
226+ list : key_list. downcast ( ) . unwrap ( ) ,
225227 }
226228 }
227229
228- fn values ( self , vm : & VirtualMachine ) -> PyIteratorValue {
230+ fn values ( self , vm : & VirtualMachine ) -> PyListIterator {
231+ // TODO: separate type. `values` should be a live view over the collection, not an iterator.
229232 let values = self
230233 . entries
231234 . borrow ( )
@@ -234,13 +237,14 @@ impl PyDictRef {
234237 . collect ( ) ;
235238 let values_list = vm. ctx . new_list ( values) ;
236239
237- PyIteratorValue {
240+ PyListIterator {
238241 position : Cell :: new ( 0 ) ,
239- iterated_obj : values_list,
242+ list : values_list. downcast ( ) . unwrap ( ) ,
240243 }
241244 }
242245
243- fn items ( self , vm : & VirtualMachine ) -> PyIteratorValue {
246+ fn items ( self , vm : & VirtualMachine ) -> PyListIterator {
247+ // TODO: separate type. `items` should be a live view over the collection, not an iterator.
244248 let items = self
245249 . entries
246250 . borrow ( )
@@ -249,9 +253,9 @@ impl PyDictRef {
249253 . collect ( ) ;
250254 let items_list = vm. ctx . new_list ( items) ;
251255
252- PyIteratorValue {
256+ PyListIterator {
253257 position : Cell :: new ( 0 ) ,
254- iterated_obj : items_list,
258+ list : items_list. downcast ( ) . unwrap ( ) ,
255259 }
256260 }
257261
@@ -332,6 +336,7 @@ pub fn init(context: &PyContext) {
332336 "clear" => context. new_rustfunc( PyDictRef :: clear) ,
333337 "values" => context. new_rustfunc( PyDictRef :: values) ,
334338 "items" => context. new_rustfunc( PyDictRef :: items) ,
339+ // TODO: separate type. `keys` should be a live view over the collection, not an iterator.
335340 "keys" => context. new_rustfunc( PyDictRef :: iter) ,
336341 "get" => context. new_rustfunc( PyDictRef :: get) ,
337342 } ) ;
0 commit comments