[Python-checkins] python/dist/src/Doc/ext newtypes.tex,1.35,1.36
pje at users.sourceforge.net
pje at users.sourceforge.net
Sun Jun 6 11:59:21 EDT 2004
Update of /cvsroot/python/python/dist/src/Doc/ext
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27746
Modified Files:
newtypes.tex
Log Message:
Added documentation to address SF bug #963246: limitations on multiple
inheritance in Python when a C type is one of the bases.
Index: newtypes.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/ext/newtypes.tex,v
retrieving revision 1.35
retrieving revision 1.36
diff -C2 -d -r1.35 -r1.36
*** newtypes.tex 7 Dec 2003 11:40:17 -0000 1.35
--- newtypes.tex 6 Jun 2004 15:59:18 -0000 1.36
***************
*** 161,164 ****
--- 161,176 ----
\cfunction{PyObject_New()}.
+ \note{If you want your type to be subclassable from Python, and your
+ type has the same \member{tp_basicsize} as its base type, you may
+ have problems with multiple inheritance. A Python subclass of your
+ type will have to list your type first in its \member{__bases__}, or
+ else it will not be able to call your type's \method{__new__} method
+ without getting an error. You can avoid this problem by ensuring
+ that your type has a larger value for \member{tp_basicsize} than
+ its base type does. Most of the time, this will be true anyway,
+ because either your base type will be \class{object}, or else you will
+ be adding data members to your base type, and therefore increasing its
+ size.}
+
\begin{verbatim}
0, /* tp_itemsize */
***************
*** 385,388 ****
--- 397,412 ----
default allocation.
+ \note{If you are creating a co-operative \member{tp_new} (one that
+ calls a base type's \member{tp_new} or \method{__new__}), you
+ must \emph{not} try to determine what method to call using
+ method resolution order at runtime. Always statically determine
+ what type you are going to call, and call its \member{tp_new}
+ directly, or via \code{type->tp_base->tp_new}. If you do
+ not do this, Python subclasses of your type that also inherit
+ from other Python-defined classes may not work correctly.
+ (Specifically, you may not be able to create instances of
+ such subclasses without getting a \exception{TypeError}.)}
+
+
We provide an initialization function:
More information about the Python-checkins
mailing list