Implement IntoIterator for PyDictRef.

This commit is contained in:
Adam Kelly
2019-04-09 11:25:18 +01:00
parent 31fd2936c5
commit ec5fd550de
6 changed files with 63 additions and 47 deletions

View File

@@ -17,11 +17,7 @@ impl PyValue for PyModule {
impl PyModuleRef {
fn dir(self: PyModuleRef, vm: &VirtualMachine) -> PyResult {
if let Some(dict) = &self.into_object().dict {
let keys = dict
.get_key_value_pairs()
.iter()
.map(|(k, _v)| k.clone())
.collect();
let keys = dict.into_iter().map(|(k, _v)| k.clone()).collect();
Ok(vm.ctx.new_list(keys))
} else {
panic!("Modules should definitely have a dict.");