Table of Contents

Class: MultiMethod ./src/peak/util/dispatch.py

Callable dispatcher with support for chaining to "next closest" matches

Usage:: from peak.util.dispatch import MultiMethod, Signature

class Foo: pass class Bar(Foo): pass class Baz(Foo): pass

spam = MultiMethod() spam[Signature(Foo,Bar)] = lambda next,x,y: "foobar, "+next()(next,x,y) spam[Signature(Foo,Foo)] = lambda next,x,y: "foofoo"

print spam(Foo(),Bar()) # prints "foobar, foofoo" print spam(Baz(),Baz()) # prints "foofoo"

MultiMethod calls the function whose Signature is closest to the classes of the supplied arguments, inserting an extra next argument at the front of the arguments. The next argument can be called to retrieve the "next closest" function matching the signature, in much the way that super can be used to find a superclass method. Note that this extra argument must be included in the definition of the functions used with the MultiMethod, but should not included as part of the Signature() rules or supplied in the call to the MultiMethod itself.

Base Classes   
Dispatch
    object
Methods   
__call__
  __call__ 
__call__ (
        self,
        *args,
        *kw,
        )


Table of Contents

This document was automatically generated on Tue Feb 17 19:55:52 2004 by HappyDoc version 2.1