mul

multipledispatch

Multiple dispatch

Showing:

Popularity

Downloads/wk

0

GitHub Stars

581

Maintenance

Last Commit

2mos ago

Contributors

21

Package

Dependencies

1

License

BSD

Categories

Readme

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

  • Dispatches on all non-keyword arguments

  • Supports inheritance

  • Supports instance methods

  • Supports union types, e.g. (int, float)

  • Supports builtin abstract classes, e.g. Iterator, Number, ...

  • Caches for fast repeated lookup

  • Identifies possible ambiguities at function definition time

  • Provides hints to resolve ambiguities when they occur

  • Supports namespaces with optional keyword arguments

  • Supports variadic dispatch

What this doesn't do

  • Diagonal dispatch

.. code-block:: python

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

  • Efficient update: The addition of a new signature requires a full resolve of the whole function. This becomes troublesome after you get to a few hundred type signatures.

Installation and Dependencies

multipledispatch is on the Python Package Index (PyPI):

::

pip install multipledispatch

or

::

easy_install multipledispatch

multipledispatch supports Python 2.6+ and Python 3.2+ with a common codebase. It is pure Python and requires only the small six <https://pypi.org/project/six/>_ library as a dependency.

It is, in short, a light weight dependency.

License

New BSD. See License file_.

  • Five-minute Multimethods in Python by Guido_
  • multimethods package on PyPI_
  • singledispatch in Python 3.4's functools_
  • Clojure Protocols_
  • Julia methods docs_
  • Karpinksi notebook: *The Design Impact of Multiple Dispatch*_
  • Wikipedia article_
  • PEP 3124 - *Overloading, Generic Functions, Interfaces, and Adaptation*_

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

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100