Table of Contents

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

Callable dispatcher that dispatches based on argument types

Usage:

        from peak.util.dispatch import GenericFunction, Signature

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

        floob = GenericFunction()
        floob[Signature(Foo,Bar)] = lambda x,y: "foo, bar"
        floob[Signature(Foo,Foo)] = lambda x,y: "foo, foo"

        print floob(Foo(),Bar())    # closest match is Foo, Bar
        print floob(Baz(),Baz())    # closes match is Foo, Foo

GenericFunction calls the function whose Signature is closest to the classes of the supplied arguments. There is no way to call the "next closest" function. (Note that although keyword arguments are passed through to the function, they cannot be used for dispatching.)

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