PEP 318

Andrew Bennetts andrew-pythonlist at puzzling.org
Wed Mar 24 08:51:19 EST 2004


On Wed, Mar 24, 2004 at 03:25:21PM +0200, Ville Vainio wrote:
> >>>>> "Andrew" == Andrew Bennetts <andrew-pythonlist at puzzling.org> writes:
> 
>     Andrew> Which is to say, I don't understand how that can work --
>     Andrew> the first definition of foo gets clobbered.
> 
> Yes, the name 'foo' gets clobbered every time, but the decorator
> always returns the *dispatcher* that is capable of dispatching the
> call to the correct definition of 'foo'. The dispatcher preserves the
> references to the callables, so they don't get decreffed out of
> existence.
> 
> The dispatcher obviously needs a reference to a module global dict
> object of some sort, with some magical name like
> '__mm_dispatcher_registry'.
> 
[...]
> 
>     Andrew> How is the registry not going to help distinguish between
>     Andrew> the foo methods from C, and the foo methods from C2?
> 
> It's not. I'm still thinking of multimethods mostly as plain functions
> with dynamic dispatching on arg types, not actual methods. To get the
> functionality in methods, you just need to call the mm function
> explicitly with an unique name inside the method.

Ah, I see.  I was thinking of methods, but you were thinking of functions.

But the same problem still applies: how would the multimethod decorator
distinguish between a "foo" function in moduleA, and a "foo" function in
moduleB?  By inspecting the function's __module__ attribute?  This degree of
introspection feels a bit too magical (i.e. implicit) to me...

-Andrew.





More information about the Python-list mailing list