mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Correct module.__dir__
This commit is contained in:
1 file changed
+13
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user