[Python-checkins] CVS: python/dist/src/Python bltinmodule.c,2.198.2.4,2.198.2.5

Guido van Rossum gvanrossum@users.sourceforge.net
Mon, 02 Jul 2001 11:06:09 -0700


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

Modified Files:
      Tag: descr-branch
	bltinmodule.c 
Log Message:
Add a new type: 'classmethod'.  This needs to be fleshed out a bit
more with docstrings and maybe attribute, but it works:

  >>> class C(object):
  ...     def f(*a): return a
  ...     f = classmethod(f)
  ... 
  >>> C.f(1, 2)
  (<type 'C'>, 1, 2)
  >>> C().f(1, 2)
  (<type 'C'>, 1, 2)
  >>> class D(C):
  ...     pass
  ... 
  >>> D.f(1, 2)
  (<type 'D'>, 1, 2)
  >>> D().f(1, 2)
  (<type 'D'>, 1, 2)
  >>> 

It doesn't work in classic classes yet (the method binding there needs
to be updated).



Index: bltinmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/bltinmodule.c,v
retrieving revision 2.198.2.4
retrieving revision 2.198.2.5
diff -C2 -r2.198.2.4 -r2.198.2.5
*** bltinmodule.c	2001/06/14 18:12:02	2.198.2.4
--- bltinmodule.c	2001/07/02 18:06:06	2.198.2.5
***************
*** 1793,1796 ****
--- 1793,1799 ----
  				 Py_NotImplemented) < 0)
  		return NULL;
+ 	if (PyDict_SetItemString(dict, "classmethod",
+ 				 (PyObject *) &PyClassMethod_Type) < 0)
+ 		return NULL;
  #ifndef WITHOUT_COMPLEX
  	if (PyDict_SetItemString(dict, "complex",