Correct module.__dir__

This commit is contained in:
Noah committed 2020-03-01 14:57:10 -06:00
1 parent 7f337e2918
commit c703bb72d0
1 file changed
+13
+13
View File
@@ -93,6 +93,19 @@ impl PyModuleRef {
let module_repr = vm.get_attribute(importlib, "_module_repr")?;
vm.invoke(&module_repr, vec![self.into_object()])
}
#[pymethod(magic)]
fn dir(self, vm: &VirtualMachine) -> PyResult<PyObjectRef> {
let dict = self
.as_object()
.dict
.as_ref()
.ok_or_else(|| vm.new_value_error("module has no dict".to_owned()))?
.borrow()
.clone();
let attrs = dict.into_iter().map(|(k, _v)| k).collect();
Ok(vm.ctx.new_list(attrs))
}
}
pub(crate) fn init(context: &PyContext) {