Skip to main content

Multiple dispatch

Project description

Multiple Dispatch 2

|Build Status| |Coverage Status| |Version Status| |Downloads|

This is a fork from `mroklin's multipledispatch<>`_, which is designed to fully support python 3's type annotation.

And it only supports python 3.3+.


.. code-block:: python

>>> from multipledispatch2 import dispatch

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

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

>>> add(1, 2)

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

What this doesn't do

- Vararg dispatch

.. code-block:: python

import typing

def add(*args: typing.Iterable[int]):

- Diagonal dispatch

.. code-block:: python

a = arbitrary_type()
def are_same_type(x: a, y: a) -> bool:
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. It can be mitigated by halting and restarting ordering see
(``halt_ordering`` and ``restart_ordering`` functions for more information.)

Installation and Dependencies

``multipledispatch2`` is on the Python Package Index (PyPI):


pip install multipledispatch2



easy_install multipledispatch2

``multipledispatch2`` is only supports Python 3.3+. It is pure Python and requires no dependencies beyond the standard

It is, in short, a light weight dependency.


New BSD. See License_.


- `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*`_
- `PEP 0484 - *Type Hints*`_

.. _`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*`:
.. _`PEP 0484 - *Type Hints*`:

.. |Build Status| image::
.. |Version Status| image::
.. |Downloads| image::
.. |Coverage Status| image::
.. _License:

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for multipledispatch2, version 0.4.0
Filename, size File type Python version Upload date Hashes
Filename, size multipledispatch2-0.4.0.tar.gz (8.0 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page