type function does not subtype

Greg Ewing (using news.cis.dfn.de) me at privacy.net
Tue Mar 25 18:07:10 EST 2003


Lenard Lindstrom wrote:
> As for uses, should not staticmethod and classmethod be subtypes
> of function? If one wants a function wrapper that looks like a function,
> e.g. has func_doc, func_code, and func_defaults members,

Staticmethods and classmethods don't have all those attributes,
so they shouldn't be subclasses of function.

> should not that wrapper class be derived from function? 

Yes, but it will only have those attributes if it's a
subtype of "function consisting of interpreted Python
bytecode", not "callable object in general". The use
cases of *that* are somewhat more restricted.

That's not to say they don't exist, and I agree that
there's no reason for function objects *not* to be
subclassable. It's just that nobody's had a pressing
enough need to subclass one yet to make it so.

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg





More information about the Python-list mailing list