[Python-3000] PEP 3124 - Overloading, Generic Functions, Interfaces, etc.

Ron Adam rrr at ronadam.com
Thu May 10 08:22:54 CEST 2007

Greg Ewing wrote:
> Phillip J. Eby wrote:
>> For 
>> example, objects to be documented with pydoc currently have to 
>> reverse engineer a bunch of inspection code, while in a GF-based 
>> design they'd just add methods.
> There's a problem with this that I haven't seen a good
> answer to yet. To add a method to a generic function,
> you have to import the module that defines the base
> function. So any module that wants its objects documented
> in a custom way ends up depending on pydoc.

If you have everything at the same level then that may be true, but I don't 
think that is what Phillip is suggesting.

There might be a group of generic functions for introspection that all 
return some consistent data format back.  This might be in the inspect module.

Then you might have another set of generic functions for combining 
different sources of information together into another data structure. 
This would be used to pre-format and order the information.  These might be 
in docutils.

Then you might have a third level of generic functions for outputting that 
data in different formats.  Ie.. text, html, xml... reST.  This might be 
part of a generic formatting package.

Then pydoc becomes a very light weight module that ties these together to 
do what it does, but it can still extend each framework where it needs to.

A lot of the apparent fear involved with ABC's and generic functions seems 
to be disregarding the notion that generally you know something about the 
data (and code) that is being used at particular points in a process.  It 
is that implicit quality that allows us to not need to LBYL or put 
try-excepts around everything we do.  I think ABC's and generic functions 
may allow us to extend that quality to more of our code.

*My feelings about ABC's and inheritance is they are very useful for easily 
creating new objects.

*I think generic functions are very useful for doing operations on those 
objects when it doesn't make since for those objects to do yet another type 
of operation on it self.  Or to put another way, not everything done to an 
object should be done by a method in that object.


More information about the Python-3000 mailing list