File: README.rst

package info (click to toggle)
python-multipledispatch 1.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 272 kB
  • sloc: python: 1,116; makefile: 141
file content (131 lines) | stat: -rw-r--r-- 3,539 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
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

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