@@ -160,6 +160,18 @@ \section{The Basics
160160This is so that Python knows how much memory to allocate when you call
161161\cfunction {PyObject_New()}.
162162
163+ \note {If you want your type to be subclassable from Python, and your
164+ type has the same \member {tp_basicsize} as its base type, you may
165+ have problems with multiple inheritance. A Python subclass of your
166+ type will have to list your type first in its \member {__bases__}, or
167+ else it will not be able to call your type's \method {__new__} method
168+ without getting an error. You can avoid this problem by ensuring
169+ that your type has a larger value for \member {tp_basicsize} than
170+ its base type does. Most of the time, this will be true anyway,
171+ because either your base type will be \class {object}, or else you will
172+ be adding data members to your base type, and therefore increasing its
173+ size.}
174+
163175\begin {verbatim }
164176 0, /* tp_itemsize */
165177\end {verbatim }
@@ -384,6 +396,18 @@ \subsection{Adding data and methods to the Basic example}
384396base class, which is \class {object} by default. Most types use the
385397default allocation.
386398
399+ \note {If you are creating a co-operative \member {tp_new} (one that
400+ calls a base type's \member {tp_new} or \method {__new__}), you
401+ must \emph {not } try to determine what method to call using
402+ method resolution order at runtime. Always statically determine
403+ what type you are going to call, and call its \member {tp_new}
404+ directly, or via \code {type->tp_base->tp_new}. If you do
405+ not do this, Python subclasses of your type that also inherit
406+ from other Python-defined classes may not work correctly.
407+ (Specifically, you may not be able to create instances of
408+ such subclasses without getting a \exception {TypeError}.)}
409+
410+
387411We provide an initialization function:
388412
389413\begin {verbatim }
0 commit comments