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

Guido van Rossum gvanrossum@users.sourceforge.net
Tue, 03 Jul 2001 02:24:41 -0700


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

Modified Files:
      Tag: descr-branch
	descrobject.c 
Log Message:
PyDescr_IsData(): change in specification.  If the argument is not a
PyDescrObject, this returns true if the argument's type supports the
tp_descr_set slot.  This allows us to created computed attributes from
a pair of get/set functions (see test_descr.py example).

This almost works for classic classes too: there, it can be used for
read-only computed attributes, but it can't be used to trap setattr
unless we change instance setattr to look in the class dict first.
Since that's expensive (a chain of dict lookups) we don't do this.

Why is it not expensive for new-style classes?  Because the class
lookup is faster: compare _PyType_Lookup() to class_lookup().


Index: descrobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/Attic/descrobject.c,v
retrieving revision 1.1.2.12
retrieving revision 1.1.2.13
diff -C2 -r1.1.2.12 -r1.1.2.13
*** descrobject.c	2001/07/02 17:08:33	1.1.2.12
--- descrobject.c	2001/07/03 09:24:39	1.1.2.13
***************
*** 427,433 ****
  		case DF_GETSET:
  			return 1;
  		}
  	}
! 	return 0;
  }
  
--- 427,435 ----
  		case DF_GETSET:
  			return 1;
+ 		default:
+ 			return 0;
  		}
  	}
! 	return d->ob_type->tp_descr_set != NULL;
  }