mrocklin / multipledispatch

Multiple dispatch
https://multiple-dispatch.readthedocs.io/en/latest/
Other
811 stars 72 forks source link

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

.. code-block:: python

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

.. code-block:: python

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_.

Links

.. Five-minute Multimethods in Python by Guido: http://www.artima.com/weblogs/viewpost.jsp?thread=101605 .. multimethods package on PyPI: https://pypi.python.org/pypi/multimethods .. singledispatch in Python 3.4's functools: http://docs.python.org/3.4/library/functools.html#functools.singledispatch .. Clojure Protocols: http://clojure.org/protocols .. Julia methods docs: https://docs.julialang.org/en/v1/manual/methods/ .. Karpinksi notebook: *The Design Impact of Multiple Dispatch*: http://nbviewer.ipython.org/gist/StefanKarpinski/b8fe9dbb36c1427b9f22 .. _Wikipedia article: http://en.wikipedia.org/wiki/Multiple_dispatch .. _PEP 3124 - *Overloading, Generic Functions, Interfaces, and Adaptation*: http://legacy.python.org/dev/peps/pep-3124/

.. |Build Status| image:: https://travis-ci.org/mrocklin/multipledispatch.svg :target: https://travis-ci.org/mrocklin/multipledispatch .. |Version Status| image:: https://pypip.in/v/multipledispatch/badge.svg :target: https://img.shields.io/pypi/v/multipledispatch.svg .. |Coverage Status| image:: https://coveralls.io/repos/mrocklin/multipledispatch/badge.svg :target: https://coveralls.io/r/mrocklin/multipledispatch .. _License file: https://github.com/mrocklin/multipledispatch/blob/master/LICENSE.txt