From d6c9f2d9725637c5167ef4fa3ec0eb9801b44bcc Mon Sep 17 00:00:00 2001 From: coolreader18 <33094578+coolreader18@users.noreply.github.com> Date: Wed, 7 Aug 2019 13:50:00 -0500 Subject: [PATCH] Add __qualname__ and __module__ getters to objtype --- vm/src/obj/objtype.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/vm/src/obj/objtype.rs b/vm/src/obj/objtype.rs index 2cc65d670..9df1a829f 100644 --- a/vm/src/obj/objtype.rs +++ b/vm/src/obj/objtype.rs @@ -108,6 +108,23 @@ impl PyClassRef { format!("", self.name) } + fn qualname(self, vm: &VirtualMachine) -> PyObjectRef { + self.attributes + .borrow() + .get("__qualname__") + .cloned() + .unwrap_or_else(|| vm.ctx.new_str(self.name.clone())) + } + + fn module(self, vm: &VirtualMachine) -> PyObjectRef { + // TODO: Implement getting the actual module a builtin type is from + self.attributes + .borrow() + .get("__module__") + .cloned() + .unwrap_or_else(|| vm.ctx.new_str("builtins".to_owned())) + } + fn prepare(_name: PyStringRef, _bases: PyObjectRef, vm: &VirtualMachine) -> PyDictRef { vm.ctx.new_dict() } @@ -210,6 +227,8 @@ pub fn init(ctx: &PyContext) { .create(), "__name__" => ctx.new_property(PyClassRef::name), "__repr__" => ctx.new_rustfunc(PyClassRef::repr), + "__qualname__" => ctx.new_property(PyClassRef::qualname), + "__module__" => ctx.new_property(PyClassRef::module), "__prepare__" => ctx.new_rustfunc(PyClassRef::prepare), "__getattribute__" => ctx.new_rustfunc(PyClassRef::getattribute), "__setattr__" => ctx.new_rustfunc(PyClassRef::set_attr),