Plum: Multiple Dispatch in Python
Everybody likes multiple dispatch, just like everybody likes plums.
The design philosophy of Plum is to provide an implementation of multiple dispatch that is Pythonic, yet close to how Julia does it.
See here for a comparison between Plum, multipledispatch, and multimethod.
Note: Plum 2 is now powered by Beartype! If you notice any issues with the new release, please open an issue.
Installation
Plum requires Python 3.8 or higher.
pip install cola-plum-dispatch
Documentation
See here.
What's This?
Plum brings your type annotations to life:
from numbers import Number
from plum import dispatch
@dispatch
def f(x: str):
return "This is a string!"
@dispatch
def f(x: int):
return "This is an integer!"
@dispatch
def f(x: Number):
return "This is a general number, but I don't know which type."
>>> f("1")
'This is a string!'
>>> f(1)
'This is an integer!'
>>> f(1.0)
'This is a number, but I don't know which type.'
>>> f(object())
NotFoundLookupError: For function `f`, `(<object object at 0x7fb528458190>,)` could not be resolved.
This also works for multiple arguments, enabling some neat design patterns:
from numbers import Number, Real, Rational
from plum import dispatch
@dispatch
def multiply(x: Number, y: Number):
return "Performing fallback implementation of multiplication..."
@dispatch
def multiply(x: Real, y: Real):
return "Performing specialised implementation for reals..."
@dispatch
def multiply(x: Rational, y: Rational):
return "Performing specialised implementation for rationals..."
>>> multiply(1, 1)
'Performing specialised implementation for rationals...'
>>> multiply(1.0, 1.0)
'Performing specialised implementation for reals...'
>>> multiply(1j, 1j)
'Performing fallback implementation of multiplication...'
>>> multiply(1, 1.0) # For mixed types, it automatically chooses the right optimisation!
'Performing specialised implementation for reals...'
Metadata
Release files for cola-plum-dispatch 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cola_plum_dispatch-0.1.4.tar.gz | 25.9 kB | Without provenance | Details for cola_plum_dispatch-0.1.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cola_plum_dispatch-0.1.4-py3-none-any.whl | Python 3 | none | any | Details for cola_plum_dispatch-0.1.4-py3-none-any.whl |
Total release size: 57.7 kB
Release files / cola_plum_dispatch-0.1.4.tar.gz
| Download URL | cola_plum_dispatch-0.1.4.tar.gz |
|---|---|
| Size | 25.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bdcaaeb4db31d5cb3fe5c80db2833ed8cc547db87cfe6e3a85e824479fd6dda6
|
|
BLAKE2b-256 checksum How to use checksums |
643ee340c4acab1dd8a8faaa78bfaed28424790b80951108e60bbca22883c5af
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.12
|
Release files / cola_plum_dispatch-0.1.4-py3-none-any.whl
| Download URL | cola_plum_dispatch-0.1.4-py3-none-any.whl |
|---|---|
| Size | 31.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c74a1a53597198a2ed1999f7c64b5c9557675fffe70b1fce583efaf4e43f35cc
|
|
BLAKE2b-256 checksum How to use checksums |
597fcec4370087e081c2768bd2e6cf053f15eba13ccf6aad660e987d76239bde
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.12
|
Security for cola-plum-dispatch 0.1.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.