[Python-3000] PyUnicodeObject implementation

"Martin v. Löwis" martin at v.loewis.de
Mon Sep 8 07:00:48 CEST 2008


>> Can you explain this a bit more? I presume you're talking about
>> subclassing in C
> 
> Yes, I mentioned Cython above.

Can you please still elaborate? I have never used Cython before, but
if it cannot efficiently subclass str, isn't that a bug in Cython?

>> I do note that the mechanisms that exist for supporting adding a __dict__
>> to a str (in 2.x; or bytes in 3.x) or a tuple could be extended for other
>> purposes.
> 
> I never looked into these, but this does not sound like it would impact
> subclassing.

To me, the relationship is fairly straight: if you want to subclass a
type, *all* you need is a way to place an __dict__ in the object, if
it doesn't already have one. If the base object already has an __dict__,
the layout of the subtype can be the same as the layout of the base
type.

Now, what Guido (probably) refers to is the implementation strategy
used for adding __dict__ could be generalized for adding additional
slots as well: for a variable-sized object (str or tuple), the
dictoffset is negative, indicating that you have to count from the
end of the object, not from the start, to find the slot. So if you
are worried about __dict__-stored attributes being too slow (*), this
approach could be a solution.

(*) This assumes that the lack of additional slots actually *is* your
concern.

Regards,
Martin


More information about the Python-3000 mailing list