[Python-Dev] Path inherits from string (original) (raw)

M.-A. Lemburg mal at egenix.com
Thu Jan 26 21:48:16 CET 2006


Martin v. Löwis wrote:

M.-A. Lemburg wrote:

Please note that inheritance from string will cause the C type checks of the form PyStringCheck(obj) to return true. C code will then assume that it has an object which is compatible to string C API which instances aren't. Oh, sure they are. Types inheriting from str have the same layout as str, and C code assuming that layout will work fine with them. Inheritance works (saying "inheritance just works would deny the many fine details that have been engineered to actually make it work").

You're right, I forgot about how the .new() works on new-style classes and that extra space is allocated appended to the base type object for the extra instance features.

From PEP 253: """ class C(B): pass

...

In any case, the work for creating C is done by M's tp_new() slot.
It allocates space for an "extended" type structure, containing:
the type object; the auxiliary structures (as_sequence etc.); the
string object containing the type name (to ensure that this object
isn't deallocated while the type object is still referencing it);and
some auxiliary storage (to be described later).  It initializes this
storage to zeros except for a few crucial slots (for example,tp_name
is set to point to the type name) and then sets the tp_base slot to
point to B.

"""

Sorry for the FUD,

Marc-Andre Lemburg eGenix.com

Professional Python Services directly from the Source (#1, Jan 26 2006)

Python/Zope Consulting and Support ... http://www.egenix.com/ mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/


::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! ::::



More information about the Python-Dev mailing list