[Python-checkins] CVS: python/dist/src/Python ceval.c,2.241.2.6,2.241.2.7

Guido van Rossum gvanrossum@users.sourceforge.net
Sun, 08 Jul 2001 04:51:57 -0700


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

Modified Files:
      Tag: descr-branch
	ceval.c 
Log Message:
Add a feature: if a global variable __metaclass__ exists, use that as
the default metaclass, rather than &PyClass_Type.  This makes it
possible to write modules where all classes are new-style classes
without having to add "__metaclass__ = type" (or a base class
'object') to each class.  This serves as a future statement for the
default metaclass.

Classes derived from classic classes defined in other modules are
exempt; the default metaclass is only used when there are no base
classes, otherwise the metaclass of the first base class is used.


Index: ceval.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/ceval.c,v
retrieving revision 2.241.2.6
retrieving revision 2.241.2.7
diff -C2 -r2.241.2.6 -r2.241.2.7
*** ceval.c	2001/07/08 04:30:29	2.241.2.6
--- ceval.c	2001/07/08 11:51:54	2.241.2.7
***************
*** 3605,3610 ****
  			metaclass = (PyObject *)
  				PyTuple_GET_ITEM(bases, 0)->ob_type;
! 		else
! 			metaclass = (PyObject *) &PyClass_Type;
  	}
  	return PyObject_CallFunction(metaclass, "OOO", name, bases, methods);
--- 3605,3616 ----
  			metaclass = (PyObject *)
  				PyTuple_GET_ITEM(bases, 0)->ob_type;
! 		else {
! 			PyObject *g = PyEval_GetGlobals();
! 			if (g != NULL && PyDict_Check(g))
! 				metaclass = PyDict_GetItemString(
! 					g, "__metaclass__");
! 			if (metaclass == NULL)
! 				metaclass = (PyObject *) &PyClass_Type;
! 		}
  	}
  	return PyObject_CallFunction(metaclass, "OOO", name, bases, methods);