/// <summary> /// ModuleObject __getattribute__ implementation. Module attributes /// are always either classes or sub-modules representing subordinate /// namespaces. CLR modules implement a lazy pattern - the sub-modules /// and classes are created when accessed and cached for future use. /// </summary> public static IntPtr tp_getattro(IntPtr ob, IntPtr key) { var self = (ModuleObject)GetManagedObject(ob); if (!Runtime.PyString_Check(key)) { Exceptions.SetError(Exceptions.TypeError, "string expected"); return(IntPtr.Zero); } IntPtr op = Runtime.PyDict_GetItem(self.dict, key); if (op != IntPtr.Zero) { Runtime.XIncref(op); return(op); } string name = InternString.GetManagedString(key); if (name == "__dict__") { Runtime.XIncref(self.dict); return(self.dict); } ManagedType attr = null; try { attr = self.GetAttribute(name, true); } catch (Exception e) { Exceptions.SetError(e); return(IntPtr.Zero); } if (attr == null) { Exceptions.SetError(Exceptions.AttributeError, name); return(IntPtr.Zero); } Runtime.XIncref(attr.pyHandle); return(attr.pyHandle); }
/// <summary> /// MethodBinding __getattribute__ implementation. /// </summary> public static IntPtr tp_getattro(IntPtr ob, IntPtr key) { var self = (MethodBinding)GetManagedObject(ob); if (!Runtime.PyString_Check(key)) { Exceptions.SetError(Exceptions.TypeError, "string expected"); return(IntPtr.Zero); } string name = InternString.GetManagedString(key); switch (name) { case "__doc__": IntPtr doc = self.m.GetDocString(); Runtime.XIncref(doc); return(doc); // FIXME: deprecate __overloads__ soon... case "__overloads__": case "Overloads": var om = new OverloadMapper(self.m, self.target); return(om.pyHandle); case "__signature__" when Runtime.InspectModule is not null: var sig = self.Signature; if (sig is null) { return(Runtime.PyObject_GenericGetAttr(ob, key)); } return(sig.NewReferenceOrNull().DangerousMoveToPointerOrNull()); case "__name__": return(self.m.GetName().DangerousMoveToPointerOrNull()); default: return(Runtime.PyObject_GenericGetAttr(ob, key)); } }