PEP 318

Andrew Bennetts andrew-pythonlist at
Thu Mar 25 01:21:19 CET 2004

On Wed, Mar 24, 2004 at 09:44:09AM -0600, Skip Montanaro wrote:
>     Andrew> How is the registry not going to help distinguish between the
>     Andrew> foo methods from C, and the foo methods from C2?
> By keying the dispatch table on (foo, Matrix) or (foo, Long).  Note that
> your classes (C and C2) make no sense given that the first parameter to the
> multimethod() calls are Matrix and Long, respectively.

The first parameter thing is just a result of the confusion between myself
and Ville about whether we were discussing methods or functions... I thought
it was odd too, but I was trying to adapt the examples given earlier in the
thread as faithfully as I could, but I didn't realise Ville was talking
about functions, not methods.  Imagine my examples with the first argument
to multimethod removed, i.e.:

    class C:
        def foo(self, other):
        foo = multimethod(Matrix)(foo)
        def foo(self, other):
        foo = multimethod(Vector)(foo)
    class C2:
        def foo(self, other):
        foo = multimethod(String)(foo)

I still don't get how a implementation of multimethod using a global
dispatch table can support all of these calls correctly:

    c, c2 = C(), C2()  # This is fine  # This is fine too  # This should fail! # This should also fail! # This is fine

Well, maybe you can do it by stack introspection in the multimethod call to
determine what class definition you're in, but that's vile.


More information about the Python-list mailing list