Name | cola-plum-dispatch JSON |
Version |
0.1.4
JSON |
| download |
home_page | |
Summary | Multiple dispatch in Python (with additional features for the CoLA library) |
upload_time | 2023-10-12 22:05:08 |
maintainer | |
docs_url | None |
author | |
requires_python | >=3.8 |
license | MIT |
keywords |
multiple
dispatch
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
|
# [Plum: Multiple Dispatch in Python](https://github.com/beartype/plum)
[![DOI](https://zenodo.org/badge/110279931.svg)](https://zenodo.org/badge/latestdoi/110279931)
[![CI](https://github.com/beartype/plum/workflows/CI/badge.svg?branch=master)](https://github.com/beartype/plum/actions?query=workflow%3ACI)
[![Coverage Status](https://coveralls.io/repos/github/beartype/plum/badge.svg?branch=master&service=github)](https://coveralls.io/github/beartype/plum?branch=master)
[![Latest Docs](https://img.shields.io/badge/docs-latest-blue.svg)](https://beartype.github.io/plum)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
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](http://julia-lang.org/) does it.
[See here for a comparison between Plum, `multipledispatch`, and `multimethod`.](https://beartype.github.io/plum/comparison.html)
*Note:*
Plum 2 is now powered by [Beartype](https://github.com/beartype/beartype)!
If you notice any issues with the new release, please open an issue.
# Installation
Plum requires Python 3.8 or higher.
```bash
pip install cola-plum-dispatch
```
# [Documentation](https://beartype.github.io/plum)
See [here](https://beartype.github.io/plum).
# What's This?
Plum brings your type annotations to life:
```python
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."
```
```python
>>> 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:
```python
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..."
```
```python
>>> 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...'
```
Raw data
{
"_id": null,
"home_page": "",
"name": "cola-plum-dispatch",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "",
"keywords": "multiple dispatch",
"author": "",
"author_email": "Wessel Bruinsma <wessel.p.bruinsma@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/64/3e/e340c4acab1dd8a8faaa78bfaed28424790b80951108e60bbca22883c5af/cola_plum_dispatch-0.1.4.tar.gz",
"platform": null,
"description": "# [Plum: Multiple Dispatch in Python](https://github.com/beartype/plum)\n\n[![DOI](https://zenodo.org/badge/110279931.svg)](https://zenodo.org/badge/latestdoi/110279931)\n[![CI](https://github.com/beartype/plum/workflows/CI/badge.svg?branch=master)](https://github.com/beartype/plum/actions?query=workflow%3ACI)\n[![Coverage Status](https://coveralls.io/repos/github/beartype/plum/badge.svg?branch=master&service=github)](https://coveralls.io/github/beartype/plum?branch=master)\n[![Latest Docs](https://img.shields.io/badge/docs-latest-blue.svg)](https://beartype.github.io/plum)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n\nEverybody likes multiple dispatch, just like everybody likes plums.\n\nThe design philosophy of Plum is to provide an implementation of multiple dispatch that is Pythonic, yet close to how [Julia](http://julia-lang.org/) does it.\n[See here for a comparison between Plum, `multipledispatch`, and `multimethod`.](https://beartype.github.io/plum/comparison.html)\n\n*Note:*\nPlum 2 is now powered by [Beartype](https://github.com/beartype/beartype)!\nIf you notice any issues with the new release, please open an issue.\n\n# Installation\n\nPlum requires Python 3.8 or higher.\n\n```bash\npip install cola-plum-dispatch\n```\n\n# [Documentation](https://beartype.github.io/plum)\n\nSee [here](https://beartype.github.io/plum).\n\n# What's This?\n\nPlum brings your type annotations to life:\n\n```python\nfrom numbers import Number\n\nfrom plum import dispatch\n\n\n@dispatch\ndef f(x: str):\n return \"This is a string!\"\n\n\n@dispatch\ndef f(x: int):\n return \"This is an integer!\"\n\n\n@dispatch\ndef f(x: Number):\n return \"This is a general number, but I don't know which type.\"\n```\n\n```python\n>>> f(\"1\")\n'This is a string!'\n\n>>> f(1)\n'This is an integer!'\n\n>>> f(1.0)\n'This is a number, but I don't know which type.'\n\n>>> f(object())\nNotFoundLookupError: For function `f`, `(<object object at 0x7fb528458190>,)` could not be resolved.\n```\n\nThis also works for multiple arguments, enabling some neat design patterns:\n\n```python\nfrom numbers import Number, Real, Rational\n\nfrom plum import dispatch\n\n\n@dispatch\ndef multiply(x: Number, y: Number):\n return \"Performing fallback implementation of multiplication...\"\n\n\n@dispatch\ndef multiply(x: Real, y: Real):\n return \"Performing specialised implementation for reals...\"\n\n\n@dispatch\ndef multiply(x: Rational, y: Rational):\n return \"Performing specialised implementation for rationals...\"\n```\n\n```python\n>>> multiply(1, 1)\n'Performing specialised implementation for rationals...'\n\n>>> multiply(1.0, 1.0)\n'Performing specialised implementation for reals...'\n\n>>> multiply(1j, 1j)\n'Performing fallback implementation of multiplication...'\n\n>>> multiply(1, 1.0) # For mixed types, it automatically chooses the right optimisation!\n'Performing specialised implementation for reals...'\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Multiple dispatch in Python (with additional features for the CoLA library)",
"version": "0.1.4",
"project_urls": {
"repository": "https://github.com/mfinzi/plum"
},
"split_keywords": [
"multiple",
"dispatch"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "597fcec4370087e081c2768bd2e6cf053f15eba13ccf6aad660e987d76239bde",
"md5": "9aa1ac7ddc636d30e3230226efacd40a",
"sha256": "c74a1a53597198a2ed1999f7c64b5c9557675fffe70b1fce583efaf4e43f35cc"
},
"downloads": -1,
"filename": "cola_plum_dispatch-0.1.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "9aa1ac7ddc636d30e3230226efacd40a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 31782,
"upload_time": "2023-10-12T22:05:05",
"upload_time_iso_8601": "2023-10-12T22:05:05.515855Z",
"url": "https://files.pythonhosted.org/packages/59/7f/cec4370087e081c2768bd2e6cf053f15eba13ccf6aad660e987d76239bde/cola_plum_dispatch-0.1.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "643ee340c4acab1dd8a8faaa78bfaed28424790b80951108e60bbca22883c5af",
"md5": "7cf76786cb22c6d8abc72dd8b96dea03",
"sha256": "bdcaaeb4db31d5cb3fe5c80db2833ed8cc547db87cfe6e3a85e824479fd6dda6"
},
"downloads": -1,
"filename": "cola_plum_dispatch-0.1.4.tar.gz",
"has_sig": false,
"md5_digest": "7cf76786cb22c6d8abc72dd8b96dea03",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 25920,
"upload_time": "2023-10-12T22:05:08",
"upload_time_iso_8601": "2023-10-12T22:05:08.687460Z",
"url": "https://files.pythonhosted.org/packages/64/3e/e340c4acab1dd8a8faaa78bfaed28424790b80951108e60bbca22883c5af/cola_plum_dispatch-0.1.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-10-12 22:05:08",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "mfinzi",
"github_project": "plum",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"tox": true,
"lcname": "cola-plum-dispatch"
}