[Python-checkins] CVS: python/dist/src/Include descrobject.h,1.1.2.5,1.1.2.6

Guido van Rossum gvanrossum@users.sourceforge.net
Tue, 01 May 2001 14:04:23 -0700


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

Modified Files:
      Tag: descr-branch
	descrobject.h 
Log Message:
There's a subtlety in type_getattr() that makes me feel the pain of
not having metaclasses -- or actually, the mistake of using
FooClass.barMethod to reference the unbound barMethod method of
FooClass instances (where Smalltalk puts the methods in
FooClass.methodDict).  To fix this, I added query functions to
determine whether a descriptor describes a method or data, and I use
this to implement the following priority rules when accessing the bar
attribute of type FooType:

1) methods in FooType.__dict__, unadorned
2) anything in FooType.__class__.__dict__, used as a descriptor
3) anything else in FooType.__dict__, unadorned

This means that if both have a __repr__, FooType.__repr__ is the
unbound __repr__ method for Foo objects, but FooType.__class__ is the
class (or type) of FooType, which is (usually) TypeType.

If you're confused by this, don't worry.  This is on a branch. :-)



Index: descrobject.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Include/Attic/descrobject.h,v
retrieving revision 1.1.2.5
retrieving revision 1.1.2.6
diff -C2 -r1.1.2.5 -r1.1.2.6
*** descrobject.h	2001/04/30 01:14:56	1.1.2.5
--- descrobject.h	2001/05/01 21:04:21	1.1.2.6
***************
*** 32,35 ****
--- 32,37 ----
  extern DL_IMPORT(PyObject *) PyDescr_NewWrapper(PyTypeObject *,
  						struct wrapperbase *, void *);
+ extern DL_IMPORT(int) PyDescr_IsMethod(PyObject *);
+ extern DL_IMPORT(int) PyDescr_IsData(PyObject *);
  
  extern DL_IMPORT(PyObject *) PyDictProxy_New(PyObject *);