Martin v. Löwis wrote:
> M.-A. Lemburg wrote:
>> Please note that inheritance from string will cause the C type
>> checks of the form PyString_Check(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 ! ::::
_______________________________________________
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com