GitHub - mrocklin/multipledispatch: Multiple dispatch (original) (raw)

Multiple Dispatch

Build Status Coverage Status Version Status

A relatively sane approach to multiple dispatch in Python.

This implementation of multiple dispatch is efficient, mostly complete, performs static analysis to avoid conflicts, and provides optional namespace support. It looks good too.

See the documentation at https://multiple-dispatch.readthedocs.io/

Example

from multipledispatch import dispatch

@dispatch(int, int) ... def add(x, y): ... return x + y

@dispatch(object, object) ... def add(x, y): ... return "%s + %s" % (x, y)

add(1, 2) 3

add(1, 'hello') '1 + hello'

What this does

What this doesn't do

a = arbitrary_type() @dispatch(a, a) def are_same_type(x, y): return True

Installation and Dependencies

multipledispatch is on the Python Package Index (PyPI):

pip install multipledispatch

It is Pure-Python and depends only on the standard library. It is a light weight dependency.

License

New BSD. See License file.