[Python-Dev] PEP 253: Subtyping Built-in Types
Guido van Rossum
Sun, 22 Jul 2001 22:40:27 -0400
> What I did was to enhance the base class' tp_alloc and tp_dealloc
> APIs to only use the free list in case the type being passed to the
> APIs is a base type; in all other cases, standard processing takes
> Perhaps ints could do the same ?
Yes, that's what I was planning to do.
> > The simplified rule is that a type should only provide *either*
> > tp_getattr *or* tp_getattro, and likewise for set. The complete rule
> > is that if you insist on having both tp_getattr and tp_getattro, they
> > should implement the same semantics -- tp_getattr should be faster
> > when PyObject_GetAttrString() is called, and tp_getattro should be
> > faster when PyObject_GetAttr() is called.
> Ah, ok, didn't know that rule.
Well, I just made it up today. :-)
But it's a sensible rule, if you want predictable results.
> I'll move to the new scheme for 2.2 then and leave the old tp_getattr
> around for backward compatibility.
You should #ifdef on the Python version, unless you make your
tp_getattr do everything that tp_getattro does (possibly by calling on
--Guido van Rossum (home page: http://www.python.org/~guido/)