Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

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:

Release History

This version
History Node


History Node


History Node


History Node


Download Files

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

Filename, Size & Hash SHA256 Hash Help File Type Python Version Upload Date
(8.0 kB) Copy SHA256 Hash SHA256
Source None May 7, 2016

Supported By

Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Google Google Cloud Servers DreamHost DreamHost Log Hosting