Skip to content

Commit d24f79b

Browse files
committed
dir show module content
1 parent a7c3f85 commit d24f79b

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

vm/src/obj/objtype.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use super::objdict;
22
use super::objstr;
33
use super::objtype; // Required for arg_check! to use isinstance
44
use crate::pyobject::{
5-
AttributeProtocol, IdProtocol, PyAttributes, PyContext, PyFuncArgs, PyObject, PyObjectPayload,
6-
PyObjectRef, PyResult, TypeProtocol,
5+
AttributeProtocol, DictProtocol, IdProtocol, PyAttributes, PyContext, PyFuncArgs, PyObject,
6+
PyObjectPayload, PyObjectRef, PyResult, TypeProtocol,
77
};
88
use crate::vm::VirtualMachine;
99
use std::cell::RefCell;
@@ -277,6 +277,13 @@ pub fn get_attributes(obj: &PyObjectRef) -> PyAttributes {
277277
attributes.insert(name.to_string(), value.clone());
278278
}
279279
}
280+
281+
// Get module attributes:
282+
if let PyObjectPayload::Module { ref scope, .. } = &obj.payload {
283+
for (name, value) in scope.locals.get_key_value_pairs().iter() {
284+
attributes.insert(objstr::get_value(name).to_string(), value.clone());
285+
}
286+
}
280287
attributes
281288
}
282289

0 commit comments

Comments
 (0)