[Python-3000] pep 3124 plans

Phillip J. Eby pje at telecommunity.com
Mon Jul 23 17:32:50 CEST 2007


At 12:07 AM 7/23/2007 -0700, Talin wrote:
>Phillip J. Eby wrote:
> > If anything, generic functions give you *better* tools to work with,
> > as there is no trivial way to fire up a program and say, "show me all
> > the classes that have a foo() method."  (You could probably write
> > something to find them using object.__subclasses__, though, at least
> > for new-style types.)
>
>I'm glad we're having this conversation - this is the kind of thing I
>want to hear more of. The intention of my posts is not to argue against
>GFs, but to challenge the proponents of GFs to explain themselves better.
>
>However, GFs are relatively non-controversial compared to method
>combinations and some of the other "advanced" stuff.

Well, as I just pointed out (and Greg has in the past, whether 
meaning to or not), method combination is pretty much isomorphic to 
method overriding and calling super()...  except that it's easier to 
say what you really mean, instead of having to work around the fact 
that there's only one native precedence.

For example, one pattern that sometimes comes up in writing methods 
is that you have a base class that always wants to do something 
*after* the subclass version of the method is called.  To implement 
that without method combination, you have to split the method into 
two parts, one of which gets called by the other, and then tell 
everybody writing subclasses to only override the second method.

With method combination and a generic function, you simply declare an 
@after method for the base type, and it'll get called after the 
normal methods for any subclasses.



More information about the Python-3000 mailing list