type function does not subtype

Tim Peters tim_one at email.msn.com
Tue Mar 25 04:38:11 CET 2003

> Nothing implemented in C is subclassable unless somebody volunteers the
> work to make it subclassable; nobody volunteered the work to make
> the function type subclassable.  It sure wasn't at the top of my
> list <wink>.

[Lenard Lindstrom]
> Okay. I think I see. I notice that functions are not provided for the
> tp_new, tp_init,  tp_alloc, and tp_free slots of PyFunction_Type. Just
> adding  Py_TPFLAGS_BASETYPE to tp_flags will not enable
> subclassing for type function. More work than I first thought.

Yup, it always is.  See the other replies in this thread too (e.g., if it
were subclassable, how would you create an instance?  the natural "def"
notation doesn't have a way to specify a base class).

> Given PEP 253 I assumed most classes would already be converted,
> leaving just thoughs which would break something if subtyping were
> permitted on them.

Or things that were low on the perceived bang-for-the-buck scale.  I made
the file type subclassable very late in the release cycle, and that may well
have been the last builtin type to become subclassable for 2.2.  Being able
to subclass file was worth something to me.  For 2.3, someone else (IIRC)
made the array type (array.array) subclassable.  The universe of volunteers
for this stuff is small.

> Instead function was simply neglected due to time constaints. ;-)

That's so even without the smiley.  There's never enough time to do all that
we'd like to do.  BTW, that's why Python is more usable than Scheme <0.8

More information about the Python-list mailing list