[Python-checkins] CVS: python/dist/src/Objects funcobject.c,2.48,2.49

Guido van Rossum gvanrossum@users.sourceforge.net
Sun, 16 Dec 2001 18:53:56 -0800


Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv16084

Modified Files:
	funcobject.c 
Log Message:
SF patch #493452: docstrings for staticmethod/classmethod (Skip
Montanaro)

(With minor adjustments.)


Index: funcobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/funcobject.c,v
retrieving revision 2.48
retrieving revision 2.49
diff -C2 -d -r2.48 -r2.49
*** funcobject.c	2001/12/03 19:22:38	2.48
--- funcobject.c	2001/12/17 02:53:53	2.49
***************
*** 492,495 ****
--- 492,516 ----
  }
  
+ static char classmethod_doc[] =
+ "classmethod(function) -> method\n\
+ \n\
+ Convert a function to be a class method.\n\
+ \n\
+ A class method receives the class as implicit first argument,\n\
+ just like an instance method receives the instance.\n\
+ To declare a class method, use this idiom:\n\
+ \n\
+   class C:\n\
+       def f(cls, arg1, arg2, ...): ...\n\
+       f = classmethod(f)\n\
+ \n\
+ It can be called either on the class (e.g. C.f()) or on an instance\n\
+ (e.g. C().f()).  The instance is ignored except for its class.\n\
+ If a class method is called for a derived class, the derived class\n\
+ object is passed as the implied first argument.\n\
+ 
+ Class methods are different than C++ or Java static methods.\n\
+ If you want those, see the staticmethod builtin.";
+ 
  PyTypeObject PyClassMethod_Type = {
  	PyObject_HEAD_INIT(&PyType_Type)
***************
*** 514,518 ****
  	0,					/* tp_as_buffer */
  	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
! 	0,					/* tp_doc */
  	0,					/* tp_traverse */
  	0,					/* tp_clear */
--- 535,539 ----
  	0,					/* tp_as_buffer */
  	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
! 	classmethod_doc,			/* tp_doc */
  	0,					/* tp_traverse */
  	0,					/* tp_clear */
***************
*** 603,606 ****
--- 624,645 ----
  }
  
+ static char staticmethod_doc[] =
+ "staticmethod(function) -> method\n\
+ \n\
+ Convert a function to be a static method.\n\
+ \n\
+ A static method does not receive an implicit first argument.\n\
+ To declare a static method, use this idiom:\n\
+ \n\
+      class C:\n\
+          def f(arg1, arg2, ...): ...\n\
+ 	 f = staticmethod(f)\n\
+ \n\
+ It can be called either on the class (e.g. C.f()) or on an instance\n\
+ (e.g. C().f()).  The instance is ignored except for its class.\n\
+ \n\
+ Static methods in Python are similar to those found in Java or C++.\n\
+ For a more advanced concept, see the classmethod builtin.";
+ 
  PyTypeObject PyStaticMethod_Type = {
  	PyObject_HEAD_INIT(&PyType_Type)
***************
*** 625,629 ****
  	0,					/* tp_as_buffer */
  	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
! 	0,					/* tp_doc */
  	0,					/* tp_traverse */
  	0,					/* tp_clear */
--- 664,668 ----
  	0,					/* tp_as_buffer */
  	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
! 	staticmethod_doc,			/* tp_doc */
  	0,					/* tp_traverse */
  	0,					/* tp_clear */