fenbux-plum-dispatch


Namefenbux-plum-dispatch JSON
Version 0.0.2 PyPI version JSON
download
home_page
SummaryMultiple dispatch in Python
upload_time2024-01-15 07:51:30
maintainer
docs_urlNone
author
requires_python>=3.8
licenseMIT
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://julialang.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 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": "fenbux-plum-dispatch",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "multiple dispatch",
    "author": "",
    "author_email": "Jia Yaobo <januzaj2011@163.com>",
    "download_url": "https://files.pythonhosted.org/packages/68/94/fdb65c477c2b49e24eb927e1bed8a256ba7c0521f23f667ca8db57051a75/fenbux_plum_dispatch-0.0.2.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://julialang.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 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",
    "version": "0.0.2",
    "project_urls": {
        "repository": "https://github.com/JiaYaobo/fenbux-plum"
    },
    "split_keywords": [
        "multiple",
        "dispatch"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7781ec5729fc6ee5c3ecd076bb5ed214fb9529739beed4b3462afef67f2a01a1",
                "md5": "f25d47e1b35f0e1440ae59d61daa8a75",
                "sha256": "65558aa9004fecf4ebaf81046fda74fc6926a3c5f2061e7a93eed296e625d135"
            },
            "downloads": -1,
            "filename": "fenbux_plum_dispatch-0.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f25d47e1b35f0e1440ae59d61daa8a75",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 32361,
            "upload_time": "2024-01-15T07:51:28",
            "upload_time_iso_8601": "2024-01-15T07:51:28.514304Z",
            "url": "https://files.pythonhosted.org/packages/77/81/ec5729fc6ee5c3ecd076bb5ed214fb9529739beed4b3462afef67f2a01a1/fenbux_plum_dispatch-0.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6894fdb65c477c2b49e24eb927e1bed8a256ba7c0521f23f667ca8db57051a75",
                "md5": "aa9bf7d9d85e7ad3d903fb323228cdf0",
                "sha256": "8f353dac1f6457c1e934f2a6e5ba2ca5497189a39a80f32cf2c6e142f89556d1"
            },
            "downloads": -1,
            "filename": "fenbux_plum_dispatch-0.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "aa9bf7d9d85e7ad3d903fb323228cdf0",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 26021,
            "upload_time": "2024-01-15T07:51:30",
            "upload_time_iso_8601": "2024-01-15T07:51:30.368273Z",
            "url": "https://files.pythonhosted.org/packages/68/94/fdb65c477c2b49e24eb927e1bed8a256ba7c0521f23f667ca8db57051a75/fenbux_plum_dispatch-0.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-15 07:51:30",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "JiaYaobo",
    "github_project": "fenbux-plum",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "tox": true,
    "lcname": "fenbux-plum-dispatch"
}
        
Elapsed time: 0.17876s