[Python-checkins] CVS: python/dist/src/Objects descrobject.c,1.1.2.13,1.1.2.14

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


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

Modified Files:
      Tag: descr-branch
	descrobject.c 
Log Message:
Total rewrite of the descriptor object implementation, to get rid of
the discriminated union.  The ultimate goal here was to make the
definition of PyDescr_IsData() more reasonable: it not just tests
whether the type has a __set__ method (i.e. a tp_descr_set slot).  If
it does, it's a data descriptor, otherwise it's not.  This is
important when an attribute is found in both the __dict__ of the class
and the __dict__ of the instance: when the descriptor in the class is
a data descriptor, it has precedence, but when it is a non-data
(e.g. method) desscriptor, the instance __dict__ takes precedence.

Previously, this function had to have special dispensation to look
inside descriptor objects -- this is no longer necessary.

Note that the presence of a __set__ method doesn't mean that the
attribute can actually be assigned to: this is also used to make
attributes deliberately read-only, by making the __set__ method always
raise an exception.  (Q: should it raise AttributeError or TypeError?
Traditionally, this has raised TypeError!)



Index: descrobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/Attic/descrobject.c,v
retrieving revision 1.1.2.13
retrieving revision 1.1.2.14
diff -C2 -r1.1.2.13 -r1.1.2.14
*** descrobject.c	2001/07/03 09:24:39	1.1.2.13
--- descrobject.c	2001/07/09 18:11:56	1.1.2.14
***************
*** 4,35 ****
  #include "structmember.h" /* Why is this not included in Python.h? */
  
! struct wrapperdescr {
! 	struct wrapperbase *base;
! 	void *wrapped; /* This can be any function pointer */
! };
  
! /* Descriptor object */
! struct PyDescrObject {
! 	PyObject_HEAD
[...1084 lines suppressed...]
  PyObject *
! PyWrapper_New(PyDescrObject *descr, PyObject *self)
  {
  	wrapperobject *wp;
  
! 	assert(descr->d_flavor == DF_WRAPPER);
  	assert(PyObject_IsInstance(self, (PyObject *)(descr->d_type)));
  
--- 820,830 ----
  
  PyObject *
! PyWrapper_New(PyObject *d, PyObject *self)
  {
  	wrapperobject *wp;
+ 	PyWrapperDescrObject *descr;
  
! 	assert(PyObject_TypeCheck(d, &PyWrapperDescr_Type));
! 	descr = (PyWrapperDescrObject *)d;
  	assert(PyObject_IsInstance(self, (PyObject *)(descr->d_type)));