builtins/pytype.rs: set __module__ in type() calls
@@ -336,7 +336,6 @@ impl PyType {
#[pyproperty(magic)]
pub fn module(&self, vm: &VirtualMachine) -> PyObjectRef {
- // TODO: Implement getting the actual module a builtin type is from
self.attributes
.read()
.get("__module__")
@@ -483,6 +482,15 @@ impl PyType {
}
}
+ if let Some(current_frame) = vm.current_frame() {
+ if !attributes.contains_key("__module__") {
+ attributes.insert(
+ "__module__".to_string(),
+ vm.unwrap_or_none(current_frame.globals.get_item_opt("__name__", vm)?),
+ );
+ }
+ }
+
// All *classes* should have a dict. Exceptions are *instances* of
// classes that define __slots__ and instances of built-in classes
// (with exceptions, e.g function)
