Commits

Ronald Oussoren  committed b23b5b2

The docstrings for newly defined methods were
hidden. Add a getter that allows you to fetch
the docstring from the function object.

  • Participants
  • Parent commits b828328
  • Branches pyobjc-ancient

Comments (0)

Files changed (2)

File pyobjc-core/Lib/objc/test/test_methodedits.py

         self.assert_(MEClass.aNewClassMethod.isClassMethod)
         self.assertEquals(MEClass.aNewClassMethod(), 'Foo cls')
 
+    def testAddedMethodType(self):
+        def anotherNewClassMethod(cls):
+            "CLS DOC STRING"
+            return "BAR CLS"
+        anotherNewClassMethod = classmethod(anotherNewClassMethod)
+
+        def anotherNewMethod(self):
+            "INST DOC STRING"
+            return "BAR SELF"
+
+        self.assert_(not MEClass.pyobjc_classMethods.respondsToSelector_("anotherNewClassMethod"))
+        self.assert_(not MEClass.pyobjc_classMethods.instancesRespondToSelector_("anotherNewMethod"))
+
+        objc.classAddMethods(MEClass, [anotherNewClassMethod, anotherNewMethod])
+        self.assert_(MEClass.pyobjc_classMethods.respondsToSelector_("anotherNewClassMethod"))
+        self.assert_(MEClass.pyobjc_classMethods.instancesRespondToSelector_("anotherNewMethod"))
+
+        self.assertEquals(MEClass.anotherNewClassMethod.__doc__, "CLS DOC STRING")
+        self.assertEquals(MEClass.anotherNewMethod.__doc__, "INST DOC STRING")
+
+
+
 
 class TestFromPythonClassToObjCClass(objc.test.TestCase):
 

File pyobjc-core/Modules/objc/selector.m

 	return PyBool_FromLong(0 != (self->sel_flags & PyObjCSelector_kREQUIRED));
 }
 
+
+
+
 static PyGetSetDef base_getset[] = {
 	{
 		"isRequired",
 	return self->callable;
 }
 
+PyDoc_STRVAR(pysel_docstring_doc,
+	"The document string for a method");
+static PyObject*
+pysel_docstring(PyObject* _self, void* closure __attribute__((__unused__)))
+{
+	PyObjCPythonSelector* self = (PyObjCPythonSelector*)_self;
+
+	PyObject* docstr = PyObject_GetAttrString(self->callable, "__doc__");
+	return docstr;
+}
+
 static PyGetSetDef pysel_getset[] = {
 	{
 		"callable",
 		0
 	},
 	{
+		"__doc__",
+		pysel_docstring,
+		0,
+		pysel_docstring_doc,
+		0
+	},
+
+	{
 		NULL,
 		NULL,
 		NULL,