[PyObjC-svn] r1991 - in trunk/pyobjc/pyobjc-core: Lib/objc/test Modules/objc

[email protected]
Newsgroups gmane.comp.python.pyobjc.cvs
Message-ID <[email protected]>
Author: ronaldoussoren
Date: Thu Feb 14 11:47:21 2008
New Revision: 1991

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


Modified:
   trunk/pyobjc/pyobjc-core/Lib/objc/test/test_methodedits.py
   trunk/pyobjc/pyobjc-core/Modules/objc/selector.m

Modified: trunk/pyobjc/pyobjc-core/Lib/objc/test/test_methodedits.py
==============================================================================
--- trunk/pyobjc/pyobjc-core/Lib/objc/test/test_methodedits.py	(original)
+++ trunk/pyobjc/pyobjc-core/Lib/objc/test/test_methodedits.py	Thu Feb 14 11:47:21 2008
@@ -101,6 +101,28 @@
         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):
 

Modified: trunk/pyobjc/pyobjc-core/Modules/objc/selector.m
==============================================================================
--- trunk/pyobjc/pyobjc-core/Modules/objc/selector.m	(original)
+++ trunk/pyobjc/pyobjc-core/Modules/objc/selector.m	Thu Feb 14 11:47:21 2008
@@ -264,6 +264,9 @@
 	return PyBool_FromLong(0 != (self->sel_flags & PyObjCSelector_kREQUIRED));
 }
 
+
+
+
 static PyGetSetDef base_getset[] = {
 	{
 		"isRequired",
@@ -1561,6 +1564,17 @@
 	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",
@@ -1570,6 +1584,14 @@
 		0
 	},
 	{
+		"__doc__",
+		pysel_docstring,
+		0,
+		pysel_docstring_doc,
+		0
+	},
+
+	{
 		NULL,
 		NULL,
 		NULL,

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.